From 76e1aa74230c44db911f395adeaef3c2b7c9321a Mon Sep 17 00:00:00 2001 From: Christopher Campbell Date: Wed, 10 Apr 2024 10:18:33 -0400 Subject: [PATCH 1/3] use header rather than block to get latest number during init --- synchronizer/init.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synchronizer/init.go b/synchronizer/init.go index 7fad7eaa..71df83c4 100644 --- a/synchronizer/init.go +++ b/synchronizer/init.go @@ -45,11 +45,11 @@ func InitStartBlock(db db.DB, em etherman.Etherman, genesisBlock uint64, validiu } func findContractDeploymentBlock(ctx context.Context, em etherman.Etherman, contract common.Address) (*big.Int, error) { - latestBlock, err := em.BlockByNumber(ctx, nil) + latestHeader, err := em.HeaderByNumber(ctx, nil) if err != nil { return nil, err } - firstBlock := findCode(ctx, em, contract, 0, latestBlock.Number().Int64()) + firstBlock := findCode(ctx, em, contract, 0, latestHeader.Number.Int64()) return big.NewInt(firstBlock), nil } From 60c2d24dd6eaa22cacd7c656ca34afcb7a02aa73 Mon Sep 17 00:00:00 2001 From: Christopher Campbell Date: Wed, 10 Apr 2024 10:23:25 -0400 Subject: [PATCH 2/3] fix test --- synchronizer/init_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synchronizer/init_test.go b/synchronizer/init_test.go index 8a3b34bb..9da0abbc 100644 --- a/synchronizer/init_test.go +++ b/synchronizer/init_test.go @@ -78,7 +78,7 @@ func Test_InitStartBlock(t *testing.T) { } if config.blockByNumberArgs != nil && config.blockByNumberReturns != nil { - emMock.On("BlockByNumber", config.blockByNumberArgs...).Return( + emMock.On("HeaderByNumber", config.blockByNumberArgs...).Return( config.blockByNumberReturns...).Once() } From 5b956c5108946eab4eeb8115ada926b2fb941979 Mon Sep 17 00:00:00 2001 From: Christopher Campbell Date: Wed, 10 Apr 2024 11:26:43 -0400 Subject: [PATCH 3/3] fix mock expectations --- synchronizer/init_test.go | 54 ++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/synchronizer/init_test.go b/synchronizer/init_test.go index 9da0abbc..3b71c063 100644 --- a/synchronizer/init_test.go +++ b/synchronizer/init_test.go @@ -28,10 +28,10 @@ func Test_InitStartBlock(t *testing.T) { storeLastProcessedBlockReturns []interface{} commitReturns []interface{} // eth client mocks - blockByNumberArgs []interface{} - blockByNumberReturns []interface{} - codeAtArgs [][]interface{} - codeAtReturns [][]interface{} + headerByNumberArgs []interface{} + headerByNumberReturns []interface{} + codeAtArgs [][]interface{} + codeAtReturns [][]interface{} isErrorExpected bool } @@ -77,9 +77,9 @@ func Test_InitStartBlock(t *testing.T) { returnArgs...).Once() } - if config.blockByNumberArgs != nil && config.blockByNumberReturns != nil { - emMock.On("HeaderByNumber", config.blockByNumberArgs...).Return( - config.blockByNumberReturns...).Once() + if config.headerByNumberArgs != nil && config.headerByNumberReturns != nil { + emMock.On("HeaderByNumber", config.headerByNumberArgs...).Return( + config.headerByNumberReturns...).Once() } if config.codeAtArgs != nil && config.codeAtReturns != nil { @@ -131,8 +131,8 @@ func Test_InitStartBlock(t *testing.T) { testFn(t, testConfig{ getLastProcessedBlockArgs: []interface{}{mock.Anything, L1SyncTask}, getLastProcessedBlockReturns: []interface{}{uint64(0), nil}, - blockByNumberArgs: []interface{}{mock.Anything, mock.Anything}, - blockByNumberReturns: []interface{}{nil, errors.New("error")}, + headerByNumberArgs: []interface{}{mock.Anything, mock.Anything}, + headerByNumberReturns: []interface{}{nil, errors.New("error")}, isErrorExpected: true, }) }) @@ -140,37 +140,33 @@ func Test_InitStartBlock(t *testing.T) { t.Run("BeginStateTransaction fails", func(t *testing.T) { t.Parallel() - block := ethTypes.NewBlockWithHeader(ðTypes.Header{ - Number: big.NewInt(0), - }) - testFn(t, testConfig{ getLastProcessedBlockArgs: []interface{}{mock.Anything, L1SyncTask}, getLastProcessedBlockReturns: []interface{}{uint64(0), nil}, beginStateTransactionArgs: []interface{}{mock.Anything}, beginStateTransactionReturns: []interface{}{nil, errors.New("error")}, - blockByNumberArgs: []interface{}{mock.Anything, mock.Anything}, - blockByNumberReturns: []interface{}{block, nil}, - isErrorExpected: true, + headerByNumberArgs: []interface{}{mock.Anything, mock.Anything}, + headerByNumberReturns: []interface{}{ethTypes.NewBlockWithHeader(ðTypes.Header{ + Number: big.NewInt(0), + }).Header(), nil}, + isErrorExpected: true, }) }) t.Run("Store off-chain data fails", func(t *testing.T) { t.Parallel() - block := ethTypes.NewBlockWithHeader(ðTypes.Header{ - Number: big.NewInt(0), - }) - testFn(t, testConfig{ getLastProcessedBlockArgs: []interface{}{mock.Anything, L1SyncTask}, getLastProcessedBlockReturns: []interface{}{uint64(0), nil}, beginStateTransactionArgs: []interface{}{mock.Anything}, storeLastProcessedBlockArgs: []interface{}{mock.Anything, L1SyncTask, uint64(0), mock.Anything}, storeLastProcessedBlockReturns: []interface{}{errors.New("error")}, - blockByNumberArgs: []interface{}{mock.Anything, mock.Anything}, - blockByNumberReturns: []interface{}{block, nil}, - isErrorExpected: true, + headerByNumberArgs: []interface{}{mock.Anything, mock.Anything}, + headerByNumberReturns: []interface{}{ethTypes.NewBlockWithHeader(ðTypes.Header{ + Number: big.NewInt(0), + }).Header(), nil}, + isErrorExpected: true, }) }) @@ -178,10 +174,10 @@ func Test_InitStartBlock(t *testing.T) { t.Parallel() testFn(t, testConfig{ - blockByNumberArgs: []interface{}{mock.Anything, mock.Anything}, - blockByNumberReturns: []interface{}{ethTypes.NewBlockWithHeader(ðTypes.Header{ + headerByNumberArgs: []interface{}{mock.Anything, mock.Anything}, + headerByNumberReturns: []interface{}{ethTypes.NewBlockWithHeader(ðTypes.Header{ Number: big.NewInt(0), - }), nil}, + }).Header(), nil}, getLastProcessedBlockArgs: []interface{}{mock.Anything, L1SyncTask}, getLastProcessedBlockReturns: []interface{}{uint64(0), nil}, storeLastProcessedBlockArgs: []interface{}{mock.Anything, L1SyncTask, uint64(0), mock.Anything}, @@ -203,10 +199,10 @@ func Test_InitStartBlock(t *testing.T) { storeLastProcessedBlockArgs: []interface{}{mock.Anything, L1SyncTask, uint64(2), mock.Anything}, storeLastProcessedBlockReturns: []interface{}{nil}, commitReturns: []interface{}{nil}, - blockByNumberArgs: []interface{}{mock.Anything, mock.Anything}, - blockByNumberReturns: []interface{}{ethTypes.NewBlockWithHeader(ðTypes.Header{ + headerByNumberArgs: []interface{}{mock.Anything, mock.Anything}, + headerByNumberReturns: []interface{}{ethTypes.NewBlockWithHeader(ðTypes.Header{ Number: big.NewInt(3), - }), nil}, + }).Header(), nil}, codeAtArgs: [][]interface{}{ {mock.Anything, common.HexToAddress(l1Config.PolygonValidiumAddress), big.NewInt(1)}, {mock.Anything, common.HexToAddress(l1Config.PolygonValidiumAddress), big.NewInt(2)},