Skip to content

Commit cf187fb

Browse files
committed
fix(fuzz) - consistent gas snapshot between runs
1 parent 1ddea96 commit cf187fb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

crates/forge/bin/cmd/snapshot.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ impl SnapshotArgs {
9494
}
9595

9696
pub async fn run(mut self) -> Result<()> {
97-
// Set fuzz seed so gas snapshots are deterministic
97+
// Set fuzz seed and disable fuzzing from state so gas snapshots are deterministic.
9898
self.test.fuzz_seed = Some(U256::from_be_bytes(STATIC_FUZZ_SEED));
99+
self.test.fuzz_dictionary_weight = Some(0);
99100

100101
let outcome = self.test.execute_tests().await?;
101102
outcome.ensure_ok()?;

crates/forge/bin/cmd/test/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ pub struct TestArgs {
102102
#[arg(long)]
103103
pub fuzz_seed: Option<U256>,
104104

105+
/// Set fuzz dictionary weight.
106+
#[arg(long)]
107+
pub fuzz_dictionary_weight: Option<u32>,
108+
105109
#[arg(long, env = "FOUNDRY_FUZZ_RUNS", value_name = "RUNS")]
106110
pub fuzz_runs: Option<u64>,
107111

@@ -227,6 +231,11 @@ impl TestArgs {
227231
config.invariant.gas_report_samples = 0;
228232
}
229233

234+
// Set fuzz dictionary weight if specified as arg.
235+
if let Some(dictionary_weight) = self.fuzz_dictionary_weight {
236+
config.fuzz.dictionary.dictionary_weight = dictionary_weight;
237+
}
238+
230239
// Set up the project.
231240
let mut project = config.project()?;
232241

0 commit comments

Comments
 (0)