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

fix(cheatcodes): clear orderings together with trace steps on debug trace stop #9529

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/cheatcodes/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,12 @@ impl Cheatcode for stopAndReturnDebugTraceRecordingCall {

let debug_steps: Vec<DebugStep> =
steps.iter().map(|&step| convert_call_trace_to_debug_step(step)).collect();

// Free up memory by clearing the steps if they are not recorded outside of cheatcode usage.
if !record_info.original_tracer_config.record_steps {
tracer.traces_mut().nodes_mut().iter_mut().for_each(|node| {
node.trace.steps = Vec::new();
node.logs = Vec::new();
node.ordering = Vec::new();
});
}

Expand Down
41 changes: 41 additions & 0 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2724,3 +2724,44 @@ Encountered a total of 1 failing tests, 0 tests succeeded

"#]]);
});

// Tests that `start/stopAndReturn` debugTraceRecording does not panic when running with
// verbosity > 3. <https://github.com/foundry-rs/foundry/issues/9526>
forgetest_init!(should_not_panic_on_debug_trace_verbose, |prj, cmd| {
prj.add_test(
"DebugTraceRecordingTest.t.sol",
r#"
import "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";

contract DebugTraceRecordingTest is Test {
function test_start_stop_recording() public {
vm.startDebugTraceRecording();
Counter counter = new Counter();
counter.increment();
vm.stopAndReturnDebugTraceRecording();
}
}
"#,
)
.unwrap();

cmd.args(["test", "--mt", "test_start_stop_recording", "-vvvv"]).assert_success().stdout_eq(
str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Compiler run successful!

Ran 1 test for test/DebugTraceRecordingTest.t.sol:DebugTraceRecordingTest
[PASS] test_start_stop_recording() ([GAS])
Traces:
[476338] DebugTraceRecordingTest::test_start_stop_recording()
└─ ← [Stop]

Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]

Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)

"#]],
);
});
Loading