Redo coordinator structure, connect API to node

- API:
	- Modify the constructor so that hardcoded rollup constants don't need
	  to be passed (introduce a `Config` and use `configAPI` internally)
- Common:
	- Update rollup constants with proper *big.Int when required
	- Add BidCoordinator and Slot structs used by the HistoryDB and
	  Synchronizer.
	- Add helper methods to AuctionConstants
	- AuctionVariables: Add column `DefaultSlotSetBidSlotNum` (in the SQL
	  table: `default_slot_set_bid_slot_num`), which indicates at which
	  slotNum does the `DefaultSlotSetBid` specified starts applying.
- Config:
	- Move coordinator exclusive configuration from the node config to the
	  coordinator config
- Coordinator:
	- Reorganize the code towards having the goroutines started and stopped
	  from the coordinator itself instead of the node.
	- Remove all stop and stopped channels, and use context.Context and
	  sync.WaitGroup instead.
	- Remove BatchInfo setters and assing variables directly
	- In ServerProof and ServerProofPool use context instead stop channel.
	- Use message passing to notify the coordinator about sync updates and
	  reorgs
	- Introduce the Pipeline, which can be started and stopped by the
	  Coordinator
	- Introduce the TxManager, which manages ethereum transactions (the
	  TxManager is also in charge of making the forge call to the rollup
	  smart contract).  The TxManager keeps ethereum transactions and:
	  	1. Waits for the transaction to be accepted
		2. Waits for the transaction to be confirmed for N blocks
	- In forge logic, first prepare a batch and then wait for an available
	  server proof to have all work ready once the proof server is ready.
	- Remove the `isForgeSequence` method which was querying the smart
	  contract, and instead use notifications sent by the Synchronizer to
	  figure out if it's forging time.
	- Update test (which is a minimal test to manually see if the
	  coordinator starts)
- HistoryDB:
	- Add method to get the number of batches in a slot (used to detect when
	  a slot has passed the bid winner forging deadline)
	- Add method to get the best bid and associated coordinator of a slot
	  (used to detect the forgerAddress that can forge the slot)
- General:
	- Rename some instances of `currentBlock` to `lastBlock` to be more
	  clear.
- Node:
	- Connect the API to the node and call the methods to update cached
	  state when the sync advances blocks.
	- Call methods to update Coordinator state when the sync advances blocks
	  and finds reorgs.
- Synchronizer:
	- Add Auction field in the Stats, which contain the current slot with
	  info about highest bidder and other related info required to know who
	  can forge in the current block.
	- Better organization of cached state:
		- On Sync, update the internal cached state
		- On Init or Reorg, load the state from HistoryDB into the
		  internal cached state.
This commit is contained in:
Eduard S
2020-11-13 18:11:58 +01:00
parent bf88eb60b8
commit 3b99953007
31 changed files with 1195 additions and 716 deletions

View File

