Skip to content

Commit

Permalink
Merge pull request #101 from pdobacz/patch-1
Browse files Browse the repository at this point in the history
default to data=fn_selector in encodeABI
  • Loading branch information
pipermerriam committed Dec 28, 2016
2 parents 1f8e753 + 5e8e425 commit d05604c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 5 additions & 5 deletions tests/contracts/test_contract_method_abi_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
@pytest.mark.parametrize(
'abi,method,arguments,data,expected',
(
(ABI_A, 'a', [], None, '0x'),
(ABI_A, 'a', [], None, '0x0dbe671f'),
(ABI_A, 'a', [], '0x12345678', '0x12345678'),
(ABI_B, 'a', [0], None, '0x0000000000000000000000000000000000000000000000000000000000000000'),
(ABI_B, 'a', [1], None, '0x0000000000000000000000000000000000000000000000000000000000000001'),
(ABI_C, 'a', [1], None, '0x0000000000000000000000000000000000000000000000000000000000000001'),
(ABI_C, 'a', ['a'], None, '0x6100000000000000000000000000000000000000000000000000000000000000'),
(ABI_B, 'a', [0], None, '0xf0fdf8340000000000000000000000000000000000000000000000000000000000000000'),
(ABI_B, 'a', [1], None, '0xf0fdf8340000000000000000000000000000000000000000000000000000000000000001'),
(ABI_C, 'a', [1], None, '0xf0fdf8340000000000000000000000000000000000000000000000000000000000000001'),
(ABI_C, 'a', ['a'], None, '0x9f3fab586100000000000000000000000000000000000000000000000000000000000000'),
),
)
def test_contract_abi_encoding(web3, abi, method, arguments, data, expected):
Expand Down
8 changes: 7 additions & 1 deletion web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,16 @@ def encodeABI(cls, fn_name, args=None, kwargs=None, data=None):
"""
encodes the arguments using the Ethereum ABI for the contract function
that matches the given name and arguments..
:param data: defaults to function selector
"""
fn_abi, _, fn_arguments = cls._get_function_info(
fn_abi, fn_selector, fn_arguments = cls._get_function_info(
fn_name, args, kwargs,
)

if data is None:
data = fn_selector

return cls._encode_abi(fn_abi, fn_arguments, data)

@combomethod
Expand Down

0 comments on commit d05604c

Please sign in to comment.