Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding fuzz flow result uncount functionality #331

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wake/testing/fuzzing/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
60 changes: 37 additions & 23 deletions wake/testing/fuzzing/fuzz_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
*,
Expand Down Expand Up @@ -82,7 +87,8 @@ def run(
self._sequence_num = i
self.pre_sequence()

for j in range(flows_count):
j = 0
while j <flows_count:
valid_flows = [
f
for f in flows
Expand Down Expand Up @@ -113,30 +119,38 @@ def run(
f"Could not find a valid flow to run.\nFlows that have reached their max_times: {max_times_flows}\nFlows that do not satisfy their precondition: {precondition_flows}"
)
flow = random.choices(valid_flows, weights=weights)[0]
flow_params = [
generate(v)
for k, v in get_type_hints(flow, include_extras=True).items()
if k != "return"
]

self._flow_num = j
self.pre_flow(flow)
flow(self, *flow_params)
flows_counter[flow] += 1
self.post_flow(flow)

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 = True
while keep_loop:
flow_params = [
generate(v)
for k, v in get_type_hints(flow, include_extras=True).items()
if k != "return"
]
ret = flow(self, *flow_params)
if ret == FlowResult.UNCOUNT:
keep_loop = False
elif ret == FlowResult.REPEAT:
keep_loop = True
else:
j+=1
flows_counter[flow] += 1
self.post_flow(flow)
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()

Expand Down
Loading