Skip to content

Commit 12bdac6

Browse files
author
Yoichi Hirai
committed
Better error message from deployment failure
This commit modifies `deploy_tester_contract()` so it raises an exception with a message with failed `require()`s. Before this commit, `deploy_tester_contract()` did not raise an exception when the deployment failed for a `require()` condition. This solves raiden-network#1329.
1 parent 7e730f6 commit 12bdac6

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

raiden_contracts/tests/fixtures/base/web3_fixtures.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
from eth_tester import EthereumTester, PyEVMBackend
66
from web3 import Web3
7-
from web3.contract import ContractFunction
7+
from web3.contract import ContractConstructor, ContractFunction
88
from web3.providers.eth_tester import EthereumTesterProvider
99

1010
from raiden_contracts.tests.utils.constants import (
@@ -77,12 +77,22 @@ def auto_revert_chain(web3: Web3) -> Generator:
7777
def _call_and_transact(
7878
contract_function: ContractFunction, transaction_params: Optional[Dict] = None
7979
) -> str:
80-
""" Executes contract_function.{call, transaction}(transaction_params) and returns txhash """
81-
# First 'call' might raise an exception
80+
""" Executes contract_function.{call, transact}(transaction_params) and returns txhash """
81+
# First 'call' might raise an exception, containing an error message from require().
8282
contract_function.call(transaction_params)
8383
return contract_function.transact(transaction_params)
8484

8585

86+
def _estimate_gas_and_transact_constructor(
87+
contract_constructor: ContractConstructor, transaction_params: Optional[Dict] = None
88+
) -> str:
89+
""" Execute contract_constructor.{estimateGas, transact}(transaction_params); return txhash """
90+
# First 'estimate_gas' might raise an exception, containing an error message from require().
91+
contract_constructor.estimateGas(transaction_params)
92+
return contract_constructor.transact(transaction_params)
93+
94+
8695
@pytest.fixture(scope="session", autouse=True)
8796
def call_and_transact() -> None:
8897
ContractFunction.call_and_transact = _call_and_transact
98+
ContractConstructor.call_and_transact = _estimate_gas_and_transact_constructor

raiden_contracts/tests/fixtures/contracts.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def fn(
3838
web3: Web3, deployer_address: HexAddress, abi: List, bytecode: str, **kwargs: Dict
3939
) -> str:
4040
contract = web3.eth.contract(abi=abi, bytecode=bytecode)
41-
# Failure does not fire an exception. Check the receipt for status.
42-
return contract.constructor(**kwargs).transact({"from": deployer_address})
41+
return contract.constructor(**kwargs).call_and_transact({"from": deployer_address})
4342

4443
return fn
4544

@@ -57,7 +56,7 @@ def fn(
5756
web3.testing.mine(1)
5857

5958
if web3.eth.getTransactionReceipt(txhash).status != 1:
60-
raise TransactionFailed("deployment failed")
59+
assert "Transaction failure must be caught in estimateGas in deploy_contract_txhash."
6160

6261
return contract(contract_address)
6362

0 commit comments

Comments
 (0)