From f58eb7a090fea4c5ef4a54c8a726b09f652d62f8 Mon Sep 17 00:00:00 2001 From: szotov Date: Tue, 10 Sep 2019 18:34:20 +0300 Subject: [PATCH] Monkey patch to prevent gas estimates --- nucypher/utilities/sandbox/blockchain.py | 3 +++ tests/fixtures.py | 8 ++++++++ 2 files changed, 11 insertions(+) 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/fixtures.py b/tests/fixtures.py index de8f84d73..bf4c8f0e0 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -369,6 +369,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)