Skip to content

Commit 64d39ca

Browse files
committed
test(rlp): tweak test cases for new functionality
1 parent c44b1d9 commit 64d39ca

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

core/types/rlp_backwards_compat.libevm_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func TestBodyRLPBackwardsCompatibility(t *testing.T) {
116116
newHdr := func(hashLow byte) *Header { return &Header{ParentHash: common.Hash{hashLow}} }
117117
newWithdraw := func(idx uint64) *Withdrawal { return &Withdrawal{Index: idx} }
118118

119-
// We build up test-case [Body] instances from the power set of each of
120-
// these components.
119+
// We build up test-case [Body] instances from the Cartesian product of each
120+
// of these components.
121121
txMatrix := [][]*Transaction{
122122
nil, {}, // Must be equivalent for non-optional field
123123
{newTx(1)},

rlp/list.libevm_test.go

+23-11
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestStructFieldHelpers(t *testing.T) {
7878
c := common.PointerTo(cVal)
7979
d := common.PointerTo(dVal)
8080
e := []uint64{40, 41}
81-
f := common.PointerTo([]uint64{50, 51})
81+
f := &[]uint64{50, 51}
8282

8383
tests := []foo{
8484
{a, b, c, d, e, f}, // 000 (which of d/e/f are nil)
@@ -91,6 +91,7 @@ func TestStructFieldHelpers(t *testing.T) {
9191
{a, b, c, nil, nil, nil}, // 111
9292
// Empty and nil slices are treated differently when optional
9393
{a, b, c, nil, []uint64{}, nil},
94+
{a, b, c, nil, nil, &[]uint64{}},
9495
}
9596

9697
for _, obj := range tests {
@@ -189,17 +190,28 @@ func TestNillable(t *testing.T) {
189190
C *[]uint64 `rlp:"nil"`
190191
}
191192

192-
aMatrix := []*uint64{nil, common.PointerTo[uint64](0)}
193-
bMatrix := []*inner{nil, {0}}
194-
cMatrix := []*[]uint64{nil, {}, {0}}
195-
193+
// Unlike the `rlp:"optional"` tag, there is no interplay between nil-tagged
194+
// fields so we don't need the Cartesian product of all possible
195+
// combinations.
196196
var tests []outer
197-
for _, a := range aMatrix {
198-
for _, b := range bMatrix {
199-
for _, c := range cMatrix {
200-
tests = append(tests, outer{a, b, c})
201-
}
202-
}
197+
for _, a := range []*uint64{
198+
nil,
199+
common.PointerTo[uint64](0),
200+
} {
201+
tests = append(tests, outer{a, nil, nil})
202+
}
203+
for _, b := range []*inner{
204+
nil,
205+
{0},
206+
} {
207+
tests = append(tests, outer{nil, b, nil})
208+
}
209+
for _, c := range []*[]uint64{
210+
nil,
211+
{},
212+
{0},
213+
} {
214+
tests = append(tests, outer{nil, nil, c})
203215
}
204216

205217
// When a Nillable encounters an empty list it MUST set the field to nil,

0 commit comments

Comments
 (0)