Skip to content

Commit 5161091

Browse files
authored
chore: potential fix flaky test_invariant_assert_shrink (#8554)
1 parent d1b2513 commit 5161091

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

crates/forge/tests/it/invariant.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,23 +285,27 @@ async fn test_invariant_shrink() {
285285
#[tokio::test(flavor = "multi_thread")]
286286
#[cfg_attr(windows, ignore = "for some reason there's different rng")]
287287
async fn test_invariant_assert_shrink() {
288-
// ensure assert and require shrinks to same sequence of 3 or less
289-
test_shrink("invariant_with_assert").await;
290-
test_shrink("invariant_with_require").await;
288+
// ensure assert shrinks to same sequence of 2 as require
289+
check_shrink_sequence("invariant_with_assert", 2).await;
291290
}
292291

293-
async fn test_shrink(test_pattern: &str) {
294-
let mut opts = TEST_DATA_DEFAULT.test_opts.clone();
295-
opts.fuzz.seed = Some(U256::from(100u32));
292+
#[tokio::test(flavor = "multi_thread")]
293+
#[cfg_attr(windows, ignore = "for some reason there's different rng")]
294+
async fn test_invariant_require_shrink() {
295+
// ensure require shrinks to same sequence of 2 as assert
296+
check_shrink_sequence("invariant_with_require", 2).await;
297+
}
298+
299+
async fn check_shrink_sequence(test_pattern: &str, expected_len: usize) {
296300
let filter =
297301
Filter::new(test_pattern, ".*", ".*fuzz/invariant/common/InvariantShrinkWithAssert.t.sol");
298302
let mut runner = TEST_DATA_DEFAULT.runner();
299-
runner.test_options = opts;
303+
runner.test_options.fuzz.seed = Some(U256::from(100u32));
300304

301305
match get_counterexample!(runner, &filter) {
302306
CounterExample::Single(_) => panic!("CounterExample should be a sequence."),
303307
CounterExample::Sequence(sequence) => {
304-
assert!(sequence.len() <= 3);
308+
assert_eq!(sequence.len(), expected_len);
305309
}
306310
};
307311
}

0 commit comments

Comments
 (0)