Skip to content

Commit 00a22fa

Browse files
committed
rlp: add test case for zero-length big.Int in struct
My initial implementation of the optimization contained a bug: the Stream didn't advance when encountering an empty big.Int because s.kind was not re-armed. The test checks for this.
1 parent 7770f25 commit 00a22fa

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

rlp/decode_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ type recstruct struct {
329329
Child *recstruct `rlp:"nil"`
330330
}
331331

332+
type bigIntStruct struct {
333+
I *big.Int
334+
B string
335+
}
336+
332337
type invalidNilTag struct {
333338
X []byte `rlp:"nil"`
334339
}
@@ -501,6 +506,13 @@ var decodeTests = []decodeTest{
501506
ptr: new(recstruct),
502507
value: recstruct{1, &recstruct{2, &recstruct{3, nil}}},
503508
},
509+
{
510+
// This checks that empty big.Int works correctly in struct context. It's easy to
511+
// miss the update of s.kind for this case, so it needs its own test.
512+
input: "C58083343434",
513+
ptr: new(bigIntStruct),
514+
value: bigIntStruct{new(big.Int), "444"},
515+
},
504516

505517
// struct errors
506518
{

0 commit comments

Comments
 (0)