diff options
Diffstat (limited to 'rlp/decode_test.go')
-rw-r--r-- | rlp/decode_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/rlp/decode_test.go b/rlp/decode_test.go index 408f1a5a9..2d465b74d 100644 --- a/rlp/decode_test.go +++ b/rlp/decode_test.go @@ -312,6 +312,26 @@ type recstruct struct { Child *recstruct `rlp:"nil"` } +type invalidTail1 struct { + A uint `rlp:"tail"` + B string +} + +type invalidTail2 struct { + A uint + B string `rlp:"tail"` +} + +type tailRaw struct { + A uint + Tail []RawValue `rlp:"tail"` +} + +type tailUint struct { + A uint + Tail []uint `rlp:"tail"` +} + var ( veryBigInt = big.NewInt(0).Add( big.NewInt(0).Lsh(big.NewInt(0xFFFFFFFFFFFFFF), 16), @@ -437,6 +457,38 @@ var decodeTests = []decodeTest{ ptr: new(recstruct), error: "rlp: expected input string or byte for uint, decoding into (rlp.recstruct).Child.I", }, + { + input: "C0", + ptr: new(invalidTail1), + error: "rlp: invalid struct tag \"tail\" for rlp.invalidTail1.A (must be on last field)", + }, + { + input: "C0", + ptr: new(invalidTail2), + error: "rlp: invalid struct tag \"tail\" for rlp.invalidTail2.B (field type is not slice)", + }, + { + input: "C50102C20102", + ptr: new(tailUint), + error: "rlp: expected input string or byte for uint, decoding into (rlp.tailUint).Tail[1]", + }, + + // struct tag "tail" + { + input: "C3010203", + ptr: new(tailRaw), + value: tailRaw{A: 1, Tail: []RawValue{unhex("02"), unhex("03")}}, + }, + { + input: "C20102", + ptr: new(tailRaw), + value: tailRaw{A: 1, Tail: []RawValue{unhex("02")}}, + }, + { + input: "C101", + ptr: new(tailRaw), + value: tailRaw{A: 1, Tail: []RawValue{}}, + }, // RawValue {input: "01", ptr: new(RawValue), value: RawValue(unhex("01"))}, |