Commit 7037cc6c authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge pull request #3751 from ethereum-optimism/jg/unit_test_for_reset_bug

op-node: Reset bug unit test
parents 438d3dab eb9b6f53
...@@ -72,6 +72,66 @@ func L1Chain(l1Times []uint64) []eth.L1BlockRef { ...@@ -72,6 +72,66 @@ func L1Chain(l1Times []uint64) []eth.L1BlockRef {
return out return out
} }
// TestBatchQueueNewOrigin tests that the batch queue properly saves the new origin
// when the safehead's origin is ahead of the pipeline's origin (as is after a reset).
// This issue was fixed in https://github.com/ethereum-optimism/optimism/pull/3694
func TestBatchQueueNewOrigin(t *testing.T) {
log := testlog.Logger(t, log.LvlCrit)
l1 := L1Chain([]uint64{10, 15, 20, 25})
safeHead := eth.L2BlockRef{
Hash: mockHash(10, 2),
Number: 0,
ParentHash: common.Hash{},
Time: 20,
L1Origin: l1[2].ID(),
SequenceNumber: 0,
}
cfg := &rollup.Config{
Genesis: rollup.Genesis{
L2Time: 10,
},
BlockTime: 2,
MaxSequencerDrift: 600,
SeqWindowSize: 2,
}
input := &fakeBatchQueueInput{
batches: []*BatchData{nil},
errors: []error{io.EOF},
origin: l1[0],
}
bq := NewBatchQueue(log, cfg, input)
_ = bq.Reset(context.Background(), l1[0])
require.Equal(t, []eth.L1BlockRef{l1[0]}, bq.l1Blocks)
// Prev Origin: 0; Safehead Origin: 2; Internal Origin: 0
// Should return no data but keep the same origin
data, err := bq.NextBatch(context.Background(), safeHead)
require.Nil(t, data)
require.Equal(t, io.EOF, err)
require.Equal(t, []eth.L1BlockRef{l1[0]}, bq.l1Blocks)
require.Equal(t, l1[0], bq.origin)
// Prev Origin: 1; Safehead Origin: 2; Internal Origin: 0
// Should wipe l1blocks + advance internal origin
input.origin = l1[1]
data, err = bq.NextBatch(context.Background(), safeHead)
require.Nil(t, data)
require.Equal(t, io.EOF, err)
require.Empty(t, bq.l1Blocks)
require.Equal(t, l1[1], bq.origin)
// Prev Origin: 2; Safehead Origin: 2; Internal Origin: 1
// Should add to l1Blocks + advance internal origin
input.origin = l1[2]
data, err = bq.NextBatch(context.Background(), safeHead)
require.Nil(t, data)
require.Equal(t, io.EOF, err)
require.Equal(t, []eth.L1BlockRef{l1[2]}, bq.l1Blocks)
require.Equal(t, l1[2], bq.origin)
}
// TestBatchQueueEager adds a bunch of contiguous batches and asserts that // TestBatchQueueEager adds a bunch of contiguous batches and asserts that
// enough calls to `NextBatch` return all of those batches. // enough calls to `NextBatch` return all of those batches.
func TestBatchQueueEager(t *testing.T) { func TestBatchQueueEager(t *testing.T) {
...@@ -205,5 +265,4 @@ func TestBatchQueueMissing(t *testing.T) { ...@@ -205,5 +265,4 @@ func TestBatchQueueMissing(t *testing.T) {
require.Equal(t, b.Timestamp, uint64(18)) require.Equal(t, b.Timestamp, uint64(18))
require.Empty(t, b.BatchV1.Transactions) require.Empty(t, b.BatchV1.Transactions)
require.Equal(t, rollup.Epoch(1), b.EpochNum) require.Equal(t, rollup.Epoch(1), b.EpochNum)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment