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: callable trace bug when estimating gas on revert-tx with no fail message #2344

Merged
merged 3 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 11 additions & 6 deletions src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
from ape.api.trace import TraceAPI
from ape.api.transactions import ReceiptAPI, TransactionAPI
from ape.exceptions import (
_SOURCE_TRACEBACK_ARG,
_TRACE_ARG,
ApeException,
APINotImplementedError,
BlockNotFoundError,
Expand Down Expand Up @@ -1245,9 +1247,9 @@ def _handle_execution_reverted(
self,
exception: Union[Exception, str],
txn: Optional[TransactionAPI] = None,
trace: Optional[TraceAPI] = None,
trace: _TRACE_ARG = None,
contract_address: Optional[AddressType] = None,
source_traceback: Optional[SourceTraceback] = None,
source_traceback: _SOURCE_TRACEBACK_ARG = None,
set_ape_traceback: Optional[bool] = None,
) -> ContractLogicError:
if hasattr(exception, "args") and len(exception.args) == 2:
Expand Down Expand Up @@ -1277,10 +1279,13 @@ def _handle_execution_reverted(
if trace is None and txn is not None:
trace = self.provider.get_transaction_trace(to_hex(txn.txn_hash))

if trace is not None and (revert_message := trace.revert_message):
message = revert_message
no_reason = False
if revert_message := trace.revert_message:
if trace is not None:
if callable(trace):
trace_called = params["trace"] = trace()
else:
trace_called = trace

if trace_called is not None and (revert_message := trace_called.revert_message):
message = revert_message
no_reason = False

Expand Down
11 changes: 10 additions & 1 deletion tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,21 @@ def test_estimate_gas_cost_of_static_fee_txn(geth_contract, geth_provider, geth_


@geth_process_test
def test_estimate_gas_cost_reverts(geth_contract, geth_provider, geth_second_account):
def test_estimate_gas_cost_reverts_with_message(geth_contract, geth_provider, geth_second_account):
# NOTE: The error message from not-owner is "!authorized".
txn = geth_contract.setNumber.as_transaction(900, sender=geth_second_account, type=0)
with pytest.raises(ContractLogicError):
geth_provider.estimate_gas_cost(txn)


@geth_process_test
def test_estimate_gas_cost_reverts_no_message(geth_contract, geth_provider, geth_account):
# NOTE: The error message from using `5` has no revert message.
txn = geth_contract.setNumber.as_transaction(5, sender=geth_account, type=0)
with pytest.raises(ContractLogicError):
geth_provider.estimate_gas_cost(txn)


@geth_process_test
@pytest.mark.parametrize("tx_type", TransactionType)
def test_prepare_transaction_with_max_gas(tx_type, geth_provider, ethereum, geth_account):
Expand Down
Loading