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
19 changes: 18 additions & 1 deletion crates/evm/evm/src/executors/fuzz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct FuzzTestData {
coverage: Option<HitMaps>,
// Stores logs for all fuzz cases
logs: Vec<Log>,
// Stores logs from the last successful run (for display at verbosity >= 2)
last_run_logs: Vec<Log>,
// Deprecated cheatcodes mapped to their replacements.
deprecated_cheatcodes: HashMap<&'static str, Option<&'static str>>,
// Runs performed in fuzz test.
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -255,14 +260,26 @@ 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,
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 @@ -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| {
Expand All @@ -1145,22 +1145,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 @@ -1182,13 +1186,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