Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: default displayable trace in repr and str for CallTreeNode #5

Merged
merged 4 commits into from
Jun 9, 2022

Conversation

antazoey
Copy link
Member

@antazoey antazoey commented May 16, 2022

What I did

Provide default tree via __repr__ and __str__ methods.

How I did it

Inspired from the answer with 66 updoots: https://stackoverflow.com/questions/9727673/list-directory-tree-structure-in-python

How to verify it

print(tree)

Checklist

  • Passes all linting checks (pre-commit and CI jobs)
  • New test cases have been added and are passing
  • Documentation has been updated
  • PR title follows Conventional Commit standard (will be automatically included in the changelog)

@@ -58,6 +58,15 @@ class CallTreeNode(BaseModel):
def validate_hexbytes(cls, v) -> HexBytes:
return _convert_hexbytes(cls, v)

def __str__(self) -> str:
spacing = self.depth * " "
title = f"{spacing} {self.call_type} call {self.address.hex()} gas={self.gas_cost}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tell me any extra useful data you'd like per default node

@antazoey
Copy link
Member Author

antazoey commented May 16, 2022

  • I want to try and get the tree branches to still appear

Comment on lines 36 to 23
@pytest.mark.parametrize("test_data", (
{"stack": ["potato"]},
{"memory": ["potato"]},
{"storage": {"piggy": "dippin"}},
)


@pytest.mark.parametrize("test_value", trace_frame_test_cases)
def test_trace_frame_validation_fails(test_value):
trace_frame_structure = deepcopy(TRACE_FRAME_STRUCTURE)
trace_frame_structure.update(test_value)

))
def test_trace_frame_validation_fails(test_data):
data = {**TRACE_FRAME_STRUCTURE, **test_data}
with pytest.raises(ValidationError):
TraceFrame(**trace_frame_structure)
TraceFrame(**data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@antazoey antazoey force-pushed the feat/jules-decode branch from 6c9f4f5 to b00be08 Compare May 17, 2022 15:29
@antazoey
Copy link
Member Author

default traces be like

Mutable call @ 0xf2df0b975c0c9efa2f8ca0491c2d1685104d2488 gas=194827
├── Mutable call @ 0xbcf7fffd8b256ec51a36782a52d0c34f6474d951 gas=168423
│   └── Mutable call @ 0x274b028b03a250ca03644e6c578d81f019ee1323 gas=160842
├── Mutable call @ 0xbcf7fffd8b256ec51a36782a52d0c34f6474d951 gas=116942
│   └── Mutable call @ 0x274b028b03a250ca03644e6c578d81f019ee1323 gas=114595
└── Mutable call @ 0xbcf7fffd8b256ec51a36782a52d0c34f6474d951 gas=93421
    ├── Mutable call @ 0x274b028b03a250ca03644e6c578d81f019ee1323 gas=91277
    ├── Mutable call @ 0x274b028b03a250ca03644e6c578d81f019ee1323 gas=46476
    └── Mutable call @ 0x274b028b03a250ca03644e6c578d81f019ee1323 gas=23491

Mutable call @ 0xf2df0b975c0c9efa2f8ca0491c2d1685104d2488 gas=228635
├── Mutable call @ 0xbcf7fffd8b256ec51a36782a52d0c34f6474d951 gas=180061
│   └── Mutable call @ 0x274b028b03a250ca03644e6c578d81f019ee1323 gas=172298
├── Mutable call @ 0xbcf7fffd8b256ec51a36782a52d0c34f6474d951 gas=145417
│   ├── Mutable call @ 0x274b028b03a250ca03644e6c578d81f019ee1323 gas=142461
│   ├── Mutable call @ 0x274b028b03a250ca03644e6c578d81f019ee1323 gas=117249
│   └── Mutable call @ 0x274b028b03a250ca03644e6c578d81f019ee1323 gas=94264
├── Mutable call @ 0xbcf7fffd8b256ec51a36782a52d0c34f6474d951 gas=73514
│   ├── Mutable call @ 0x274b028b03a250ca03644e6c578d81f019ee1323 gas=71681
│   ├── Mutable call @ 0x274b028b03a250ca03644e6c578d81f019ee1323 gas=48537
│   └── Mutable call @ 0x274b028b03a250ca03644e6c578d81f019ee1323 gas=25552
└── Static call @ 0xbcf7fffd8b256ec51a36782a52d0c34f6474d951 gas=3805

@antazoey antazoey changed the title feat: default trace print ability feat: default displayable trace in repr and str for CallTreeNode May 17, 2022
@antazoey antazoey requested review from NotPeopling2day and fubuloubu and removed request for fubuloubu and NotPeopling2day May 20, 2022 19:31
@antazoey antazoey marked this pull request as draft May 20, 2022 20:42
evm_trace/_display.py Outdated Show resolved Hide resolved
evm_trace/_display.py Outdated Show resolved Hide resolved
@antazoey antazoey marked this pull request as ready for review May 23, 2022 18:51
setup.py Show resolved Hide resolved
@antazoey antazoey force-pushed the feat/jules-decode branch from 36d848f to 45da160 Compare June 8, 2022 17:48
@antazoey antazoey merged commit 71b07d7 into ApeWorX:main Jun 9, 2022
@antazoey antazoey deleted the feat/jules-decode branch June 9, 2022 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants