Skip to content

Commit

Permalink
fix TestReorg
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak committed Aug 13, 2024
1 parent c8c79c9 commit 98a4f34
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions miner/scroll_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,9 +1051,7 @@ func TestReorg(t *testing.T) {

// This test chain imports the mined blocks.
b.genesis.MustCommit(db)
chain, _ := core.NewBlockChain(db, nil, b.chain.Config(), engine, vm.Config{
Debug: true,
Tracer: vm.NewStructLogger(&vm.LogConfig{EnableMemory: true, EnableReturnData: true})}, nil, nil)
chain, _ := core.NewBlockChain(db, nil, b.chain.Config(), engine, vm.Config{}, nil, nil)
defer chain.Stop()

// Insert local tx
Expand Down Expand Up @@ -1093,13 +1091,53 @@ firstReorg:
}

require.Equal(t, oldBlock.NumberU64(), newBlock.NumberU64())
require.Equal(t, oldBlock.Transactions()[:1], newBlock.Transactions())
// should skip second txn
require.Equal(t, oldBlock.Transactions()[:1].Len(), newBlock.Transactions().Len())
for i := 0; i < newBlock.Transactions().Len(); i++ {
require.Equal(t, oldBlock.Transactions()[:1][i].Hash(), newBlock.Transactions()[i].Hash())
}

time.Sleep(time.Second * 5)

const secondReorgHeight = 15
w.asyncChecker.ScheduleError(secondReorgHeight, 0)

sub.Unsubscribe()

w.asyncChecker.ScheduleError(25, 1)
// Insert local tx
for i := 0; i < 40; i++ {
for i := 0; i < 20; i++ {
b.txPool.AddLocal(b.newRandomTx(true))
}
time.Sleep(time.Second * 5)

// resubscribe
sub = w.mux.Subscribe(core.NewMinedBlockEvent{})
defer sub.Unsubscribe()

oldBlock = nil
newBlock = nil

secondReorg:
for {
select {
case ev := <-sub.Chan():
block := ev.Data.(core.NewMinedBlockEvent).Block
if block.NumberU64() == secondReorgHeight {
if oldBlock == nil {
oldBlock = block
} else {
newBlock = block
break secondReorg
}
}
case <-time.After(3 * time.Second): // Worker needs 1s to include new changes.
t.Fatalf("timeout")
}
}

require.Equal(t, oldBlock.NumberU64(), newBlock.NumberU64())
// should skip first txn and the next txn will fail nonce check
require.Equal(t, 0, newBlock.Transactions().Len())
for i := 0; i < newBlock.Transactions().Len(); i++ {
require.Equal(t, oldBlock.Transactions()[1:][i].Hash(), newBlock.Transactions()[i].Hash())
}
}

0 comments on commit 98a4f34

Please # to comment.