Skip to content

Commit c761301

Browse files
committed
test: properly test tx precedence
1 parent cdadf80 commit c761301

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

sequencers/single/sequencer_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,10 @@ func TestSequencer_GetNextBatch_AlwaysCheckPendingForcedInclusion(t *testing.T)
624624

625625
mockFI := &MockForcedInclusionRetriever{}
626626

627-
// First call returns a large forced tx that gets deferred
628-
largeForcedTx := make([]byte, 150)
627+
// First call returns a large forced tx that will get evicted
628+
largeForcedTx1, largeForcedTx2 := make([]byte, 75), make([]byte, 75)
629629
mockFI.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
630-
Txs: [][]byte{largeForcedTx},
630+
Txs: [][]byte{largeForcedTx1, largeForcedTx2},
631631
StartDaHeight: 100,
632632
EndDaHeight: 100,
633633
}, nil).Once()
@@ -671,23 +671,22 @@ func TestSequencer_GetNextBatch_AlwaysCheckPendingForcedInclusion(t *testing.T)
671671
require.NoError(t, err)
672672

673673
// First call with maxBytes = 100
674-
// Large forced tx (150 bytes) won't fit, gets deferred
675-
// Batch tx (50 bytes) should be returned
676674
getReq := coresequencer.GetNextBatchRequest{
677675
Id: []byte("test-chain"),
678-
MaxBytes: 100,
676+
MaxBytes: 125,
679677
LastBatchData: nil,
680678
}
681679

682680
resp, err := seq.GetNextBatch(ctx, getReq)
683681
require.NoError(t, err)
684682
require.NotNil(t, resp.Batch)
685-
assert.Equal(t, 1, len(resp.Batch.Transactions), "Should have batch tx only")
686-
assert.Equal(t, 50, len(resp.Batch.Transactions[0]))
683+
assert.Equal(t, 2, len(resp.Batch.Transactions), "Should have 1 batch tx + 1 forced tx")
684+
assert.Equal(t, 75, len(resp.Batch.Transactions[0])) // forced tx is 75 bytes
685+
assert.Equal(t, 50, len(resp.Batch.Transactions[1])) // batch tx is 50 bytes
687686

688687
// Verify checkpoint shows no forced tx was consumed (tx too large)
689-
assert.Equal(t, uint64(0), seq.checkpoint.TxIndex, "No forced tx should be consumed yet")
690-
assert.Equal(t, 1, len(seq.cachedForcedInclusionTxs), "Forced tx should still be cached")
688+
assert.Equal(t, uint64(1), seq.checkpoint.TxIndex, "Only one forced tx should be consumed")
689+
assert.Greater(t, len(seq.cachedForcedInclusionTxs), 1, "Remaining forced tx should still be cached")
691690

692691
// Second call with larger maxBytes = 200
693692
// Should process pending forced tx first
@@ -701,7 +700,7 @@ func TestSequencer_GetNextBatch_AlwaysCheckPendingForcedInclusion(t *testing.T)
701700
require.NoError(t, err)
702701
require.NotNil(t, resp2.Batch)
703702
assert.Equal(t, 1, len(resp2.Batch.Transactions), "Should include pending forced tx")
704-
assert.Equal(t, 150, len(resp2.Batch.Transactions[0]))
703+
assert.Equal(t, 75, len(resp2.Batch.Transactions[0]))
705704

706705
// Checkpoint should reflect that forced tx was consumed
707706
assert.Equal(t, uint64(101), seq.checkpoint.DAHeight, "Should have moved to next DA height")

types/epoch_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ func TestCalculateEpochNumber(t *testing.T) {
9191
daHeight: 105,
9292
expectedEpoch: 6,
9393
},
94+
{
95+
name: "epoch size 0",
96+
daStartHeight: 100,
97+
daEpochSize: 0,
98+
daHeight: 105,
99+
expectedEpoch: 1,
100+
},
94101
}
95102

96103
for _, tt := range tests {

0 commit comments

Comments
 (0)