Skip to content

Commit 88b40d3

Browse files
DaniPopesrplusq
authored andcommitted
feat: rewrite inline config using figment (foundry-rs#9414)
* feat: rewrite inline config using figment * wip * wip * fix: use same GasLimit type * wip * fixes * tests * test fixes * fmt * test update
1 parent 182a184 commit 88b40d3

File tree

32 files changed

+969
-1162
lines changed

32 files changed

+969
-1162
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/config/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ dirs-next = "2"
2727
dunce.workspace = true
2828
eyre.workspace = true
2929
figment = { workspace = true, features = ["toml", "env"] }
30-
globset = "0.4"
3130
glob = "0.3"
31+
globset = "0.4"
3232
Inflector = "0.11"
33-
number_prefix = "0.4"
33+
itertools.workspace = true
3434
mesc.workspace = true
35+
number_prefix = "0.4"
3536
regex.workspace = true
3637
reqwest.workspace = true
3738
semver = { workspace = true, features = ["serde"] }

crates/config/src/fuzz.rs

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
//! Configuration for fuzz testing.
22
3-
use crate::inline::{
4-
parse_config_bool, parse_config_u32, InlineConfigParser, InlineConfigParserError,
5-
INLINE_CONFIG_FUZZ_KEY,
6-
};
73
use alloy_primitives::U256;
84
use serde::{Deserialize, Serialize};
95
use std::path::PathBuf;
@@ -53,50 +49,13 @@ impl FuzzConfig {
5349
/// Creates fuzz configuration to write failures in `{PROJECT_ROOT}/cache/fuzz` dir.
5450
pub fn new(cache_dir: PathBuf) -> Self {
5551
Self {
56-
runs: 256,
57-
max_test_rejects: 65536,
58-
seed: None,
59-
dictionary: FuzzDictionaryConfig::default(),
60-
gas_report_samples: 256,
6152
failure_persist_dir: Some(cache_dir),
6253
failure_persist_file: Some("failures".to_string()),
63-
show_logs: false,
54+
..Default::default()
6455
}
6556
}
6657
}
6758

68-
impl InlineConfigParser for FuzzConfig {
69-
fn config_key() -> String {
70-
INLINE_CONFIG_FUZZ_KEY.into()
71-
}
72-
73-
fn try_merge(&self, configs: &[String]) -> Result<Option<Self>, InlineConfigParserError> {
74-
let overrides: Vec<(String, String)> = Self::get_config_overrides(configs);
75-
76-
if overrides.is_empty() {
77-
return Ok(None)
78-
}
79-
80-
let mut conf_clone = self.clone();
81-
82-
for pair in overrides {
83-
let key = pair.0;
84-
let value = pair.1;
85-
match key.as_str() {
86-
"runs" => conf_clone.runs = parse_config_u32(key, value)?,
87-
"max-test-rejects" => conf_clone.max_test_rejects = parse_config_u32(key, value)?,
88-
"dictionary-weight" => {
89-
conf_clone.dictionary.dictionary_weight = parse_config_u32(key, value)?
90-
}
91-
"failure-persist-file" => conf_clone.failure_persist_file = Some(value),
92-
"show-logs" => conf_clone.show_logs = parse_config_bool(key, value)?,
93-
_ => Err(InlineConfigParserError::InvalidConfigProperty(key))?,
94-
}
95-
}
96-
Ok(Some(conf_clone))
97-
}
98-
}
99-
10059
/// Contains for fuzz testing
10160
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
10261
pub struct FuzzDictionaryConfig {
@@ -132,68 +91,3 @@ impl Default for FuzzDictionaryConfig {
13291
}
13392
}
13493
}
135-
136-
#[cfg(test)]
137-
mod tests {
138-
use crate::{inline::InlineConfigParser, FuzzConfig};
139-
140-
#[test]
141-
fn unrecognized_property() {
142-
let configs = &["forge-config: default.fuzz.unknownprop = 200".to_string()];
143-
let base_config = FuzzConfig::default();
144-
if let Err(e) = base_config.try_merge(configs) {
145-
assert_eq!(e.to_string(), "'unknownprop' is an invalid config property");
146-
} else {
147-
unreachable!()
148-
}
149-
}
150-
151-
#[test]
152-
fn successful_merge() {
153-
let configs = &[
154-
"forge-config: default.fuzz.runs = 42424242".to_string(),
155-
"forge-config: default.fuzz.dictionary-weight = 42".to_string(),
156-
"forge-config: default.fuzz.failure-persist-file = fuzz-failure".to_string(),
157-
];
158-
let base_config = FuzzConfig::default();
159-
let merged: FuzzConfig = base_config.try_merge(configs).expect("No errors").unwrap();
160-
assert_eq!(merged.runs, 42424242);
161-
assert_eq!(merged.dictionary.dictionary_weight, 42);
162-
assert_eq!(merged.failure_persist_file, Some("fuzz-failure".to_string()));
163-
}
164-
165-
#[test]
166-
fn merge_is_none() {
167-
let empty_config = &[];
168-
let base_config = FuzzConfig::default();
169-
let merged = base_config.try_merge(empty_config).expect("No errors");
170-
assert!(merged.is_none());
171-
}
172-
173-
#[test]
174-
fn merge_is_none_unrelated_property() {
175-
let unrelated_configs = &["forge-config: default.invariant.runs = 2".to_string()];
176-
let base_config = FuzzConfig::default();
177-
let merged = base_config.try_merge(unrelated_configs).expect("No errors");
178-
assert!(merged.is_none());
179-
}
180-
181-
#[test]
182-
fn override_detection() {
183-
let configs = &[
184-
"forge-config: default.fuzz.runs = 42424242".to_string(),
185-
"forge-config: ci.fuzz.runs = 666666".to_string(),
186-
"forge-config: default.invariant.runs = 2".to_string(),
187-
"forge-config: default.fuzz.dictionary-weight = 42".to_string(),
188-
];
189-
let variables = FuzzConfig::get_config_overrides(configs);
190-
assert_eq!(
191-
variables,
192-
vec![
193-
("runs".into(), "42424242".into()),
194-
("runs".into(), "666666".into()),
195-
("dictionary-weight".into(), "42".into())
196-
]
197-
);
198-
}
199-
}

crates/config/src/inline/conf_parser.rs

Lines changed: 0 additions & 169 deletions
This file was deleted.

crates/config/src/inline/error.rs

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)