From ac2c8ee1c65f7b3b91080bbd13361e5100bb22a9 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Mon, 25 Mar 2024 10:11:17 +0100 Subject: [PATCH 1/4] Notify user of tx fail in boa call output Closes #138 --- boa/contracts/vyper/vyper_contract.py | 10 ++++++---- boa/network.py | 2 ++ tests/integration/network/anvil/test_network_env.py | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/boa/contracts/vyper/vyper_contract.py b/boa/contracts/vyper/vyper_contract.py index 3ff09399..54d76dd1 100644 --- a/boa/contracts/vyper/vyper_contract.py +++ b/boa/contracts/vyper/vyper_contract.py @@ -160,6 +160,7 @@ def __init__( override_address=None, blueprint_preamble=b"\xFE\x71\x00", filename=None, + gas=None, ): # note slight code duplication with VyperContract ctor, # maybe use common base class? @@ -177,7 +178,7 @@ def __init__( deploy_bytecode += blueprint_bytecode addr, self.bytecode = self.env.deploy_code( - bytecode=deploy_bytecode, override_address=override_address + bytecode=deploy_bytecode, override_address=override_address, gas=gas ) self._address = Address(addr) @@ -472,6 +473,7 @@ def __init__( skip_initcode=False, created_from: Address = None, filename: str = None, + gas=None, ): super().__init__(compiler_data, env, filename) @@ -492,7 +494,7 @@ def __init__( if skip_initcode: addr = Address(override_address) else: - addr = self._run_init(*args, override_address=override_address) + addr = self._run_init(*args, override_address=override_address, gas=gas) self._address = addr for fn_name, fn in external_fns.items(): @@ -513,14 +515,14 @@ def __init__( self.env.register_contract(self._address, self) - def _run_init(self, *args, override_address=None): + def _run_init(self, *args, override_address=None, gas=None): encoded_args = b"" if self._ctor: encoded_args = self._ctor.prepare_calldata(*args) initcode = self.compiler_data.bytecode + encoded_args addr, self.bytecode = self.env.deploy_code( - bytecode=initcode, override_address=override_address + bytecode=initcode, override_address=override_address, gas=gas ) return Address(addr) diff --git a/boa/network.py b/boa/network.py index ddcbc2e8..b9265646 100644 --- a/boa/network.py +++ b/boa/network.py @@ -419,6 +419,8 @@ def _send_txn(self, from_, to=None, gas=None, value=None, data=None): print(f"tx broadcasted: {tx_hash}") receipt = self._rpc.wait_for_tx_receipt(tx_hash, self.tx_settings.poll_timeout) + if receipt["status"] != "0x1": + raise RuntimeError(f"txn failed: {receipt}") trace = None if self._tracer is not None: diff --git a/tests/integration/network/anvil/test_network_env.py b/tests/integration/network/anvil/test_network_env.py index 13ad59d5..9f6bc2ce 100644 --- a/tests/integration/network/anvil/test_network_env.py +++ b/tests/integration/network/anvil/test_network_env.py @@ -56,4 +56,11 @@ def test_raise_exception(simple_contract, t): simple_contract.raise_exception(t) +def test_failed_transaction(): + with pytest.raises(RuntimeError) as ctx: + boa.loads(code, STARTING_SUPPLY, gas=149377) + error = str(ctx.value) + assert error.startswith("txn failed:") + + # XXX: probably want to test deployment revert behavior From 30a9671bd84b08f3120a21234282922eef6dfe63 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Mon, 25 Mar 2024 10:14:33 +0100 Subject: [PATCH 2/4] Fix master lint --- tests/unitary/test_fixture_order.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/unitary/test_fixture_order.py b/tests/unitary/test_fixture_order.py index 6540f512..ac4efba5 100644 --- a/tests/unitary/test_fixture_order.py +++ b/tests/unitary/test_fixture_order.py @@ -6,20 +6,23 @@ # eth_utils.exceptions.ValidationError: No checkpoint 31 was found -@pytest.fixture(scope='module', autouse=True, params=[7,8,9]) +@pytest.fixture(scope="module", autouse=True, params=[7, 8, 9]) def fixture_autouse(request): print(f"SETUP FIXTURE AUTOUSE {request.param}") yield print(f"TEARDOWN FIXTURE AUTOUSE {request.param}") -@pytest.fixture(scope='module', params=[1,2,3]) + +@pytest.fixture(scope="module", params=[1, 2, 3]) def fixture_test(request): print(f"SETUP FIXTURE TEST {request.param}") yield print(f"TEARDOWN FIXTURE TEST {request.param}") + def test_1(fixture_test): pass + def test_2(): pass From fabe52d61016a5cfd7962e8f232b1a5a90c2094d Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Wed, 19 Jun 2024 16:10:55 +0200 Subject: [PATCH 3/4] Fix test --- tests/unitary/jupyter/test_browser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unitary/jupyter/test_browser.py b/tests/unitary/jupyter/test_browser.py index a76090ec..1ec2d821 100644 --- a/tests/unitary/jupyter/test_browser.py +++ b/tests/unitary/jupyter/test_browser.py @@ -210,6 +210,7 @@ def dummy() -> bool: "blockHash": "0x123", "blockNumber": "0x123", "contractAddress": "0x520c4BbBb1153fBB42742fEf935283e19Bb2a2e0", + "status": "0x1", }, ) mock_callback("debug_traceTransaction", error={"message": "error"}) From 4a3ae3f09d03a620858c28c4a66d77aed46a5915 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Wed, 19 Jun 2024 16:13:21 +0200 Subject: [PATCH 4/4] Use `get` and `Exception` --- boa/network.py | 4 ++-- tests/integration/network/anvil/test_network_env.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/boa/network.py b/boa/network.py index a4b71009..2e252178 100644 --- a/boa/network.py +++ b/boa/network.py @@ -512,8 +512,8 @@ def _send_txn(self, from_, to=None, gas=None, value=None, data=None): print(f"tx broadcasted: {tx_hash}") receipt = self._rpc.wait_for_tx_receipt(tx_hash, self.tx_settings.poll_timeout) - if receipt["status"] != "0x1": - raise RuntimeError(f"txn failed: {receipt}") + if receipt.get("status") != "0x1": + raise Exception(f"txn failed: {receipt}") trace = self._debug_tt(tx_hash) diff --git a/tests/integration/network/anvil/test_network_env.py b/tests/integration/network/anvil/test_network_env.py index 9f6bc2ce..c544ed13 100644 --- a/tests/integration/network/anvil/test_network_env.py +++ b/tests/integration/network/anvil/test_network_env.py @@ -57,7 +57,7 @@ def test_raise_exception(simple_contract, t): def test_failed_transaction(): - with pytest.raises(RuntimeError) as ctx: + with pytest.raises(Exception) as ctx: boa.loads(code, STARTING_SUPPLY, gas=149377) error = str(ctx.value) assert error.startswith("txn failed:")