aboutsummaryrefslogtreecommitdiffstats
path: root/rlp/decode_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-21 01:13:46 +0800
committerobscuren <geffobscura@gmail.com>2015-02-21 01:13:46 +0800
commitbd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca (patch)
tree46ab5943fd5e26198067aeec4a44287452eb2a32 /rlp/decode_test.go
parent771bfe9e78f9952002a71cccc8d41c8c544fdfcb (diff)
parentd586a633ff005ac01c9f1eb33552d147cf6c883e (diff)
downloaddexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar
dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.gz
dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.bz2
dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.lz
dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.xz
dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.tar.zst
dexon-bd7ebbcd5b77ce4fdd471b44f0acda80f2b3ceca.zip
Merge branch 'release/0.9.0'
Diffstat (limited to 'rlp/decode_test.go')
-rw-r--r--rlp/decode_test.go65
1 files changed, 50 insertions, 15 deletions
diff --git a/rlp/decode_test.go b/rlp/decode_test.go
index 7a1743937..9f66840b1 100644
--- a/rlp/decode_test.go
+++ b/rlp/decode_test.go
@@ -8,8 +8,6 @@ import (
"math/big"
"reflect"
"testing"
-
- "github.com/ethereum/go-ethereum/ethutil"
)
func TestStreamKind(t *testing.T) {
@@ -231,7 +229,12 @@ var decodeTests = []decodeTest{
{input: "8D6162636465666768696A6B6C6D", ptr: new([]byte), value: []byte("abcdefghijklm")},
{input: "C0", ptr: new([]byte), value: []byte{}},
{input: "C3010203", ptr: new([]byte), value: []byte{1, 2, 3}},
- {input: "C3820102", ptr: new([]byte), error: "rlp: input string too long for uint8"},
+
+ {
+ input: "C3820102",
+ ptr: new([]byte),
+ error: "rlp: input string too long for uint8, decoding into ([]uint8)[0]",
+ },
// byte arrays
{input: "01", ptr: new([5]byte), value: [5]byte{1}},
@@ -239,9 +242,22 @@ var decodeTests = []decodeTest{
{input: "850102030405", ptr: new([5]byte), value: [5]byte{1, 2, 3, 4, 5}},
{input: "C0", ptr: new([5]byte), value: [5]byte{}},
{input: "C3010203", ptr: new([5]byte), value: [5]byte{1, 2, 3, 0, 0}},
- {input: "C3820102", ptr: new([5]byte), error: "rlp: input string too long for uint8"},
- {input: "86010203040506", ptr: new([5]byte), error: "rlp: input string too long for [5]uint8"},
- {input: "850101", ptr: new([5]byte), error: io.ErrUnexpectedEOF.Error()},
+
+ {
+ input: "C3820102",
+ ptr: new([5]byte),
+ error: "rlp: input string too long for uint8, decoding into ([5]uint8)[0]",
+ },
+ {
+ input: "86010203040506",
+ ptr: new([5]byte),
+ error: "rlp: input string too long for [5]uint8",
+ },
+ {
+ input: "850101",
+ ptr: new([5]byte),
+ error: io.ErrUnexpectedEOF.Error(),
+ },
// byte array reuse (should be zeroed)
{input: "850102030405", ptr: &sharedByteArray, value: [5]byte{1, 2, 3, 4, 5}},
@@ -272,13 +288,23 @@ var decodeTests = []decodeTest{
{input: "C0", ptr: new(simplestruct), value: simplestruct{0, ""}},
{input: "C105", ptr: new(simplestruct), value: simplestruct{5, ""}},
{input: "C50583343434", ptr: new(simplestruct), value: simplestruct{5, "444"}},
- {input: "C3010101", ptr: new(simplestruct), error: "rlp: input list has too many elements for rlp.simplestruct"},
{
input: "C501C302C103",
ptr: new(recstruct),
value: recstruct{1, &recstruct{2, &recstruct{3, nil}}},
},
+ {
+ input: "C3010101",
+ ptr: new(simplestruct),
+ error: "rlp: input list has too many elements for rlp.simplestruct",
+ },
+ {
+ input: "C501C3C00000",
+ ptr: new(recstruct),
+ error: "rlp: expected input string or byte for uint, decoding into (rlp.recstruct).Child.I",
+ },
+
// pointers
{input: "00", ptr: new(*uint), value: (*uint)(nil)},
{input: "80", ptr: new(*uint), value: (*uint)(nil)},
@@ -299,6 +325,11 @@ var decodeTests = []decodeTest{
{input: "850505050505", ptr: new(interface{}), value: []byte{5, 5, 5, 5, 5}},
{input: "C0", ptr: new(interface{}), value: []interface{}{}},
{input: "C50183040404", ptr: new(interface{}), value: []interface{}{[]byte{1}, []byte{4, 4, 4}}},
+ {
+ input: "C3010203",
+ ptr: new([]io.Reader),
+ error: "rlp: type io.Reader is not RLP-serializable",
+ },
}
func uintp(i uint) *uint { return &i }
@@ -481,13 +512,13 @@ func ExampleStream() {
}
func BenchmarkDecode(b *testing.B) {
- enc := encTest(90000)
+ enc := encodeTestSlice(90000)
b.SetBytes(int64(len(enc)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
- var s []int
+ var s []uint
r := bytes.NewReader(enc)
if err := Decode(r, &s); err != nil {
b.Fatalf("Decode error: %v", err)
@@ -496,12 +527,12 @@ func BenchmarkDecode(b *testing.B) {
}
func BenchmarkDecodeIntSliceReuse(b *testing.B) {
- enc := encTest(100000)
+ enc := encodeTestSlice(100000)
b.SetBytes(int64(len(enc)))
b.ReportAllocs()
b.ResetTimer()
- var s []int
+ var s []uint
for i := 0; i < b.N; i++ {
r := bytes.NewReader(enc)
if err := Decode(r, &s); err != nil {
@@ -510,12 +541,16 @@ func BenchmarkDecodeIntSliceReuse(b *testing.B) {
}
}
-func encTest(n int) []byte {
- s := make([]interface{}, n)
- for i := 0; i < n; i++ {
+func encodeTestSlice(n uint) []byte {
+ s := make([]uint, n)
+ for i := uint(0); i < n; i++ {
s[i] = i
}
- return ethutil.Encode(s)
+ b, err := EncodeToBytes(s)
+ if err != nil {
+ panic(fmt.Sprintf("encode error: %v", err))
+ }
+ return b
}
func unhex(str string) []byte {