Browse Source

Update some eth types, update eth dependencies to new changes

feature/sql-semaphore1
Eduard S 3 years ago
parent
commit
329d2796c6
11 changed files with 241 additions and 202 deletions
  1. +2
    -0
      common/ethauction.go
  2. +2
    -2
      common/ethwdelayer.go
  3. +2
    -0
      common/l1tx_test.go
  4. +1
    -1
      db/historydb/historydb_test.go
  5. +3
    -3
      db/migrations/0001.sql
  6. +1
    -1
      eth/README.md
  7. +57
    -20
      eth/rollup.go
  8. +136
    -143
      eth/rollup_test.go
  9. +6
    -9
      synchronizer/synchronizer.go
  10. +29
    -22
      test/ethclient.go
  11. +2
    -1
      test/ethclient_test.go

+ 2
- 0
common/ethauction.go

@ -58,6 +58,8 @@ type AuctionVariables struct {
DonationAddress ethCommon.Address `json:"donationAddress" meddler:"donation_address" validate:"required"` DonationAddress ethCommon.Address `json:"donationAddress" meddler:"donation_address" validate:"required"`
// Boot Coordinator Address // Boot Coordinator Address
BootCoordinator ethCommon.Address `json:"bootCoordinator" meddler:"boot_coordinator" validate:"required"` BootCoordinator ethCommon.Address `json:"bootCoordinator" meddler:"boot_coordinator" validate:"required"`
// Boot Coordinator URL
BootCoordinatorURL string `json:"bootCoordinatorUrl" meddler:"boot_coordinator_url" validate:"required"`
// The minimum bid value in a series of 6 slots // The minimum bid value in a series of 6 slots
DefaultSlotSetBid [6]*big.Int `json:"defaultSlotSetBid" meddler:"default_slot_set_bid,json" validate:"required"` DefaultSlotSetBid [6]*big.Int `json:"defaultSlotSetBid" meddler:"default_slot_set_bid,json" validate:"required"`
// SlotNum at which the new default_slot_set_bid applies // SlotNum at which the new default_slot_set_bid applies

+ 2
- 2
common/ethwdelayer.go

@ -16,8 +16,8 @@ type WDelayerConstants struct {
type WDelayerVariables struct { type WDelayerVariables struct {
EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"` EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"`
// HermezRollupAddress ethCommon.Address `json:"hermezRollupAddress" meddler:"rollup_address"` // HermezRollupAddress ethCommon.Address `json:"hermezRollupAddress" meddler:"rollup_address"`
HermezGovernanceAddress ethCommon.Address `json:"hermezGovernanceAddress" meddler:"govdao_address" validate:"required"`
EmergencyCouncilAddress ethCommon.Address `json:"whiteHackGroupAddress" meddler:"whg_address" validate:"required"`
HermezGovernanceAddress ethCommon.Address `json:"hermezGovernanceAddress" meddler:"gov_address" validate:"required"`
EmergencyCouncilAddress ethCommon.Address `json:"emergencyCouncilAddress" meddler:"emg_address" validate:"required"`
WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay" validate:"required"` WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay" validate:"required"`
EmergencyModeStartingTime uint64 `json:"emergencyModeStartingTime" meddler:"emergency_start_time"` EmergencyModeStartingTime uint64 `json:"emergencyModeStartingTime" meddler:"emergency_start_time"`
EmergencyMode bool `json:"emergencyMode" meddler:"emergency_mode"` EmergencyMode bool `json:"emergencyMode" meddler:"emergency_mode"`

+ 2
- 0
common/l1tx_test.go

@ -96,6 +96,7 @@ func TestL1TxFromDataAvailability(t *testing.T) {
txCompressedData, err := tx.BytesDataAvailability(32) txCompressedData, err := tx.BytesDataAvailability(32)
assert.Nil(t, err) assert.Nil(t, err)
l1tx, err := L1TxFromDataAvailability(txCompressedData, 32) l1tx, err := L1TxFromDataAvailability(txCompressedData, 32)
require.NoError(t, err)
assert.Equal(t, tx.FromIdx, l1tx.FromIdx) assert.Equal(t, tx.FromIdx, l1tx.FromIdx)
assert.Equal(t, tx.ToIdx, l1tx.ToIdx) assert.Equal(t, tx.ToIdx, l1tx.ToIdx)
@ -107,6 +108,7 @@ func TestL1TxFromDataAvailability(t *testing.T) {
txCompressedData, err = tx.BytesDataAvailability(32) txCompressedData, err = tx.BytesDataAvailability(32)
assert.Nil(t, err) assert.Nil(t, err)
l1tx, err = L1TxFromDataAvailability(txCompressedData, 32) l1tx, err = L1TxFromDataAvailability(txCompressedData, 32)
require.NoError(t, err)
assert.Equal(t, tx.FromIdx, l1tx.FromIdx) assert.Equal(t, tx.FromIdx, l1tx.FromIdx)
assert.Equal(t, tx.ToIdx, l1tx.ToIdx) assert.Equal(t, tx.ToIdx, l1tx.ToIdx)
assert.Equal(t, tx.EffectiveAmount, l1tx.EffectiveAmount) assert.Equal(t, tx.EffectiveAmount, l1tx.EffectiveAmount)

+ 1
- 1
db/historydb/historydb_test.go

@ -654,6 +654,7 @@ func exampleInitSCVars() (*common.RollupVariables, *common.AuctionVariables, *co
0, 0,
ethCommon.BigToAddress(big.NewInt(2)), ethCommon.BigToAddress(big.NewInt(2)),
ethCommon.BigToAddress(big.NewInt(3)), ethCommon.BigToAddress(big.NewInt(3)),
"https://boot.coord.com",
[6]*big.Int{ [6]*big.Int{
big.NewInt(1), big.NewInt(2), big.NewInt(3), big.NewInt(1), big.NewInt(2), big.NewInt(3),
big.NewInt(4), big.NewInt(5), big.NewInt(6), big.NewInt(4), big.NewInt(5), big.NewInt(6),
@ -670,7 +671,6 @@ func exampleInitSCVars() (*common.RollupVariables, *common.AuctionVariables, *co
0, 0,
ethCommon.BigToAddress(big.NewInt(2)), ethCommon.BigToAddress(big.NewInt(2)),
ethCommon.BigToAddress(big.NewInt(3)), ethCommon.BigToAddress(big.NewInt(3)),
ethCommon.BigToAddress(big.NewInt(4)),
13, 13,
14, 14,
false, false,

+ 3
- 3
db/migrations/0001.sql

@ -537,6 +537,7 @@ CREATE TABLE auction_vars (
eth_block_num BIGINT PRIMARY KEY REFERENCES block (eth_block_num) ON DELETE CASCADE, eth_block_num BIGINT PRIMARY KEY REFERENCES block (eth_block_num) ON DELETE CASCADE,
donation_address BYTEA NOT NULL, donation_address BYTEA NOT NULL,
boot_coordinator BYTEA NOT NULL, boot_coordinator BYTEA NOT NULL,
boot_coordinator_url BYTEA NOT NULL,
default_slot_set_bid BYTEA NOT NULL, default_slot_set_bid BYTEA NOT NULL,
default_slot_set_bid_slot_num BIGINT NOT NULL, -- slot_num after which the new default_slot_set_bid applies default_slot_set_bid_slot_num BIGINT NOT NULL, -- slot_num after which the new default_slot_set_bid applies
closed_auction_slots INT NOT NULL, closed_auction_slots INT NOT NULL,
@ -548,9 +549,8 @@ CREATE TABLE auction_vars (
CREATE TABLE wdelayer_vars ( CREATE TABLE wdelayer_vars (
eth_block_num BIGINT PRIMARY KEY REFERENCES block (eth_block_num) ON DELETE CASCADE, eth_block_num BIGINT PRIMARY KEY REFERENCES block (eth_block_num) ON DELETE CASCADE,
govdao_address BYTEA NOT NULL,
whg_address BYTEA NOT NULL,
keeper_address BYTEA NOT NULL,
gov_address BYTEA NOT NULL,
emg_address BYTEA NOT NULL,
withdrawal_delay BIGINT NOT NULL, withdrawal_delay BIGINT NOT NULL,
emergency_start_time BIGINT NOT NULL, emergency_start_time BIGINT NOT NULL,
emergency_mode BOOLEAN NOT NULL emergency_mode BOOLEAN NOT NULL

+ 1
- 1
eth/README.md

@ -8,7 +8,7 @@ The first step is to clone the github repository where the contracts are located
While the prepared deployment is not found to master, branch in repository must be changed: While the prepared deployment is not found to master, branch in repository must be changed:
`git checkout feature/newDeploymentScript-eth` (tested with commit `f3b627d2145a029fd967f05c1fd32f23d614ec8e`)
`git checkout feature/newDeploymentScript-eth` (tested with commit `6335252b073dc59afafc45040dae8630c72ecdf3`)
Now, install the dependencies: Now, install the dependencies:

+ 57
- 20
eth/rollup.go

@ -59,7 +59,7 @@ type RollupEventL1UserTx struct {
} }
// RollupEventL1UserTxAux is an event of the Rollup Smart Contract // RollupEventL1UserTxAux is an event of the Rollup Smart Contract
type RollupEventL1UserTxAux struct {
type rollupEventL1UserTxAux struct {
ToForgeL1TxsNum uint64 // QueueIndex *big.Int ToForgeL1TxsNum uint64 // QueueIndex *big.Int
Position uint8 // TransactionIndex *big.Int Position uint8 // TransactionIndex *big.Int
L1UserTx []byte L1UserTx []byte
@ -97,21 +97,40 @@ type RollupEventWithdraw struct {
TxHash ethCommon.Hash // Hash of the transaction that generated this event TxHash ethCommon.Hash // Hash of the transaction that generated this event
} }
// RollupEventUpdateBucketWithdraw is an event of the Rollup Smart Contract
type RollupEventUpdateBucketWithdraw struct {
type rollupEventUpdateBucketWithdrawAux struct {
NumBucket uint8 NumBucket uint8
BlockStamp *big.Int BlockStamp *big.Int
Withdrawals *big.Int Withdrawals *big.Int
} }
// RollupEventUpdateBucketWithdraw is an event of the Rollup Smart Contract
type RollupEventUpdateBucketWithdraw struct {
NumBucket int
BlockStamp int64 // blockNum
Withdrawals *big.Int
}
// RollupEventUpdateWithdrawalDelay is an event of the Rollup Smart Contract // RollupEventUpdateWithdrawalDelay is an event of the Rollup Smart Contract
type RollupEventUpdateWithdrawalDelay struct { type RollupEventUpdateWithdrawalDelay struct {
NewWithdrawalDelay uint64 NewWithdrawalDelay uint64
} }
// RollupUpdateBucketsParameters are the bucket parameters used in an update
type RollupUpdateBucketsParameters struct {
CeilUSD *big.Int
Withdrawals *big.Int
BlockWithdrawalRate *big.Int
MaxWithdrawals *big.Int
}
type rollupEventUpdateBucketsParametersAux struct {
ArrayBuckets [common.RollupConstNumBuckets][4]*big.Int
}
// RollupEventUpdateBucketsParameters is an event of the Rollup Smart Contract // RollupEventUpdateBucketsParameters is an event of the Rollup Smart Contract
type RollupEventUpdateBucketsParameters struct { type RollupEventUpdateBucketsParameters struct {
ArrayBuckets [common.RollupConstNumBuckets][4]*big.Int
// ArrayBuckets [common.RollupConstNumBuckets][4]*big.Int
ArrayBuckets [common.RollupConstNumBuckets]RollupUpdateBucketsParameters
} }
// RollupEventUpdateTokenExchange is an event of the Rollup Smart Contract // RollupEventUpdateTokenExchange is an event of the Rollup Smart Contract
@ -170,7 +189,7 @@ type RollupForgeBatchArgs struct {
} }
// RollupForgeBatchArgsAux are the arguments to the ForgeBatch function in the Rollup Smart Contract // RollupForgeBatchArgsAux are the arguments to the ForgeBatch function in the Rollup Smart Contract
type RollupForgeBatchArgsAux struct {
type rollupForgeBatchArgsAux struct {
NewLastIdx *big.Int NewLastIdx *big.Int
NewStRoot *big.Int NewStRoot *big.Int
NewExitRoot *big.Int NewExitRoot *big.Int
@ -519,11 +538,20 @@ func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (tx *typ
} }
// RollupUpdateBucketsParameters is the interface to call the smart contract function // RollupUpdateBucketsParameters is the interface to call the smart contract function
func (c *RollupClient) RollupUpdateBucketsParameters(arrayBuckets [common.RollupConstNumBuckets][4]*big.Int) (tx *types.Transaction, err error) {
func (c *RollupClient) RollupUpdateBucketsParameters(
arrayBuckets [common.RollupConstNumBuckets]RollupUpdateBucketsParameters,
) (tx *types.Transaction, err error) {
params := [common.RollupConstNumBuckets][4]*big.Int{}
for i, bucket := range arrayBuckets {
params[i][0] = bucket.CeilUSD
params[i][1] = bucket.Withdrawals
params[i][2] = bucket.BlockWithdrawalRate
params[i][3] = bucket.MaxWithdrawals
}
if tx, err = c.client.CallAuth( if tx, err = c.client.CallAuth(
12500000,
12500000, //nolint:gomnd
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) { func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.hermez.UpdateBucketsParameters(auth, arrayBuckets)
return c.hermez.UpdateBucketsParameters(auth, params)
}, },
); err != nil { ); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed update Buckets Parameters: %w", err)) return nil, tracerr.Wrap(fmt.Errorf("Failed update Buckets Parameters: %w", err))
@ -545,11 +573,11 @@ func (c *RollupClient) RollupUpdateTokenExchange(addressArray []ethCommon.Addres
} }
// RollupUpdateWithdrawalDelay is the interface to call the smart contract function // RollupUpdateWithdrawalDelay is the interface to call the smart contract function
func (c *RollupClient) RollupUpdateWithdrawalDelay(newWithdrawalDelay uint64) (tx *types.Transaction, err error) {
func (c *RollupClient) RollupUpdateWithdrawalDelay(newWithdrawalDelay int64) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth( if tx, err = c.client.CallAuth(
0, 0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) { func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.hermez.UpdateWithdrawalDelay(auth, newWithdrawalDelay)
return c.hermez.UpdateWithdrawalDelay(auth, uint64(newWithdrawalDelay))
}, },
); err != nil { ); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed update WithdrawalDelay: %w", err)) return nil, tracerr.Wrap(fmt.Errorf("Failed update WithdrawalDelay: %w", err))
@ -662,7 +690,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
} }
switch vLog.Topics[0] { switch vLog.Topics[0] {
case logHermezL1UserTxEvent: case logHermezL1UserTxEvent:
var L1UserTxAux RollupEventL1UserTxAux
var L1UserTxAux rollupEventL1UserTxAux
var L1UserTx RollupEventL1UserTx var L1UserTx RollupEventL1UserTx
err := c.contractAbi.Unpack(&L1UserTxAux, "L1UserTxEvent", vLog.Data) err := c.contractAbi.Unpack(&L1UserTxAux, "L1UserTxEvent", vLog.Data)
if err != nil { if err != nil {
@ -726,13 +754,15 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
withdraw.TxHash = vLog.TxHash withdraw.TxHash = vLog.TxHash
rollupEvents.Withdraw = append(rollupEvents.Withdraw, withdraw) rollupEvents.Withdraw = append(rollupEvents.Withdraw, withdraw)
case logHermezUpdateBucketWithdraw: case logHermezUpdateBucketWithdraw:
var updateBucketWithdrawAux rollupEventUpdateBucketWithdrawAux
var updateBucketWithdraw RollupEventUpdateBucketWithdraw var updateBucketWithdraw RollupEventUpdateBucketWithdraw
err := c.contractAbi.Unpack(&updateBucketWithdraw, "UpdateBucketWithdraw", vLog.Data)
err := c.contractAbi.Unpack(&updateBucketWithdrawAux, "UpdateBucketWithdraw", vLog.Data)
if err != nil { if err != nil {
return nil, nil, tracerr.Wrap(err) return nil, nil, tracerr.Wrap(err)
} }
updateBucketWithdraw.NumBucket = uint8(new(big.Int).SetBytes(vLog.Topics[1][:]).Int64())
updateBucketWithdraw.BlockStamp = new(big.Int).SetBytes(vLog.Topics[2][:])
updateBucketWithdraw.Withdrawals = updateBucketWithdrawAux.Withdrawals
updateBucketWithdraw.NumBucket = int(new(big.Int).SetBytes(vLog.Topics[1][:]).Int64())
updateBucketWithdraw.BlockStamp = new(big.Int).SetBytes(vLog.Topics[2][:]).Int64()
rollupEvents.UpdateBucketWithdraw = append(rollupEvents.UpdateBucketWithdraw, updateBucketWithdraw) rollupEvents.UpdateBucketWithdraw = append(rollupEvents.UpdateBucketWithdraw, updateBucketWithdraw)
case logHermezUpdateWithdrawalDelay: case logHermezUpdateWithdrawalDelay:
@ -743,11 +773,18 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
} }
rollupEvents.UpdateWithdrawalDelay = append(rollupEvents.UpdateWithdrawalDelay, withdrawalDelay) rollupEvents.UpdateWithdrawalDelay = append(rollupEvents.UpdateWithdrawalDelay, withdrawalDelay)
case logHermezUpdateBucketsParameters: case logHermezUpdateBucketsParameters:
var bucketsParametersAux rollupEventUpdateBucketsParametersAux
var bucketsParameters RollupEventUpdateBucketsParameters var bucketsParameters RollupEventUpdateBucketsParameters
err := c.contractAbi.Unpack(&bucketsParameters, "UpdateBucketsParameters", vLog.Data)
err := c.contractAbi.Unpack(&bucketsParametersAux, "UpdateBucketsParameters", vLog.Data)
if err != nil { if err != nil {
return nil, nil, tracerr.Wrap(err) return nil, nil, tracerr.Wrap(err)
} }
for i, bucket := range bucketsParametersAux.ArrayBuckets {
bucketsParameters.ArrayBuckets[i].CeilUSD = bucket[0]
bucketsParameters.ArrayBuckets[i].Withdrawals = bucket[1]
bucketsParameters.ArrayBuckets[i].BlockWithdrawalRate = bucket[2]
bucketsParameters.ArrayBuckets[i].MaxWithdrawals = bucket[3]
}
rollupEvents.UpdateBucketsParameters = append(rollupEvents.UpdateBucketsParameters, bucketsParameters) rollupEvents.UpdateBucketsParameters = append(rollupEvents.UpdateBucketsParameters, bucketsParameters)
case logHermezUpdateTokenExchange: case logHermezUpdateTokenExchange:
var tokensExchange RollupEventUpdateTokenExchange var tokensExchange RollupEventUpdateTokenExchange
@ -766,7 +803,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
// RollupForgeBatchArgs returns the arguments used in a ForgeBatch call in the // RollupForgeBatchArgs returns the arguments used in a ForgeBatch call in the
// Rollup Smart Contract in the given transaction, and the sender address. // Rollup Smart Contract in the given transaction, and the sender address.
func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, numL1TxUser uint16) (*RollupForgeBatchArgs, *ethCommon.Address, error) {
func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, l1UserTxsLen uint16) (*RollupForgeBatchArgs, *ethCommon.Address, error) {
tx, _, err := c.client.client.TransactionByHash(context.Background(), ethTxHash) tx, _, err := c.client.client.TransactionByHash(context.Background(), ethTxHash)
if err != nil { if err != nil {
return nil, nil, tracerr.Wrap(err) return nil, nil, tracerr.Wrap(err)
@ -785,7 +822,7 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, numL1TxUse
if err != nil { if err != nil {
return nil, nil, tracerr.Wrap(err) return nil, nil, tracerr.Wrap(err)
} }
var aux RollupForgeBatchArgsAux
var aux rollupForgeBatchArgsAux
if err := method.Inputs.Unpack(&aux, txData[4:]); err != nil { if err := method.Inputs.Unpack(&aux, txData[4:]); err != nil {
return nil, nil, tracerr.Wrap(err) return nil, nil, tracerr.Wrap(err)
} }
@ -809,15 +846,15 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, numL1TxUse
} }
nLevels := rollupConsts.Verifiers[rollupForgeBatchArgs.VerifierIdx].NLevels nLevels := rollupConsts.Verifiers[rollupForgeBatchArgs.VerifierIdx].NLevels
lenL1L2TxsBytes := int((nLevels/8)*2 + 2 + 1) lenL1L2TxsBytes := int((nLevels/8)*2 + 2 + 1)
numBytesL1TxUser := int(numL1TxUser) * lenL1L2TxsBytes
numBytesL1TxUser := int(l1UserTxsLen) * lenL1L2TxsBytes
numTxsL1Coord := len(aux.EncodedL1CoordinatorTx) / common.L1CoordinatorTxBytesLen numTxsL1Coord := len(aux.EncodedL1CoordinatorTx) / common.L1CoordinatorTxBytesLen
numBytesL1TxCoord := numTxsL1Coord * lenL1L2TxsBytes numBytesL1TxCoord := numTxsL1Coord * lenL1L2TxsBytes
numBeginL2Tx := numBytesL1TxCoord + numBytesL1TxUser numBeginL2Tx := numBytesL1TxCoord + numBytesL1TxUser
l1UserTxsData := []byte{} l1UserTxsData := []byte{}
if numL1TxUser > 0 {
if l1UserTxsLen > 0 {
l1UserTxsData = aux.L1L2TxsData[:numBytesL1TxUser] l1UserTxsData = aux.L1L2TxsData[:numBytesL1TxUser]
} }
for i := 0; i < int(numL1TxUser); i++ {
for i := 0; i < int(l1UserTxsLen); i++ {
l1Tx, err := common.L1TxFromDataAvailability(l1UserTxsData[i*lenL1L2TxsBytes:(i+1)*lenL1L2TxsBytes], uint32(nLevels)) l1Tx, err := common.L1TxFromDataAvailability(l1UserTxsData[i*lenL1L2TxsBytes:(i+1)*lenL1L2TxsBytes], uint32(nLevels))
if err != nil { if err != nil {
return nil, nil, tracerr.Wrap(err) return nil, nil, tracerr.Wrap(err)

+ 136
- 143
eth/rollup_test.go

@ -57,7 +57,7 @@ func genKeysBjj(i int64) *keys {
func TestRollupConstants(t *testing.T) { func TestRollupConstants(t *testing.T) {
rollupConstants, err := rollupClient.RollupConstants() rollupConstants, err := rollupClient.RollupConstants()
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, absoluteMaxL1L2BatchTimeout, rollupConstants.AbsoluteMaxL1L2BatchTimeout) assert.Equal(t, absoluteMaxL1L2BatchTimeout, rollupConstants.AbsoluteMaxL1L2BatchTimeout)
assert.Equal(t, auctionAddressConst, rollupConstants.HermezAuctionContract) assert.Equal(t, auctionAddressConst, rollupConstants.HermezAuctionContract)
assert.Equal(t, tokenHEZAddressConst, rollupConstants.TokenHEZ) assert.Equal(t, tokenHEZAddressConst, rollupConstants.TokenHEZ)
@ -69,7 +69,7 @@ func TestRollupConstants(t *testing.T) {
func TestRollupRegisterTokensCount(t *testing.T) { func TestRollupRegisterTokensCount(t *testing.T) {
registerTokensCount, err := rollupClient.RollupRegisterTokensCount() registerTokensCount, err := rollupClient.RollupRegisterTokensCount()
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, big.NewInt(1), registerTokensCount) assert.Equal(t, big.NewInt(1), registerTokensCount)
} }
@ -77,13 +77,13 @@ func TestRollupAddToken(t *testing.T) {
feeAddToken := big.NewInt(10) feeAddToken := big.NewInt(10)
// Addtoken ERC20Permit // Addtoken ERC20Permit
registerTokensCount, err := rollupClient.RollupRegisterTokensCount() registerTokensCount, err := rollupClient.RollupRegisterTokensCount()
require.Nil(t, err)
require.NoError(t, err)
_, err = rollupClient.RollupAddToken(tokenHEZAddressConst, feeAddToken, deadline) _, err = rollupClient.RollupAddToken(tokenHEZAddressConst, feeAddToken, deadline)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, tokenHEZAddressConst, rollupEvents.AddToken[0].TokenAddress) assert.Equal(t, tokenHEZAddressConst, rollupEvents.AddToken[0].TokenAddress)
assert.Equal(t, registerTokensCount, common.TokenID(rollupEvents.AddToken[0].TokenID).BigInt()) assert.Equal(t, registerTokensCount, common.TokenID(rollupEvents.AddToken[0].TokenID).BigInt())
@ -95,11 +95,11 @@ func TestRollupForgeBatch(t *testing.T) {
// Register Coordinator // Register Coordinator
forgerAddress := governanceAddressConst forgerAddress := governanceAddressConst
_, err := auctionClient.AuctionSetCoordinator(forgerAddress, URL) _, err := auctionClient.AuctionSetCoordinator(forgerAddress, URL)
require.Nil(t, err)
require.NoError(t, err)
// MultiBid // MultiBid
currentSlot, err := auctionClient.AuctionGetCurrentSlotNumber() currentSlot, err := auctionClient.AuctionGetCurrentSlotNumber()
require.Nil(t, err)
require.NoError(t, err)
slotSet := [6]bool{true, false, true, false, true, false} slotSet := [6]bool{true, false, true, false, true, false}
maxBid := new(big.Int) maxBid := new(big.Int)
maxBid.SetString("15000000000000000000", 10) maxBid.SetString("15000000000000000000", 10)
@ -108,12 +108,12 @@ func TestRollupForgeBatch(t *testing.T) {
budget := new(big.Int) budget := new(big.Int)
budget.SetString("45200000000000000000", 10) budget.SetString("45200000000000000000", 10)
_, err = auctionClient.AuctionMultiBid(budget, currentSlot+4, currentSlot+10, slotSet, maxBid, minBid, deadline) _, err = auctionClient.AuctionMultiBid(budget, currentSlot+4, currentSlot+10, slotSet, maxBid, minBid, deadline)
require.Nil(t, err)
require.NoError(t, err)
// Add Blocks // Add Blocks
blockNum := int64(int(blocksPerSlot)*int(currentSlot+4) + int(genesisBlock)) blockNum := int64(int(blocksPerSlot)*int(currentSlot+4) + int(genesisBlock))
currentBlockNum, err := auctionClient.client.EthLastBlock() currentBlockNum, err := auctionClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
blocksToAdd := blockNum - currentBlockNum blocksToAdd := blockNum - currentBlockNum
addBlocks(blocksToAdd, ethClientDialURL) addBlocks(blocksToAdd, ethClientDialURL)
@ -121,7 +121,7 @@ func TestRollupForgeBatch(t *testing.T) {
args := new(RollupForgeBatchArgs) args := new(RollupForgeBatchArgs)
args.FeeIdxCoordinator = []common.Idx{} // When encoded, 64 times the 0 idx means that no idx to collect fees is specified. args.FeeIdxCoordinator = []common.Idx{} // When encoded, 64 times the 0 idx means that no idx to collect fees is specified.
l1CoordinatorBytes, err := hex.DecodeString("1c660323607bb113e586183609964a333d07ebe4bef3be82ec13af453bae9590bd7711cdb6abf42f176eadfbe5506fbef5e092e5543733f91b0061d9a7747fa10694a915a6470fa230de387b51e6f4db0b09787867778687b55197ad6d6a86eac000000001") l1CoordinatorBytes, err := hex.DecodeString("1c660323607bb113e586183609964a333d07ebe4bef3be82ec13af453bae9590bd7711cdb6abf42f176eadfbe5506fbef5e092e5543733f91b0061d9a7747fa10694a915a6470fa230de387b51e6f4db0b09787867778687b55197ad6d6a86eac000000001")
require.Nil(t, err)
require.NoError(t, err)
numTxsL1 := len(l1CoordinatorBytes) / common.L1CoordinatorTxBytesLen numTxsL1 := len(l1CoordinatorBytes) / common.L1CoordinatorTxBytesLen
for i := 0; i < numTxsL1; i++ { for i := 0; i < numTxsL1; i++ {
bytesL1Coordinator := l1CoordinatorBytes[i*common.L1CoordinatorTxBytesLen : (i+1)*common.L1CoordinatorTxBytesLen] bytesL1Coordinator := l1CoordinatorBytes[i*common.L1CoordinatorTxBytesLen : (i+1)*common.L1CoordinatorTxBytesLen]
@ -133,7 +133,7 @@ func TestRollupForgeBatch(t *testing.T) {
signature = append(signature, s[:]...) signature = append(signature, s[:]...)
signature = append(signature, v) signature = append(signature, v)
l1Tx, err := common.L1CoordinatorTxFromBytes(bytesL1Coordinator, chainid, rollupClient.address) l1Tx, err := common.L1CoordinatorTxFromBytes(bytesL1Coordinator, chainid, rollupClient.address)
require.Nil(t, err)
require.NoError(t, err)
args.L1CoordinatorTxs = append(args.L1CoordinatorTxs, *l1Tx) args.L1CoordinatorTxs = append(args.L1CoordinatorTxs, *l1Tx)
args.L1CoordinatorTxsAuths = append(args.L1CoordinatorTxsAuths, signature) args.L1CoordinatorTxsAuths = append(args.L1CoordinatorTxsAuths, signature)
} }
@ -143,7 +143,7 @@ func TestRollupForgeBatch(t *testing.T) {
newStateRoot.SetString("18317824016047294649053625209337295956588174734569560016974612130063629505228", 10) newStateRoot.SetString("18317824016047294649053625209337295956588174734569560016974612130063629505228", 10)
newExitRoot := new(big.Int) newExitRoot := new(big.Int)
bytesNumExitRoot, err := hex.DecodeString("10a89d5fe8d488eda1ba371d633515739933c706c210c604f5bd209180daa43b") bytesNumExitRoot, err := hex.DecodeString("10a89d5fe8d488eda1ba371d633515739933c706c210c604f5bd209180daa43b")
require.Nil(t, err)
require.NoError(t, err)
newExitRoot.SetBytes(bytesNumExitRoot) newExitRoot.SetBytes(bytesNumExitRoot)
args.NewLastIdx = int64(300) args.NewLastIdx = int64(300)
args.NewStRoot = newStateRoot args.NewStRoot = newStateRoot
@ -161,12 +161,12 @@ func TestRollupForgeBatch(t *testing.T) {
argsForge = args argsForge = args
_, err = rollupClient.RollupForgeBatch(argsForge) _, err = rollupClient.RollupForgeBatch(argsForge)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err = rollupClient.client.EthLastBlock() currentBlockNum, err = rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, int64(1), rollupEvents.ForgeBatch[0].BatchNum) assert.Equal(t, int64(1), rollupEvents.ForgeBatch[0].BatchNum)
assert.Equal(t, uint16(len(L1UserTxs)), rollupEvents.ForgeBatch[0].L1UserTxsLen) assert.Equal(t, uint16(len(L1UserTxs)), rollupEvents.ForgeBatch[0].L1UserTxsLen)
@ -175,7 +175,7 @@ func TestRollupForgeBatch(t *testing.T) {
func TestRollupForgeBatchArgs(t *testing.T) { func TestRollupForgeBatchArgs(t *testing.T) {
args, sender, err := rollupClient.RollupForgeBatchArgs(ethHashForge, uint16(len(L1UserTxs))) args, sender, err := rollupClient.RollupForgeBatchArgs(ethHashForge, uint16(len(L1UserTxs)))
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, *sender, rollupClient.client.account.Address) assert.Equal(t, *sender, rollupClient.client.account.Address)
assert.Equal(t, argsForge.FeeIdxCoordinator, args.FeeIdxCoordinator) assert.Equal(t, argsForge.FeeIdxCoordinator, args.FeeIdxCoordinator)
assert.Equal(t, argsForge.L1Batch, args.L1Batch) assert.Equal(t, argsForge.L1Batch, args.L1Batch)
@ -190,12 +190,12 @@ func TestRollupForgeBatchArgs(t *testing.T) {
func TestRollupUpdateForgeL1L2BatchTimeout(t *testing.T) { func TestRollupUpdateForgeL1L2BatchTimeout(t *testing.T) {
newForgeL1L2BatchTimeout := int64(222) newForgeL1L2BatchTimeout := int64(222)
_, err := rollupClient.RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout) _, err := rollupClient.RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, newForgeL1L2BatchTimeout, rollupEvents.UpdateForgeL1L2BatchTimeout[0].NewForgeL1L2BatchTimeout) assert.Equal(t, newForgeL1L2BatchTimeout, rollupEvents.UpdateForgeL1L2BatchTimeout[0].NewForgeL1L2BatchTimeout)
} }
@ -203,49 +203,43 @@ func TestRollupUpdateForgeL1L2BatchTimeout(t *testing.T) {
func TestRollupUpdateFeeAddToken(t *testing.T) { func TestRollupUpdateFeeAddToken(t *testing.T) {
newFeeAddToken := big.NewInt(12) newFeeAddToken := big.NewInt(12)
_, err := rollupClient.RollupUpdateFeeAddToken(newFeeAddToken) _, err := rollupClient.RollupUpdateFeeAddToken(newFeeAddToken)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, newFeeAddToken, rollupEvents.UpdateFeeAddToken[0].NewFeeAddToken) assert.Equal(t, newFeeAddToken, rollupEvents.UpdateFeeAddToken[0].NewFeeAddToken)
} }
func TestRollupUpdateBucketsParameters(t *testing.T) { func TestRollupUpdateBucketsParameters(t *testing.T) {
var bucketsParameters [common.RollupConstNumBuckets][4]*big.Int
var bucketsParameters [common.RollupConstNumBuckets]RollupUpdateBucketsParameters
for i := range bucketsParameters { for i := range bucketsParameters {
bucketsParameters[i][0] = big.NewInt(int64((i + 1) * 100)) // ceilUSD
bucketsParameters[i][1] = big.NewInt(int64(i + 1)) // withdrawals
bucketsParameters[i][2] = big.NewInt(int64(i+1) * 100) // blockWithdrawalRate
bucketsParameters[i][3] = big.NewInt(int64(100000000000)) // maxWithdrawals
bucketsParameters[i].CeilUSD = big.NewInt(int64((i + 1) * 100))
bucketsParameters[i].Withdrawals = big.NewInt(int64(i + 1))
bucketsParameters[i].BlockWithdrawalRate = big.NewInt(int64(i+1) * 100)
bucketsParameters[i].MaxWithdrawals = big.NewInt(int64(100000000000))
} }
_, err := rollupClient.RollupUpdateBucketsParameters(bucketsParameters) _, err := rollupClient.RollupUpdateBucketsParameters(bucketsParameters)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
blockStampBucket = currentBlockNum blockStampBucket = currentBlockNum
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
for i := range bucketsParameters {
assert.Equal(t, bucketsParameters[i][0].String(), rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i][0].String())
assert.Equal(t, bucketsParameters[i][1].String(), rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i][1].String())
assert.Equal(t, bucketsParameters[i][2].String(), rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i][2].String())
assert.Equal(t, bucketsParameters[i][3].String(), rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i][3].String())
}
require.NoError(t, err)
assert.Equal(t, bucketsParameters, rollupEvents.UpdateBucketsParameters[0].ArrayBuckets)
} }
func TestRollupUpdateWithdrawalDelay(t *testing.T) { func TestRollupUpdateWithdrawalDelay(t *testing.T) {
newWithdrawalDelay := uint64(100000)
newWithdrawalDelay := int64(100000)
_, err := rollupClient.RollupUpdateWithdrawalDelay(newWithdrawalDelay) _, err := rollupClient.RollupUpdateWithdrawalDelay(newWithdrawalDelay)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
assert.Equal(t, newWithdrawalDelay, rollupEvents.UpdateWithdrawalDelay[0].NewWithdrawalDelay)
require.NoError(t, err)
assert.Equal(t, newWithdrawalDelay, int64(rollupEvents.UpdateWithdrawalDelay[0].NewWithdrawalDelay))
} }
func TestRollupUpdateTokenExchange(t *testing.T) { func TestRollupUpdateTokenExchange(t *testing.T) {
@ -255,20 +249,20 @@ func TestRollupUpdateTokenExchange(t *testing.T) {
addressArray = append(addressArray, addressToken1) addressArray = append(addressArray, addressToken1)
tokenPrice := 10 tokenPrice := 10
valueArray = append(valueArray, uint64(tokenPrice*1e14)) valueArray = append(valueArray, uint64(tokenPrice*1e14))
require.Nil(t, err)
require.NoError(t, err)
_, err = rollupClient.RollupUpdateTokenExchange(addressArray, valueArray) _, err = rollupClient.RollupUpdateTokenExchange(addressArray, valueArray)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, addressArray, rollupEvents.UpdateTokenExchange[0].AddressArray) assert.Equal(t, addressArray, rollupEvents.UpdateTokenExchange[0].AddressArray)
assert.Equal(t, valueArray, rollupEvents.UpdateTokenExchange[0].ValueArray) assert.Equal(t, valueArray, rollupEvents.UpdateTokenExchange[0].ValueArray)
} }
func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) { func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
key := genKeysBjj(2) key := genKeysBjj(2)
fromIdxInt64 := int64(0) fromIdxInt64 := int64(0)
toIdxInt64 := int64(0) toIdxInt64 := int64(0)
@ -285,12 +279,12 @@ func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64) _, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ) assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
@ -301,7 +295,7 @@ func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) { func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ) rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
key := genKeysBjj(1) key := genKeysBjj(1)
fromIdxInt64 := int64(0) fromIdxInt64 := int64(0)
toIdxInt64 := int64(0) toIdxInt64 := int64(0)
@ -317,12 +311,12 @@ func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64) _, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ) assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
@ -333,7 +327,7 @@ func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) { func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
key := genKeysBjj(3) key := genKeysBjj(3)
fromIdxInt64 := int64(0) fromIdxInt64 := int64(0)
toIdxInt64 := int64(0) toIdxInt64 := int64(0)
@ -349,12 +343,12 @@ func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline) _, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ) assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
@ -365,7 +359,7 @@ func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) {
func TestRollupL1UserTxETHDeposit(t *testing.T) { func TestRollupL1UserTxETHDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(256) fromIdxInt64 := int64(256)
toIdxInt64 := int64(0) toIdxInt64 := int64(0)
tokenIDUint32 := uint32(0) tokenIDUint32 := uint32(0)
@ -381,12 +375,12 @@ func TestRollupL1UserTxETHDeposit(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64) _, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -396,7 +390,7 @@ func TestRollupL1UserTxETHDeposit(t *testing.T) {
func TestRollupL1UserTxERC20Deposit(t *testing.T) { func TestRollupL1UserTxERC20Deposit(t *testing.T) {
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ) rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(257) fromIdxInt64 := int64(257)
toIdxInt64 := int64(0) toIdxInt64 := int64(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10) loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
@ -411,12 +405,12 @@ func TestRollupL1UserTxERC20Deposit(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64) _, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -426,7 +420,7 @@ func TestRollupL1UserTxERC20Deposit(t *testing.T) {
func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) { func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(258) fromIdxInt64 := int64(258)
toIdxInt64 := int64(0) toIdxInt64 := int64(0)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10) loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
@ -440,12 +434,12 @@ func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline) _, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -455,7 +449,7 @@ func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
func TestRollupL1UserTxETHDepositTransfer(t *testing.T) { func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(256) fromIdxInt64 := int64(256)
toIdxInt64 := int64(257) toIdxInt64 := int64(257)
tokenIDUint32 := uint32(0) tokenIDUint32 := uint32(0)
@ -471,12 +465,12 @@ func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64) _, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -486,7 +480,7 @@ func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) { func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ) rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(257) fromIdxInt64 := int64(257)
toIdxInt64 := int64(258) toIdxInt64 := int64(258)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10) loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
@ -501,12 +495,12 @@ func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64) _, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -516,7 +510,7 @@ func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) { func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(258) fromIdxInt64 := int64(258)
toIdxInt64 := int64(259) toIdxInt64 := int64(259)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10) loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
@ -531,12 +525,12 @@ func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline) _, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -546,7 +540,7 @@ func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) { func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(256) fromIdxInt64 := int64(256)
toIdxInt64 := int64(257) toIdxInt64 := int64(257)
tokenIDUint32 := uint32(0) tokenIDUint32 := uint32(0)
@ -562,12 +556,12 @@ func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64) _, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -577,7 +571,7 @@ func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) { func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ) rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(257) fromIdxInt64 := int64(257)
toIdxInt64 := int64(258) toIdxInt64 := int64(258)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10) loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
@ -592,12 +586,12 @@ func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64) _, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -607,7 +601,7 @@ func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) { func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(258) fromIdxInt64 := int64(258)
toIdxInt64 := int64(259) toIdxInt64 := int64(259)
loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10) loadAmount, _ := new(big.Int).SetString("1000000000000000000000", 10)
@ -622,12 +616,12 @@ func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline) _, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -637,7 +631,7 @@ func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
func TestRollupL1UserTxETHForceTransfer(t *testing.T) { func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(256) fromIdxInt64 := int64(256)
toIdxInt64 := int64(257) toIdxInt64 := int64(257)
tokenIDUint32 := uint32(0) tokenIDUint32 := uint32(0)
@ -652,12 +646,12 @@ func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64) _, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -667,7 +661,7 @@ func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) { func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ) rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(257) fromIdxInt64 := int64(257)
toIdxInt64 := int64(258) toIdxInt64 := int64(258)
amount, _ := new(big.Int).SetString("10000000000000000000", 10) amount, _ := new(big.Int).SetString("10000000000000000000", 10)
@ -681,12 +675,12 @@ func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64) _, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -696,7 +690,7 @@ func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) { func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(259) fromIdxInt64 := int64(259)
toIdxInt64 := int64(260) toIdxInt64 := int64(260)
amount, _ := new(big.Int).SetString("30000000000000000000", 10) amount, _ := new(big.Int).SetString("30000000000000000000", 10)
@ -710,12 +704,12 @@ func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline) _, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -725,7 +719,7 @@ func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
func TestRollupL1UserTxETHForceExit(t *testing.T) { func TestRollupL1UserTxETHForceExit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(256) fromIdxInt64 := int64(256)
toIdxInt64 := int64(1) toIdxInt64 := int64(1)
tokenIDUint32 := uint32(0) tokenIDUint32 := uint32(0)
@ -740,12 +734,12 @@ func TestRollupL1UserTxETHForceExit(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64) _, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -755,7 +749,7 @@ func TestRollupL1UserTxETHForceExit(t *testing.T) {
func TestRollupL1UserTxERC20ForceExit(t *testing.T) { func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ) rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(257) fromIdxInt64 := int64(257)
toIdxInt64 := int64(1) toIdxInt64 := int64(1)
amount, _ := new(big.Int).SetString("20000000000000000000", 10) amount, _ := new(big.Int).SetString("20000000000000000000", 10)
@ -769,12 +763,12 @@ func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64) _, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -784,7 +778,7 @@ func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) { func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
fromIdxInt64 := int64(258) fromIdxInt64 := int64(258)
toIdxInt64 := int64(1) toIdxInt64 := int64(1)
fromIdx := new(common.Idx) fromIdx := new(common.Idx)
@ -800,12 +794,12 @@ func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
L1UserTxs = append(L1UserTxs, l1Tx) L1UserTxs = append(L1UserTxs, l1Tx)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline) _, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx) assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount) assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID) assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
@ -816,11 +810,11 @@ func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
func TestRollupForgeBatch2(t *testing.T) { func TestRollupForgeBatch2(t *testing.T) {
// Forge Batch 2 // Forge Batch 2
_, err := rollupClient.RollupForgeBatch(argsForge) _, err := rollupClient.RollupForgeBatch(argsForge)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, int64(2), rollupEvents.ForgeBatch[0].BatchNum) assert.Equal(t, int64(2), rollupEvents.ForgeBatch[0].BatchNum)
@ -833,9 +827,9 @@ func TestRollupForgeBatch2(t *testing.T) {
l1UserTx := L1UserTxs[i] l1UserTx := L1UserTxs[i]
l1UserTx.EffectiveAmount = l1UserTx.Amount l1UserTx.EffectiveAmount = l1UserTx.Amount
l1Bytes, err := l1UserTx.BytesDataAvailability(uint32(nLevels)) l1Bytes, err := l1UserTx.BytesDataAvailability(uint32(nLevels))
require.Nil(t, err)
require.NoError(t, err)
l1UserTxDataAvailability, err := common.L1TxFromDataAvailability(l1Bytes, uint32(nLevels)) l1UserTxDataAvailability, err := common.L1TxFromDataAvailability(l1Bytes, uint32(nLevels))
require.Nil(t, err)
require.NoError(t, err)
args.L1UserTxs = append(args.L1UserTxs, *l1UserTxDataAvailability) args.L1UserTxs = append(args.L1UserTxs, *l1UserTxDataAvailability)
} }
newStateRoot := new(big.Int) newStateRoot := new(big.Int)
@ -869,22 +863,21 @@ func TestRollupForgeBatch2(t *testing.T) {
argsForge = args argsForge = args
_, err = rollupClient.RollupForgeBatch(argsForge) _, err = rollupClient.RollupForgeBatch(argsForge)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err = rollupClient.client.EthLastBlock() currentBlockNum, err = rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err = rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err = rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, int64(3), rollupEvents.ForgeBatch[0].BatchNum) assert.Equal(t, int64(3), rollupEvents.ForgeBatch[0].BatchNum)
assert.Equal(t, uint16(len(L1UserTxs)), rollupEvents.ForgeBatch[0].L1UserTxsLen) assert.Equal(t, uint16(len(L1UserTxs)), rollupEvents.ForgeBatch[0].L1UserTxsLen)
ethHashForge = rollupEvents.ForgeBatch[0].EthTxHash ethHashForge = rollupEvents.ForgeBatch[0].EthTxHash
} }
func TestRollupForgeBatchArgs2(t *testing.T) { func TestRollupForgeBatchArgs2(t *testing.T) {
args, sender, err := rollupClient.RollupForgeBatchArgs(ethHashForge, uint16(len(L1UserTxs))) args, sender, err := rollupClient.RollupForgeBatchArgs(ethHashForge, uint16(len(L1UserTxs)))
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, *sender, rollupClient.client.account.Address) assert.Equal(t, *sender, rollupClient.client.account.Address)
assert.Equal(t, argsForge.FeeIdxCoordinator, args.FeeIdxCoordinator) assert.Equal(t, argsForge.FeeIdxCoordinator, args.FeeIdxCoordinator)
assert.Equal(t, argsForge.L1Batch, args.L1Batch) assert.Equal(t, argsForge.L1Batch, args.L1Batch)
@ -899,38 +892,38 @@ func TestRollupForgeBatchArgs2(t *testing.T) {
func TestRollupWithdrawMerkleProof(t *testing.T) { func TestRollupWithdrawMerkleProof(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ) rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
require.NoError(t, err)
var pkComp babyjub.PublicKeyComp var pkComp babyjub.PublicKeyComp
pkCompBE, err := hex.DecodeString("adc3b754f8da621967b073a787bef8eec7052f2ba712b23af57d98f65beea8b2") pkCompBE, err := hex.DecodeString("adc3b754f8da621967b073a787bef8eec7052f2ba712b23af57d98f65beea8b2")
require.Nil(t, err)
require.NoError(t, err)
pkCompLE := common.SwapEndianness(pkCompBE) pkCompLE := common.SwapEndianness(pkCompBE)
copy(pkComp[:], pkCompLE) copy(pkComp[:], pkCompLE)
pk, err := pkComp.Decompress() pk, err := pkComp.Decompress()
require.Nil(t, err)
require.NoError(t, err)
require.Nil(t, err)
require.NoError(t, err)
tokenID := uint32(tokenHEZID) tokenID := uint32(tokenHEZID)
numExitRoot := int64(3) numExitRoot := int64(3)
fromIdx := int64(256) fromIdx := int64(256)
amount, _ := new(big.Int).SetString("20000000000000000000", 10) amount, _ := new(big.Int).SetString("20000000000000000000", 10)
// siblingBytes0, err := new(big.Int).SetString("19508838618377323910556678335932426220272947530531646682154552299216398748115", 10) // siblingBytes0, err := new(big.Int).SetString("19508838618377323910556678335932426220272947530531646682154552299216398748115", 10)
// require.Nil(t, err)
// require.NoError(t, err)
// siblingBytes1, err := new(big.Int).SetString("15198806719713909654457742294233381653226080862567104272457668857208564789571", 10) // siblingBytes1, err := new(big.Int).SetString("15198806719713909654457742294233381653226080862567104272457668857208564789571", 10)
// require.Nil(t, err)
// require.NoError(t, err)
var siblings []*big.Int var siblings []*big.Int
// siblings = append(siblings, siblingBytes0) // siblings = append(siblings, siblingBytes0)
// siblings = append(siblings, siblingBytes1) // siblings = append(siblings, siblingBytes1)
instantWithdraw := true instantWithdraw := true
_, err = rollupClientAux.RollupWithdrawMerkleProof(pk, tokenID, numExitRoot, fromIdx, amount, siblings, instantWithdraw) _, err = rollupClientAux.RollupWithdrawMerkleProof(pk, tokenID, numExitRoot, fromIdx, amount, siblings, instantWithdraw)
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, uint64(fromIdx), rollupEvents.Withdraw[0].Idx) assert.Equal(t, uint64(fromIdx), rollupEvents.Withdraw[0].Idx)
assert.Equal(t, instantWithdraw, rollupEvents.Withdraw[0].InstantWithdraw) assert.Equal(t, instantWithdraw, rollupEvents.Withdraw[0].InstantWithdraw)
@ -941,19 +934,19 @@ func TestRollupWithdrawMerkleProof(t *testing.T) {
// Bucket 1 // Bucket 1
// Bucket[0].withdrawals = 1, Bucket[1].withdrawals = 2, ... // Bucket[0].withdrawals = 1, Bucket[1].withdrawals = 2, ...
// Bucket[1].withdrawals - 1 = 1 // Bucket[1].withdrawals - 1 = 1
assert.Equal(t, uint8(1), rollupEvents.UpdateBucketWithdraw[0].NumBucket)
assert.Equal(t, big.NewInt(blockStampBucket), rollupEvents.UpdateBucketWithdraw[0].BlockStamp)
assert.Equal(t, 1, rollupEvents.UpdateBucketWithdraw[0].NumBucket)
assert.Equal(t, blockStampBucket, rollupEvents.UpdateBucketWithdraw[0].BlockStamp)
assert.Equal(t, big.NewInt(1), rollupEvents.UpdateBucketWithdraw[0].Withdrawals) assert.Equal(t, big.NewInt(1), rollupEvents.UpdateBucketWithdraw[0].Withdrawals)
} }
func TestRollupSafeMode(t *testing.T) { func TestRollupSafeMode(t *testing.T) {
_, err := rollupClient.RollupSafeMode() _, err := rollupClient.RollupSafeMode()
require.Nil(t, err)
require.NoError(t, err)
currentBlockNum, err := rollupClient.client.EthLastBlock() currentBlockNum, err := rollupClient.client.EthLastBlock()
require.Nil(t, err)
require.NoError(t, err)
rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum) rollupEvents, _, err := rollupClient.RollupEventsByBlock(currentBlockNum)
require.Nil(t, err)
require.NoError(t, err)
auxEvent := new(RollupEventSafeMode) auxEvent := new(RollupEventSafeMode)
assert.Equal(t, auxEvent, &rollupEvents.SafeMode[0]) assert.Equal(t, auxEvent, &rollupEvents.SafeMode[0])
} }

