aboutsummaryrefslogtreecommitdiffstats
path: root/rlp/decode_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-04-17 09:11:24 +0800
committerFelix Lange <fjl@twurst.com>2015-04-17 20:45:10 +0800
commit7180699d401e64b52447ccb2cfb33004b7deb672 (patch)
tree88c3a13dfde87cca5a0ad7de20bffee2bcc11b7a /rlp/decode_test.go
parent9c7281c17ebbdd6a8c10ecc618bcb9121215a21f (diff)
downloadgo-tangerine-7180699d401e64b52447ccb2cfb33004b7deb672.tar
go-tangerine-7180699d401e64b52447ccb2cfb33004b7deb672.tar.gz
go-tangerine-7180699d401e64b52447ccb2cfb33004b7deb672.tar.bz2
go-tangerine-7180699d401e64b52447ccb2cfb33004b7deb672.tar.lz
go-tangerine-7180699d401e64b52447ccb2cfb33004b7deb672.tar.xz
go-tangerine-7180699d401e64b52447ccb2cfb33004b7deb672.tar.zst
go-tangerine-7180699d401e64b52447ccb2cfb33004b7deb672.zip
rlp: require declared number of input elements for array types
Diffstat (limited to 'rlp/decode_test.go')
-rw-r--r--rlp/decode_test.go26
1 files changed, 11 insertions, 15 deletions
diff --git a/rlp/decode_test.go b/rlp/decode_test.go
index 0b69ff1f4..d07520bd0 100644
--- a/rlp/decode_test.go
+++ b/rlp/decode_test.go
@@ -290,11 +290,6 @@ var (
)
)
-var (
- sharedByteArray [5]byte
- sharedPtr = new(*uint)
-)
-
var decodeTests = []decodeTest{
// integers
{input: "05", ptr: new(uint32), value: uint32(5)},
@@ -315,11 +310,16 @@ var decodeTests = []decodeTest{
{input: "F8020004", ptr: new([]uint), error: "rlp: non-canonical size information for []uint"},
// arrays
- {input: "C0", ptr: new([5]uint), value: [5]uint{}},
{input: "C50102030405", ptr: new([5]uint), value: [5]uint{1, 2, 3, 4, 5}},
+ {input: "C0", ptr: new([5]uint), error: "rlp: input list has too few elements for [5]uint"},
+ {input: "C102", ptr: new([5]uint), error: "rlp: input list has too few elements for [5]uint"},
{input: "C6010203040506", ptr: new([5]uint), error: "rlp: input list has too many elements for [5]uint"},
{input: "F8020004", ptr: new([5]uint), error: "rlp: non-canonical size information for [5]uint"},
+ // zero sized arrays
+ {input: "C0", ptr: new([0]uint), value: [0]uint{}},
+ {input: "C101", ptr: new([0]uint), error: "rlp: input list has too many elements for [0]uint"},
+
// byte slices
{input: "01", ptr: new([]byte), value: []byte{1}},
{input: "80", ptr: new([]byte), value: []byte{}},
@@ -328,21 +328,17 @@ var decodeTests = []decodeTest{
{input: "8105", ptr: new([]byte), error: "rlp: non-canonical size information for []uint8"},
// byte arrays
- {input: "01", ptr: new([5]byte), value: [5]byte{1}},
- {input: "80", ptr: new([5]byte), value: [5]byte{}},
+ {input: "02", ptr: new([1]byte), value: [1]byte{2}},
{input: "850102030405", ptr: new([5]byte), value: [5]byte{1, 2, 3, 4, 5}},
// byte array errors
+ {input: "02", ptr: new([5]byte), error: "rlp: input string too short for [5]uint8"},
+ {input: "80", ptr: new([5]byte), error: "rlp: input string too short for [5]uint8"},
+ {input: "820000", ptr: new([5]byte), error: "rlp: input string too short for [5]uint8"},
{input: "C0", ptr: new([5]byte), error: "rlp: expected input string or byte for [5]uint8"},
{input: "C3010203", ptr: new([5]byte), error: "rlp: expected input string or byte for [5]uint8"},
{input: "86010203040506", ptr: new([5]byte), error: "rlp: input string too long for [5]uint8"},
- {input: "8105", ptr: new([5]byte), error: "rlp: non-canonical size information for [5]uint8"},
-
- // byte array reuse (should be zeroed)
- {input: "850102030405", ptr: &sharedByteArray, value: [5]byte{1, 2, 3, 4, 5}},
- {input: "01", ptr: &sharedByteArray, value: [5]byte{1}}, // kind: String
- {input: "850102030405", ptr: &sharedByteArray, value: [5]byte{1, 2, 3, 4, 5}},
- {input: "01", ptr: &sharedByteArray, value: [5]byte{1}}, // kind: Byte
+ {input: "8105", ptr: new([1]byte), error: "rlp: non-canonical size information for [1]uint8"},
// zero sized byte arrays
{input: "80", ptr: new([0]byte), value: [0]byte{}},