Skip to content

Commit

Permalink
fix: transferring eth fix
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Jan 17, 2024
1 parent a2fb33b commit 0963dfc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
6 changes: 0 additions & 6 deletions docs/userguides/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,6 @@ At the end of test suite, you will see tables such as:
changeOnStatus 2 23827 45739 34783 34783
getSecret 1 24564 24564 24564 24564

Transferring ETH Gas

Method Times called Min. Max. Mean Median
───────────────────────────────────────────────────────
to:test0 2 2400 9100 5750 5750

TestContract Gas

Method Times called Min. Max. Mean Median
Expand Down
18 changes: 18 additions & 0 deletions docs/userguides/trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ DSProxy.execute(_target=LoanShifterTaker, _data=0x35..0000) -> "" [1421947 gas]
) [6057 gas]
```

Similarly, you can use the provider directly to get a trace.
This is useful if you want to interact with the trace or change some parameters for creating the trace.

```python
from ape import chain

# Change the `debug_traceTransaction` parameter dictionary
trace = chain.provider.get_transaction_trace(
"0x...", debug_trace_transaction_parameters={"enableMemory": False}
)

# You can still print the pretty call-trace (as we did in the example above)
print(trace)

# Interact with low-level logs for deeper analysis.
struct_logs = trace.get_raw_frames()
```

## Tracing Calls

Some network providers trace calls in addition to transactions.
Expand Down
2 changes: 1 addition & 1 deletion src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ def _enrich_calltree(self, call: Dict, **kwargs) -> Dict:

depth = call.get("depth", 0)
if depth == 0 and address in self.account_manager:
call["contract_id"] = "Transferring ETH"
call["contract_id"] = f"__{self.fee_token_symbol}_transfer__"
else:
call["contract_id"] = self._enrich_contract_id(call["contract_id"], **kwargs)

Expand Down
10 changes: 4 additions & 6 deletions src/ape_ethereum/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,13 @@ def get_gas_report(self, exclude: Optional[Sequence[ContractFunctionPath]] = Non
tx = self.transaction

# Enrich transfers.
if (
call.get("contract_id", "").startswith("Transferring ")
and tx.get("to") is not None
and tx["to"] in self.account_manager
):
contract_id = call.get("contract_id", "")
is_transfer = contract_id.startswith("__") and contract_id.endswith("transfer__")
if is_transfer and tx.get("to") is not None and tx["to"] in self.account_manager:
receiver_id = self.account_manager[tx["to"]].alias or tx["to"]
call["method_id"] = f"to:{receiver_id}"

elif call.get("contract_id", "").startswith("Transferring ") and (receiver := tx.get("to")):
elif is_transfer and (receiver := tx.get("to")):
call["method_id"] = f"to:{receiver}"

exclusions = exclude or []
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_get_gas_report_transfer(gas_tracker, sender, receiver):
tx = sender.transfer(receiver, 0)
trace = tx.trace
actual = trace.get_gas_report()
expected = {"Transferring ETH": {"to:TEST::2": [tx.gas_used]}}
expected = {"__ETH_transfer__": {"to:TEST::2": [tx.gas_used]}}
assert actual == expected


Expand Down

0 comments on commit 0963dfc

Please sign in to comment.