This repository was archived by the owner on May 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -373,8 +373,12 @@ def decode_single(typ, data):
373
373
return encode_hex (data [12 :])
374
374
elif base == 'hash' :
375
375
return data [32 - int (sub ):]
376
- elif base == 'string' or base == 'bytes' or base == 'hash' :
377
- return data [:int (sub )] if len (sub ) else data
376
+ elif base == 'string' or base == 'bytes' :
377
+ if len (sub ):
378
+ return data [:int (sub )]
379
+ else :
380
+ l = big_endian_to_int (data [0 :32 ])
381
+ return data [32 :][:l ]
378
382
elif base == 'uint' :
379
383
return big_endian_to_int (data )
380
384
elif base == 'int' :
Original file line number Diff line number Diff line change @@ -34,6 +34,13 @@ def test_abi_decode_single_hash():
34
34
typ = ['hash' , '8' , []]
35
35
assert b'\x01 ' * 8 == abi .decode_single (typ , abi .encode_single (typ , b'\x01 ' * 8 ))
36
36
37
+ def test_abi_decode_single_bytes ():
38
+ typ = ['bytes' , '8' , []]
39
+ assert (b'\x01 \x02 ' + b'\x00 ' * 6 ) == abi .decode_single (typ , abi .encode_single (typ , '\x01 \x02 ' ))
40
+
41
+ typ = ['bytes' , '' , []]
42
+ assert b'\x01 \x02 ' == abi .decode_single (typ , abi .encode_single (typ , '\x01 \x02 ' ))
43
+
37
44
# SETUP TESTS IN GLOBAL NAME SPACE
38
45
def gen_func (filename , testname , testdata ):
39
46
return lambda : do_test_state (filename , testname , testdata )
You can’t perform that action at this time.
0 commit comments