diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-22 01:18:19 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-22 01:18:19 +0800 |
commit | 7f85608f30a2e34005c8d15566849229c758c2f1 (patch) | |
tree | 7aeb9d8bdfda7ec10ea38688a96ed245028764ad /rlp/decode_test.go | |
parent | 09766d1729f7530093aec7e9acd3e5339b2c2028 (diff) | |
parent | fcacfabe1959c4aff6a63cb4e275f65328660601 (diff) | |
download | dexon-7f85608f30a2e34005c8d15566849229c758c2f1.tar dexon-7f85608f30a2e34005c8d15566849229c758c2f1.tar.gz dexon-7f85608f30a2e34005c8d15566849229c758c2f1.tar.bz2 dexon-7f85608f30a2e34005c8d15566849229c758c2f1.tar.lz dexon-7f85608f30a2e34005c8d15566849229c758c2f1.tar.xz dexon-7f85608f30a2e34005c8d15566849229c758c2f1.tar.zst dexon-7f85608f30a2e34005c8d15566849229c758c2f1.zip |
Merge branch 'conversion' into develop
Diffstat (limited to 'rlp/decode_test.go')
-rw-r--r-- | rlp/decode_test.go | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/rlp/decode_test.go b/rlp/decode_test.go index 9f66840b1..a18ff1d08 100644 --- a/rlp/decode_test.go +++ b/rlp/decode_test.go @@ -39,7 +39,7 @@ func TestStreamKind(t *testing.T) { s := NewStream(bytes.NewReader(unhex(test.input))) kind, len, err := s.Kind() if err != nil { - t.Errorf("test %d: Type returned error: %v", i, err) + t.Errorf("test %d: Kind returned error: %v", i, err) continue } if kind != test.wantKind { @@ -93,6 +93,23 @@ func TestStreamErrors(t *testing.T) { {"C3C2010201", calls{"List", "List", "Uint", "Uint", "ListEnd", "Uint"}, EOL}, {"00", calls{"ListEnd"}, errNotInList}, {"C40102", calls{"List", "Uint", "ListEnd"}, errNotAtEOL}, + + // This test verifies that the input position is advanced + // correctly when calling Bytes for empty strings. Kind can be called + // any number of times in between and doesn't advance. + {"C3808080", calls{ + "List", // enter the list + "Bytes", // past first element + + "Kind", "Kind", "Kind", // this shouldn't advance + + "Bytes", // past second element + + "Kind", "Kind", // can't hurt to try + + "Bytes", // past final element + "Bytes", // this one should fail + }, EOL}, } testfor: @@ -148,6 +165,20 @@ func TestStreamList(t *testing.T) { } } +func TestStreamRaw(t *testing.T) { + s := NewStream(bytes.NewReader(unhex("C58401010101"))) + s.List() + + want := unhex("8401010101") + raw, err := s.Raw() + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(want, raw) { + t.Errorf("raw mismatch: got %x, want %x", raw, want) + } +} + func TestDecodeErrors(t *testing.T) { r := bytes.NewReader(nil) @@ -314,6 +345,9 @@ var decodeTests = []decodeTest{ {input: "C109", ptr: new(*[]uint), value: &[]uint{9}}, {input: "C58403030303", ptr: new(*[][]byte), value: &[][]byte{{3, 3, 3, 3}}}, + // check that input position is advanced also for empty values. + {input: "C3808005", ptr: new([]*uint), value: []*uint{nil, nil, uintp(5)}}, + // pointer should be reset to nil {input: "05", ptr: sharedPtr, value: uintp(5)}, {input: "80", ptr: sharedPtr, value: (*uint)(nil)}, |