|
1 | 1 | //! Configuration for fuzz testing. |
2 | 2 |
|
3 | | -use crate::inline::{ |
4 | | - parse_config_bool, parse_config_u32, InlineConfigParser, InlineConfigParserError, |
5 | | - INLINE_CONFIG_FUZZ_KEY, |
6 | | -}; |
7 | 3 | use alloy_primitives::U256; |
8 | 4 | use serde::{Deserialize, Serialize}; |
9 | 5 | use std::path::PathBuf; |
@@ -53,50 +49,13 @@ impl FuzzConfig { |
53 | 49 | /// Creates fuzz configuration to write failures in `{PROJECT_ROOT}/cache/fuzz` dir. |
54 | 50 | pub fn new(cache_dir: PathBuf) -> Self { |
55 | 51 | Self { |
56 | | - runs: 256, |
57 | | - max_test_rejects: 65536, |
58 | | - seed: None, |
59 | | - dictionary: FuzzDictionaryConfig::default(), |
60 | | - gas_report_samples: 256, |
61 | 52 | failure_persist_dir: Some(cache_dir), |
62 | 53 | failure_persist_file: Some("failures".to_string()), |
63 | | - show_logs: false, |
| 54 | + ..Default::default() |
64 | 55 | } |
65 | 56 | } |
66 | 57 | } |
67 | 58 |
|
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 | | - |
100 | 59 | /// Contains for fuzz testing |
101 | 60 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] |
102 | 61 | pub struct FuzzDictionaryConfig { |
@@ -132,68 +91,3 @@ impl Default for FuzzDictionaryConfig { |
132 | 91 | } |
133 | 92 | } |
134 | 93 | } |
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 | | -} |
0 commit comments