Skip to content

Commit baaf104

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

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

tests/core/contracts/conftest.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,90 @@ def FALLBACK_FUNCTION_CONTRACT(FALLBACK_FUNCTION_CODE,
526526
def FallballFunctionContract(web3, FALLBACK_FUNCTION_CONTRACT):
527527
return web3.eth.contract(**FALLBACK_FUNCTION_CONTRACT)
528528

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

530614
class LogFunctions:
531615
LogAnonymous = 0

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)