Skip to content

Instantly share code, notes, and snippets.

@feuGeneA
Created February 1, 2019 16:17
Show Gist options
  • Save feuGeneA/d07b1c4839161bfc0bc5f1240b8d8d87 to your computer and use it in GitHub Desktop.
Save feuGeneA/d07b1c4839161bfc0bc5f1240b8d8d87 to your computer and use it in GitHub Desktop.
diff --git a/setup.py b/setup.py
index fa28a32..7d756dc 100644
--- a/setup.py
+++ b/setup.py
@@ -57,7 +57,7 @@ extras_require['dev'] = (
)
setup(
- name='web3',
+ name='0x-web3',
# *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility.
version='5.0.0-alpha.2',
description="""Web3.py""",
diff --git a/tests/core/contracts/conftest.py b/tests/core/contracts/conftest.py
index 85f56fe..4d3851a 100644
--- a/tests/core/contracts/conftest.py
+++ b/tests/core/contracts/conftest.py
@@ -528,77 +528,129 @@ def FallballFunctionContract(web3, FALLBACK_FUNCTION_CONTRACT):
CONTRACT_TUPLE_SOURCE = """
-pragma experimental ABIEncoderV3;
-
-contract Tuple {
+pragma experimental ABIEncoderV2;
+ contract Tuple {
struct Struct {
int anInt;
bool aBool;
address anAddress;
}
-
- function method(Struct memory m)
+ function methodTakingStruct(Struct memory m)
public
pure
returns (Struct memory)
{
return m;
}
+ function methodTakingArrayOfStructs(Struct[] memory m)
+ public
+ pure
+ returns (Struct[] memory)
+ {
+ return m;
+ }
}"""
-CONTRACT_TUPLE_CODE = "608060405234801561001057600080fd5b506102ed806100206000396000f3fe608060405234801561001057600080fd5b5060043610610048576000357c0100000000000000000000000000000000000000000000000000000000900480634e3269761461004d575b600080fd5b61006760048036036100629190810190610163565b61007d565b60405161007491906101fb565b60405180910390f35b61008561008d565b819050919050565b60606040519081016040528060008152602001600015158152602001600073ffffffffffffffffffffffffffffffffffffffff1681525090565b60006100d3823561028b565b905092915050565b60006100e7823561029d565b905092915050565b60006100fb82356102a9565b905092915050565b60006060828403121561011557600080fd5b61011f6060610216565b9050600061012f848285016100ef565b6000830152506020610143848285016100db565b6020830152506040610157848285016100c7565b60408301525092915050565b60006060828403121561017557600080fd5b600061018384828501610103565b91505092915050565b61019581610243565b82525050565b6101a481610255565b82525050565b6101b381610261565b82525050565b6060820160008201516101cf60008501826101aa565b5060208201516101e2602085018261019b565b5060408201516101f5604085018261018c565b50505050565b600060608201905061021060008301846101b9565b92915050565b6000604051905081810181811067ffffffffffffffff8211171561023957600080fd5b8060405250919050565b600061024e8261026b565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006102968261026b565b9050919050565b60008115159050919050565b600081905091905056fea265627a7a723058203f779dc401e40b86d552e03af453e4f759bd8e4f8f0ca5ffb05909e2af7567b76c6578706572696d656e74616cf50037" # noqa: E501
+CONTRACT_TUPLE_CODE = "608060405234801561001057600080fd5b50610571806100206000396000f3fe608060405260043610610046576000357c0100000000000000000000000000000000000000000000000000000000900480635442981a1461004b578063d0723aff14610088575b600080fd5b34801561005757600080fd5b50610072600480360361006d919081019061029a565b6100c5565b60405161007f9190610410565b60405180910390f35b34801561009457600080fd5b506100af60048036036100aa91908101906102db565b6100cf565b6040516100bc9190610432565b60405180910390f35b6060819050919050565b6100d76100df565b819050919050565b60606040519081016040528060008152602001600015158152602001600073ffffffffffffffffffffffffffffffffffffffff1681525090565b6000610125823561050f565b905092915050565b600082601f830112151561014057600080fd5b813561015361014e8261047a565b61044d565b9150818183526020840193506020810190508385606084028201111561017857600080fd5b60005b838110156101a8578161018e88826101da565b84526020840193506060830192505060018101905061017b565b5050505092915050565b60006101be8235610521565b905092915050565b60006101d2823561052d565b905092915050565b6000606082840312156101ec57600080fd5b6101f6606061044d565b90506000610206848285016101c6565b600083015250602061021a848285016101b2565b602083015250604061022e84828501610119565b60408301525092915050565b60006060828403121561024c57600080fd5b610256606061044d565b90506000610266848285016101c6565b600083015250602061027a848285016101b2565b602083015250604061028e84828501610119565b60408301525092915050565b6000602082840312156102ac57600080fd5b600082013567ffffffffffffffff8111156102c657600080fd5b6102d28482850161012d565b91505092915050565b6000606082840312156102ed57600080fd5b60006102fb8482850161023a565b91505092915050565b61030d816104c7565b82525050565b600061031e826104af565b808452602084019350610330836104a2565b60005b82811015610362576103468683516103ce565b61034f826104ba565b9150606086019550600181019050610333565b50849250505092915050565b610377816104d9565b82525050565b610386816104e5565b82525050565b6060820160008201516103a2600085018261037d565b5060208201516103b5602085018261036e565b5060408201516103c86040850182610304565b50505050565b6060820160008201516103e4600085018261037d565b5060208201516103f7602085018261036e565b50604082015161040a6040850182610304565b50505050565b6000602082019050818103600083015261042a8184610313565b905092915050565b6000606082019050610447600083018461038c565b92915050565b6000604051905081810181811067ffffffffffffffff8211171561047057600080fd5b8060405250919050565b600067ffffffffffffffff82111561049157600080fd5b602082029050602081019050919050565b6000602082019050919050565b600081519050919050565b6000602082019050919050565b60006104d2826104ef565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061051a826104ef565b9050919050565b60008115159050919050565b600081905091905056fea265627a7a7230582016790dbe833dd3fd348c5d67805f5fae4b7caa58b6f6cd2e1e146e725d1b09506c6578706572696d656e74616cf50037" # noqa: E501
-CONTRACT_TUPLE_RUNTIME = "608060405234801561001057600080fd5b5060043610610048576000357c0100000000000000000000000000000000000000000000000000000000900480634e3269761461004d575b600080fd5b61006760048036036100629190810190610163565b61007d565b60405161007491906101fb565b60405180910390f35b61008561008d565b819050919050565b60606040519081016040528060008152602001600015158152602001600073ffffffffffffffffffffffffffffffffffffffff1681525090565b60006100d3823561028b565b905092915050565b60006100e7823561029d565b905092915050565b60006100fb82356102a9565b905092915050565b60006060828403121561011557600080fd5b61011f6060610216565b9050600061012f848285016100ef565b6000830152506020610143848285016100db565b6020830152506040610157848285016100c7565b60408301525092915050565b60006060828403121561017557600080fd5b600061018384828501610103565b91505092915050565b61019581610243565b82525050565b6101a481610255565b82525050565b6101b381610261565b82525050565b6060820160008201516101cf60008501826101aa565b5060208201516101e2602085018261019b565b5060408201516101f5604085018261018c565b50505050565b600060608201905061021060008301846101b9565b92915050565b6000604051905081810181811067ffffffffffffffff8211171561023957600080fd5b8060405250919050565b600061024e8261026b565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006102968261026b565b9050919050565b60008115159050919050565b600081905091905056fea265627a7a723058203f779dc401e40b86d552e03af453e4f759bd8e4f8f0ca5ffb05909e2af7567b76c6578706572696d656e74616cf50037" # noqa: E501
+CONTRACT_TUPLE_RUNTIME = "608060405260043610610046576000357c0100000000000000000000000000000000000000000000000000000000900480635442981a1461004b578063d0723aff14610088575b600080fd5b34801561005757600080fd5b50610072600480360361006d919081019061029a565b6100c5565b60405161007f9190610410565b60405180910390f35b34801561009457600080fd5b506100af60048036036100aa91908101906102db565b6100cf565b6040516100bc9190610432565b60405180910390f35b6060819050919050565b6100d76100df565b819050919050565b60606040519081016040528060008152602001600015158152602001600073ffffffffffffffffffffffffffffffffffffffff1681525090565b6000610125823561050f565b905092915050565b600082601f830112151561014057600080fd5b813561015361014e8261047a565b61044d565b9150818183526020840193506020810190508385606084028201111561017857600080fd5b60005b838110156101a8578161018e88826101da565b84526020840193506060830192505060018101905061017b565b5050505092915050565b60006101be8235610521565b905092915050565b60006101d2823561052d565b905092915050565b6000606082840312156101ec57600080fd5b6101f6606061044d565b90506000610206848285016101c6565b600083015250602061021a848285016101b2565b602083015250604061022e84828501610119565b60408301525092915050565b60006060828403121561024c57600080fd5b610256606061044d565b90506000610266848285016101c6565b600083015250602061027a848285016101b2565b602083015250604061028e84828501610119565b60408301525092915050565b6000602082840312156102ac57600080fd5b600082013567ffffffffffffffff8111156102c657600080fd5b6102d28482850161012d565b91505092915050565b6000606082840312156102ed57600080fd5b60006102fb8482850161023a565b91505092915050565b61030d816104c7565b82525050565b600061031e826104af565b808452602084019350610330836104a2565b60005b82811015610362576103468683516103ce565b61034f826104ba565b9150606086019550600181019050610333565b50849250505092915050565b610377816104d9565b82525050565b610386816104e5565b82525050565b6060820160008201516103a2600085018261037d565b5060208201516103b5602085018261036e565b5060408201516103c86040850182610304565b50505050565b6060820160008201516103e4600085018261037d565b5060208201516103f7602085018261036e565b50604082015161040a6040850182610304565b50505050565b6000602082019050818103600083015261042a8184610313565b905092915050565b6000606082019050610447600083018461038c565b92915050565b6000604051905081810181811067ffffffffffffffff8211171561047057600080fd5b8060405250919050565b600067ffffffffffffffff82111561049157600080fd5b602082029050602081019050919050565b6000602082019050919050565b600081519050919050565b6000602082019050919050565b60006104d2826104ef565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061051a826104ef565b9050919050565b60008115159050919050565b600081905091905056fea265627a7a7230582016790dbe833dd3fd348c5d67805f5fae4b7caa58b6f6cd2e1e146e725d1b09506c6578706572696d656e74616cf50037" # noqa: E501
CONTRACT_TUPLE_ABI = json.loads("""
[
- {
- "constant": true,
- "inputs": [
- {
- "components": [
- {
- "name": "anInt",
- "type": "int256"
- },
- {
- "name": "aBool",
- "type": "bool"
- },
- {
- "name": "anAddress",
- "type": "address"
- }
- ],
- "name": "m",
- "type": "tuple"
- }
- ],
- "name": "method",
- "outputs": [
- {
- "components": [
- {
- "name": "anInt",
- "type": "int256"
- },
- {
- "name": "aBool",
- "type": "bool"
- },
- {
- "name": "anAddress",
- "type": "address"
- }
- ],
- "name": "",
- "type": "tuple"
- }
- ],
- "payable": false,
- "stateMutability": "pure",
- "type": "function"
- }
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "components": [
+ {
+ "name": "anInt",
+ "type": "int256"
+ },
+ {
+ "name": "aBool",
+ "type": "bool"
+ },
+ {
+ "name": "anAddress",
+ "type": "address"
+ }
+ ],
+ "name": "m",
+ "type": "tuple[]"
+ }
+ ],
+ "name": "methodTakingArrayOfStructs",
+ "outputs": [
+ {
+ "components": [
+ {
+ "name": "anInt",
+ "type": "int256"
+ },
+ {
+ "name": "aBool",
+ "type": "bool"
+ },
+ {
+ "name": "anAddress",
+ "type": "address"
+ }
+ ],
+ "name": "",
+ "type": "tuple[]"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "pure",
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "components": [
+ {
+ "name": "anInt",
+ "type": "int256"
+ },
+ {
+ "name": "aBool",
+ "type": "bool"
+ },
+ {
+ "name": "anAddress",
+ "type": "address"
+ }
+ ],
+ "name": "m",
+ "type": "tuple"
+ }
+ ],
+ "name": "methodTakingStruct",
+ "outputs": [
+ {
+ "components": [
+ {
+ "name": "anInt",
+ "type": "int256"
+ },
+ {
+ "name": "aBool",
+ "type": "bool"
+ },
+ {
+ "name": "anAddress",
+ "type": "address"
+ }
+ ],
+ "name": "",
+ "type": "tuple"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "pure",
+ "type": "function"
+ }
]""")
diff --git a/tests/core/contracts/test_contract_call_interface.py b/tests/core/contracts/test_contract_call_interface.py
index 92a5023..954e88a 100644
--- a/tests/core/contracts/test_contract_call_interface.py
+++ b/tests/core/contracts/test_contract_call_interface.py
@@ -631,6 +631,24 @@ def test_invalid_fixed_value_reflections(web3, fixed_reflection_contract, functi
),
)
)
-def test_call_tuple_contract(tuple_contract, method_input, expected):
- result = tuple_contract.functions.method(method_input).call()
+def test_call_tuple_contract_struct(tuple_contract, method_input, expected):
+ result = tuple_contract.functions.methodTakingStruct(method_input).call()
+ assert result == expected
+
+
+@pytest.mark.parametrize(
+ 'method_input, expected',
+ (
+ (
+ [{'anInt': 0, 'aBool': True, 'anAddress': '0x' + 'f' * 40}],
+ ((0, True, '0x' + 'f' * 40))
+ ),
+ (
+ [(0, True, '0x' + 'f' * 40)],
+ [(0, True, '0x' + 'f' * 40)],
+ ),
+ )
+)
+def test_call_tuple_contract_struct_array(tuple_contract, method_input, expected):
+ result = tuple_contract.functions.methodTakingArrayOfStructs(method_input).call()
assert result == expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment