forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
64 lines (52 loc) · 1.85 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use proptest::test_runner::{RngAlgorithm, TestRng, TestRunner};
use tracing::trace;
/// Gas reports
pub mod gas_report;
/// Coverage reports
pub mod coverage;
/// The Forge test runner
mod runner;
pub use runner::ContractRunner;
/// Forge test runners for multiple contracts
mod multi_runner;
pub use multi_runner::{MultiContractRunner, MultiContractRunnerBuilder};
/// reexport
pub use foundry_common::traits::TestFilter;
pub mod result;
/// The Forge EVM backend
pub use foundry_evm::*;
/// Metadata on how to run fuzz/invariant tests
#[derive(Debug, Clone, Copy, Default)]
pub struct TestOptions {
/// The fuzz test configuration
pub fuzz: foundry_config::FuzzConfig,
/// The invariant test configuration
pub invariant: foundry_config::InvariantConfig,
}
impl TestOptions {
pub fn invariant_fuzzer(&self) -> TestRunner {
self.fuzzer_with_cases(self.invariant.runs)
}
pub fn fuzzer(&self) -> TestRunner {
self.fuzzer_with_cases(self.fuzz.runs)
}
pub fn fuzzer_with_cases(&self, cases: u32) -> TestRunner {
// TODO: Add Options to modify the persistence
let cfg = proptest::test_runner::Config {
failure_persistence: None,
cases,
max_global_rejects: self.fuzz.max_test_rejects,
..Default::default()
};
if let Some(ref fuzz_seed) = self.fuzz.seed {
trace!(target: "forge::test", "building deterministic fuzzer with seed {}", fuzz_seed);
let mut bytes: [u8; 32] = [0; 32];
fuzz_seed.to_big_endian(&mut bytes);
let rng = TestRng::from_seed(RngAlgorithm::ChaCha, &bytes);
proptest::test_runner::TestRunner::new_with_rng(cfg, rng)
} else {
trace!(target: "forge::test", "building stochastic fuzzer");
proptest::test_runner::TestRunner::new(cfg)
}
}
}