diff --git a/nucypher/utilities/sandbox/blockchain.py b/nucypher/utilities/sandbox/blockchain.py index 4029e6d01..ff25559e6 100644 --- a/nucypher/utilities/sandbox/blockchain.py +++ b/nucypher/utilities/sandbox/blockchain.py @@ -20,6 +20,7 @@ import os from typing import List, Tuple import maya +from eth_tester.exceptions import TransactionFailed from twisted.logger import Logger from web3 import Web3 @@ -265,5 +266,7 @@ class TesterBlockchain(BlockchainDeployerInterface): """Wait for a transaction receipt and return it""" timeout = timeout or self.TIMEOUT result = self.w3.eth.waitForTransactionReceipt(txhash, timeout=timeout) + if result.status == 0: + raise TransactionFailed() return result diff --git a/tests/blockchain/eth/interfaces/test_chains.py b/tests/blockchain/eth/interfaces/test_chains.py index b0efc2e85..1fdc33972 100644 --- a/tests/blockchain/eth/interfaces/test_chains.py +++ b/tests/blockchain/eth/interfaces/test_chains.py @@ -48,6 +48,7 @@ def test_testerchain_creation(testerchain, another_testerchain): assert 'tester' in chain.provider_uri # ... and that there are already some blocks mined + chain.w3.eth.web3.testing.mine(1) assert chain.w3.eth.blockNumber > 0 # Check that we have enough test accounts diff --git a/tests/fixtures.py b/tests/fixtures.py index 3ec358837..7601ae85c 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -23,6 +23,8 @@ import tempfile import maya import pytest +from eth_tester import PyEVMBackend + from constant_sorrow.constants import NON_PAYMENT from sqlalchemy.engine import create_engine from twisted.logger import Logger @@ -366,6 +368,14 @@ def _make_testerchain(): eth._utils.headers.GAS_LIMIT_MINIMUM = TEST_GAS_LIMIT eth._utils.headers.GENESIS_GAS_LIMIT = TEST_GAS_LIMIT eth.vm.forks.frontier.headers.GENESIS_GAS_LIMIT = TEST_GAS_LIMIT + + # Monkey patch to prevent gas estimates + def _get_buffered_gas_estimate(web3, transaction, gas_buffer=100000): + return TEST_GAS_LIMIT + + import web3 + web3.eth.get_buffered_gas_estimate = _get_buffered_gas_estimate + # Create the blockchain testerchain = TesterBlockchain(eth_airdrop=True, free_transactions=True) BlockchainInterfaceFactory.register_interface(interface=testerchain) @@ -387,6 +397,11 @@ def _testerchain(): def testerchain(_testerchain): testerchain = _testerchain + # Reset chain state + pyevm_backend = testerchain.provider.ethereum_tester.backend + snapshot = pyevm_backend.chain.get_canonical_block_by_number(0).hash + pyevm_backend.revert_to_snapshot(snapshot) + coinbase, *addresses = testerchain.client.accounts for address in addresses: