From f6bcd9e43e05eda9176932d87bb13e7f2c806f0e Mon Sep 17 00:00:00 2001 From: MeditationDuck Date: Wed, 17 Jul 2024 17:20:44 +0200 Subject: [PATCH 1/2] :sparkles: add the fuzz-flow-result uncount functionality --- wake/testing/fuzzing/__init__.py | 2 +- wake/testing/fuzzing/fuzz_test.py | 34 ++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/wake/testing/fuzzing/__init__.py b/wake/testing/fuzzing/__init__.py index a794910e3..6d75e6ff6 100644 --- a/wake/testing/fuzzing/__init__.py +++ b/wake/testing/fuzzing/__init__.py @@ -1,4 +1,4 @@ -from .fuzz_test import FuzzTest, flow, invariant +from .fuzz_test import FuzzTest, flow, invariant, FlowResult from .generators import ( random_account, random_address, diff --git a/wake/testing/fuzzing/fuzz_test.py b/wake/testing/fuzzing/fuzz_test.py index 3b06923ab..256430a24 100644 --- a/wake/testing/fuzzing/fuzz_test.py +++ b/wake/testing/fuzzing/fuzz_test.py @@ -10,6 +10,11 @@ from ..core import get_connected_chains from .generators import generate +from enum import Enum + +class FlowResult(Enum): + UNCOUNT = 1 + REPEAT = 2 def flow( *, @@ -82,7 +87,8 @@ def run( self._sequence_num = i self.pre_sequence() - for j in range(flows_count): + j = 0 + while j Date: Wed, 17 Jul 2024 17:36:25 +0200 Subject: [PATCH 2/2] :sparkles: fix to execute invariants --- wake/testing/fuzzing/fuzz_test.py | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/wake/testing/fuzzing/fuzz_test.py b/wake/testing/fuzzing/fuzz_test.py index 256430a24..60c936f76 100644 --- a/wake/testing/fuzzing/fuzz_test.py +++ b/wake/testing/fuzzing/fuzz_test.py @@ -121,8 +121,8 @@ def run( flow = random.choices(valid_flows, weights=weights)[0] self._flow_num = j self.pre_flow(flow) - - while True: + keep_loop = True + while keep_loop: flow_params = [ generate(v) for k, v in get_type_hints(flow, include_extras=True).items() @@ -130,27 +130,27 @@ def run( ] ret = flow(self, *flow_params) if ret == FlowResult.UNCOUNT: - break + keep_loop = False elif ret == FlowResult.REPEAT: - continue + keep_loop = True else: j+=1 flows_counter[flow] += 1 self.post_flow(flow) - break - - if not dry_run: - self.pre_invariants() - for inv in invariants: - if invariant_periods[inv] == 0: - self.pre_invariant(inv) - inv(self) - self.post_invariant(inv) - - invariant_periods[inv] += 1 - if invariant_periods[inv] == getattr(inv, "period"): - invariant_periods[inv] = 0 - self.post_invariants() + keep_loop = False + + if not dry_run: + self.pre_invariants() + for inv in invariants: + if invariant_periods[inv] == 0: + self.pre_invariant(inv) + inv(self) + self.post_invariant(inv) + + invariant_periods[inv] += 1 + if invariant_periods[inv] == getattr(inv, "period"): + invariant_periods[inv] = 0 + self.post_invariants() self.post_sequence()