Skip to content

Commit 05463ce

Browse files
committed
test(core/types): fuzz Body RLP backwards compatibility
1 parent 1efa2eb commit 05463ce

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

core/types/rlp_backwards_compat.libevm_test.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package types_test
1919
import (
2020
"bytes"
2121
"encoding/hex"
22+
"fmt"
2223
"testing"
2324

2425
"github.com/google/go-cmp/cmp"
@@ -110,23 +111,39 @@ func testHeaderRLPBackwardsCompatibility(t *testing.T) {
110111
}
111112

112113
func TestBodyRLPBackwardsCompatibility(t *testing.T) {
113-
rng := ethtest.NewPseudoRand(0)
114+
t.Parallel()
115+
for seed := uint64(0); seed < 1_000; seed++ {
116+
seed := seed
117+
t.Run(fmt.Sprintf("seed_%d", seed), func(t *testing.T) {
118+
t.Parallel()
119+
testBodyRLPBackwardsCompatibility(t, seed)
120+
})
121+
}
122+
}
114123

115-
body := new(Body)
116-
for i, n := 0, rng.Intn(3)+1; i < n; i++ {
124+
func testBodyRLPBackwardsCompatibility(t *testing.T, seed uint64) {
125+
rng := ethtest.NewPseudoRand(seed)
126+
127+
body := &Body{
128+
// As this is a round-trip test, the slices MUST NOT be nil as the rlp
129+
// package will always set them.
130+
Transactions: []*Transaction{},
131+
Uncles: []*Header{},
132+
}
133+
for i, n := 0, rng.Intn(5); i < n; i++ {
117134
tx := NewTx(&LegacyTx{
118135
Nonce: rng.Uint64(),
119136
})
120137
body.Transactions = append(body.Transactions, tx)
121138
}
122-
for i, n := 0, rng.Intn(3)+1; i < n; i++ {
139+
for i, n := 0, rng.Intn(5); i < n; i++ {
123140
body.Uncles = append(body.Uncles, &Header{
124141
ParentHash: rng.Hash(),
125142
})
126143
}
127144

128145
var withdrawals Withdrawals
129-
for i, n := 0, rng.Intn(3)+1; i < n; i++ {
146+
for i, n := 0, rng.Intn(4)+1; i < n; i++ {
130147
withdrawals = append(withdrawals, &Withdrawal{
131148
Index: rng.Uint64(),
132149
})
@@ -156,7 +173,7 @@ func TestBodyRLPBackwardsCompatibility(t *testing.T) {
156173
t.Run(tt.name, func(t *testing.T) {
157174
body.Withdrawals = tt.withdrawals
158175

159-
// The originaly [Body] doesn't implement [rlp.Encoder] nor
176+
// The original [Body] doesn't implement [rlp.Encoder] nor
160177
// [rlp.Decoder] so we can use a methodless equivalent as gold
161178
// standard.
162179
type withoutMethods Body

0 commit comments

Comments
 (0)