Skip to content

Commit

Permalink
fix: callable trace bug when estimating gas on revert-tx with no fail…
Browse files Browse the repository at this point in the history
… message (#2344)
  • Loading branch information
antazoey authored Oct 26, 2024
1 parent fee84bb commit 54dcc57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
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

0 comments on commit 54dcc57

Please sign in to comment.