Skip to content

Commit

Permalink
Adding pause on invariance fail in fuzz bots script (#1485)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheng Lundquist authored May 22, 2024
1 parent 52c1ad2 commit 97f9bed
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions scripts/local_fuzz_bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
from __future__ import annotations

import argparse
import logging
import random
import sys
import time
from typing import NamedTuple, Sequence

import numpy as np

from agent0 import LocalChain, LocalHyperdrive
from agent0.hyperfuzz import FuzzAssertionException
from agent0.hyperfuzz.system_fuzz import generate_fuzz_hyperdrive_config, run_local_fuzz_bots
from agent0.hyperlogs.rollbar_utilities import initialize_rollbar

Expand Down Expand Up @@ -53,19 +56,29 @@ def main(argv: Sequence[str] | None = None) -> None:
)
hyperdrive_pool = LocalHyperdrive(chain, hyperdrive_config)

raise_error_on_fail = False
if parsed_args.pause_on_invariance_fail:
raise_error_on_fail = True

# TODO submit multiple transactions per block
run_local_fuzz_bots(
hyperdrive_pool,
check_invariance=True,
raise_error_on_failed_invariance_checks=False,
raise_error_on_crash=False,
log_to_rollbar=log_to_rollbar,
run_async=False,
random_advance_time=True,
random_variable_rate=True,
num_iterations=3000,
lp_share_price_test=parsed_args.lp_share_price_test,
)
try:
run_local_fuzz_bots(
hyperdrive_pool,
check_invariance=True,
raise_error_on_failed_invariance_checks=raise_error_on_fail,
raise_error_on_crash=False,
log_to_rollbar=log_to_rollbar,
run_async=False,
random_advance_time=True,
random_variable_rate=True,
num_iterations=3000,
lp_share_price_test=parsed_args.lp_share_price_test,
)

except FuzzAssertionException as e:
logging.error("Pausing pool on fuzz assertion exception %s", repr(e))
while True:
time.sleep(1000000)

chain.cleanup()

Expand All @@ -74,6 +87,7 @@ class Args(NamedTuple):
"""Command line arguments for the invariant checker."""

lp_share_price_test: bool
pause_on_invariance_fail: bool


def namespace_to_args(namespace: argparse.Namespace) -> Args:
Expand All @@ -91,6 +105,7 @@ def namespace_to_args(namespace: argparse.Namespace) -> Args:
"""
return Args(
lp_share_price_test=namespace.lp_share_price_test,
pause_on_invariance_fail=namespace.pause_on_invariance_fail,
)


Expand All @@ -114,6 +129,12 @@ def parse_arguments(argv: Sequence[str] | None = None) -> Args:
action="store_true",
help="Runs the lp share price fuzz with specific fee and rate parameters.",
)
parser.add_argument(
"--pause-on-invariance-fail",
default=False,
action="store_true",
help="Pause execution on invariance failure.",
)

# Use system arguments if none were passed
if argv is None:
Expand Down

0 comments on commit 97f9bed

Please sign in to comment.