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

Commit f10bad9

Browse files
author
Jan Xie
committed
fix real type encoding in abi
1 parent 0ab9579 commit f10bad9

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

ethereum/abi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def encode_single(typ, arg):
200200
high, low = [int(x) for x in sub.split('x')]
201201
if not -2**(high - 1) <= arg < 2**(high - 1):
202202
raise ValueOutOfBounds(repr(arg))
203-
return zpad(encode_int((arg % 2**high) * 2**low), 32)
203+
return zpad(encode_int(int((arg % 2**high) * 2**low)), 32)
204204
# Strings
205205
elif base == 'string' or base == 'bytes':
206206
if not is_string(arg):

ethereum/tests/test_abi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def test_abi_encode_single_int():
2828
with pytest.raises(abi.ValueOutOfBounds):
2929
assert abi.encode_single(['int', '8', []], 128)
3030

31+
def test_abi_encode_single_real():
32+
assert abi.encode_single(['real', '128x128', []], 1.125) == (b'\x00'*15 + b'\x01' + b'\x20' + b'\x00'*15)
33+
3134
def test_abi_encode_single_hash():
3235
assert abi.encode_single(['hash', '8', []], b'\x00'*8) == b'\x00'*32
3336
assert abi.encode_single(['hash', '8', []], '00'*8) == b'\x00'*32

0 commit comments

Comments
 (0)