diff --git a/src/ape_ethereum/trace.py b/src/ape_ethereum/trace.py index 01fa157919..386fef7eca 100644 --- a/src/ape_ethereum/trace.py +++ b/src/ape_ethereum/trace.py @@ -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]: diff --git a/tests/functional/test_trace.py b/tests/functional/test_trace.py index e3b310ccd4..eac30de080 100644 --- a/tests/functional/test_trace.py +++ b/tests/functional/test_trace.py @@ -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