-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(traces): add a -d | --depth flag for verbose traces, like tree #12643
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
Conversation
grandizzy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you! left some comments, please check
crates/evm/traces/src/lib.rs
Outdated
| pub fn prune_trace_depth(arena: &mut CallTraceArena, depth: usize) { | ||
| for node in arena.nodes_mut() { | ||
| if node.trace.depth >= depth { | ||
| Vec::clear(&mut node.ordering); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can be node.ordering.clear();
crates/forge/src/cmd/test/mod.rs
Outdated
|
|
||
| /// Defines the depth of a trace | ||
| #[arg(long, short)] | ||
| depth: Option<usize>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think trace_depth would be better naming
Also the ticket mentions cast as well, so let's extend the option to cast too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added for cast run as well. I noticed we use traces on cast call as well. Shall we add prune trace depth over there as well?
https://github.com/foundry-rs/foundry/blob/master/crates/cast/src/cmd/call.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cast run should be fine for now, will extend if needed for other
| } | ||
|
|
||
| #[test] | ||
| fn depth_trace() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please apply the new option in similar test as with test_trace test here
foundry/crates/forge/tests/cli/test_cmd/trace.rs
Lines 199 to 210 in 6063717
| [..] TraceTest::testRecurseCall() | |
| ├─ [..] Node 0::recurseCall(8, 0) | |
| │ ├─ [..] Node 0::recurseCall(8, 1) | |
| │ │ ├─ [..] Node 0::recurseCall(8, 2) | |
| │ │ │ ├─ [..] Node 0::recurseCall(8, 3) | |
| │ │ │ │ ├─ [..] Node 0::recurseCall(8, 4) | |
| │ │ │ │ │ ├─ [..] Node 0::recurseCall(8, 5) | |
| │ │ │ │ │ │ ├─ [..] Node 0::recurseCall(8, 6) | |
| │ │ │ │ │ │ │ ├─ [..] Node 0::recurseCall(8, 7) | |
| │ │ │ │ │ │ │ │ ├─ [..] Node 0::recurseCall(8, 8) | |
| │ │ │ │ │ │ │ │ │ ├─ [..] Node 0::negativeNum() [staticcall] | |
| │ │ │ │ │ │ │ │ │ │ └─ ← [Return] -1000000000 [-1e9] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added another test in the same file. Use the same contract RecursiveCall that was used in that file.
grandizzy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thank you!
Motivation
Closes #12446
This PR introduces a new
--depth(or-d) CLI option toforge testthat allows users to limit how many levels of the call tree are displayed. This change makes traces easier to read.Solution
Example:
Debugging passing tests
Trace output:
a) Command example:
forge test --depth 3 -vvvvTrace output:
b) Command example:
forge test --depth 1 -vvvvDebugging failing tests
Trace output:
a) Command example
forge test --depth 1 -vvvTrace output:
b) Command example:
forge test --depth 3 -vvvPR Checklist