aboutsummaryrefslogtreecommitdiffstats
path: root/rlp/decode_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-12-22 04:05:20 +0800
committerFelix Lange <fjl@twurst.com>2016-02-19 18:14:29 +0800
commitbb07ce3eedabb2133227ba1d7569d171d8e5b25c (patch)
tree9e5b8ff9506f39ca1b94a21833b96646ccb7a19b /rlp/decode_test.go
parentfdb936ee95d09b1b98418735a813deba6770ad5a (diff)
downloaddexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.tar
dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.tar.gz
dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.tar.bz2
dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.tar.lz
dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.tar.xz
dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.tar.zst
dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.zip
rlp: add "tail" struct tag
Diffstat (limited to 'rlp/decode_test.go')
-rw-r--r--rlp/decode_test.go52
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"))},