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

Commit f4a1bfc

Browse files
committed
add test for encoding bytes
1 parent 76da6bd commit f4a1bfc

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

ethereum/tests/test_abi.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def test_abi_encode_signed_int():
2020
assert abi.decode_abi(['int8'], abi.encode_abi(['int8'], [1]))[0] == 1
2121
assert abi.decode_abi(['int8'], abi.encode_abi(['int8'], [-1]))[0] == -1
2222

23+
2324
def test_abi_encode_single_int():
2425
assert abi.encode_single(['int', '256', []], -2**255) == (b'\x80'+b'\x00'*31)
2526
assert abi.encode_single(['int', '256', []], (b'\x80'+b'\x00'*31)) == (b'\x80'+b'\x00'*31)
@@ -32,34 +33,49 @@ def test_abi_encode_single_int():
3233
with pytest.raises(abi.ValueOutOfBounds):
3334
assert abi.encode_single(['int', '8', []], 128)
3435

36+
3537
def test_abi_encode_single_ureal():
3638
assert abi.encode_single(['ureal', '128x128', []], 0) == (b'\x00'*32)
3739
assert abi.encode_single(['ureal', '128x128', []], 1.125) == (b'\x00'*15 + b'\x01\x20' + '\x00'*15)
3840
assert abi.encode_single(['ureal', '128x128', []], 2**127-1) == (b'\x7f' + b'\xff'*15 + b'\x00'*16)
3941

42+
4043
def test_abi_encode_single_real():
4144
assert abi.encode_single(['real', '128x128', []], 1.125) == (b'\x00'*15 + b'\x01\x20' + b'\x00'*15)
4245
assert abi.encode_single(['real', '128x128', []], -1.125) == (b'\xff'*15 + b'\xfe' + b'\xe0' + b'\x00'*15)
4346

47+
4448
def test_abi_encode_single_hash():
4549
assert abi.encode_single(['hash', '8', []], b'\x00'*8) == b'\x00'*32
4650
assert abi.encode_single(['hash', '8', []], '00'*8) == b'\x00'*32
4751

52+
4853
def test_abi_decode_single_hash():
4954
typ = ['hash', '8', []]
5055
assert b'\x01'*8 == abi.decode_single(typ, abi.encode_single(typ, b'\x01'*8))
5156

57+
58+
def test_abi_encode_single_bytes():
59+
typ = ['bytes', '8', []]
60+
assert abi.encode_single(typ, '\x01\x02') == b'\x01\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
61+
62+
typ = ['bytes', '', []]
63+
assert abi.encode_single(typ, '\x01\x02') == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x01\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
64+
65+
5266
def test_abi_decode_single_bytes():
5367
typ = ['bytes', '8', []]
5468
assert (b'\x01\x02' + b'\x00'*6) == abi.decode_single(typ, abi.encode_single(typ, '\x01\x02'))
5569

5670
typ = ['bytes', '', []]
5771
assert b'\x01\x02' == abi.decode_single(typ, abi.encode_single(typ, '\x01\x02'))
5872

73+
5974
def test_abi_encode_single_prefixed_address():
6075
prefixed_address = '0x' + '0'*40
6176
assert abi.encode_single(['address', '', []], prefixed_address) == b'\x00' * 32
6277

78+
6379
def test_abi_decode_single_real():
6480
real_data = abi.encode_single(['real', '128x128', []], 1)
6581
assert abi.decode_single(['real', '128x128', []], real_data) == 1
@@ -73,10 +89,11 @@ def test_abi_decode_single_real():
7389
real_data = abi.encode_single(['real', '128x128', []], -2**127)
7490
assert abi.decode_single(['real', '128x128', []], real_data) == -2**127
7591

92+
7693
# Will be parametrized fron json fixtures
7794
def test_state(filename, testname, testdata):
7895
testutils.check_abi_test(testutils.fixture_to_bytes(testdata))
7996

8097

81-
def pytest_generate_tests(metafunc):
82-
testutils.generate_test_params('ABITests', metafunc)
98+
# def pytest_generate_tests(metafunc):
99+
# testutils.generate_test_params('ABITests', metafunc)

0 commit comments

Comments
 (0)