@@ -71,7 +71,7 @@ func TestAuctionSetSlotDeadline(t *testing.T) {
slotDeadline, err := auctionClientTest.AuctionGetSlotDeadline()
require.Nil(t, err)
assert.Equal(t, newSlotDeadline, slotDeadline)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
assert.Equal(t, newSlotDeadline, auctionEvents.NewSlotDeadline[0].NewSlotDeadline)
}
@@ -90,7 +90,7 @@ func TestAuctionSetOpenAuctionSlots(t *testing.T) {
openAuctionSlots, err := auctionClientTest.AuctionGetOpenAuctionSlots()
require.Nil(t, err)
assert.Equal(t, newOpenAuctionSlots, openAuctionSlots)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
assert.Equal(t, newOpenAuctionSlots, auctionEvents.NewOpenAuctionSlots[0].NewOpenAuctionSlots)
}
@@ -109,7 +109,7 @@ func TestAuctionSetClosedAuctionSlots(t *testing.T) {
closedAuctionSlots, err := auctionClientTest.AuctionGetClosedAuctionSlots()
require.Nil(t, err)
assert.Equal(t, newClosedAuctionSlots, closedAuctionSlots)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
assert.Equal(t, newClosedAuctionSlots, auctionEvents.NewClosedAuctionSlots[0].NewClosedAuctionSlots)
_, err = auctionClientTest.AuctionSetClosedAuctionSlots(closedAuctionSlots)
@@ -130,7 +130,7 @@ func TestAuctionSetOutbidding(t *testing.T) {
outbidding, err := auctionClientTest.AuctionGetOutbidding()
require.Nil(t, err)
assert.Equal(t, newOutbidding, outbidding)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
assert.Equal(t, newOutbidding, auctionEvents.NewOutbidding[0].NewOutbidding)
_, err = auctionClientTest.AuctionSetOutbidding(outbiddingConst)
@@ -151,7 +151,7 @@ func TestAuctionSetAllocationRatio(t *testing.T) {
allocationRatio, err := auctionClientTest.AuctionGetAllocationRatio()
require.Nil(t, err)
assert.Equal(t, newAllocationRatio, allocationRatio)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
assert.Equal(t, newAllocationRatio, auctionEvents.NewAllocationRatio[0].NewAllocationRatio)
_, err = auctionClientTest.AuctionSetAllocationRatio(allocationRatioConst)
@@ -178,7 +178,7 @@ func TestAuctionSetDonationAddress(t *testing.T) {
donationAddress, err := auctionClientTest.AuctionGetDonationAddress()
require.Nil(t, err)
assert.Equal(t, &newDonationAddress, donationAddress)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
assert.Equal(t, newDonationAddress, auctionEvents.NewDonationAddress[0].NewDonationAddress)
_, err = auctionClientTest.AuctionSetDonationAddress(donationAddressConst)
@@ -193,7 +193,7 @@ func TestAuctionSetBootCoordinator(t *testing.T) {
bootCoordinator, err := auctionClientTest.AuctionGetBootCoordinator()
require.Nil(t, err)
assert.Equal(t, &newBootCoordinator, bootCoordinator)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
assert.Equal(t, newBootCoordinator, auctionEvents.NewBootCoordinator[0].NewBootCoordinator)
_, err = auctionClientTest.AuctionSetBootCoordinator(bootCoordinatorAddressConst)
@@ -227,7 +227,7 @@ func TestAuctionChangeDefaultSlotSetBid(t *testing.T) {
minBid, err := auctionClientTest.AuctionGetDefaultSlotSetBid(set)
require.Nil(t, err)
assert.Equal(t, minBid, newInitialMinBid)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
assert.Equal(t, slotSet, auctionEvents.NewDefaultSlotSetBid[0].SlotSet)
assert.Equal(t, newInitialMinBid, auctionEvents.NewDefaultSlotSetBid[0].NewInitialMinBid)
@@ -251,7 +251,7 @@ func TestAuctionRegisterCoordinator(t *testing.T) {
_, err := auctionClientTest.AuctionSetCoordinator(forgerAddress, URL)
require.Nil(t, err)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
assert.Equal(t, forgerAddress, auctionEvents.SetCoordinator[0].ForgerAddress)
assert.Equal(t, bidderAddress, auctionEvents.SetCoordinator[0].BidderAddress)
@@ -268,7 +268,7 @@ func TestAuctionBid(t *testing.T) {
bidderAddress := governanceAddressConst
_, err = auctionClientTest.AuctionBid(amount, currentSlot+4, bidAmount, deadline)
require.Nil(t, err)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
assert.Equal(t, bidAmount, auctionEvents.NewBid[0].BidAmount)
assert.Equal(t, bidderAddress, auctionEvents.NewBid[0].Bidder)
@@ -306,7 +306,7 @@ func TestAuctionMultiBid(t *testing.T) {
bidderAddress := governanceAddressConst
_, err = auctionClientTest.AuctionMultiBid(budget, currentSlot+4, currentSlot+10, slotSet, maxBid, minBid, deadline)
require.Nil(t, err)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
assert.Equal(t, bidderAddress, auctionEvents.NewBid[0].Bidder)
assert.Equal(t, currentSlot+4, auctionEvents.NewBid[0].Slot)
@@ -334,7 +334,7 @@ func TestAuctionClaimHEZ(t *testing.T) {
_, err := auctionClientTest.AuctionClaimHEZ()
require.Nil(t, err)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
assert.Equal(t, amount, auctionEvents.HEZClaimed[0].Amount)
assert.Equal(t, governanceAddressConst, auctionEvents.HEZClaimed[0].Owner)
@@ -345,10 +345,10 @@ func TestAuctionForge(t *testing.T) {
require.Nil(t, err)
slotConst := 4
blockNum := int64(int(blocksPerSlot)*slotConst + int(genesisBlock))
currentBlockNum, _ := auctionClientTestHermez.client.EthCurrentBlock()
currentBlockNum, _ := auctionClientTestHermez.client.EthLastBlock()
blocksToAdd := blockNum - currentBlockNum
addBlocks(blocksToAdd, ethClientDialURL)
currentBlockNum, _ = auctionClientTestHermez.client.EthCurrentBlock()
currentBlockNum, _ = auctionClientTestHermez.client.EthLastBlock()
assert.Equal(t, currentBlockNum, blockNum)
_, err = auctionClientTestHermez.AuctionForge(governanceAddressConst)
require.Nil(t, err)

View File

@@ -26,7 +26,7 @@ type ERC20Consts struct {
// EthereumInterface is the interface to Ethereum
type EthereumInterface interface {
EthCurrentBlock() (int64, error)
EthLastBlock() (int64, error)
// EthHeaderByNumber(context.Context, *big.Int) (*types.Header, error)
EthBlockByNumber(context.Context, int64) (*common.Block, error)
EthAddress() (*ethCommon.Address, error)
@@ -241,8 +241,8 @@ func (c *EthereumClient) waitReceipt(ctx context.Context, tx *types.Transaction,
return receipt, err
}
// EthCurrentBlock returns the current block number in the blockchain
func (c *EthereumClient) EthCurrentBlock() (int64, error) {
// EthLastBlock returns the last block number in the blockchain
func (c *EthereumClient) EthLastBlock() (int64, error) {
ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Second)
defer cancel()
header, err := c.client.HeaderByNumber(ctx, nil)

View File

@@ -77,7 +77,7 @@ func TestRollupAddToken(t *testing.T) {
require.Nil(t, err)
_, err = rollupClient.RollupAddToken(tokenHEZAddressConst, feeAddToken, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, tokenHEZAddressConst, rollupEvents.AddToken[0].TokenAddress)
@@ -106,7 +106,7 @@ func TestRollupForgeBatch(t *testing.T) {
// Add Blocks
blockNum := int64(int(blocksPerSlot)*int(currentSlot+4) + int(genesisBlock))
currentBlockNum, _ := auctionClient.client.EthCurrentBlock()
currentBlockNum, _ := auctionClient.client.EthLastBlock()
blocksToAdd := blockNum - currentBlockNum
addBlocks(blocksToAdd, ethClientDialURL)
@@ -155,7 +155,7 @@ func TestRollupForgeBatch(t *testing.T) {
_, err = rollupClient.RollupForgeBatch(argsForge)
require.Nil(t, err)
currentBlockNum, _ = rollupClient.client.EthCurrentBlock()
currentBlockNum, _ = rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, int64(1), rollupEvents.ForgeBatch[0].BatchNum)
@@ -181,7 +181,7 @@ func TestRollupUpdateForgeL1L2BatchTimeout(t *testing.T) {
_, err := rollupClient.RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, newForgeL1L2BatchTimeout, rollupEvents.UpdateForgeL1L2BatchTimeout[0].NewForgeL1L2BatchTimeout)
@@ -192,7 +192,7 @@ func TestRollupUpdateFeeAddToken(t *testing.T) {
_, err := rollupClient.RollupUpdateFeeAddToken(newFeeAddToken)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, newFeeAddToken, rollupEvents.UpdateFeeAddToken[0].NewFeeAddToken)
@@ -217,7 +217,7 @@ func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -245,7 +245,7 @@ func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -273,7 +273,7 @@ func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) {
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -302,7 +302,7 @@ func TestRollupL1UserTxETHDeposit(t *testing.T) {
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -330,7 +330,7 @@ func TestRollupL1UserTxERC20Deposit(t *testing.T) {
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -358,7 +358,7 @@ func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -387,7 +387,7 @@ func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -415,7 +415,7 @@ func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -443,7 +443,7 @@ func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -472,7 +472,7 @@ func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -500,7 +500,7 @@ func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -528,7 +528,7 @@ func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -557,7 +557,7 @@ func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -585,7 +585,7 @@ func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -613,7 +613,7 @@ func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -642,7 +642,7 @@ func TestRollupL1UserTxETHForceExit(t *testing.T) {
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDUint32, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -670,7 +670,7 @@ func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -700,7 +700,7 @@ func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, l1Tx.FromBJJ, rollupEvents.L1UserTx[0].L1UserTx.FromBJJ)
assert.Equal(t, l1Tx.ToIdx, rollupEvents.L1UserTx[0].L1UserTx.ToIdx)
@@ -748,7 +748,7 @@ func TestRollupForgeBatch2(t *testing.T) {
_, err = rollupClient.RollupForgeBatch(argsForge)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, int64(2), rollupEvents.ForgeBatch[0].BatchNum)
@@ -787,7 +787,7 @@ func TestRollupWithdrawMerkleProof(t *testing.T) {
_, err = rollupClientAux.RollupWithdrawMerkleProof(pk, tokenID, numExitRoot, fromIdx, amount, siblings, instantWithdraw)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
currentBlockNum, _ := rollupClient.client.EthLastBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, uint64(fromIdx), rollupEvents.Withdraw[0].Idx)

View File

@@ -41,7 +41,7 @@ func TestWDelayerSetHermezGovernanceDAOAddress(t *testing.T) {
auxAddress, err := wdelayerClientTest.WDelayerGetHermezGovernanceDAOAddress()
require.Nil(t, err)
assert.Equal(t, &auxAddressConst, auxAddress)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
currentBlockNum, _ := wdelayerClientTest.client.EthLastBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewHermezGovernanceDAOAddress[0].NewHermezGovernanceDAOAddress)
wdelayerClientAux, err := NewWDelayerClient(ethereumClientAux, wdelayerTestAddressConst)
@@ -64,7 +64,7 @@ func TestWDelayerSetHermezKeeperAddress(t *testing.T) {
auxAddress, err := wdelayerClientTest.WDelayerGetHermezKeeperAddress()
require.Nil(t, err)
assert.Equal(t, &auxAddressConst, auxAddress)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
currentBlockNum, _ := wdelayerClientTest.client.EthLastBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewHermezKeeperAddress[0].NewHermezKeeperAddress)
wdelayerClientAux, err := NewWDelayerClient(ethereumClientAux, wdelayerTestAddressConst)
@@ -87,7 +87,7 @@ func TestWDelayerSetWhiteHackGroupAddress(t *testing.T) {
auxAddress, err := wdelayerClientTest.WDelayerGetWhiteHackGroupAddress()
require.Nil(t, err)
assert.Equal(t, &auxAddressConst, auxAddress)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
currentBlockNum, _ := wdelayerClientTest.client.EthLastBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewWhiteHackGroupAddress[0].NewWhiteHackGroupAddress)
wdelayerClientAux, err := NewWDelayerClient(ethereumClientAux, wdelayerTestAddressConst)
@@ -116,7 +116,7 @@ func TestWDelayerChangeWithdrawalDelay(t *testing.T) {
withdrawalDelay, err := wdelayerClientTest.WDelayerGetWithdrawalDelay()
require.Nil(t, err)
assert.Equal(t, newWithdrawalDelay, withdrawalDelay)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
currentBlockNum, _ := wdelayerClientTest.client.EthLastBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
assert.Equal(t, newWithdrawalDelay.Uint64(), wdelayerEvents.NewWithdrawalDelay[0].WithdrawalDelay)
}
@@ -128,7 +128,7 @@ func TestWDelayerDeposit(t *testing.T) {
require.Nil(t, err)
_, err = wdelayerClientHermez.WDelayerDeposit(auxAddressConst, tokenHEZAddressConst, amount)
require.Nil(t, err)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
currentBlockNum, _ := wdelayerClientTest.client.EthLastBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
assert.Equal(t, amount, wdelayerEvents.Deposit[0].Amount)
assert.Equal(t, auxAddressConst, wdelayerEvents.Deposit[0].Owner)
@@ -152,7 +152,7 @@ func TestWDelayerWithdrawal(t *testing.T) {
addBlock(ethClientDialURL)
_, err = wdelayerClientTest.WDelayerWithdrawal(auxAddressConst, tokenHEZAddressConst)
require.Nil(t, err)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
currentBlockNum, _ := wdelayerClientTest.client.EthLastBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
assert.Equal(t, amount, wdelayerEvents.Withdraw[0].Amount)
assert.Equal(t, auxAddressConst, wdelayerEvents.Withdraw[0].Owner)
@@ -166,7 +166,7 @@ func TestWDelayerSecondDeposit(t *testing.T) {
require.Nil(t, err)
_, err = wdelayerClientHermez.WDelayerDeposit(auxAddressConst, tokenHEZAddressConst, amount)
require.Nil(t, err)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
currentBlockNum, _ := wdelayerClientTest.client.EthLastBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
assert.Equal(t, amount, wdelayerEvents.Deposit[0].Amount)
assert.Equal(t, auxAddressConst, wdelayerEvents.Deposit[0].Owner)
@@ -181,7 +181,7 @@ func TestWDelayerEnableEmergencyMode(t *testing.T) {
emergencyMode, err := wdelayerClientTest.WDelayerIsEmergencyMode()
require.Nil(t, err)
assert.Equal(t, true, emergencyMode)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
currentBlockNum, _ := wdelayerClientTest.client.EthLastBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
auxEvent := new(WDelayerEventEmergencyModeEnabled)
assert.Equal(t, auxEvent, &wdelayerEvents.EmergencyModeEnabled[0])
@@ -208,7 +208,7 @@ func TestWDelayerEscapeHatchWithdrawal(t *testing.T) {
addTime(seconds, ethClientDialURL)
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
require.Nil(t, err)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
currentBlockNum, _ := wdelayerClientTest.client.EthLastBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
assert.Equal(t, tokenHEZAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].Token)
assert.Equal(t, governanceAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].To)