@@ -1937,51 +1937,50 @@ func TestLogValueRefEncodeRLP(t *testing.T) {
19371937 {
19381938 name : "topic reference - offset 0" ,
19391939 ref : LogValueRef {Offset : 0 },
1940- expected : []byte {0x80 , 0x80 }, // RLP encoding of uint64(0)
1940+ expected : []byte {0xc2 , 0x80 , 0x80 }, // RLP encoding of uint64(0)
19411941 },
19421942 {
19431943 name : "topic reference - offset 3" ,
19441944 ref : LogValueRef {Offset : 3 },
1945- expected : []byte {0x80 , 0x03 }, // RLP encoding of uint64(3)
1945+ expected : []byte {0xc2 , 0x80 , 0x03 }, // RLP encoding of uint64(3)
19461946 },
19471947 {
19481948 name : "data reference - offset 4" ,
19491949 ref : LogValueRef {Offset : 4 },
1950- expected : []byte {0x80 , 0x04 }, // RLP encoding of uint64(4)
1950+ expected : []byte {0xc2 , 0x80 , 0x04 }, // RLP encoding of uint64(4)
19511951 },
19521952 {
19531953 name : "data reference - offset 5" ,
19541954 ref : LogValueRef {Offset : 5 },
1955- expected : []byte {0x80 , 0x05 }, // RLP encoding of uint64(5)
1955+ expected : []byte {0xc2 , 0x80 , 0x05 }, // RLP encoding of uint64(5)
19561956 },
19571957 {
19581958 name : "data reference - offset 10" ,
19591959 ref : LogValueRef {Offset : 10 },
1960- expected : []byte {0x80 , 0x0a }, // RLP encoding of uint64(10)
1960+ expected : []byte {0xc2 , 0x80 , 0x0a }, // RLP encoding of uint64(10)
19611961 },
19621962 {
19631963 name : "data reference - offset 10, dynamic" ,
19641964 ref : LogValueRef {Offset : 10 , Dynamic : true },
1965- expected : []byte {0x01 , 0x0a }, // RLP encoding of uint64(10)
1965+ expected : []byte {0xc2 , 0x01 , 0x0a }, // RLP encoding of uint64(10)
19661966 },
19671967 {
19681968 name : "large offset" ,
19691969 ref : LogValueRef {Offset : 1000 , Dynamic : false },
1970- expected : []byte {0x80 , 0x82 , 0x03 , 0xe8 }, // RLP encoding of uint64(1000)
1970+ expected : []byte {0xc4 , 0x80 , 0x82 , 0x03 , 0xe8 }, // RLP encoding of uint64(1000)
19711971 },
19721972 {
19731973 name : "large offset, dynamic" ,
19741974 ref : LogValueRef {Offset : 1000 , Dynamic : true },
1975- expected : []byte {0x01 , 0x82 , 0x03 , 0xe8 }, // RLP encoding of uint64(1000)
1975+ expected : []byte {0xc4 , 0x01 , 0x82 , 0x03 , 0xe8 }, // RLP encoding of uint64(1000)
19761976 },
19771977 }
19781978
19791979 for _ , tt := range tests {
19801980 t .Run (tt .name , func (t * testing.T ) {
1981- var buf bytes.Buffer
1982- err := tt .ref .EncodeRLP (& buf )
1981+ encoded , err := rlp .EncodeToBytes (tt .ref )
19831982 assert .NilError (t , err , "EncodeRLP should not fail" )
1984- assert .DeepEqual (t , tt .expected , buf . Bytes () )
1983+ assert .DeepEqual (t , tt .expected , encoded )
19851984 })
19861985 }
19871986}
@@ -1996,57 +1995,57 @@ func TestLogValueRefDecodeRLP(t *testing.T) {
19961995 }{
19971996 {
19981997 name : "topic reference - offset 0" ,
1999- encoded : []byte {0x80 , 0x80 }, // RLP encoding of uint64(0)
1998+ encoded : []byte {0xc2 , 0x80 , 0x80 }, // RLP encoding of uint64(0)
20001999 expected : LogValueRef {Offset : 0 },
20012000 wantErr : false ,
20022001 },
20032002 {
20042003 name : "topic reference - offset 3" ,
2005- encoded : []byte {0x80 , 0x03 }, // RLP encoding of uint64(3)
2004+ encoded : []byte {0xc2 , 0x80 , 0x03 }, // RLP encoding of uint64(3)
20062005 expected : LogValueRef {Offset : 3 },
20072006 wantErr : false ,
20082007 },
20092008 {
20102009 name : "data reference - offset 4" ,
2011- encoded : []byte {0x80 , 0x04 }, // RLP encoding of uint64(4)
2010+ encoded : []byte {0xc2 , 0x80 , 0x04 }, // RLP encoding of uint64(4)
20122011 expected : LogValueRef {Offset : 4 },
20132012 wantErr : false ,
20142013 },
20152014 {
20162015 name : "data reference - offset 5, dynamic true" ,
2017- encoded : []byte {0x01 , 0x05 }, // RLP encoding of uint64(5)
2016+ encoded : []byte {0xc2 , 0x01 , 0x05 }, // RLP encoding of uint64(5)
20182017 expected : LogValueRef {Offset : 5 , Dynamic : true },
20192018 wantErr : false ,
20202019 },
20212020 {
20222021 name : "data reference - offset 10" ,
2023- encoded : []byte {0x80 , 0x0a }, // RLP encoding of uint64(10)
2022+ encoded : []byte {0xc2 , 0x80 , 0x0a }, // RLP encoding of uint64(10)
20242023 expected : LogValueRef {Offset : 10 },
20252024 wantErr : false ,
20262025 },
20272026 {
20282027 name : "large offset" ,
2029- encoded : []byte {0x80 , 0x82 , 0x03 , 0xe8 }, // RLP encoding of uint64(1000)
2028+ encoded : []byte {0xc4 , 0x80 , 0x82 , 0x03 , 0xe8 }, // RLP encoding of uint64(1000)
20302029 expected : LogValueRef {Offset : 1000 },
20312030 wantErr : false ,
20322031 },
20332032 {
20342033 name : "invalid - empty RLP data" ,
20352034 encoded : []byte {},
20362035 wantErr : true ,
2037- errMsg : "failed to decode LogValueRef " ,
2036+ errMsg : "EOF " ,
20382037 },
20392038 {
20402039 name : "invalid - malformed RLP" ,
20412040 encoded : []byte {0xFF , 0xFF },
20422041 wantErr : true ,
2043- errMsg : "failed to decode LogValueRef " ,
2042+ errMsg : "rlp: value size exceeds available input length " ,
20442043 },
20452044 {
20462045 name : "invalid - incomplete list" ,
2047- encoded : []byte {0xc1 , 0x04 }, // List with only one element
2046+ encoded : []byte {0xc2 , 0x04 }, // List with only one element
20482047 wantErr : true ,
2049- errMsg : "LogValueRef can't be a list " ,
2048+ errMsg : "rlp: value size exceeds available input length " ,
20502049 },
20512050 }
20522051
@@ -2092,16 +2091,18 @@ func TestLogValueRefRLPRoundTrip(t *testing.T) {
20922091 name : "large values" ,
20932092 ref : LogValueRef {Offset : 65535 },
20942093 },
2094+ {
2095+ name : "large values - dynamic" ,
2096+ ref : LogValueRef {Offset : 65535 , Dynamic : true },
2097+ },
20952098 }
20962099
20972100 for _ , tt := range tests {
20982101 t .Run (tt .name , func (t * testing.T ) {
20992102 // Encode
2100- var buf bytes.Buffer
2101- err := tt .ref .EncodeRLP (& buf )
2103+ encoded , err := rlp .EncodeToBytes (tt .ref )
21022104 assert .NilError (t , err , "EncodeRLP should not fail" )
21032105
2104- encoded := buf .Bytes ()
21052106 assert .Assert (t , len (encoded ) > 0 , "Encoded data should not be empty" )
21062107
21072108 // Decode
@@ -2113,10 +2114,9 @@ func TestLogValueRefRLPRoundTrip(t *testing.T) {
21132114 assert .Equal (t , tt .ref .Offset , decoded .Offset )
21142115
21152116 // Encode again and verify consistency
2116- var buf2 bytes.Buffer
2117- err = decoded .EncodeRLP (& buf2 )
2117+ encoded2 , err := rlp .EncodeToBytes (decoded )
21182118 assert .NilError (t , err , "Second EncodeRLP should not fail" )
2119- assert .DeepEqual (t , encoded , buf2 . Bytes () )
2119+ assert .DeepEqual (t , encoded , encoded2 )
21202120 })
21212121 }
21222122}
0 commit comments