Commit 18665405 authored by zhiqiangxu's avatar zhiqiangxu Committed by GitHub

op-node/rollup/derive: enhance `TestBatchReader` (#13306)

* enhance TestBatchReader

* add more test

* address comments

* address comments

* remove extra comment
parent 69cc5bd5
...@@ -145,12 +145,20 @@ func TestFrameValidity(t *testing.T) { ...@@ -145,12 +145,20 @@ func TestFrameValidity(t *testing.T) {
func TestBatchReader(t *testing.T) { func TestBatchReader(t *testing.T) {
rng := rand.New(rand.NewSource(0x543331)) 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) encodedBatch := new(bytes.Buffer)
err := batchDataInput.EncodeRLP(encodedBatch) for _, batchData := range batches {
require.NoError(t, err) err := batchData.EncodeRLP(encodedBatch)
require.NoError(t, err)
}
const Zstd CompressionAlgo = "zstd" // invalid algo const Zstd CompressionAlgo = "zstd" // invalid algo
compressor := func(ca CompressionAlgo) func(buf *bytes.Buffer, t *testing.T) { compressor := func(ca CompressionAlgo) func(buf *bytes.Buffer, t *testing.T) {
...@@ -253,17 +261,22 @@ func TestBatchReader(t *testing.T) { ...@@ -253,17 +261,22 @@ func TestBatchReader(t *testing.T) {
} }
require.NoError(t, err) require.NoError(t, err)
// read the batch data for i := 0; i < batchCount; i++ {
batchData, err := reader() batchData, err := reader()
require.NoError(t, err) require.NoError(t, err)
require.NotNil(t, batchData) require.NotNil(t, batchData)
if tc.algo.IsBrotli() { if tc.algo.IsBrotli() {
// special case because reader doesn't decode level // special case because reader doesn't decode level
batchDataInput.ComprAlgo = Brotli batches[i].ComprAlgo = Brotli
} else { } else {
batchDataInput.ComprAlgo = tc.algo 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)
}) })
} }
} }
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