-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(forge
): backtraces
#11547
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(forge
): backtraces
#11547
Conversation
… failures + pass SourceData by reference
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, nits.
This does enable steps tracing on -vvv which is 2-3x slower even when no tests fail. I think this is probably fine, however we might want to look into re-executing failing tests since this level of tracing is only needed when they fail.
Edit: we can further optimize this by not requesting stack snapshots since we don't need them. I think we just want jump steps.
Motivation
Closes #2328
Forge lacks backtraces, which are useful for pinpointing the line where the revert/error originated in the call stack. This is especially useful when there are multiple nested calls between different contracts, making traces hard to follow. Backtraces help you easily "goto" the line throwing the error.
Solution
forge test
verbosity >= 3
and printed if there is a revertverbosity >= 3
, we collect the source maps, deployed bytecode, and source content using theBacktraceBuilder
.BacktraceBuilder::from_trace(arena)
; thebytecode.pc
(program counter) is mapped to the instruction pointer and then source maps are used to pinpoint the source locations in the call stack.BacktraceFrame
containing the source location of the call along with the contract and function names.Implementation can be tested using:
foundryup --pr 11547
Clone: https://github.com/yash-atreya/test-backtraces
Run
forge t -vvv
Should work across fresh and cached artifacts, i.e, when there are compiler source ID conflicts - 028b1aa + 5c93b5c
Fork test backtraces with and without
ETHERSCAN_API_KEY
c9ce5bcResolve external libs ac1208c
Handle breaking tests f929071
Cleanup and remove debug logs
Handling assertions feat: extend (error) traces to include source code line number and filename #2328 (comment)
In this case, we are just showing the assertion frame without source location e.g
foundry/crates/forge/tests/cli/test_cmd.rs
Line 2990 in d75a675
Followup
foundry/crates/forge/src/cmd/test/mod.rs
Lines 310 to 327 in 9d4f7eb
PR Checklist