Skip to content

Commit 050bd27

Browse files
committed
Add test for revert interface
1 parent fc997a3 commit 050bd27

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

tests/core/contracts/conftest.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,82 @@ def CallerTesterContract(web3, CALLER_TESTER_CONTRACT):
832832
return web3.eth.contract(**CALLER_TESTER_CONTRACT)
833833

834834

835+
REVERT_CONTRACT_SOURCE = """
836+
pragma solidity ^0.6.1;
837+
838+
contract RevertContract {
839+
function normalFunction() public pure returns (bool) {
840+
return true;
841+
}
842+
843+
function revertFunction() public pure {
844+
revert('Function has been reverted.');
845+
}
846+
}
847+
"""
848+
849+
850+
REVERT_CONTRACT_BYTECODE = "608060405234801561001057600080fd5b5061010c806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806383fcb85e146037578063d67e4b8414603f575b600080fd5b603d605f565b005b604560cd565b604051808215151515815260200191505060405180910390f35b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f46756e6374696f6e20686173206265656e2072657665727465642e000000000081525060200191505060405180910390fd5b6000600190509056fea26469706673582212206b3e8456a530e8c500866943d9e7c5e083be8e70bfd6f57502e9cb19b9ef3e4464736f6c63430006010033" # noqa: E501
851+
852+
853+
REVERT_CONTRACT_RUNTIME_CODE = "6080604052348015600f57600080fd5b506004361060325760003560e01c806383fcb85e146037578063d67e4b8414603f575b600080fd5b603d605f565b005b604560cd565b604051808215151515815260200191505060405180910390f35b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f46756e6374696f6e20686173206265656e2072657665727465642e000000000081525060200191505060405180910390fd5b6000600190509056fea26469706673582212206b3e8456a530e8c500866943d9e7c5e083be8e70bfd6f57502e9cb19b9ef3e4464736f6c63430006010033" # noqa: E501
854+
855+
856+
_REVERT_CONTRACT_ABI = json.loads('''[
857+
{
858+
"inputs": [],
859+
"name": "normalFunction",
860+
"outputs": [
861+
{
862+
"internalType": "bool",
863+
"name": "",
864+
"type": "bool"
865+
}
866+
],
867+
"stateMutability": "pure",
868+
"type": "function"
869+
},
870+
{
871+
"inputs": [],
872+
"name": "revertFunction",
873+
"outputs": [],
874+
"stateMutability": "pure",
875+
"type": "function"
876+
}
877+
]''') # noqa: E501
878+
879+
880+
@pytest.fixture()
881+
def REVERT_CONTRACT_CODE():
882+
return REVERT_CONTRACT_BYTECODE
883+
884+
885+
@pytest.fixture()
886+
def REVERT_CONTRACT_RUNTIME():
887+
return REVERT_CONTRACT_RUNTIME_CODE
888+
889+
890+
@pytest.fixture()
891+
def REVERT_CONTRACT_ABI():
892+
return _REVERT_CONTRACT_ABI
893+
894+
895+
@pytest.fixture()
896+
def REVERT_FUNCTION_CONTRACT(REVERT_CONTRACT_CODE,
897+
REVERT_CONTRACT_RUNTIME,
898+
REVERT_CONTRACT_ABI):
899+
return {
900+
'bytecode': REVERT_CONTRACT_CODE,
901+
'bytecode_runtime': REVERT_CONTRACT_RUNTIME,
902+
'abi': REVERT_CONTRACT_ABI,
903+
}
904+
905+
906+
@pytest.fixture()
907+
def RevertContract(web3, REVERT_FUNCTION_CONTRACT):
908+
return web3.eth.contract(**REVERT_FUNCTION_CONTRACT)
909+
910+
835911
class LogFunctions:
836912
LogAnonymous = 0
837913
LogNoArguments = 1

tests/core/contracts/test_contract_call_interface.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
MismatchedABI,
3030
NoABIFound,
3131
NoABIFunctionsFound,
32+
SolidityError,
3233
ValidationError,
3334
)
3435

@@ -122,6 +123,10 @@ def payable_tester_contract(web3, PayableTesterContract, address_conversion_func
122123
return deploy(web3, PayableTesterContract, address_conversion_func)
123124

124125

126+
@pytest.fixture()
127+
def revert_contract(web3, RevertContract, address_conversion_func):
128+
return deploy(web3, RevertContract, address_conversion_func)
129+
125130
@pytest.fixture()
126131
def call_transaction():
127132
return {
@@ -819,3 +824,10 @@ def test_call_tuple_contract(tuple_contract, method_input, expected):
819824
def test_call_nested_tuple_contract(nested_tuple_contract, method_input, expected):
820825
result = nested_tuple_contract.functions.method(method_input).call()
821826
assert result == expected
827+
828+
829+
def test_call_revert_contract(revert_contract):
830+
with pytest.raises(SolidityError):
831+
result = revert_contract.functions.revertFunction().call()
832+
# TODO - figure out what result actually is and what we'll need to do to parse out the string
833+
assert "Function has been reverted." in result

0 commit comments

Comments
 (0)