forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rollup/derive: encode/decode multiple batches (l2 blocks) per sequenc…
…er transaction
- Loading branch information
1 parent
05b1bad
commit 71ae668
Showing
3 changed files
with
142 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,45 @@ | ||
package derive | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/ethereum-optimism/optimistic-specs/opnode/rollup" | ||
|
||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBatchRoundTrip(t *testing.T) { | ||
batches := []BatchV1{ | ||
batches := []*BatchData{ | ||
{ | ||
Epoch: 0, | ||
Timestamp: 0, | ||
Transactions: []hexutil.Bytes{}, | ||
BatchV1: BatchV1{ | ||
Epoch: 0, | ||
Timestamp: 0, | ||
Transactions: []hexutil.Bytes{}, | ||
}, | ||
}, | ||
{ | ||
Epoch: 1, | ||
Timestamp: 1647026951, | ||
Transactions: []hexutil.Bytes{[]byte{0, 0, 0}, []byte{0x76, 0xfd, 0x7c}}, | ||
BatchV1: BatchV1{ | ||
Epoch: 1, | ||
Timestamp: 1647026951, | ||
Transactions: []hexutil.Bytes{[]byte{0, 0, 0}, []byte{0x76, 0xfd, 0x7c}}, | ||
}, | ||
}, | ||
} | ||
|
||
for i, batch := range batches { | ||
enc, err := batch.MarshalBinary() | ||
assert.NoError(t, err) | ||
var dec BatchV1 | ||
var dec BatchData | ||
err = dec.UnmarshalBinary(enc) | ||
assert.NoError(t, err) | ||
assert.Equal(t, batch, dec, "Batch not equal test case %v", i) | ||
assert.Equal(t, batch, &dec, "Batch not equal test case %v", i) | ||
} | ||
var buf bytes.Buffer | ||
err := EncodeBatches(&rollup.Config{}, batches, &buf) | ||
assert.NoError(t, err) | ||
out, err := DecodeBatches(&rollup.Config{}, &buf) | ||
assert.NoError(t, err) | ||
assert.Equal(t, batches, out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters