Skip to content

Commit

Permalink
Merge pull request #8 from unparalleled-js/feat/jules/fixes-from-alchemy
Browse files Browse the repository at this point in the history
fix: better handling of None gas and parity reverts
  • Loading branch information
antazoey authored Jun 15, 2022
2 parents eeb3515 + 9c16880 commit 64f4031
Show file tree
Hide file tree
Showing 6 changed files with 340 additions and 25 deletions.
4 changes: 2 additions & 2 deletions evm_trace/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import math
from typing import Any, Dict, Iterable, Iterator, List, Optional, Type
from typing import Any, Dict, Iterator, List, Optional, Type

from eth_utils import to_int
from hexbytes import HexBytes
Expand Down Expand Up @@ -50,7 +50,7 @@ class CallTreeNode(BaseModel):
display_cls: Type[DisplayableCallTreeNode] = DisplayableCallTreeNode

@property
def display_nodes(self) -> Iterable[DisplayableCallTreeNode]:
def display_nodes(self) -> Iterator[DisplayableCallTreeNode]:
return self.display_cls.make_tree(self)

@validator("address", "calldata", "returndata", pre=True)
Expand Down
20 changes: 14 additions & 6 deletions evm_trace/display.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Iterable, Optional
from typing import TYPE_CHECKING, Iterator, Optional

from eth_utils import to_checksum_address

Expand Down Expand Up @@ -38,20 +38,28 @@ def title(self) -> str:
address = address_hex_str

cost = self.call.gas_cost

call_path = str(address)
call_path = str(address) if address else ""
if self.call.calldata:
call_path = f"{call_path}.<{self.call.calldata[:4].hex()}>"
call_path = f"{call_path}." if call_path else ""
call_path = f"{call_path}<{self.call.calldata[:4].hex()}>"

call_path = (
f"[reverted] {call_path}" if self.call.failed and self.parent is None else call_path
)
call_path = call_path.strip()
node_title = f"{call_type}: {call_path}" if call_path else call_type
if cost is not None:
node_title = f"{node_title} [{cost} gas]"

return f"{call_type}: {call_path} [{cost} gas]"
return node_title

@classmethod
def make_tree(
cls,
root: "CallTreeNode",
parent: Optional["DisplayableCallTreeNode"] = None,
is_last: bool = False,
) -> Iterable["DisplayableCallTreeNode"]:
) -> Iterator["DisplayableCallTreeNode"]:
displayable_root = cls(root, parent=parent, is_last=is_last)
yield displayable_root

Expand Down
15 changes: 9 additions & 6 deletions evm_trace/parity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional, Type, Union
from typing import Any, Dict, List, Optional, Type, Union

from pydantic import BaseModel, Field, validator

Expand Down Expand Up @@ -96,6 +96,7 @@ def get_calltree_from_parity_trace(
traces: ParityTraceList,
root: Optional[ParityTrace] = None,
display_cls: Type[DisplayableCallTreeNode] = DisplayableCallTreeNode,
**root_kwargs,
) -> CallTreeNode:
"""
Create a :class:`~evm_trace.base.CallTreeNode` from output models using the Parity approach
Expand All @@ -108,17 +109,19 @@ def get_calltree_from_parity_trace(
the first item by default.
display_cls (Type[DisplayableCallTreeNode]]: A custom class to use for representing
the call tree. Defaults to :class:`~evm_trace.display.DisplayableCallTreeNode`.
**root_kwargs: Additional kwargs to append to the root node. Useful for adding gas for
reverted calls.
Returns:
:class:`~evm_trace.base.CallTreeNode`
"""
if root is None:
root = traces[0]

node_kwargs = dict(
root = root or traces[0]
failed = root.error is not None
node_kwargs: Dict[Any, Any] = dict(
call_type=root.call_type,
error=root.error is not None,
failed=failed,
display_cls=display_cls,
**root_kwargs,
)

if root.call_type == CallType.CREATE:
Expand Down
285 changes: 285 additions & 0 deletions tests/data/parity/revert_with_message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
[
{
"action": {
"from": "0x7768fbc67afecf2b4caee9d1841ad14637d13652",
"callType": "call",
"gas": "0x3c8c1",
"input": "0x5ae401dc0000000000000000000000000000000000000000000000000000000062a8f38e00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e4472b43f300000000000000000000000000000000000000000000000007b3c18f3a57800000000000000000000000000000000000000000000000000009288316522878cc00000000000000000000000000000000000000000000000000000000000000800000000000000000000000007768fbc67afecf2b4caee9d1841ad14637d136520000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000005be7632014b307bd29304bbceab6478a89fa738400000000000000000000000000000000000000000000000000000000",
"to": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
"value": "0x7b3c18f3a578000"
},
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
"blockNumber": 14963663,
"error": "Reverted",
"result": null,
"subtraces": 1,
"traceAddress": [],
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
"transactionPosition": 248,
"type": "call"
},
{
"action": {
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
"callType": "delegatecall",
"gas": "0x3b497",
"input": "0x472b43f300000000000000000000000000000000000000000000000007b3c18f3a57800000000000000000000000000000000000000000000000000009288316522878cc00000000000000000000000000000000000000000000000000000000000000800000000000000000000000007768fbc67afecf2b4caee9d1841ad14637d136520000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000005be7632014b307bd29304bbceab6478a89fa7384",
"to": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
"value": "0x7b3c18f3a578000"
},
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
"blockNumber": 14963663,
"error": "Reverted",
"result": null,
"subtraces": 7,
"traceAddress": [
0
],
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
"transactionPosition": 248,
"type": "call"
},
{
"action": {
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
"callType": "call",
"gas": "0x379a1",
"input": "0xd0e30db0",
"to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"value": "0x7b3c18f3a578000"
},
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
"blockNumber": 14963663,
"result": {
"gasUsed": "0x5da6",
"output": "0x"
},
"subtraces": 0,
"traceAddress": [
0,
0
],
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
"transactionPosition": 248,
"type": "call"
},
{
"action": {
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
"callType": "call",
"gas": "0x31bc9",
"input": "0xa9059cbb0000000000000000000000002c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e00000000000000000000000000000000000000000000000007b3c18f3a578000",
"to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"value": "0x0"
},
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
"blockNumber": 14963663,
"result": {
"gasUsed": "0x1f7e",
"output": "0x0000000000000000000000000000000000000000000000000000000000000001"
},
"subtraces": 0,
"traceAddress": [
0,
1
],
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
"transactionPosition": 248,
"type": "call"
},
{
"action": {
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
"callType": "staticcall",
"gas": "0x2f059",
"input": "0x70a082310000000000000000000000007768fbc67afecf2b4caee9d1841ad14637d13652",
"to": "0x5be7632014b307bd29304bbceab6478a89fa7384",
"value": "0x0"
},
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
"blockNumber": 14963663,
"result": {
"gasUsed": "0x1a14",
"output": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"subtraces": 0,
"traceAddress": [
0,
2
],
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
"transactionPosition": 248,
"type": "call"
},
{
"action": {
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
"callType": "staticcall",
"gas": "0x2c6b3",
"input": "0x0902f1ac",
"to": "0x2c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
"value": "0x0"
},
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
"blockNumber": 14963663,
"result": {
"gasUsed": "0x9c8",
"output": "0x000000000000000000000000000000000000000000000000caa825830eefc756000000000000000000000000000000000000000000000000b73b0cd356c097060000000000000000000000000000000000000000000000000000000062a8ef1e"
},
"subtraces": 0,
"traceAddress": [
0,
3
],
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
"transactionPosition": 248,
"type": "call"
},
{
"action": {
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
"callType": "staticcall",
"gas": "0x2b9bd",
"input": "0x70a082310000000000000000000000002c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
"to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"value": "0x0"
},
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
"blockNumber": 14963663,
"result": {
"gasUsed": "0x216",
"output": "0x000000000000000000000000000000000000000000000000beeece6291181706"
},
"subtraces": 0,
"traceAddress": [
0,
4
],
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
"transactionPosition": 248,
"type": "call"
},
{
"action": {
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
"callType": "call",
"gas": "0x2b124",
"input": "0x022c0d9f0000000000000000000000000000000000000000000000000826cda4f5acb78e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000007768fbc67afecf2b4caee9d1841ad14637d1365200000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000",
"to": "0x2c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
"value": "0x0"
},
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
"blockNumber": 14963663,
"result": {
"gasUsed": "0x1d480",
"output": "0x"
},
"subtraces": 3,
"traceAddress": [
0,
5
],
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
"transactionPosition": 248,
"type": "call"
},
{
"action": {
"from": "0x2c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
"callType": "call",
"gas": "0x27c8f",
"input": "0xa9059cbb0000000000000000000000007768fbc67afecf2b4caee9d1841ad14637d136520000000000000000000000000000000000000000000000000826cda4f5acb78e",
"to": "0x5be7632014b307bd29304bbceab6478a89fa7384",
"value": "0x0"
},
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
"blockNumber": 14963663,
"result": {
"gasUsed": "0x1764b",
"output": "0x0000000000000000000000000000000000000000000000000000000000000001"
},
"subtraces": 0,
"traceAddress": [
0,
5,
0
],
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
"transactionPosition": 248,
"type": "call"
},
{
"action": {
"from": "0x2c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
"callType": "staticcall",
"gas": "0x109b0",
"input": "0x70a082310000000000000000000000002c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
"to": "0x5be7632014b307bd29304bbceab6478a89fa7384",
"value": "0x0"
},
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
"blockNumber": 14963663,
"result": {
"gasUsed": "0xa74",
"output": "0x000000000000000000000000000000000000000000000000c28157de19430fc8"
},
"subtraces": 0,
"traceAddress": [
0,
5,
1
],
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
"transactionPosition": 248,
"type": "call"
},
{
"action": {
"from": "0x2c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
"callType": "staticcall",
"gas": "0xfdd0",
"input": "0x70a082310000000000000000000000002c6b0aa42d4fcb880f5ffffbd0e39e4b48548c1e",
"to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"value": "0x0"
},
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
"blockNumber": 14963663,
"result": {
"gasUsed": "0x216",
"output": "0x000000000000000000000000000000000000000000000000beeece6291181706"
},
"subtraces": 0,
"traceAddress": [
0,
5,
2
],
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
"transactionPosition": 248,
"type": "call"
},
{
"action": {
"from": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45",
"callType": "staticcall",
"gas": "0xe144",
"input": "0x70a082310000000000000000000000007768fbc67afecf2b4caee9d1841ad14637d13652",
"to": "0x5be7632014b307bd29304bbceab6478a89fa7384",
"value": "0x0"
},
"blockHash": "0x5126b891b46a265d31df884f4cffadbdfed6e34d8be4d93694d200ccc48e72d6",
"blockNumber": 14963663,
"result": {
"gasUsed": "0xa74",
"output": "0x0000000000000000000000000000000000000000000000000794ba2117ad6d45"
},
"subtraces": 0,
"traceAddress": [
0,
6
],
"transactionHash": "0x15cddbe410208d3c819a6f2ee50b8cc9c4b0f3362ca2f99fe1bf5c0ab955b1f7",
"transactionPosition": 248,
"type": "call"
}
]
Loading

0 comments on commit 64f4031

Please sign in to comment.