Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Notify user of tx fail in boa call output #188

Merged
merged 5 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why RuntimeError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BoaError expects a stack trace. Which should we use?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuntimeError might be ok, but i'm not sure. i think the only way we can reach here is if the fork mode simulation did not raise any errors, but there is an error when actually sending the transaction (presumably caused by a state change between our snapshot and now).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@charles-cooper charles-cooper Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, i'm a bit confused why it's not already being caught in one of these two places:

if trace.is_error and not computation.is_error:

or
if local_address != create_address:


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
7 changes: 5 additions & 2 deletions tests/unitary/test_fixture_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading