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

Commit 97db0e5

Browse files
author
Jan Xie
committed
fix ureal type encoding in abi
1 parent e91843d commit 97db0e5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ethereum/abi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def encode_single(typ, arg):
194194
high, low = [int(x) for x in sub.split('x')]
195195
if not 0 <= arg < 2**high:
196196
raise ValueOutOfBounds(repr(arg))
197-
return zpad(encode_int(arg * 2**low), 32)
197+
return zpad(encode_int(int(arg * 2**low)), 32)
198198
# Signed reals: real<high>x<low>
199199
elif base == 'real':
200200
high, low = [int(x) for x in sub.split('x')]

ethereum/tests/test_abi.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ 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_ureal():
32+
assert abi.encode_single(['ureal', '128x128', []], 0) == (b'\x00'*32)
33+
assert abi.encode_single(['ureal', '128x128', []], 1.125) == (b'\x00'*15 + b'\x01\x20' + '\x00'*15)
34+
assert abi.encode_single(['ureal', '128x128', []], 2**127-1) == (b'\x7f' + b'\xff'*15 + b'\x00'*16)
35+
3136
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)
37+
assert abi.encode_single(['real', '128x128', []], 1.125) == (b'\x00'*15 + b'\x01\x20' + b'\x00'*15)
3338
assert abi.encode_single(['real', '128x128', []], -1.125) == (b'\xff'*15 + b'\xfe' + b'\xe0' + b'\x00'*15)
3439

3540
def test_abi_encode_single_hash():

0 commit comments

Comments
 (0)