Skip to content

Commit

Permalink
fix mock expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
christophercampbell committed Apr 10, 2024
1 parent 60c2d24 commit 5b956c5
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions synchronizer/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -131,57 +131,53 @@ 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,
})
})

t.Run("BeginStateTransaction fails", func(t *testing.T) {
t.Parallel()

block := ethTypes.NewBlockWithHeader(&ethTypes.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(&ethTypes.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(&ethTypes.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(&ethTypes.Header{
Number: big.NewInt(0),
}).Header(), nil},
isErrorExpected: true,
})
})

t.Run("Commit fails", func(t *testing.T) {
t.Parallel()

testFn(t, testConfig{
blockByNumberArgs: []interface{}{mock.Anything, mock.Anything},
blockByNumberReturns: []interface{}{ethTypes.NewBlockWithHeader(&ethTypes.Header{
headerByNumberArgs: []interface{}{mock.Anything, mock.Anything},
headerByNumberReturns: []interface{}{ethTypes.NewBlockWithHeader(&ethTypes.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},
Expand All @@ -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(&ethTypes.Header{
headerByNumberArgs: []interface{}{mock.Anything, mock.Anything},
headerByNumberReturns: []interface{}{ethTypes.NewBlockWithHeader(&ethTypes.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)},
Expand Down

0 comments on commit 5b956c5

Please sign in to comment.