Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 8fdd2e3

Browse files
author
Jan Xie
committed
fix hash decoding in abi
1 parent 6739d5e commit 8fdd2e3

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

ethereum/abi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ def decode_single(typ, data):
371371
base, sub, _ = typ
372372
if base == 'address':
373373
return encode_hex(data[12:])
374+
elif base == 'hash':
375+
return data[32-int(sub):]
374376
elif base == 'string' or base == 'bytes' or base == 'hash':
375377
return data[:int(sub)] if len(sub) else data
376378
elif base == 'uint':

ethereum/tests/test_abi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def test_abi_encode_single_hash():
3030
assert abi.encode_single(['hash', '8', []], b'\x00'*8) == b'\x00'*32
3131
assert abi.encode_single(['hash', '8', []], '00'*8) == b'\x00'*32
3232

33+
def test_abi_decode_single_hash():
34+
typ = ['hash', '8', []]
35+
assert b'\x01'*8 == abi.decode_single(typ, abi.encode_single(typ, b'\x01'*8))
36+
3337
# SETUP TESTS IN GLOBAL NAME SPACE
3438
def gen_func(filename, testname, testdata):
3539
return lambda: do_test_state(filename, testname, testdata)

0 commit comments

Comments
 (0)