diff --git a/woke/testing/fuzzing/fuzz_test.py b/woke/testing/fuzzing/fuzz_test.py index 3d4b6cb4a..42d1a63ec 100644 --- a/woke/testing/fuzzing/fuzz_test.py +++ b/woke/testing/fuzzing/fuzz_test.py @@ -28,10 +28,11 @@ def decorator(fn): return decorator -def invariant(*, period: int = 1): +def invariant(*, period: int = 1, commit_changes=False): def decorator(fn): fn.invariant = True fn.period = period + fn.commit_changes = commit_changes return fn return decorator @@ -128,10 +129,18 @@ def run( self.pre_invariants() for inv in invariants: if invariant_periods[inv] == 0: + isnapshots = [] + # if changes that occur during checking the invariant are not to be committed take a snapshot + if getattr(inv, "commit_changes") == False: + isnapshots = [chain.snapshot() for chain in chains] self.pre_invariant(inv) inv(self) self.post_invariant(inv) + # restore any snapshots saved before the invariant + for snapshot, chain in zip(isnapshots, chains): + chain.revert(snapshot) + invariant_periods[inv] += 1 if invariant_periods[inv] == getattr(inv, "period"): invariant_periods[inv] = 0