-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: add timeouts to fuzz testing #9394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
47bf075
b2a5f8d
a9003b3
b704851
73c1b77
af9324a
851275e
364c33b
4111e13
da87095
b6c137e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,7 +98,19 @@ impl FuzzedExecutor { | |
| let max_traces_to_collect = std::cmp::max(1, self.config.gas_report_samples) as usize; | ||
| let show_logs = self.config.show_logs; | ||
|
|
||
| // Start a timer if timeout is set | ||
| let start_time = self.config.timeout_secs.map(|timeout| { | ||
| (std::time::Instant::now(), std::time::Duration::from_secs(timeout)) | ||
| }); | ||
|
|
||
| let run_result = self.runner.clone().run(&strategy, |calldata| { | ||
| // Check if the timeout has been reached | ||
| if let Some((start_time, timeout)) = start_time { | ||
| if start_time.elapsed() > timeout { | ||
|
||
| return Err(TestCaseError::fail("Timeout reached")) | ||
grandizzy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| let fuzz_res = self.single_fuzz(address, should_fail, calldata)?; | ||
|
|
||
| // If running with progress then increment current run. | ||
|
|
@@ -193,17 +205,23 @@ impl FuzzedExecutor { | |
| } | ||
| Err(TestError::Fail(reason, _)) => { | ||
| let reason = reason.to_string(); | ||
| result.reason = (!reason.is_empty()).then_some(reason); | ||
| result.reason = (!reason.is_empty()).then_some(reason.clone()); | ||
|
|
||
| let args = if let Some(data) = calldata.get(4..) { | ||
| func.abi_decode_input(data, false).unwrap_or_default() | ||
| if reason == "Timeout reached" { | ||
smartcontracts marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if self.config.allow_timeouts { | ||
| result.success = true; | ||
| } | ||
| } else { | ||
| vec![] | ||
| }; | ||
| let args = if let Some(data) = calldata.get(4..) { | ||
| func.abi_decode_input(data, false).unwrap_or_default() | ||
| } else { | ||
| vec![] | ||
| }; | ||
smartcontracts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| result.counterexample = Some(CounterExample::Single( | ||
| BaseCounterExample::from_fuzz_call(calldata, args, call.traces), | ||
| )); | ||
| result.counterexample = Some(CounterExample::Single( | ||
| BaseCounterExample::from_fuzz_call(calldata, args, call.traces), | ||
| )); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.