Skip to content

Commit 1efa2eb

Browse files
committed
fix(core/types): failing tests differentiating nil/empty optional slice
1 parent d5b6b82 commit 1efa2eb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

core/types/block.libevm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (b *Body) EncodeRLP(dst io.Writer) error {
134134
return err
135135
}
136136

137-
withdraws := len(b.Withdrawals) > 0
137+
withdraws := b.Withdrawals != nil
138138

139139
// TODO(arr4n): call hook here, passing `withdraws` as a
140140
// mustWriteEmptyOptional flag. The hook could also return a

rlp/list.libevm.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ func (s *Stream) FromList(fn func() error) error {
4747
}
4848

4949
func DecodeList[T any](s *Stream) ([]*T, error) {
50-
var vals []*T
50+
// From the package-level documentation:
51+
//
52+
// > Note that package rlp never leaves a pointer-type struct field as nil
53+
// > unless one of the "nil" struct tags is present.
54+
//
55+
// We therefore return a non-nil pointer to maintain said invariant as it
56+
// makes use of this function easier.
57+
vals := make([]*T, 0)
5158
err := s.FromList(func() error {
5259
for s.MoreDataInList() {
5360
var v T

0 commit comments

Comments
 (0)