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

Commit fb73b38

Browse files
author
Jan Xie
committed
test for encoding int in abi
1 parent 0637385 commit fb73b38

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ethereum/tests/test_abi.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import os
2+
import pytest
23
import ethereum.testutils as testutils
34
from ethereum.slogging import get_logger
45
import ethereum.abi as abi
6+
from ethereum.utils import zpad
7+
58
logger = get_logger()
69

710
def test_abi_encode_var_sized_array():
@@ -14,6 +17,14 @@ def test_abi_encode_signed_int():
1417
assert abi.decode_abi(['int8'], abi.encode_abi(['int8'], [1]))[0] == 1
1518
assert abi.decode_abi(['int8'], abi.encode_abi(['int8'], [-1]))[0] == -1
1619

20+
def test_abi_encode_single_int():
21+
assert abi.encode_single(['int', '8', []], -128) == zpad(b'\x80', 32)
22+
with pytest.raises(abi.ValueOutOfBounds):
23+
assert abi.encode_single(['int', '8', []], -129)
24+
25+
assert abi.encode_single(['int', '8', []], 127) == zpad(b'\x7f', 32)
26+
with pytest.raises(abi.ValueOutOfBounds):
27+
assert abi.encode_single(['int', '8', []], 128)
1728

1829
# SETUP TESTS IN GLOBAL NAME SPACE
1930
def gen_func(filename, testname, testdata):

0 commit comments

Comments
 (0)