Skip to content

Commit

Permalink
Notify user of tx fail in boa call output
Browse files Browse the repository at this point in the history
Closes #138
  • Loading branch information
DanielSchiavini committed Mar 25, 2024
1 parent 48d8514 commit e3c4e9c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 6 additions & 4 deletions boa/contracts/vyper/vyper_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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)
Expand Down Expand Up @@ -472,6 +473,7 @@ def __init__(
skip_initcode=False,
created_from: Address = None,
filename: str = None,
gas=None,
):
super().__init__(compiler_data, env, filename)

Expand All @@ -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():
Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions boa/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/network/anvil/test_network_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e3c4e9c

Please sign in to comment.