Skip to content

Commit

Permalink
add logs field in FuzzTestData
Browse files Browse the repository at this point in the history
  • Loading branch information
Azleal committed Jul 9, 2024
1 parent fc02af8 commit 9b864dc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions crates/evm/evm/src/executors/fuzz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct FuzzTestData {
pub breakpoints: Option<Breakpoints>,
// Stores coverage information for all fuzz cases.
pub coverage: Option<HitMaps>,
//Stores logs for all fuzz cases
pub logs: Vec<Log>,
}

/// Wrapper around an [`Executor`] which provides fuzzing support using [`proptest`].
Expand Down Expand Up @@ -92,8 +94,6 @@ impl FuzzedExecutor {
let max_traces_to_collect = std::cmp::max(1, self.config.gas_report_samples) as usize;
let show_fuzz_logs = self.config.show_fuzz_logs;

//Stores logs for all fuzz cases
let logs: RefCell<Vec<Log>> = RefCell::default();

let run_result = self.runner.clone().run(&strat, |calldata| {
let fuzz_res = self.single_fuzz(address, should_fail, calldata)?;
Expand All @@ -117,7 +117,7 @@ impl FuzzedExecutor {
data.traces.push(call_traces);
data.breakpoints.replace(case.breakpoints);
}
logs.borrow_mut().extend(case.logs);
data.logs.extend(case.logs);

// Collect and merge coverage if `forge snapshot` context.
match &mut data.coverage {
Expand All @@ -137,8 +137,9 @@ impl FuzzedExecutor {
// our failure - when a fuzz case fails, proptest will try
// to run at least one more case to find a minimal failure
// case.
logs.borrow_mut().extend(outcome.1.logs.clone());
let reason = rd.maybe_decode(&outcome.1.result, Some(status));
let cloned_logs = outcome.1.logs.clone();
execution_data.borrow_mut().logs.extend(cloned_logs);
execution_data.borrow_mut().counterexample = outcome;
// HACK: we have to use an empty string here to denote `None`.
Err(TestCaseError::fail(reason.unwrap_or_default()))
Expand All @@ -157,7 +158,7 @@ impl FuzzedExecutor {
};

// decide whether to use trace logs or only error logs
let actual_logs = if show_fuzz_logs { logs.into_inner() } else { call.logs };
let actual_logs = if show_fuzz_logs { fuzz_result.logs } else { call.logs };

let mut result = FuzzTestResult {
first_case: fuzz_result.first_case.unwrap_or_default(),
Expand Down

0 comments on commit 9b864dc

Please sign in to comment.