simtypes

package
v0.0.0-...-3786997 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

README

Simtypes

This package defines:

  • Interfaces for Actions
  • Interfaces for Property Checks
  • Interfaces for AppModules to integrate w/ the simulator
  • Interfaces for an App to integrate with the simulator

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurryMsgGenerator

func CurryMsgGenerator[K interface{}, M sdk.Msg](k K, f func(K, *SimCtx, sdk.Context) (M, error)) func(*SimCtx, sdk.Context) (M, error)

func GenAndDeliverTx

func GenAndDeliverTx(
	app *baseapp.BaseApp,
	txGen client.TxConfig,
	msg legacytx.LegacyMsg,
	fees sdk.Coins,
	ctx sdk.Context,
	simAccount simulation.Account,
	ak AccountKeeper,
	moduleName string,
) (simulation.OperationMsg, []simulation.FutureOperation, error)

TODO: Must delete

func GenAndDeliverTxWithRandFees

func GenAndDeliverTxWithRandFees(
	r *rand.Rand,
	app *baseapp.BaseApp,
	txGen client.TxConfig,
	msg legacytx.LegacyMsg,
	coinsSpentInMsg sdk.Coins,
	ctx sdk.Context,
	simAccount simulation.Account,
	ak AccountKeeper,
	bk BankKeeper,
	moduleName string,
) (simulation.OperationMsg, []simulation.FutureOperation, error)

TODO: Must delete

func RandLTBound

func RandLTBound[T constraints.Integer](sim *SimCtx, upperbound T) T

func RandLTEBound

func RandLTEBound[T constraints.Integer](sim *SimCtx, upperbound T) T

func RandSelect

func RandSelect[T interface{}](sim *SimCtx, args ...T) T

func RemoveIndex

func RemoveIndex(s sdk.Coins, index int) sdk.Coins

Types

type AccountKeeper

type AccountKeeper interface {
	GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
}

type Action

type Action interface {
	Name() string
	// I envision this frequency being provided from a config.
	// Module providers can optionally provide a default from an enum,
	// but this should not be the default.
	Frequency() Frequency
	// resultData is data that is eventually merkelized every block and
	// used to compare consistency across multiple simulation runs.
	Execute(*SimCtx, sdk.Context) (
		OperationMsg simulation.OperationMsg, futureOps []simulation.FutureOperation, resultData []byte, err error)
	WithFrequency(w Frequency) Action
}

Action represents a simulator action. The details of this struct are internal, we currently plan on maintaining 2 constructors for it. * weightedOperationAction - for legacy simulator compatibility * msgBasedAction - An easy API to go from creating a message via simctx to something simulator can deal with

func NewKeeperlessMsgBasedAction

func NewKeeperlessMsgBasedAction[M sdk.Msg](actionName string, msgGenerator func(sim *SimCtx, ctx sdk.Context) (M, error)) Action

func NewMsgBasedAction

func NewMsgBasedAction[K interface{}, M sdk.Msg](actionName string, k K, f func(K, *SimCtx, sdk.Context) (M, error)) Action

type ActionsWithMetadata

type ActionsWithMetadata struct {
	Action
	ModuleName string
}

type App

type App interface {
	GetBaseApp() *baseapp.BaseApp
	AppCodec() codec.Codec
	GetAccountKeeper() AccountKeeper
	GetBankKeeper() BankKeeper
	GetStakingKeeper() stakingkeeper.Keeper
	ModuleManager() module.Manager
}

type AppCreator

type AppCreator = func(homepath string, legacyInvariantPeriod uint, baseappOptions ...func(*baseapp.BaseApp)) App

type AppModuleSimulation

type AppModuleSimulation interface {
	module.AppModule

	Actions() []Action
}

AppModuleSimulation defines the standard functions that every module should expose for the SDK blockchain simulator

type AppModuleSimulationGenesis

type AppModuleSimulationGenesis interface {
	AppModuleSimulation
	// TODO: Come back and improve SimulationState interface
	SimulatorGenesisState(*module.SimulationState, *SimCtx)
}

type AppModuleSimulationPropertyCheck

