Skip to content

Commit 5942fa5

Browse files
author
pacrob
committed
work on typing
1 parent 1709f03 commit 5942fa5

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

tests/core/contracts/conftest.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,6 @@ def NestedTupleContractWithDecodeTuples(w3, NESTED_TUPLE_CONTRACT_DECODE_TUPLES)
117117
return w3.eth.contract(**NESTED_TUPLE_CONTRACT_DECODE_TUPLES)
118118

119119

120-
@pytest.fixture()
121-
def AsyncNestedTupleContract(async_w3, NESTED_TUPLE_CONTRACT):
122-
return async_w3.eth.contract(**NESTED_TUPLE_CONTRACT)
123-
124-
125-
@pytest.fixture()
126-
def AsyncNestedTupleContractWithDecodeTuples(
127-
async_w3, NESTED_TUPLE_CONTRACT_DECODE_TUPLES
128-
):
129-
return async_w3.eth.contract(**NESTED_TUPLE_CONTRACT_DECODE_TUPLES)
130-
131-
132120
CONTRACT_TUPLE_SOURCE = """
133121
pragma solidity >=0.4.19 <0.6.0;
134122
pragma experimental ABIEncoderV2;
@@ -178,11 +166,6 @@ def TupleContract(w3, TUPLE_CONTRACT):
178166
return w3.eth.contract(**TUPLE_CONTRACT)
179167

180168

181-
@pytest.fixture()
182-
def AsyncTupleContract(async_w3, TUPLE_CONTRACT):
183-
return async_w3.eth.contract(**TUPLE_CONTRACT)
184-
185-
186169
@pytest.fixture()
187170
def TUPLE_CONTRACT_DECODE_TUPLES(TUPLE_CODE, TUPLE_RUNTIME, TUPLE_ABI):
188171
return {
@@ -198,11 +181,6 @@ def TupleContractWithDecodeTuples(w3, TUPLE_CONTRACT_DECODE_TUPLES):
198181
return w3.eth.contract(**TUPLE_CONTRACT_DECODE_TUPLES)
199182

200183

201-
@pytest.fixture()
202-
def AsyncTupleContractWithDecodeTuples(async_w3, TUPLE_CONTRACT_DECODE_TUPLES):
203-
return async_w3.eth.contract(**TUPLE_CONTRACT_DECODE_TUPLES)
204-
205-
206184
CONTRACT_CODE = "0x606060405261022e806100126000396000f360606040523615610074576000357c01000000000000000000000000000000000000000000000000000000009004806316216f391461007657806361bc221a146100995780637cf5dab0146100bc578063a5f3c23b146100e8578063d09de08a1461011d578063dcf537b11461014057610074565b005b610083600480505061016c565b6040518082815260200191505060405180910390f35b6100a6600480505061017f565b6040518082815260200191505060405180910390f35b6100d26004808035906020019091905050610188565b6040518082815260200191505060405180910390f35b61010760048080359060200190919080359060200190919050506101ea565b6040518082815260200191505060405180910390f35b61012a6004805050610201565b6040518082815260200191505060405180910390f35b6101566004808035906020019091905050610217565b6040518082815260200191505060405180910390f35b6000600d9050805080905061017c565b90565b60006000505481565b6000816000600082828250540192505081905550600060005054905080507f3496c3ede4ec3ab3686712aa1c238593ea6a42df83f98a5ec7df9834cfa577c5816040518082815260200191505060405180910390a18090506101e5565b919050565b6000818301905080508090506101fb565b92915050565b600061020d6001610188565b9050610214565b90565b60006007820290508050809050610229565b91905056" # noqa: E501
207185
CONTRACT_RUNTIME = "0x60606040523615610074576000357c01000000000000000000000000000000000000000000000000000000009004806316216f391461007657806361bc221a146100995780637cf5dab0146100bc578063a5f3c23b146100e8578063d09de08a1461011d578063dcf537b11461014057610074565b005b610083600480505061016c565b6040518082815260200191505060405180910390f35b6100a6600480505061017f565b6040518082815260200191505060405180910390f35b6100d26004808035906020019091905050610188565b6040518082815260200191505060405180910390f35b61010760048080359060200190919080359060200190919050506101ea565b6040518082815260200191505060405180910390f35b61012a6004805050610201565b6040518082815260200191505060405180910390f35b6101566004808035906020019091905050610217565b6040518082815260200191505060405180910390f35b6000600d9050805080905061017c565b90565b60006000505481565b6000816000600082828250540192505081905550600060005054905080507f3496c3ede4ec3ab3686712aa1c238593ea6a42df83f98a5ec7df9834cfa577c5816040518082815260200191505060405180910390a18090506101e5565b919050565b6000818301905080508090506101fb565b92915050565b600061020d6001610188565b9050610214565b90565b60006007820290508050809050610229565b91905056" # noqa: E501
208186
CONTRACT_ABI = json.loads(
@@ -1218,11 +1196,23 @@ def AsyncNestedTupleContract(async_w3, NESTED_TUPLE_CONTRACT):
12181196
return async_w3.eth.contract(**NESTED_TUPLE_CONTRACT)
12191197

12201198

1199+
@pytest.fixture()
1200+
def AsyncNestedTupleContractWithDecodeTuples(
1201+
async_w3, NESTED_TUPLE_CONTRACT_DECODE_TUPLES
1202+
):
1203+
return async_w3.eth.contract(**NESTED_TUPLE_CONTRACT_DECODE_TUPLES)
1204+
1205+
12211206
@pytest.fixture()
12221207
def AsyncTupleContract(async_w3, TUPLE_CONTRACT):
12231208
return async_w3.eth.contract(**TUPLE_CONTRACT)
12241209

12251210

1211+
@pytest.fixture()
1212+
def AsyncTupleContractWithDecodeTuples(async_w3, TUPLE_CONTRACT_DECODE_TUPLES):
1213+
return async_w3.eth.contract(**TUPLE_CONTRACT_DECODE_TUPLES)
1214+
1215+
12261216
@pytest.fixture()
12271217
def AsyncMathContract(async_w3, MATH_ABI, MATH_CODE, MATH_RUNTIME):
12281218
return async_w3.eth.contract(

web3/_utils/abi.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,13 +924,17 @@ def named_tree(
924924

925925

926926
def named_subtree(
927-
abi: Dict[str, Any], data: Tuple[Any, ...]
927+
# TODO make this a better type
928+
abi: Any,
929+
data: Tuple[Any, ...],
928930
) -> Union[Dict[str, Any], Tuple[Any, ...], Any]:
929-
abi_type = parse(collapse_if_tuple(abi))
931+
abi_type = parse(collapse_if_tuple(dict(abi)))
930932

931933
if abi_type.is_array:
932934
item_type = abi_type.item_type.to_type_str()
933935
item_abi = {**abi, "type": item_type, "name": ""}
936+
# cast(ABIFunctionParams, item_abi)
937+
# breakpoint()
934938
items = [named_subtree(item_abi, item) for item in data]
935939
return items
936940

web3/_utils/contracts.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
cast,
1111
)
1212

13-
from eth_abi import (
14-
decode,
15-
)
1613
from eth_abi.codec import (
1714
ABICodec,
1815
)
@@ -50,7 +47,6 @@
5047
get_receive_func_abi,
5148
map_abi_data,
5249
merge_args_and_kwargs,
53-
named_tree,
5450
)
5551
from web3._utils.blocks import (
5652
is_hex_encoded_block_hash,
@@ -317,15 +313,6 @@ def encode_transaction_data(
317313
return add_0x_prefix(encode_abi(w3, fn_abi, fn_arguments, fn_selector))
318314

319315

320-
def decode_transaction_data(fn_abi, data, normalizers=None):
321-
data = HexBytes(data)
322-
types = get_abi_input_types(fn_abi)
323-
decoded = decode(types, data[4:])
324-
if normalizers:
325-
decoded = map_abi_data(normalizers, types, decoded)
326-
return named_tree(fn_abi["inputs"], decoded)
327-
328-
329316
def get_fallback_function_info(
330317
contract_abi: Optional[ABI] = None, fn_abi: Optional[ABIFunction] = None
331318
) -> Tuple[ABIFunction, HexStr, Tuple[Any, ...]]:

0 commit comments

Comments
 (0)