Skip to content

Commit

Permalink
op-node/rollup/derive: enhance TestBatchReader (ethereum-optimism#1…
Browse files Browse the repository at this point in the history
…3306)

* enhance TestBatchReader

* add more test

* address comments

* address comments

* remove extra comment
  • Loading branch information
zhiqiangxu authored Dec 10, 2024
1 parent 69cc5bd commit 1866540
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions op-node/rollup/derive/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,20 @@ func TestFrameValidity(t *testing.T) {

func TestBatchReader(t *testing.T) {
rng := rand.New(rand.NewSource(0x543331))
singularBatch := RandomSingularBatch(rng, 20, big.NewInt(333))
batchDataInput := NewBatchData(singularBatch)

batchCount := 3
batches := make([]*BatchData, batchCount)
for i := 0; i < batchCount; i++ {
singularBatch := RandomSingularBatch(rng, 20, big.NewInt(333))
batchDataInput := NewBatchData(singularBatch)
batches[i] = batchDataInput
}

encodedBatch := new(bytes.Buffer)
err := batchDataInput.EncodeRLP(encodedBatch)
require.NoError(t, err)
for _, batchData := range batches {
err := batchData.EncodeRLP(encodedBatch)
require.NoError(t, err)
}

const Zstd CompressionAlgo = "zstd" // invalid algo
compressor := func(ca CompressionAlgo) func(buf *bytes.Buffer, t *testing.T) {
Expand Down Expand Up @@ -253,17 +261,22 @@ func TestBatchReader(t *testing.T) {
}
require.NoError(t, err)

// read the batch data
batchData, err := reader()
require.NoError(t, err)
require.NotNil(t, batchData)
if tc.algo.IsBrotli() {
// special case because reader doesn't decode level
batchDataInput.ComprAlgo = Brotli
} else {
batchDataInput.ComprAlgo = tc.algo
for i := 0; i < batchCount; i++ {
batchData, err := reader()
require.NoError(t, err)
require.NotNil(t, batchData)
if tc.algo.IsBrotli() {
// special case because reader doesn't decode level
batches[i].ComprAlgo = Brotli
} else {
batches[i].ComprAlgo = tc.algo
}
require.Equal(t, batches[i], batchData)
}
require.Equal(t, batchDataInput, batchData)

// further read should error out
_, err = reader()
require.Error(t, err)
})
}
}

0 comments on commit 1866540

Please sign in to comment.