+ 6
- 9
synchronizer/synchronizer.go

@ -736,7 +736,8 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e
position := 0 position := 0
// Get the input for each Tx // Get the input for each Tx
forgeBatchArgs, sender, err := s.ethClient.RollupForgeBatchArgs(evtForgeBatch.EthTxHash)
forgeBatchArgs, sender, err := s.ethClient.RollupForgeBatchArgs(evtForgeBatch.EthTxHash,
evtForgeBatch.L1UserTxsLen)
if err != nil { if err != nil {
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
@ -1074,16 +1075,12 @@ func (s *Synchronizer) wdelayerSync(ethBlock *common.Block) (*common.WDelayerDat
s.vars.WDelayer.WithdrawalDelay = evt.WithdrawalDelay s.vars.WDelayer.WithdrawalDelay = evt.WithdrawalDelay
varsUpdate = true varsUpdate = true
} }
for _, evt := range wDelayerEvents.NewHermezKeeperAddress {
s.vars.WDelayer.HermezKeeperAddress = evt.NewHermezKeeperAddress
for _, evt := range wDelayerEvents.NewEmergencyCouncil {
s.vars.WDelayer.EmergencyCouncilAddress = evt.NewEmergencyCouncil
varsUpdate = true varsUpdate = true
} }
for _, evt := range wDelayerEvents.NewWhiteHackGroupAddress {
s.vars.WDelayer.WhiteHackGroupAddress = evt.NewWhiteHackGroupAddress
varsUpdate = true
}
for _, evt := range wDelayerEvents.NewHermezGovernanceDAOAddress {
s.vars.WDelayer.HermezGovernanceDAOAddress = evt.NewHermezGovernanceDAOAddress
for _, evt := range wDelayerEvents.NewHermezGovernanceAddress {
s.vars.WDelayer.HermezGovernanceAddress = evt.NewHermezGovernanceAddress
varsUpdate = true varsUpdate = true
} }

+ 29
- 22
test/ethclient.go

@ -311,8 +311,9 @@ func NewClientSetupExample() *ClientSetup {
HermezRollup: ethCommon.HexToAddress("0x474B6e29852257491cf283EfB1A9C61eBFe48369"), HermezRollup: ethCommon.HexToAddress("0x474B6e29852257491cf283EfB1A9C61eBFe48369"),
} }
auctionVariables := &common.AuctionVariables{ auctionVariables := &common.AuctionVariables{
DonationAddress: ethCommon.HexToAddress("0x61Ed87CF0A1496b49A420DA6D84B58196b98f2e7"),
BootCoordinator: ethCommon.HexToAddress("0xE39fEc6224708f0772D2A74fd3f9055A90E0A9f2"),
DonationAddress: ethCommon.HexToAddress("0x61Ed87CF0A1496b49A420DA6D84B58196b98f2e7"),
BootCoordinator: ethCommon.HexToAddress("0xE39fEc6224708f0772D2A74fd3f9055A90E0A9f2"),
BootCoordinatorURL: "https://boot.coordinator.com",
DefaultSlotSetBid: [6]*big.Int{ DefaultSlotSetBid: [6]*big.Int{
big.NewInt(1000), big.NewInt(1100), big.NewInt(1200), big.NewInt(1000), big.NewInt(1100), big.NewInt(1200),
big.NewInt(1300), big.NewInt(1400), big.NewInt(1500)}, big.NewInt(1300), big.NewInt(1400), big.NewInt(1500)},
@ -940,8 +941,9 @@ func (c *Client) addBatch(args *eth.RollupForgeBatchArgs) (*types.Transaction, e
ethTx := r.addTransaction(c.newTransaction("forgebatch", args)) ethTx := r.addTransaction(c.newTransaction("forgebatch", args))
c.forgeBatchArgsPending[ethTx.Hash()] = &batch{*args, *c.addr} c.forgeBatchArgsPending[ethTx.Hash()] = &batch{*args, *c.addr}
r.Events.ForgeBatch = append(r.Events.ForgeBatch, eth.RollupEventForgeBatch{ r.Events.ForgeBatch = append(r.Events.ForgeBatch, eth.RollupEventForgeBatch{
BatchNum: int64(len(r.State.ExitRoots)) - 1,
EthTxHash: ethTx.Hash(),
BatchNum: int64(len(r.State.ExitRoots)) - 1,
EthTxHash: ethTx.Hash(),
L1UserTxsLen: uint16(len(args.L1UserTxs)),
}) })
return ethTx, nil return ethTx, nil
@ -1059,7 +1061,7 @@ func (c *Client) RollupEventsByBlock(blockNum int64) (*eth.RollupEvents, *ethCom
} }
// RollupForgeBatchArgs returns the arguments used in a ForgeBatch call in the Rollup Smart Contract in the given transaction // RollupForgeBatchArgs returns the arguments used in a ForgeBatch call in the Rollup Smart Contract in the given transaction
func (c *Client) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, numL1TxUser uint16) (*eth.RollupForgeBatchArgs, *ethCommon.Address, error) {
func (c *Client) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, l1UserTxsLen uint16) (*eth.RollupForgeBatchArgs, *ethCommon.Address, error) {
c.rw.RLock() c.rw.RLock()
defer c.rw.RUnlock() defer c.rw.RUnlock()
@ -1518,8 +1520,8 @@ func (c *Client) WDelayerGetHermezGovernanceAddress() (*ethCommon.Address, error
return nil, tracerr.Wrap(errTODO) return nil, tracerr.Wrap(errTODO)
} }
// WDelayerSetHermezGovernanceAddress is the interface to call the smart contract function
func (c *Client) WDelayerSetHermezGovernanceAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerTransferGovernance is the interface to call the smart contract function
func (c *Client) WDelayerTransferGovernance(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
c.rw.Lock() c.rw.Lock()
defer c.rw.Unlock() defer c.rw.Unlock()
cpy := c.nextBlock().copy() cpy := c.nextBlock().copy()
@ -1532,17 +1534,8 @@ func (c *Client) WDelayerSetHermezGovernanceAddress(newAddress ethCommon.Address
return nil, tracerr.Wrap(errTODO) return nil, tracerr.Wrap(errTODO)
} }
// WDelayerGetHermezKeeperAddress is the interface to call the smart contract function
func (c *Client) WDelayerGetHermezKeeperAddress() (*ethCommon.Address, error) {
c.rw.RLock()
defer c.rw.RUnlock()
log.Error("TODO")
return nil, tracerr.Wrap(errTODO)
}
// WDelayerSetHermezKeeperAddress is the interface to call the smart contract function
func (c *Client) WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerClaimGovernance is the interface to call the smart contract function
func (c *Client) WDelayerClaimGovernance() (tx *types.Transaction, err error) {
c.rw.Lock() c.rw.Lock()
defer c.rw.Unlock() defer c.rw.Unlock()
cpy := c.nextBlock().copy() cpy := c.nextBlock().copy()
@ -1555,8 +1548,8 @@ func (c *Client) WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (t
return nil, tracerr.Wrap(errTODO) return nil, tracerr.Wrap(errTODO)
} }
// WDelayerGetWhiteHackGroupAddress is the interface to call the smart contract function
func (c *Client) WDelayerGetWhiteHackGroupAddress() (*ethCommon.Address, error) {
// WDelayerGetEmergencyCouncil is the interface to call the smart contract function
func (c *Client) WDelayerGetEmergencyCouncil() (*ethCommon.Address, error) {
c.rw.RLock() c.rw.RLock()
defer c.rw.RUnlock() defer c.rw.RUnlock()
@ -1564,8 +1557,22 @@ func (c *Client) WDelayerGetWhiteHackGroupAddress() (*ethCommon.Address, error)
return nil, tracerr.Wrap(errTODO) return nil, tracerr.Wrap(errTODO)
} }
// WDelayerSetWhiteHackGroupAddress is the interface to call the smart contract function
func (c *Client) WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerTransferEmergencyCouncil is the interface to call the smart contract function
func (c *Client) WDelayerTransferEmergencyCouncil(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
c.rw.Lock()
defer c.rw.Unlock()
cpy := c.nextBlock().copy()
defer func() { c.revertIfErr(err, cpy) }()
if c.addr == nil {
return nil, tracerr.Wrap(eth.ErrAccountNil)
}
log.Error("TODO")
return nil, tracerr.Wrap(errTODO)
}
// WDelayerClaimEmergencyCouncil is the interface to call the smart contract function
func (c *Client) WDelayerClaimEmergencyCouncil() (tx *types.Transaction, err error) {
c.rw.Lock() c.rw.Lock()
defer c.rw.Unlock() defer c.rw.Unlock()
cpy := c.nextBlock().copy() cpy := c.nextBlock().copy()

+ 2
- 1
test/ethclient_test.go

@ -235,7 +235,8 @@ func TestClientRollup(t *testing.T) {
rollupEvents, _, err = c.RollupEventsByBlock(blockNum) rollupEvents, _, err = c.RollupEventsByBlock(blockNum)
require.Nil(t, err) require.Nil(t, err)
rollupForgeBatchArgs1, sender, err := c.RollupForgeBatchArgs(rollupEvents.ForgeBatch[0].EthTxHash)
rollupForgeBatchArgs1, sender, err := c.RollupForgeBatchArgs(rollupEvents.ForgeBatch[0].EthTxHash,
rollupEvents.ForgeBatch[0].L1UserTxsLen)
require.Nil(t, err) require.Nil(t, err)
assert.Equal(t, *c.addr, *sender) assert.Equal(t, *c.addr, *sender)
assert.Equal(t, rollupForgeBatchArgs0, rollupForgeBatchArgs1) assert.Equal(t, rollupForgeBatchArgs0, rollupForgeBatchArgs1)

Loading…
Cancel
Save