Skip to content

Commit

Permalink
fix: issue where trace.return_data was no decoded in some cases (#2213
Browse files Browse the repository at this point in the history
)
  • Loading branch information
antazoey authored Aug 8, 2024
1 parent 508aa50 commit f1bf080
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/ape_ethereum/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,18 @@ def _return_value_from_enriched_calltree(self) -> Any:

# If enriching too much, Ethereum places regular values in a key
# named "unenriched_return_values".
return calltree.get("unenriched_return_values") or calltree.get("returndata")
if "unenriched_return_values" in calltree:
return calltree["unenriched_return_values"]

if raw_return_data := calltree.get("returndata"):
if abi := self.root_method_abi:
try:
return self._ecosystem.decode_returndata(abi, HexBytes(raw_return_data))
except Exception as err:
logger.debug(f"Failed decoding raw returndata. Error: {err}")
return raw_return_data

return None

@cached_property
def revert_message(self) -> Optional[str]:
Expand Down
13 changes: 13 additions & 0 deletions tests/functional/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ def test_revert_message_empty(owner):
assert trace.revert_message is None


def test_return_value_never_enriched(owner, solidity_contract_instance):
tx = solidity_contract_instance.myNumber.transact(sender=owner)
trace = TransactionTrace.model_validate({"transaction_hash": tx.txn_hash})

# Hack in criteria to cause it to look for a revert message more.
returndata = "0x0000000000000000000000000000000000000000000000bdbc41e0348b300000"
trace._enriched_calltree = {"failed": True, "returndata": returndata}

actual = trace.return_value
expected = 3500000000000000000000 # returndata as an int.
assert actual == (expected,)


def test_enriched_calltree_adds_missing_gas(simple_trace_cls):
compute_gas = 1234
base_gas = 21_000
Expand Down

0 comments on commit f1bf080

Please sign in to comment.