Skip to content

Commit 1cdf328

Browse files
committed
Add tuple support to _utils.abi.data_tree_map()
This is a workaround for the following error: gene@precision5510:~/0x-monorepo-upstream/python-packages/order_utils$ pytest test/test_get_order_info.py ======================== test session starts ========================= platform linux -- Python 3.7.0, pytest-3.3.2, py-1.6.0, pluggy-0.6.0 hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/gene/0x-monorepo-upstream/python-packages/order_utils/.hypothesis/examples') rootdir: /home/gene/0x-monorepo-upstream/python-packages/order_utils, inifile: plugins: xdist-1.22.3, pythonpath-0.7.3, forked-0.2, hypothesis-3.82.1 collected 1 item test/test_get_order_info.py F [100%] ============================== FAILURES ============================== __________________ test_get_order_info__happy_path ___________________ def test_get_order_info__happy_path(): """Test that get_order_info() works as expected.""" get_order_info( Web3.HTTPProvider("http://127.0.0.1:8545"), { 'makerAddress': "0x0000000000000000000000000000000000000000", 'takerAddress': "0x0000000000000000000000000000000000000000", 'feeRecipientAddress': ( "0x0000000000000000000000000000000000000000" ), 'senderAddress': "0x0000000000000000000000000000000000000000", 'makerAssetAmount': 1000000000000000000, 'takerAssetAmount': 1000000000000000000, 'makerFee': 0, 'takerFee': 0, 'expirationTimeSeconds': 12345, 'salt': 12345, 'makerAssetData': b"0000000000000000000000000000000000000000", > 'takerAssetData': b"0000000000000000000000000000000000000000", }, ) test/test_get_order_info.py:27: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/zero_ex/order_utils/__init__.py:234: in get_order_info return contract.call().getOrderInfo(order) ../../../web3.py/web3/contract.py:1370: in call_contract_function fn_kwargs=kwargs, ../../../web3.py/web3/_utils/contracts.py:245: in prepare_transaction fn_kwargs, ../../../web3.py/web3/_utils/contracts.py:266: in encode_transaction_data return add_0x_prefix(encode_abi(web3, fn_abi, fn_arguments, fn_selector)) ../../../web3.py/web3/_utils/contracts.py:190: in encode_abi arguments, cytoolz/functoolz.pyx:232: in cytoolz.functoolz.curry.__call__ ??? ../../../web3.py/web3/_utils/abi.py:543: in map_abi_data return pipe(data, *pipeline) cytoolz/functoolz.pyx:589: in cytoolz.functoolz.pipe ??? cytoolz/functoolz.pyx:565: in cytoolz.functoolz.c_pipe ??? cytoolz/functoolz.pyx:232: in cytoolz.functoolz.curry.__call__ ??? ../../../web3.py/web3/_utils/abi.py:575: in data_tree_map return recursive_map(map_to_typed_data, data_tree) ../../../web3.py/web3/_utils/decorators.py:35: in wrapped wrapped_val = to_wrap(*args) ../../../web3.py/web3/_utils/formatters.py:115: in recursive_map items_mapped = map_collection(recurse, data) ../../../web3.py/web3/_utils/formatters.py:102: in map_collection return datatype(map(func, collection)) ../../../web3.py/web3/_utils/formatters.py:114: in recurse return recursive_map(func, item) ../../../web3.py/web3/_utils/decorators.py:35: in wrapped wrapped_val = to_wrap(*args) ../../../web3.py/web3/_utils/formatters.py:116: in recursive_map return func(items_mapped) ../../../web3.py/web3/_utils/abi.py:572: in map_to_typed_data return ABITypedData(func(*elements)) ../../../web3.py/web3/_utils/normalizers.py:50: in wrapper modified = to_wrap(abi_type, data) ../../../web3.py/web3/_utils/normalizers.py:121: in abi_bytes_to_bytes base, sub, arrlist = process_type(abi_type) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ type_str = '(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes)' def process_type(type_str): normalized_type_str = normalize(type_str) abi_type = parse(normalized_type_str) type_str_repr = repr(type_str) if type_str != normalized_type_str: type_str_repr = '{} (normalized to {})'.format( type_str_repr, repr(normalized_type_str), ) if isinstance(abi_type, TupleType): raise ValueError( "Cannot process type {}: tuple types not supported".format( > type_str_repr, ) ) E ValueError: Cannot process type '(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes)': tuple types not supported ../../../eth-abi/eth_abi/utils/parsing.py:25: ValueError ------------------------- Captured log call -------------------------- manager.py 90 DEBUG Making request. Method: net_version rpc.py 63 DEBUG Making request HTTP. URI: http://127.0.0.1:8545, Method: net_version connectionpool.py 205 DEBUG Starting new HTTP connection (1): 127.0.0.1:8545 connectionpool.py 393 DEBUG http://127.0.0.1:8545 "POST / HTTP/1.1" 200 None rpc.py 73 DEBUG Getting response HTTP. URI: http://127.0.0.1:8545, Method: net_version, Response: {'id': 0, 'jsonrpc': '2.0', 'result': '50'} ====================== 1 failed in 0.49 seconds ======================
1 parent 23e4a2f commit 1cdf328

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

web3/_utils/abi.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,13 @@ def data_tree_map(func, data_tree):
568568
receive two args: abi_type, and data
569569
'''
570570
def map_to_typed_data(elements):
571-
if isinstance(elements, ABITypedData) and elements.abi_type is not None:
572-
return ABITypedData(func(*elements))
571+
if isinstance(elements, str) and elements[0] == "(":
572+
return elements
573+
elif isinstance(elements, ABITypedData):
574+
if elements.abi_type[0] == "(":
575+
return elements
576+
elif elements.abi_type is not None:
577+
return ABITypedData(func(*elements))
573578
else:
574579
return elements
575580
return recursive_map(map_to_typed_data, data_tree)

0 commit comments

Comments
 (0)