sims

package
v3.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const SimAppChainID = "simulation-app"

Variables

This section is empty.

Functions

func FauxMerkleModeOpt

func FauxMerkleModeOpt(bapp *baseapp.BaseApp)

FauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of an IAVLStore for faster simulation speed.

func Run

func Run[T SimulationApp](
	t *testing.T,
	appFactory func(
		logger log.Logger,
		db dbm.DB,
		traceStore io.Writer,
		loadLatest bool,
		appOpts servertypes.AppOptions,
		baseAppOptions ...func(*baseapp.BaseApp),
	) T,
	setupStateFactory func(app T) SimStateFactory,
	postRunActions ...func(t *testing.T, app TestInstance[T]),
)

Run is a helper function that runs a simulation test with the given parameters. It calls the RunWithSeeds function with the default seeds and parameters.

This is the entrypoint to run simulation tests that used to run with the runsim binary.

func RunWithSeeds

func RunWithSeeds[T SimulationApp](
	t *testing.T,
	appFactory func(
		logger log.Logger,
		db dbm.DB,
		traceStore io.Writer,
		loadLatest bool,
		appOpts servertypes.AppOptions,
		baseAppOptions ...func(*baseapp.BaseApp),
	) T,
	setupStateFactory func(app T) SimStateFactory,
	seeds []int64,
	fuzzSeed []byte,
	postRunActions ...func(t *testing.T, app TestInstance[T]),
)

RunWithSeeds is a helper function that runs a simulation test with the given parameters. It iterates over the provided seeds and runs the simulation test for each seed in parallel.

It sets up the environment, creates an instance of the simulation app, calls the simulation.SimulateFromSeed function to run the simulation, and performs post-run actions for each seed. The execution is deterministic and can be used for fuzz tests as well.

The system under test is isolated for each run but unlike the old runsim command, there is no Process separation. This means, global caches may be reused for example. This implementation build upon the vanialla Go stdlib test framework.

func WriteToDebugLog

func WriteToDebugLog(logger log.Logger) io.Writer

WriteToDebugLog is an adapter to io.Writer interface

Types

type AppOptionsFn

type AppOptionsFn func(string) any

AppOptionsFn is an adapter to the single method AppOptions interface

func (AppOptionsFn) Get

func (f AppOptionsFn) Get(k string) any

type SimStateFactory

type SimStateFactory struct {
	Codec       codec.Codec
	AppStateFn  simtypes.AppStateFn
	BlockedAddr map[string]bool
}

type SimulationApp

type SimulationApp interface {
	runtime.AppSimI
	SetNotSigverifyTx()
	GetBaseApp() *baseapp.BaseApp
	TxConfig() client.TxConfig
}

SimulationApp abstract app that is used by sims

type TestInstance

type TestInstance[T SimulationApp] struct {
	App           T
	DB            dbm.DB
	WorkDir       string
	Cfg           simtypes.Config
	AppLogger     log.Logger
	ExecLogWriter simulation.LogWriter
}

TestInstance is a generic type that represents an instance of a SimulationApp used for testing simulations. It contains the following fields:

  • App: The instance of the SimulationApp under test.
  • DB: The LevelDB database for the simulation app.
  • WorkDir: The temporary working directory for the simulation app.
  • Cfg: The configuration flags for the simulator.
  • AppLogger: The logger used for logging in the app during the simulation, with seed value attached.
  • ExecLogWriter: Captures block and operation data coming from the simulation

func NewSimulationAppInstance

func NewSimulationAppInstance[T SimulationApp](
	t *testing.T,
	tCfg simtypes.Config,
	appFactory func(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp)) T,
) TestInstance[T]

NewSimulationAppInstance initializes and returns a TestInstance of a SimulationApp. The function takes a testing.T instance, a simtypes.Config instance, and an appFactory function as parameters. It creates a temporary working directory and a LevelDB database for the simulation app. The function then initializes a logger based on the verbosity flag and sets the logger's seed to the test configuration's seed. The database is closed and cleaned up on test completion.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL