From a08106f32fda5529cc45987b4845a36592d280d3 Mon Sep 17 00:00:00 2001 From: Avory Date: Thu, 6 Nov 2025 19:42:54 +0200 Subject: [PATCH 1/4] Update mod.rs --- crates/evm/evm/src/executors/fuzz/mod.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/evm/evm/src/executors/fuzz/mod.rs b/crates/evm/evm/src/executors/fuzz/mod.rs index dfe969ea2c193..a89ef3c267ebd 100644 --- a/crates/evm/evm/src/executors/fuzz/mod.rs +++ b/crates/evm/evm/src/executors/fuzz/mod.rs @@ -48,6 +48,8 @@ struct FuzzTestData { coverage: Option, // Stores logs for all fuzz cases logs: Vec, + // Stores logs from the last successful run (for display at verbosity >= 2) + last_run_logs: Vec, // Deprecated cheatcodes mapped to their replacements. deprecated_cheatcodes: HashMap<&'static str, Option<&'static str>>, // Runs performed in fuzz test. @@ -198,6 +200,9 @@ impl FuzzedExecutor { test_data.breakpoints.replace(case.breakpoints); } + // Always store logs from the last run for display at verbosity >= 2 + test_data.last_run_logs = case.logs.clone(); + if self.config.show_logs { test_data.logs.extend(case.logs); } @@ -255,6 +260,18 @@ impl FuzzedExecutor { (call.traces.clone(), call.cheatcodes.map(|c| c.breakpoints)) }; + // Include logs from the last run if show_logs is false, so they can be displayed + // at verbosity >= 2. If show_logs is true, test_data.logs already contains all logs. + // For failed tests, use logs from the counterexample. + let result_logs = if test_data.failure.is_some() { + // For failed tests, logs are already included in test_data.logs from the counterexample + test_data.logs + } else if self.config.show_logs { + test_data.logs + } else { + test_data.last_run_logs + }; + let mut result = FuzzTestResult { first_case: test_data.first_case.unwrap_or_default(), gas_by_case: test_data.gas_by_case, @@ -262,7 +279,7 @@ impl FuzzedExecutor { skipped: false, reason: None, counterexample: None, - logs: test_data.logs, + logs: result_logs, labels: call.labels, traces: last_run_traces, breakpoints: last_run_breakpoints, From e5b7bfa71dc5629dfc0b6e9dcf7f893c69a1d4bb Mon Sep 17 00:00:00 2001 From: Avory Date: Thu, 6 Nov 2025 19:43:11 +0200 Subject: [PATCH 2/4] Update mod.rs --- crates/forge/tests/cli/test_cmd/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/forge/tests/cli/test_cmd/mod.rs b/crates/forge/tests/cli/test_cmd/mod.rs index 821af8a7e7a9c..3389967a67cb0 100644 --- a/crates/forge/tests/cli/test_cmd/mod.rs +++ b/crates/forge/tests/cli/test_cmd/mod.rs @@ -1122,8 +1122,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| { @@ -1145,6 +1145,7 @@ 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] @@ -1152,6 +1153,9 @@ 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) @@ -1159,8 +1163,8 @@ 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| { @@ -1182,6 +1186,7 @@ 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] @@ -1189,6 +1194,9 @@ 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) From 262a16f6e6add16b098c7896dfd961eddd42775c Mon Sep 17 00:00:00 2001 From: Avory Date: Thu, 13 Nov 2025 22:03:57 +0200 Subject: [PATCH 3/4] Update mod.rs --- crates/evm/evm/src/executors/fuzz/mod.rs | 27 +++++++++--------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/crates/evm/evm/src/executors/fuzz/mod.rs b/crates/evm/evm/src/executors/fuzz/mod.rs index a89ef3c267ebd..cc69ea306ad85 100644 --- a/crates/evm/evm/src/executors/fuzz/mod.rs +++ b/crates/evm/evm/src/executors/fuzz/mod.rs @@ -46,10 +46,8 @@ struct FuzzTestData { breakpoints: Option, // Stores coverage information for all fuzz cases. coverage: Option, - // 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, - // Stores logs from the last successful run (for display at verbosity >= 2) - last_run_logs: Vec, // Deprecated cheatcodes mapped to their replacements. deprecated_cheatcodes: HashMap<&'static str, Option<&'static str>>, // Runs performed in fuzz test. @@ -200,11 +198,12 @@ impl FuzzedExecutor { test_data.breakpoints.replace(case.breakpoints); } - // Always store logs from the last run for display at verbosity >= 2 - test_data.last_run_logs = case.logs.clone(); - + // 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); @@ -260,17 +259,11 @@ impl FuzzedExecutor { (call.traces.clone(), call.cheatcodes.map(|c| c.breakpoints)) }; - // Include logs from the last run if show_logs is false, so they can be displayed - // at verbosity >= 2. If show_logs is true, test_data.logs already contains all logs. - // For failed tests, use logs from the counterexample. - let result_logs = if test_data.failure.is_some() { - // For failed tests, logs are already included in test_data.logs from the counterexample - test_data.logs - } else if self.config.show_logs { - test_data.logs - } else { - test_data.last_run_logs - }; + // 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(), From 5607b62e24af4b3f5b7ec6bf0179c2ea61468232 Mon Sep 17 00:00:00 2001 From: Avory Date: Thu, 13 Nov 2025 22:07:16 +0200 Subject: [PATCH 4/4] Update mod.rs --- crates/evm/evm/src/executors/fuzz/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/evm/evm/src/executors/fuzz/mod.rs b/crates/evm/evm/src/executors/fuzz/mod.rs index cc69ea306ad85..435bdcba1ace7 100644 --- a/crates/evm/evm/src/executors/fuzz/mod.rs +++ b/crates/evm/evm/src/executors/fuzz/mod.rs @@ -46,7 +46,8 @@ struct FuzzTestData { breakpoints: Option, // Stores coverage information for all fuzz cases. coverage: Option, - // Stores logs for all fuzz cases (when show_logs is true) or just the last run (when show_logs is false) + // Stores logs for all fuzz cases (when show_logs is true) or just the last run (when show_logs + // is false) logs: Vec, // Deprecated cheatcodes mapped to their replacements. deprecated_cheatcodes: HashMap<&'static str, Option<&'static str>>, @@ -198,8 +199,9 @@ 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. + // 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 {