Skip to content

Commit a2e0583

Browse files
committed
Test passing a tuple into a contract call
1 parent 2b8d47e commit a2e0583

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

tests/core/contracts/conftest.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,91 @@ def FallballFunctionContract(web3, FALLBACK_FUNCTION_CONTRACT):
527527
return web3.eth.contract(**FALLBACK_FUNCTION_CONTRACT)
528528

529529

530+
CONTRACT_TUPLE_CODE = "608060405234801561001057600080fd5b506102ed806100206000396000f3fe608060405234801561001057600080fd5b5060043610610048576000357c0100000000000000000000000000000000000000000000000000000000900480634e3269761461004d575b600080fd5b61006760048036036100629190810190610163565b61007d565b60405161007491906101fb565b60405180910390f35b61008561008d565b819050919050565b60606040519081016040528060008152602001600015158152602001600073ffffffffffffffffffffffffffffffffffffffff1681525090565b60006100d3823561028b565b905092915050565b60006100e7823561029d565b905092915050565b60006100fb82356102a9565b905092915050565b60006060828403121561011557600080fd5b61011f6060610216565b9050600061012f848285016100ef565b6000830152506020610143848285016100db565b6020830152506040610157848285016100c7565b60408301525092915050565b60006060828403121561017557600080fd5b600061018384828501610103565b91505092915050565b61019581610243565b82525050565b6101a481610255565b82525050565b6101b381610261565b82525050565b6060820160008201516101cf60008501826101aa565b5060208201516101e2602085018261019b565b5060408201516101f5604085018261018c565b50505050565b600060608201905061021060008301846101b9565b92915050565b6000604051905081810181811067ffffffffffffffff8211171561023957600080fd5b8060405250919050565b600061024e8261026b565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006102968261026b565b9050919050565b60008115159050919050565b600081905091905056fea265627a7a723058203f779dc401e40b86d552e03af453e4f759bd8e4f8f0ca5ffb05909e2af7567b76c6578706572696d656e74616cf50037" # noqa: E501
531+
532+
CONTRACT_TUPLE_RUNTIME = "608060405234801561001057600080fd5b5060043610610048576000357c0100000000000000000000000000000000000000000000000000000000900480634e3269761461004d575b600080fd5b61006760048036036100629190810190610163565b61007d565b60405161007491906101fb565b60405180910390f35b61008561008d565b819050919050565b60606040519081016040528060008152602001600015158152602001600073ffffffffffffffffffffffffffffffffffffffff1681525090565b60006100d3823561028b565b905092915050565b60006100e7823561029d565b905092915050565b60006100fb82356102a9565b905092915050565b60006060828403121561011557600080fd5b61011f6060610216565b9050600061012f848285016100ef565b6000830152506020610143848285016100db565b6020830152506040610157848285016100c7565b60408301525092915050565b60006060828403121561017557600080fd5b600061018384828501610103565b91505092915050565b61019581610243565b82525050565b6101a481610255565b82525050565b6101b381610261565b82525050565b6060820160008201516101cf60008501826101aa565b5060208201516101e2602085018261019b565b5060408201516101f5604085018261018c565b50505050565b600060608201905061021060008301846101b9565b92915050565b6000604051905081810181811067ffffffffffffffff8211171561023957600080fd5b8060405250919050565b600061024e8261026b565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006102968261026b565b9050919050565b60008115159050919050565b600081905091905056fea265627a7a723058203f779dc401e40b86d552e03af453e4f759bd8e4f8f0ca5ffb05909e2af7567b76c6578706572696d656e74616cf50037" # noqa: E501
533+
534+
CONTRACT_TUPLE_ABI = json.loads("""
535+
[
536+
{
537+
"constant": true,
538+
"inputs": [
539+
{
540+
"components": [
541+
{
542+
"name": "anInt",
543+
"type": "int256"
544+
},
545+
{
546+
"name": "aBool",
547+
"type": "bool"
548+
},
549+
{
550+
"name": "anAddress",
551+
"type": "address"
552+
}
553+
],
554+
"name": "m",
555+
"type": "tuple"
556+
}
557+
],
558+
"name": "method",
559+
"outputs": [
560+
{
561+
"components": [
562+
{
563+
"name": "anInt",
564+
"type": "int256"
565+
},
566+
{
567+
"name": "aBool",
568+
"type": "bool"
569+
},
570+
{
571+
"name": "anAddress",
572+
"type": "address"
573+
}
574+
],
575+
"name": "",
576+
"type": "tuple"
577+
}
578+
],
579+
"payable": false,
580+
"stateMutability": "pure",
581+
"type": "function"
582+
}
583+
]""")
584+
585+
586+
@pytest.fixture()
587+
def TUPLE_CODE():
588+
return CONTRACT_TUPLE_CODE
589+
590+
591+
@pytest.fixture()
592+
def TUPLE_RUNTIME():
593+
return CONTRACT_TUPLE_RUNTIME
594+
595+
596+
@pytest.fixture()
597+
def TUPLE_ABI():
598+
return CONTRACT_TUPLE_ABI
599+
600+
601+
@pytest.fixture()
602+
def TUPLE_CONTRACT(TUPLE_CODE, TUPLE_RUNTIME, TUPLE_ABI):
603+
return {
604+
'bytecode': TUPLE_CODE,
605+
'bytecode_runtime': TUPLE_RUNTIME,
606+
'abi': TUPLE_ABI,
607+
}
608+
609+
610+
@pytest.fixture()
611+
def TupleContract(web3, TUPLE_CONTRACT):
612+
return web3.eth.contract(**TUPLE_CONTRACT)
613+
614+
530615
class LogFunctions:
531616
LogAnonymous = 0
532617
LogNoArguments = 1

tests/core/contracts/test_contract_call_interface.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ def fallback_function_contract(web3, FallballFunctionContract, address_conversio
134134
return deploy(web3, FallballFunctionContract, address_conversion_func)
135135

136136

137+
@pytest.fixture()
138+
def tuple_contract(web3, TupleContract, address_conversion_func):
139+
return deploy(web3, TupleContract, address_conversion_func)
140+
141+
137142
def test_invalid_address_in_deploy_arg(web3, WithConstructorAddressArgumentsContract):
138143
with pytest.raises(InvalidAddress):
139144
WithConstructorAddressArgumentsContract.constructor(
@@ -611,3 +616,21 @@ def test_invalid_fixed_value_reflections(web3, fixed_reflection_contract, functi
611616
contract_func = fixed_reflection_contract.functions[function]
612617
with pytest.raises(ValidationError, match=error):
613618
contract_func(value).call({'gas': 420000})
619+
620+
621+
@pytest.mark.parametrize(
622+
'method_input, expected',
623+
(
624+
(
625+
{'anInt': 0, 'aBool': True, 'anAddress': '0x' + 'f' * 40},
626+
(0, True, '0x' + 'f' * 40)
627+
),
628+
(
629+
(0, True, '0x' + 'f' * 40),
630+
(0, True, '0x' + 'f' * 40),
631+
),
632+
)
633+
)
634+
def test_call_tuple_contract(tuple_contract, method_input, expected):
635+
result = tuple_contract.functions.method(method_input).call()
636+
assert result == expected

0 commit comments

Comments
 (0)