Skip to content
Merged
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
7 changes: 1 addition & 6 deletions cli/src/cmd/forge/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,7 @@ impl CoverageArgs {
.sender(evm_opts.sender)
.with_fork(evm_opts.get_fork(&config, env.clone()))
.with_cheats_config(CheatsConfig::new(&config, &evm_opts))
.with_test_options(TestOptions {
fuzz_runs: config.fuzz_runs,
fuzz_max_local_rejects: config.fuzz_max_local_rejects,
fuzz_max_global_rejects: config.fuzz_max_global_rejects,
..Default::default()
})
.with_test_options(TestOptions { fuzz: config.fuzz, ..Default::default() })
.set_coverage(true)
.build(root.clone(), output, env, evm_opts)?;

Expand Down
11 changes: 1 addition & 10 deletions cli/src/cmd/forge/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,7 @@ pub fn custom_run(args: TestArgs) -> eyre::Result<TestOutcome> {
// Merge all configs
let (config, mut evm_opts) = args.load_config_and_evm_opts_emit_warnings()?;

let test_options = TestOptions {
fuzz_runs: config.fuzz_runs,
fuzz_max_local_rejects: config.fuzz_max_local_rejects,
fuzz_max_global_rejects: config.fuzz_max_global_rejects,
fuzz_seed: config.fuzz_seed,
invariant_runs: config.invariant_runs,
invariant_depth: config.invariant_depth,
invariant_fail_on_revert: config.invariant_fail_on_revert,
invariant_call_override: config.invariant_call_override,
};
let test_options = TestOptions { fuzz: config.fuzz, invariant: config.invariant };

let mut filter = args.filter(&config);

Expand Down
18 changes: 9 additions & 9 deletions cli/tests/it/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use foundry_cli_test_utils::{
};
use foundry_config::{
cache::{CachedChains, CachedEndpoints, StorageCachingConfig},
Config, OptimizerDetails, SolcReq,
Config, FuzzConfig, InvariantConfig, OptimizerDetails, SolcReq,
};
use path_slash::PathBufExt;
use std::{fs, path::PathBuf, str::FromStr};
Expand Down Expand Up @@ -57,14 +57,14 @@ forgetest!(can_extract_config_values, |prj: TestProject, mut cmd: TestCommand| {
contract_pattern_inverse: None,
path_pattern: None,
path_pattern_inverse: None,
fuzz_runs: 1000,
fuzz_max_local_rejects: 2000,
fuzz_max_global_rejects: 100203,
fuzz_seed: Some(1000.into()),
invariant_runs: 256,
invariant_depth: 15,
invariant_fail_on_revert: false,
invariant_call_override: false,
fuzz: FuzzConfig {
runs: 1000,
max_local_rejects: 2000,
max_global_rejects: 100203,
seed: Some(1000.into()),
..Default::default()
},
invariant: InvariantConfig { runs: 256, ..Default::default() },
ffi: true,
sender: "00a329c0648769A73afAc7F9381D08FB43dBEA72".parse().unwrap(),
tx_origin: "00a329c0648769A73afAc7F9F81E08FB43dBEA72".parse().unwrap(),
Expand Down
32 changes: 23 additions & 9 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ match_contract = "Foo"
no_match_contract = "Bar"
match_path = "*/Foo*"
no_match_path = "*/Bar*"
fuzz_runs = 256
invariant_runs = 256
invariant_depth = 15
invariant_fail_on_revert = false
invariant_call_override = false
ffi = false
sender = '0x00a329c0648769a73afac7f9381e08fb43dbea72'
tx_origin = '0x00a329c0648769a73afac7f9381e08fb43dbea72'
Expand All @@ -132,9 +127,6 @@ block_gas_limit = 30000000
memory_limit = 33554432
extra_output = ["metadata"]
extra_output_files = []
fuzz_max_local_rejects = 1024
fuzz_max_global_rejects = 65536
fuzz_seed = '0x3e8'
names = false
sizes = false
via_ir = false
Expand All @@ -160,8 +152,30 @@ revert_strings = "default"
sparse_mode = false
build_info = true
build_info_path = "build-info"
fmt = { line_length = 100, tab_width = 2, bracket_spacing = true }
root = "root"

[fuzz]
runs = 256
max_local_rejects = 1024
max_global_rejects = 65536
seed = '0x3e8'
dictionary_weight = 40
include_storage = true
include_push_bytes = true

[invariant]
runs = 256
depth = 15
fail_on_revert = false
call_override = false
dictionary_weight = 80
include_storage = true
include_push_bytes = true

[fmt]
line_length = 100
tab_width = 2
bracket_spacing = true
Comment on lines +157 to +178
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome

```

#### Additional Optimizer settings
Expand Down
45 changes: 45 additions & 0 deletions config/src/fuzz.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//! Configuration for fuzz testing

use ethers_core::types::U256;
use serde::{Deserialize, Serialize};

/// Contains for fuzz testing
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct FuzzConfig {
/// The number of test cases that must execute for each property test
pub runs: u32,
/// The maximum number of local test case rejections allowed
/// by proptest, to be encountered during usage of `vm.assume`
/// cheatcode.
pub max_local_rejects: u32,
/// The maximum number of global test case rejections allowed
/// by proptest, to be encountered during usage of `vm.assume`
/// cheatcode.
pub max_global_rejects: u32,
/// Optional seed for the fuzzing RNG algorithm
#[serde(
deserialize_with = "ethers_core::types::serde_helpers::deserialize_stringified_numeric_opt"
)]
pub seed: Option<U256>,
/// The weight of the dictionary
#[serde(deserialize_with = "crate::deserialize_stringified_percent")]
pub dictionary_weight: u32,
/// The flag indicating whether to include values from storage
pub include_storage: bool,
/// The flag indicating whether to include push bytes values
pub include_push_bytes: bool,
}

impl Default for FuzzConfig {
fn default() -> Self {
FuzzConfig {
runs: 256,
max_local_rejects: 1024,
max_global_rejects: 65536,
seed: None,
dictionary_weight: 40,
include_storage: true,
include_push_bytes: true,
}
}
}
38 changes: 38 additions & 0 deletions config/src/invariant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! Configuration for invariant testing

use serde::{Deserialize, Serialize};

/// Contains for invariant testing
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct InvariantConfig {
/// The number of runs that must execute for each invariant test group.
pub runs: u32,
/// The number of calls executed to attempt to break invariants in one run.
pub depth: u32,
/// Fails the invariant fuzzing if a revert occurs
pub fail_on_revert: bool,
/// Allows overriding an unsafe external call when running invariant tests. eg. reentrancy
/// checks
pub call_override: bool,
/// The weight of the dictionary
#[serde(deserialize_with = "crate::deserialize_stringified_percent")]
pub dictionary_weight: u32,
/// The flag indicating whether to include values from storage
pub include_storage: bool,
/// The flag indicating whether to include push bytes values
pub include_push_bytes: bool,
}

impl Default for InvariantConfig {
fn default() -> Self {
InvariantConfig {
runs: 256,
depth: 15,
fail_on_revert: false,
call_override: false,
dictionary_weight: 80,
include_storage: true,
include_push_bytes: true,
}
}
}
Loading