type AppModuleSimulationPropertyCheck interface {
	module.AppModule

	PropertyChecks() []PropertyCheck
}

type BankKeeper

type BankKeeper interface {
	GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
	GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
	// TODO: Revisit
	SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
}

type Frequency

type Frequency string
const (
	Rare       Frequency = "Rare"
	Infrequent Frequency = "Infrequent"
	Common     Frequency = "Common"
	Frequent   Frequency = "Frequent"
)

type ModuleGenesisGenerator

type ModuleGenesisGenerator interface {
	GenerateGenesisStates(simState *module.SimulationState, sim *SimCtx)
}

type PropertyCheck

type PropertyCheck interface {
	// A property check listens for signals on the listed channels, that the simulator can emit.
	// Known channel types right now:
	// * Post-Action execute
	// * Pre-Action execute
	// * Block end (can make listener execute every Nth block end)
	SubscriptionKeys() []string
	Check(sim *SimCtx, ctx sdk.Context, key string, value interface{}) error
}

type PubSubManager

type PubSubManager interface {
	Subscribe(key string, subName string, callback SimCallbackFn)
	Publish(sim *SimCtx, ctx sdk.Context, key string, value interface{}) error
}

type SimAccountConstraint

type SimAccountConstraint = func(account simulation.Account) bool

type SimCallbackFn

type SimCallbackFn func(sim *SimCtx, ctx sdk.Context, value interface{}) error

type SimCtx

type SimCtx struct {
	Accounts []simulation.Account
	Cdc      codec.JSONCodec // application codec
	// contains filtered or unexported fields
}

TODO: Contemplate name better

func NewSimCtx

func NewSimCtx(r *rand.Rand, app App, accounts []simulation.Account, chainID string) *SimCtx

func (SimCtx) AccountKeeper

func (sim SimCtx) AccountKeeper() AccountKeeper

func (*SimCtx) AddAccount

func (sim *SimCtx) AddAccount(acc simulation.Account)

func (SimCtx) AppCodec

func (sim SimCtx) AppCodec() codec.Codec

func (SimCtx) BankKeeper

func (sim SimCtx) BankKeeper() BankKeeper

func (SimCtx) BaseApp

func (sim SimCtx) BaseApp() *baseapp.BaseApp

func (SimCtx) ChainID

func (sim SimCtx) ChainID() string

func (*SimCtx) FindAccount

func (sim *SimCtx) FindAccount(address sdk.Address) (simulation.Account, bool)

FindAccount iterates over all the simulation accounts to find the one that matches the given address TODO: Benchmark time in here, we should probably just make a hashmap indexing this.

func (*SimCtx) GetRand

func (sim *SimCtx) GetRand() *rand.Rand

TODO: Consider rename to Rand()

func (*SimCtx) GetRandSubsetOfKDenoms

func (sim *SimCtx) GetRandSubsetOfKDenoms(ctx sdk.Context, acc simulation.Account, k int) (sdk.Coins, bool)

GetRandSubsetOfKDenoms returns a random subset of coins of k unique denoms from the provided account TODO: Write unit test

func (*SimCtx) GetSeededRand

func (sim *SimCtx) GetSeededRand(seed string) *rand.Rand

TODO: Consider rename to SeededRand() or DomainSeparatedRand

func (*SimCtx) RandCoinSubset

func (sim *SimCtx) RandCoinSubset(ctx sdk.Context, addr sdk.AccAddress, denoms []string) sdk.Coins

func (*SimCtx) RandExponentialCoin

func (sim *SimCtx) RandExponentialCoin(ctx sdk.Context, addr sdk.AccAddress) sdk.Coin

RandGeometricCoin uniformly samples a denom from the addr's balances. Then it samples an Exponentially distributed amount of the addr's coins, with rate = 10. (Meaning that on average it samples 10% of the chosen balance) Pre-condition: Addr must have a spendable balance

func (*SimCtx) RandIntBetween

func (sim *SimCtx) RandIntBetween(min, max int) int

RandIntBetween returns a random int between two numbers, inclusive of min, exclusive of max.

func (*SimCtx) RandPositiveInt

