Skip to content

Commit

Permalink
perf: check last fuzz result instead of adding aditional run (#5264)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evalir authored Jul 1, 2023
1 parent c7a3c18 commit d369d24
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions forge/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,31 +537,25 @@ impl<'a> ContractRunner<'a> {
) -> TestResult {
let TestSetup { address, mut logs, mut traces, mut labeled_addresses, .. } = setup;

let skip_fuzz_config = FuzzConfig { runs: 1, ..Default::default() };

// Fuzz the test with only 1 run to check if it needs to be skipped.
let result =
FuzzedExecutor::new(&self.executor, runner.clone(), self.sender, skip_fuzz_config)
.fuzz(func, address, should_fail, self.errors);
if let Some(reason) = result.reason {
if matches!(reason.as_str(), "SKIPPED") {
return TestResult {
status: TestStatus::Skipped,
reason: None,
decoded_logs: decode_console_logs(&logs),
traces,
labeled_addresses,
kind: TestKind::Standard(0),
..Default::default()
}
}
}

// Run fuzz test
let start = Instant::now();
let mut result = FuzzedExecutor::new(&self.executor, runner, self.sender, fuzz_config)
.fuzz(func, address, should_fail, self.errors);

// Check the last test result and skip the test
// if it's marked as so.
if let Some("SKIPPED") = result.reason.as_deref() {
return TestResult {
status: TestStatus::Skipped,
reason: None,
decoded_logs: decode_console_logs(&logs),
traces,
labeled_addresses,
kind: TestKind::Standard(0),
..Default::default()
}
}

let kind = TestKind::Fuzz {
median_gas: result.median_gas(false),
mean_gas: result.mean_gas(false),
Expand Down

0 comments on commit d369d24

Please sign in to comment.