Skip to content

Commit

Permalink
Better error message from deployment failure
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pirapira committed Oct 31, 2019
1 parent 7e730f6 commit 6c6dc31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 13 additions & 3 deletions raiden_contracts/tests/fixtures/base/web3_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from eth_tester import EthereumTester, PyEVMBackend
from web3 import Web3
from web3.contract import ContractFunction
from web3.contract import ContractConstructor, ContractFunction
from web3.providers.eth_tester import EthereumTesterProvider

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


def _estimate_gas_and_transact_constructor(
contract_constructor: ContractConstructor, transaction_params: Optional[Dict] = None
) -> str:
""" Execute contract_constructor.{estimateGas, transact}(transaction_params); return txhash """
# First 'estimate_gas' might raise an exception, containing an error message from require().
contract_constructor.estimateGas(transaction_params)
return contract_constructor.transact(transaction_params)


@pytest.fixture(scope="session", autouse=True)
def call_and_transact() -> None:
ContractFunction.call_and_transact = _call_and_transact
ContractConstructor.call_and_transact = _estimate_gas_and_transact_constructor
3 changes: 1 addition & 2 deletions raiden_contracts/tests/fixtures/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def fn(
web3: Web3, deployer_address: HexAddress, abi: List, bytecode: str, **kwargs: Dict
) -> str:
contract = web3.eth.contract(abi=abi, bytecode=bytecode)
# Failure does not fire an exception. Check the receipt for status.
return contract.constructor(**kwargs).transact({"from": deployer_address})
return contract.constructor(**kwargs).call_and_transact({"from": deployer_address})

return fn

Expand Down

0 comments on commit 6c6dc31

Please sign in to comment.