agent0.hyperfuzz.unit_fuzz.helpers

Shared functions for interactive fuzz testing.

Submodules

Functions

advance_time_after_checkpoint(→ None)

Advance time on the chain to the next checkpoint boundary plus some buffer.

advance_time_before_checkpoint(→ None)

Advance time on the chain a random amount that is less than the next checkpoint time.

close_trades(→ None)

Close trades provided.

permute_trade_events(...)

Given a list of trade events, returns the list in random order.

execute_random_trades(...)

Conduct some trades specified by the trade list.

setup_fuzz(...)

Setup the fuzz experiment.

Package Contents

agent0.hyperfuzz.unit_fuzz.helpers.advance_time_after_checkpoint(chain: agent0.core.hyperdrive.interactive.LocalChain, interactive_hyperdrive: agent0.core.hyperdrive.interactive.LocalHyperdrive) None

Advance time on the chain to the next checkpoint boundary plus some buffer.

Parameters:
  • chain (LocalChain) – An instantiated LocalChain.

  • interactive_hyperdrive (InteractiveHyperdrive) – An instantiated InteractiveHyperdrive object.

agent0.hyperfuzz.unit_fuzz.helpers.advance_time_before_checkpoint(chain: agent0.core.hyperdrive.interactive.LocalChain, rng: numpy.random.Generator, interactive_hyperdrive: agent0.core.hyperdrive.interactive.LocalHyperdrive) None

Advance time on the chain a random amount that is less than the next checkpoint time.

Parameters:
  • chain (LocalChain) – An instantiated LocalChain.

  • rng (Generator) – The numpy Generator provides access to a wide range of distributions, and stores the random state.

  • interactive_hyperdrive (InteractiveHyperdrive) – An instantiated InteractiveHyperdrive object.

agent0.hyperfuzz.unit_fuzz.helpers.close_trades(trade_events: list[tuple[agent0.core.hyperdrive.interactive.local_hyperdrive_agent.LocalHyperdriveAgent, hyperdrivetypes.OpenLongEventFP | hyperdrivetypes.OpenShortEventFP]]) None

Close trades provided.

Parameters:

trade_events (list[tuple[InteractiveHyperdriveAgent, OpenLong | OpenShort]]) –

A list with an entry per trade, containing a tuple with:
  • the agent executing the trade

  • either the OpenLong or OpenShort trade event

agent0.hyperfuzz.unit_fuzz.helpers.permute_trade_events(trade_events: list[tuple[agent0.core.hyperdrive.interactive.local_hyperdrive_agent.LocalHyperdriveAgent, hyperdrivetypes.OpenLongEventFP | hyperdrivetypes.OpenShortEventFP]], rng: numpy.random.Generator) list[tuple[agent0.core.hyperdrive.interactive.local_hyperdrive_agent.LocalHyperdriveAgent, hyperdrivetypes.OpenLongEventFP | hyperdrivetypes.OpenShortEventFP]]

Given a list of trade events, returns the list in random order.

Parameters:
  • trade_events (list[tuple[InteractiveHyperdriveAgent, OpenLong | OpenShort]]) –

    A list with an entry per trade, containing a tuple with:
    • the agent executing the trade

    • either the OpenLong or OpenShort trade event

  • rng – The numpy Generator provides access to a wide range of distributions, and stores the random state.

Returns:

The trade event list in random order

Return type:

list[tuple[InteractiveHyperdriveAgent, OpenLong | OpenShort]]

agent0.hyperfuzz.unit_fuzz.helpers.execute_random_trades(num_trades: int, chain: agent0.core.hyperdrive.interactive.LocalChain, rng: numpy.random.Generator, interactive_hyperdrive: agent0.core.hyperdrive.interactive.LocalHyperdrive, advance_time: bool = False) list[tuple[agent0.core.hyperdrive.interactive.local_hyperdrive_agent.LocalHyperdriveAgent, hyperdrivetypes.OpenLongEventFP | hyperdrivetypes.OpenShortEventFP]]

Conduct some trades specified by the trade list. If advance time is true, the sum of all time passed between all trades will be between 0 and the position duration.

Parameters:
  • num_trades (int) – The number of trades to execute.

  • chain (LocalChain) – An instantiated LocalChain.

  • rng – The numpy Generator provides access to a wide range of distributions, and stores the random state.

  • interactive_hyperdrive (InteractiveHyperdrive) – An instantiated InteractiveHyperdrive object.

  • advance_time (bool, optional) – If True, advance time a random amount between 0 and the position duration after each trade. Defaults to False, which follows the anvil settings. Typically this advances one block and 12 seconds between each trade.

Returns:

A list with an entry per trade, containing a tuple with:
  • the agent executing the trade

  • either the OpenLong or OpenShort trade event

Return type:

list[tuple[InteractiveHyperdriveAgent, OpenLong | OpenShort]]

agent0.hyperfuzz.unit_fuzz.helpers.setup_fuzz(chain_config: agent0.core.hyperdrive.interactive.LocalChain.Config, log_to_rollbar: bool = True, crash_log_level: int | None = None, fuzz_test_name: str | None = None, curve_fee: fixedpointmath.FixedPoint | None = None, flat_fee: fixedpointmath.FixedPoint | None = None, governance_lp_fee: fixedpointmath.FixedPoint | None = None, governance_zombie_fee: fixedpointmath.FixedPoint | None = None, var_interest: fixedpointmath.FixedPoint | None = None, steth: bool = False) tuple[agent0.core.hyperdrive.interactive.LocalChain, int, numpy.random.Generator, agent0.core.hyperdrive.interactive.LocalHyperdrive]

Setup the fuzz experiment.

Parameters:
  • chain_config (LocalChain.Config, optional) – Configuration options for the local chain.

  • log_to_rollbar (bool, optional) – If True, log errors rollbar. Defaults to True.

  • crash_log_level (int | None, optional) – The log level to log crashes at. Defaults to critical.

  • fuzz_test_name (str | None, optional) – The prefix to prepend to rollbar exception messages

  • curve_fee (FixedPoint | None, optional) – The curve fee for the test. Defaults to using the default fee

  • flat_fee (FixedPoint | None, optional) – The flat fee for the test. Defaults to using the default fee

  • governance_lp_fee (FixedPoint | None, optional) – The governance lp fee for the test. Defaults to using the default fee

  • governance_zombie_fee (FixedPoint | None, optional) – The governance zombie fee for the test. Defaults to using the default fee

  • var_interest (FixedPoint | None, optional) – The variable interest rate. Defaults to using the default variable interest rate defined in interactive hyperdrive.

  • steth (bool, optional) – If True, use steth. Defaults to False.

Returns:

A tuple containing:
chain: LocalChain

An instantiated LocalChain.

random_seed: int

The random seed used to construct the Generator.

rng: Generator

The numpy Generator provides access to a wide range of distributions, and stores the random state.

interactive_hyperdrive: InteractiveHyperdrive

An instantiated InteractiveHyperdrive object.

Return type:

tuple[str, LocalChain, int, Generator, InteractiveHyperdrive]