55 "math/big"
66 "reflect"
77 "testing"
8+
9+ "github.com/ethereum/go-ethereum/rlp"
810)
911
1012func TestNonInterfaceSlice (t * testing.T ) {
@@ -19,13 +21,16 @@ func TestNonInterfaceSlice(t *testing.T) {
1921
2022func TestRlpValueEncoding (t * testing.T ) {
2123 val := EmptyValue ()
22- val .AppendList ().Append (1 ) .Append (2 ) .Append (3 )
23- val .Append ("4" ).AppendList ().Append (5 )
24+ val .AppendList ().Append (byte ( 1 )) .Append (byte ( 2 )) .Append (byte ( 3 ) )
25+ val .Append ("4" ).AppendList ().Append (byte ( 5 ) )
2426
25- res := val .Encode ()
27+ res , err := rlp .EncodeToBytes (val )
28+ if err != nil {
29+ t .Fatalf ("encode error: %v" , err )
30+ }
2631 exp := Encode ([]interface {}{[]interface {}{1 , 2 , 3 }, "4" , []interface {}{5 }})
2732 if bytes .Compare (res , exp ) != 0 {
28- t .Errorf ("expected %q , got %q " , res , exp )
33+ t .Errorf ("expected %x , got %x " , exp , res )
2934 }
3035}
3136
@@ -57,9 +62,7 @@ func TestValueSlice(t *testing.T) {
5762func TestLargeData (t * testing.T ) {
5863 data := make ([]byte , 100000 )
5964 enc := Encode (data )
60- value := NewValue (enc )
61- value .Decode ()
62-
65+ value := NewValueFromBytes (enc )
6366 if value .Len () != len (data ) {
6467 t .Error ("Expected data to be" , len (data ), "got" , value .Len ())
6568 }
@@ -133,15 +136,16 @@ func TestEncodeDecodeBigInt(t *testing.T) {
133136}
134137
135138func TestEncodeDecodeBytes (t * testing.T ) {
136- b := NewValue ([]interface {}{[]byte {1 , 2 , 3 , 4 , 5 }, byte (6 )})
137- val := NewValueFromBytes (b .Encode ())
138- if ! b .Cmp (val ) {
139- t .Errorf ("Expected %v, got %v" , val , b )
139+ bv := NewValue ([]interface {}{[]byte {1 , 2 , 3 , 4 , 5 }, []byte {6 }})
140+ b , _ := rlp .EncodeToBytes (bv )
141+ val := NewValueFromBytes (b )
142+ if ! bv .Cmp (val ) {
143+ t .Errorf ("Expected %#v, got %#v" , bv , val )
140144 }
141145}
142146
143147func TestEncodeZero (t * testing.T ) {
144- b := NewValue (0 ). Encode ( )
148+ b , _ := rlp . EncodeToBytes ( NewValue (0 ))
145149 exp := []byte {0xc0 }
146150 if bytes .Compare (b , exp ) == 0 {
147151 t .Error ("Expected" , exp , "got" , b )
0 commit comments