|
4 | 4 | import pytest
|
5 | 5 | from eth_tester import EthereumTester, PyEVMBackend
|
6 | 6 | from web3 import Web3
|
7 |
| -from web3.contract import ContractFunction |
| 7 | +from web3.contract import ContractConstructor, ContractFunction |
8 | 8 | from web3.providers.eth_tester import EthereumTesterProvider
|
9 | 9 |
|
10 | 10 | from raiden_contracts.tests.utils.constants import (
|
@@ -77,12 +77,22 @@ def auto_revert_chain(web3: Web3) -> Generator:
|
77 | 77 | def _call_and_transact(
|
78 | 78 | contract_function: ContractFunction, transaction_params: Optional[Dict] = None
|
79 | 79 | ) -> 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(). |
82 | 82 | contract_function.call(transaction_params)
|
83 | 83 | return contract_function.transact(transaction_params)
|
84 | 84 |
|
85 | 85 |
|
| 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 | + |
86 | 95 | @pytest.fixture(scope="session", autouse=True)
|
87 | 96 | def call_and_transact() -> None:
|
88 | 97 | ContractFunction.call_and_transact = _call_and_transact
|
| 98 | + ContractConstructor.call_and_transact = _estimate_gas_and_transact_constructor |
0 commit comments