simtypes

package
v11.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Rare       = "Rare"
	Infrequent = "Infrequent"
	Common     = "Common"
	Frequent   = "Frequent"
)

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 GetSelectActionFn

func GetSelectActionFn(actions []ActionsWithMetadata) selectActionFn

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
	Execute(*SimCtx, sdk.Context) (
		OperationMsg simulation.OperationMsg, futureOps []simulation.FutureOperation, 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 ActionsFromWeightedOperations

func ActionsFromWeightedOperations(ops legacysimexec.WeightedOperations) []Action

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
}

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 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

type Manager

type Manager struct {
	Modules map[string]AppModuleSimulation // map of all non-legacy app modules;
	// contains filtered or unexported fields
}

SimulationManager defines a simulation manager that provides the high level utility for managing and executing simulation functionalities for a group of modules

func NewSimulationManager

func NewSimulationManager(manager module.Manager, overrideModules map[string]module.AppModuleSimulation) Manager

func (Manager) Actions

func (m Manager) Actions(seed int64, cdc codec.JSONCodec) []ActionsWithMetadata

TODO: Can we use sim here instead? Perhaps by passing in the simulation module manager to the simulator.

func (Manager) GenerateGenesisStates

func (m Manager) GenerateGenesisStates(simState *module.SimulationState, sim *SimCtx)

TODO: Fix this Unfortunately I'm temporarily giving up on fixing genesis logic, its very screwed up in the legacy designs and I want to move on to the more interesting goals of this simulation refactor. We do need to come back and un-screw up alot of this genesis work.

Thankfully for Osmosis-custom modules, we don't really care about genesis logic. (yet) The architectural errors for future readers revolve around on the design of the * Design of the AppStateFn (just look at it, osmosis/simapp/state.go)

  • Abstraction leaks overt amounts of code riddle it!

* Configs being read key by key per module via AppParams, should be a typed config * Operation/Action weights being read from params, rather than from come generic config loading * every module not just returning a genesis struct, and instead mutating things in place The only error corrected in the genesis work over what was present in prior code is: better rand handling (simCtx), and calling genesis in the InitGenesis ordering.

type SimAccountConstraint

type SimAccountConstraint = func(account simulation.Account) bool

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) 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)

type SimulatorManagerI

type SimulatorManagerI interface {
	Actions() []ActionsWithMetadata
}

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