Skip to content

Commit

Permalink
fix: unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Aug 22, 2024
1 parent a5e7d16 commit 6b33ded
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions synchronizer/synchronizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestGivenPermissionlessNodeWhenSyncronizeFirstTimeABatchThenStoreItInALocal
// but it used a feature that is not implemented in new one that is asking beyond the last block on L1
func TestForcedBatchEtrog(t *testing.T) {
genesis := state.Genesis{
RollupBlockNumber: uint64(123456),
RollupBlockNumber: uint64(0),
}
cfg := Config{
SyncInterval: cfgTypes.Duration{Duration: 1 * time.Second},
Expand All @@ -147,24 +147,33 @@ func TestForcedBatchEtrog(t *testing.T) {
ToBatchNumber: ^uint64(0),
}
m.State.EXPECT().GetForkIDInMemory(uint64(7)).Return(&forkIdInterval)
parentHash := common.HexToHash("0x111")
ethHeader := &ethTypes.Header{Number: big.NewInt(1), ParentHash: parentHash}
ethBlock := ethTypes.NewBlockWithHeader(ethHeader)
lastBlock := &state.Block{BlockHash: ethBlock.Hash(), BlockNumber: ethBlock.Number().Uint64(), ParentHash: ethBlock.ParentHash()}

m.State.
On("GetLastBlock", mock.Anything, nil).
Return(lastBlock, nil).
Once()
m.State.
On("BeginStateTransaction", ctxMatchBy).
Run(func(args mock.Arguments) {
ctx := args[0].(context.Context)
parentHash := common.HexToHash("0x111")
ethHeader := &ethTypes.Header{Number: big.NewInt(1), ParentHash: parentHash}
ethBlock := ethTypes.NewBlockWithHeader(ethHeader)
lastBlock := &state.Block{BlockHash: ethBlock.Hash(), BlockNumber: ethBlock.Number().Uint64()}
lastBlock := &state.Block{BlockHash: ethBlock.Hash(), BlockNumber: ethBlock.Number().Uint64(), ParentHash: ethBlock.ParentHash()}

m.State.
On("GetForkIDByBatchNumber", mock.Anything).
Return(uint64(7), nil).
Maybe()

m.State.
On("GetLastBlock", ctx, m.DbTx).
Return(lastBlock, nil).
Once()
Maybe()

m.State.
On("GetLastBatchNumber", ctx, m.DbTx).
Expand Down Expand Up @@ -377,7 +386,7 @@ func TestForcedBatchEtrog(t *testing.T) {
// but it used a feature that is not implemented in new one that is asking beyond the last block on L1
func TestSequenceForcedBatchIncaberry(t *testing.T) {
genesis := state.Genesis{
RollupBlockNumber: uint64(123456),
RollupBlockNumber: uint64(0),
}
cfg := Config{
SyncInterval: cfgTypes.Duration{Duration: 1 * time.Second},
Expand All @@ -396,7 +405,14 @@ func TestSequenceForcedBatchIncaberry(t *testing.T) {
ethermanForL1 := []syncinterfaces.EthermanFullInterface{m.Etherman}
sync, err := NewSynchronizer(true, m.Etherman, ethermanForL1, m.State, m.Pool, m.EthTxManager, m.ZKEVMClient, nil, genesis, cfg, false)
require.NoError(t, err)

parentHash := common.HexToHash("0x111")
ethHeader := &ethTypes.Header{Number: big.NewInt(1), ParentHash: parentHash}
ethBlock := ethTypes.NewBlockWithHeader(ethHeader)
lastBlock := &state.Block{BlockHash: ethBlock.Hash(), BlockNumber: ethBlock.Number().Uint64(), ParentHash: ethBlock.ParentHash()}
m.State.
On("GetLastBlock", mock.Anything, nil).
Return(lastBlock, nil).
Once()
// state preparation
ctxMatchBy := mock.MatchedBy(func(ctx context.Context) bool { return ctx != nil })
m.State.
Expand All @@ -406,7 +422,7 @@ func TestSequenceForcedBatchIncaberry(t *testing.T) {
parentHash := common.HexToHash("0x111")
ethHeader := &ethTypes.Header{Number: big.NewInt(1), ParentHash: parentHash}
ethBlock := ethTypes.NewBlockWithHeader(ethHeader)
lastBlock := &state.Block{BlockHash: ethBlock.Hash(), BlockNumber: ethBlock.Number().Uint64()}
lastBlock := &state.Block{BlockHash: ethBlock.Hash(), BlockNumber: ethBlock.Number().Uint64(), ParentHash: ethBlock.ParentHash()}
m.State.
On("GetForkIDByBatchNumber", mock.Anything).
Return(uint64(1), nil).
Expand All @@ -416,11 +432,6 @@ func TestSequenceForcedBatchIncaberry(t *testing.T) {
Return(uint64(1), nil).
Maybe()

m.State.
On("GetLastBlock", ctx, m.DbTx).
Return(lastBlock, nil).
Once()

m.State.
On("GetLastBatchNumber", ctx, m.DbTx).
Return(uint64(10), nil).
Expand Down

0 comments on commit 6b33ded

Please sign in to comment.