func (sim *SimCtx) RandPositiveInt(max sdk.Int) sdk.Int

RandPositiveInt get a rand positive sdk.Int

func (*SimCtx) RandStringOfLength

func (sim *SimCtx) RandStringOfLength(n int) string

RandStringOfLength generates a random string of a particular length

func (*SimCtx) RandSubsetCoins

func (sim *SimCtx) RandSubsetCoins(coins sdk.Coins) sdk.Coins

returns random subset of the provided coins will return at least one coin unless coins argument is empty or malformed i.e. 0 amt in coins

func (*SimCtx) RandTimestamp

func (sim *SimCtx) RandTimestamp() time.Time

RandTimestamp generates a random timestamp

func (*SimCtx) RandomAmount

func (sim *SimCtx) RandomAmount(max sdk.Int) sdk.Int

RandomAmount generates a random amount that is biased to return max and 0.

func (*SimCtx) RandomDecAmount

func (sim *SimCtx) RandomDecAmount(max sdk.Dec) sdk.Dec

RandomDecAmount generates a random decimal amount Note: The range of RandomDecAmount includes max, and is, in fact, biased to return max as well as 0.

func (*SimCtx) RandomExistingAddress

func (sim *SimCtx) RandomExistingAddress() sdk.AccAddress

func (*SimCtx) RandomFees

func (sim *SimCtx) RandomFees(ctx sdk.Context, spendableCoins sdk.Coins) (sdk.Coins, error)

RandomFees returns a random fee by selecting a random coin denomination and amount from the account's available balance. If the user doesn't have enough funds for paying fees, it returns empty coins.

func (*SimCtx) RandomSimAccount

func (sim *SimCtx) RandomSimAccount() simulation.Account

func (*SimCtx) RandomSimAccountWithBalance

func (sim *SimCtx) RandomSimAccountWithBalance(ctx sdk.Context) (simulation.Account, error)

func (*SimCtx) RandomSimAccountWithConstraint

func (sim *SimCtx) RandomSimAccountWithConstraint(f SimAccountConstraint) (simulation.Account, bool)

returns acc, accExists := sim.RandomSimAccountWithConstraint(f) where acc is a uniformly sampled account from all accounts satisfying the constraint f a constraint is satisfied for an account `acc` if f(acc) = true accExists is false, if there is no such account.

func (*SimCtx) RandomSimAccountWithKDenoms

func (sim *SimCtx) RandomSimAccountWithKDenoms(ctx sdk.Context, k int) (simulation.Account, bool)

RandomSimAccountWithKDenoms returns an account that possesses k unique denoms

func (*SimCtx) RandomSimAccountWithMinCoins

func (sim *SimCtx) RandomSimAccountWithMinCoins(ctx sdk.Context, coins sdk.Coins) (simulation.Account, error)

func (*SimCtx) SelAddrWithDenom

func (sim *SimCtx) SelAddrWithDenom(ctx sdk.Context, denom string) (simulation.Account, sdk.Coin, bool)

SelAddrWithDenom attempts to find an address with the provided denom. This function returns (account, randSubsetCoins, found), so if found = false, then no such address exists. randSubsetCoins is a random subset of the provided denoms, if the account is found. TODO: Write unit test

func (*SimCtx) SelAddrWithDenoms

func (sim *SimCtx) SelAddrWithDenoms(ctx sdk.Context, denoms []string) (simulation.Account, sdk.Coins, bool)

Returns (account, randSubsetCoins, found), so if found = false, then no such address exists. randSubsetCoins is a random subset of the provided denoms, if the account is found. TODO: Write unit test

func (SimCtx) StakingKeeper

func (sim SimCtx) StakingKeeper() stakingkeeper.Keeper

func (*SimCtx) WrapRand

func (sim *SimCtx) WrapRand(domainSeparator string) (wrappedSim *SimCtx, cleanup func())

WrapRand returns a new sim object and a cleanup function to write Accounts changes to the parent (and invalidate the prior)

Directories

Path Synopsis
This package is a hack.
This package is a hack.

Jump to

Keyboard shortcuts

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