Skip to content
Open
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
16 changes: 14 additions & 2 deletions crates/evm/evm/src/executors/fuzz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ struct FuzzTestData {
breakpoints: Option<Breakpoints>,
// Stores coverage information for all fuzz cases.
coverage: Option<HitMaps>,
// Stores logs for all fuzz cases
// Stores logs for all fuzz cases (when show_logs is true) or just the last run (when show_logs
// is false)
logs: Vec<Log>,
// Deprecated cheatcodes mapped to their replacements.
deprecated_cheatcodes: HashMap<&'static str, Option<&'static str>>,
Expand Down Expand Up @@ -198,8 +199,13 @@ impl FuzzedExecutor {
test_data.breakpoints.replace(case.breakpoints);
}

// Always store logs from the last run in test_data.logs for display at
// verbosity >= 2. When show_logs is true,
// accumulate all logs. When false, only keep the last run's logs.
if self.config.show_logs {
test_data.logs.extend(case.logs);
} else {
test_data.logs = case.logs;
}

HitMaps::merge_opt(&mut test_data.coverage, case.coverage);
Expand Down Expand Up @@ -255,14 +261,20 @@ impl FuzzedExecutor {
(call.traces.clone(), call.cheatcodes.map(|c| c.breakpoints))
};

// test_data.logs already contains the appropriate logs:
// - For failed tests: logs from the counterexample
// - For successful tests with show_logs=true: all logs from all runs
// - For successful tests with show_logs=false: logs from the last run only
let result_logs = test_data.logs;

let mut result = FuzzTestResult {
first_case: test_data.first_case.unwrap_or_default(),
gas_by_case: test_data.gas_by_case,
success: test_data.failure.is_none(),
skipped: false,
reason: None,
counterexample: None,
logs: test_data.logs,
logs: result_logs,
labels: call.labels,
traces: last_run_traces,
breakpoints: last_run_breakpoints,
Expand Down
16 changes: 12 additions & 4 deletions crates/forge/tests/cli/test_cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,8 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
"#]]);
});

// tests that `forge test` with config `show_logs: false` for fuzz tests will not display
// `console.log` info
// tests that `forge test` with config `show_logs: false` for fuzz tests will
// still display `console.log` from the last run at verbosity >= 2 (issue #11039)
forgetest_init!(should_not_show_logs_when_fuzz_test, |prj, cmd| {
// run fuzz test 3 times
prj.update_config(|config| {
Expand All @@ -1149,22 +1149,26 @@ forgetest_init!(should_not_show_logs_when_fuzz_test, |prj, cmd| {
}
"#,
);
// At verbosity >= 2, logs from the last run should be shown even when show_logs is false
cmd.args(["test", "-vv"]).assert_success().stdout_eq(str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Compiler run successful!

Ran 1 test for test/ContractFuzz.t.sol:ContractFuzz
[PASS] testFuzzConsoleLog(uint256) (runs: 3, [AVG_GAS])
Logs:
inside fuzz test, x is: [..]

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)

"#]]);
});

// tests that `forge test` with inline config `show_logs = false` for fuzz tests will not
// display `console.log` info
// tests that `forge test` with inline config `show_logs = false` for fuzz tests will
// still display `console.log` from the last run at verbosity >= 2 (issue #11039)
forgetest_init!(should_not_show_logs_when_fuzz_test_inline_config, |prj, cmd| {
// run fuzz test 3 times
prj.update_config(|config| {
Expand All @@ -1186,13 +1190,17 @@ contract ContractFuzz is Test {
}
"#,
);
// At verbosity >= 2, logs from the last run should be shown even when show_logs is false
cmd.args(["test", "-vv"]).assert_success().stdout_eq(str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Compiler run successful!

Ran 1 test for test/ContractFuzz.t.sol:ContractFuzz
[PASS] testFuzzConsoleLog(uint256) (runs: 3, [AVG_GAS])
Logs:
inside fuzz test, x is: [..]

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)
Expand Down
Loading