Documentation
¶
Index ¶
- Constants
- func BlockTime(ctx context.Context) time.Time
- func Collect[T, E any](source []T, f func(a T) E) []E
- func DeliverSimsMsg(ctx context.Context, reporter SimulationReporter, app AppEntrypoint, ...) simtypes.OperationMsg
- func FauxMerkleModeOpt(bapp *baseapp.BaseApp)
- func First[T any](source []T, f func(a T) bool) *T
- func OneOf[T any](r interface{ ... }, s []T) T
- func Run[T SimulationApp](t *testing.T, ...)
- func RunWithSeed[T SimulationApp](tb testing.TB, cfg simtypes.Config, ...)
- func RunWithSeeds[T SimulationApp](t *testing.T, ...)
- func WriteToDebugLog(logger log.Logger) io.Writer
- type AbstractRegistry
- type AccountSource
- type AccountSourceX
- type AppEntrypoint
- type AppOptionsFn
- type BalanceSource
- type BasicSimulationReporter
- func (x *BasicSimulationReporter) Close() error
- func (x *BasicSimulationReporter) Comment() string
- func (x *BasicSimulationReporter) Fail(err error, comments ...string)
- func (x *BasicSimulationReporter) IsSkipped() bool
- func (x *BasicSimulationReporter) Skip(comment string)
- func (x *BasicSimulationReporter) Skipf(comment string, args ...any)
- func (x *BasicSimulationReporter) Success(msg sdk.Msg, comments ...string)
- func (x *BasicSimulationReporter) Summary() *ExecutionSummary
- func (x *BasicSimulationReporter) ToLegacyOperationMsg() simtypes.OperationMsg
- func (x *BasicSimulationReporter) WithScope(msg sdk.Msg, optionalSkipHook ...SkipHook) SimulationReporter
- type ChainDataSource
- func (c *ChainDataSource) AccountAt(reporter SimulationReporter, i int) SimAccount
- func (c *ChainDataSource) AccountsCount() int
- func (c *ChainDataSource) AddressCodec() address.Codec
- func (c *ChainDataSource) AllAccounts() []simtypes.Account
- func (c *ChainDataSource) AnyAccount(r SimulationReporter, filters ...SimAccountFilter) SimAccount
- func (c ChainDataSource) GetAccount(reporter SimulationReporter, addr string) SimAccount
- func (c ChainDataSource) GetAccountbyAccAddr(reporter SimulationReporter, addr sdk.AccAddress) SimAccount
- func (c ChainDataSource) HasAccount(addr string) bool
- func (c *ChainDataSource) IsSendEnabledDenom(denom string) bool
- func (c *ChainDataSource) ModuleAccountAddress(reporter SimulationReporter, moduleName string) string
- func (c *ChainDataSource) Rand() *XRand
- type CoinsFilter
- type CoinsFilterFn
- type ExecutionSummary
- type FactoryMethod
- type FactoryMethodWithDeliveryResultHandler
- type FactoryMethodWithFutureOps
- type FutureOperationRegistryAdapter
- type FutureOpsRegistry
- type HasFutureOpsRegistry
- type HasLegacyProposalContents
- type HasLegacyProposalMsgs
- type HasLegacyWeightedOperations
- type HasProposalMsgsX
- type HasWeightedOperationsX
- type HasWeightedOperationsXWithProposals
- type LazyStateSimMsgFactory
- type ModuleAccountSource
- type Registry
- type ReporterStatus
- type ResultHandlingSimMsgFactory
- type SimAccount
- type SimAccountFilter
- func ExcludeAccounts(others ...SimAccount) SimAccountFilter
- func ExcludeAddresses(addrs ...string) SimAccountFilter
- func UniqueAccounts() SimAccountFilter
- func WithDenomBalance(denom string) SimAccountFilter
- func WithLiquidBalanceGTE(amount ...sdk.Coin) SimAccountFilter
- func WithSpendableBalance() SimAccountFilter
- type SimAccountFilterFn
- type SimDeliveryResultHandler
- type SimMsgFactoryFn
- type SimMsgFactoryX
- type SimStateFactory
- type SimsAccountBalance
- func (b *SimsAccountBalance) BlockAmount(amount sdk.Coin) bool
- func (b *SimsAccountBalance) RandFees() sdk.Coins
- func (b *SimsAccountBalance) RandSubsetCoin(reporter SimulationReporter, denom string, filters ...CoinsFilter) sdk.Coin
- func (b *SimsAccountBalance) RandSubsetCoins(reporter SimulationReporter, filters ...CoinsFilter) sdk.Coins
- type SimulationApp
- type SimulationReporter
- type SkipHook
- type SkipHookFn
- type TestInstance
- type UniqueTypeRegistry
- type WeightSource
- type WeightSourceFn
- type WeightedFactory
- type WeightedFactoryMethod
- type WeightedFactoryMethods
- type WeightedOperationRegistryAdapter
- type WeightedProposalMsgIter
- type XRand
- func (r *XRand) Amount(balance math.Int) math.Int
- func (r *XRand) Bool() bool
- func (r *XRand) Coin(src sdk.Coins) sdk.Coin
- func (r *XRand) DecN(max math.LegacyDec) math.LegacyDec
- func (r *XRand) IntInRange(min, max int) int
- func (r *XRand) PositiveSDKIntInRange(min, max math.Int) (math.Int, error)
- func (r *XRand) PositiveSDKIntn(max math.Int) (math.Int, error)
- func (r *XRand) StringN(max int) string
- func (r *XRand) SubsetCoins(src sdk.Coins) sdk.Coins
- func (r *XRand) Timestamp() time.Time
- func (r *XRand) Uint32InRange(min, max uint32) uint32
- func (r *XRand) Uint64InRange(min, max uint64) uint64
Constants ¶
const SimAppChainID = "simulation-app"
Variables ¶
This section is empty.
Functions ¶
func BlockTime ¶
BlockTime read header block time from sdk context or sims context key if not present
func Collect ¶
func Collect[T, E any](source []T, f func(a T) E) []E
Collect applies the function f to each element in the source slice, returning a new slice containing the results.
The source slice can contain elements of any type T, and the function f should take an element of type T as input and return a value of any type E.
Example usage:
source := []int{1, 2, 3, 4, 5} double := Collect(source, func(x int) int { return x * 2 }) // double is now []int{2, 4, 6, 8, 10}
func DeliverSimsMsg ¶
func DeliverSimsMsg( ctx context.Context, reporter SimulationReporter, app AppEntrypoint, r *rand.Rand, txGen client.TxConfig, ak AccountSource, chainID string, msg sdk.Msg, deliveryResultHandler SimDeliveryResultHandler, senders ...SimAccount, ) simtypes.OperationMsg
DeliverSimsMsg delivers a simulation message by creating and signing a mock transaction, then delivering it to the application through the specified entrypoint. It returns a legacy operation message representing the result of the delivery.
The function takes the following parameters: - reporter: SimulationReporter - Interface for reporting the result of the delivery - r: *rand.Rand - Random number generator used for creating the mock transaction - app: AppEntrypoint - Entry point for delivering the simulation transaction to the application - txGen: client.TxConfig - Configuration for generating transactions - ak: AccountSource - Source for retrieving accounts - msg: sdk.Msg - The simulation message to be delivered - ctx: sdk.Context - The simulation context - chainID: string - The chain ID - senders: ...SimAccount - Accounts from which to send the simulation message
The function returns a simtypes.OperationMsg, which is a legacy representation of the result of the delivery.
func FauxMerkleModeOpt ¶
FauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of an IAVLStore for faster simulation speed.
func OneOf ¶
OneOf returns a random element from the given slice using the provided random number generator. Panics for empty or nil slice
func Run ¶
func Run[T SimulationApp]( t *testing.T, appFactory func( logger log.Logger, db corestore.KVStoreWithBatch, traceStore io.Writer, loadLatest bool, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) T, setupStateFactory func(app T) SimStateFactory, postRunActions ...func(t testing.TB, app TestInstance[T], accs []simtypes.Account), )
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 RunWithSeed ¶
func RunWithSeed[T SimulationApp]( tb testing.TB, cfg simtypes.Config, appFactory func(logger log.Logger, db corestore.KVStoreWithBatch, traceStore io.Writer, loadLatest bool, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp)) T, setupStateFactory func(app T) SimStateFactory, seed int64, fuzzSeed []byte, postRunActions ...func(t testing.TB, app TestInstance[T], accs []simtypes.Account), )
RunWithSeed 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 the seed. The execution is deterministic and can be used for fuzz tests as well.
func RunWithSeeds ¶
func RunWithSeeds[T SimulationApp]( t *testing.T, appFactory func( logger log.Logger, db corestore.KVStoreWithBatch, 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.TB, app TestInstance[T], accs []simtypes.Account), )
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 vanilla Go stdlib test framework.
Types ¶
type AbstractRegistry ¶
type AbstractRegistry[T any] struct { // contains filtered or unexported fields }
func (*AbstractRegistry[T]) ToLegacyObjects ¶
func (l *AbstractRegistry[T]) ToLegacyObjects() []T
ToLegacyObjects returns the legacy properties of the SimsRegistryAdapter as a slice of type T.
type AccountSource ¶
type AccountSourceX ¶
type AccountSourceX interface { AccountSource ModuleAccountSource }
AccountSourceX Account and Module account
type AppEntrypoint ¶
type AppEntrypoint = simtypes.AppEntrypoint
AppEntrypoint is an alias to the simtype interface
type AppOptionsFn ¶
AppOptionsFn is an adapter to the single method AppOptions interface
func (AppOptionsFn) Get ¶
func (f AppOptionsFn) Get(k string) any
func (AppOptionsFn) GetString ¶
func (f AppOptionsFn) GetString(k string) string
type BalanceSource ¶
type BalanceSource interface { SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins IsSendEnabledDenom(ctx context.Context, denom string) bool }
BalanceSource is an interface for retrieving balance-related information for a given account.
type BasicSimulationReporter ¶
type BasicSimulationReporter struct {
// contains filtered or unexported fields
}
func NewBasicSimulationReporter ¶
func NewBasicSimulationReporter(optionalSkipHook ...SkipHook) *BasicSimulationReporter
NewBasicSimulationReporter constructor that accepts an optional callback hook that is called on state transition to skipped status A typical implementation for this hook is testing.T or testing.B.
func (*BasicSimulationReporter) Close ¶
func (x *BasicSimulationReporter) Close() error
func (*BasicSimulationReporter) Comment ¶
func (x *BasicSimulationReporter) Comment() string
func (*BasicSimulationReporter) Fail ¶
func (x *BasicSimulationReporter) Fail(err error, comments ...string)
func (*BasicSimulationReporter) IsSkipped ¶
func (x *BasicSimulationReporter) IsSkipped() bool
func (*BasicSimulationReporter) Skip ¶
func (x *BasicSimulationReporter) Skip(comment string)
func (*BasicSimulationReporter) Skipf ¶
func (x *BasicSimulationReporter) Skipf(comment string, args ...any)
func (*BasicSimulationReporter) Success ¶
func (x *BasicSimulationReporter) Success(msg sdk.Msg, comments ...string)
func (*BasicSimulationReporter) Summary ¶
func (x *BasicSimulationReporter) Summary() *ExecutionSummary
func (*BasicSimulationReporter) ToLegacyOperationMsg ¶
func (x *BasicSimulationReporter) ToLegacyOperationMsg() simtypes.OperationMsg
func (*BasicSimulationReporter) WithScope ¶
func (x *BasicSimulationReporter) WithScope(msg sdk.Msg, optionalSkipHook ...SkipHook) SimulationReporter
WithScope is a method of the BasicSimulationReporter type that creates a new instance of SimulationReporter with an additional scope specified by the input `msg`. The msg is used to set type, module and binary data as context for the legacy operation. The WithScope method acts as a constructor to initialize state and has to be called before using the instance in DeliverSimsMsg.
The method accepts an optional `optionalSkipHook` parameter that can be used to add a callback hook that is triggered on skip operations additional to any parent skip hook. This method returns the newly created SimulationReporter instance.
type ChainDataSource ¶
type ChainDataSource struct {
// contains filtered or unexported fields
}
ChainDataSource provides common sims test data and helper methods
func NewChainDataSource ¶
func NewChainDataSource( ctx context.Context, r *rand.Rand, ak ModuleAccountSource, bk BalanceSource, codec address.Codec, oldSimAcc ...simtypes.Account, ) *ChainDataSource
NewChainDataSource constructor
func (*ChainDataSource) AccountAt ¶
func (c *ChainDataSource) AccountAt(reporter SimulationReporter, i int) SimAccount
func (*ChainDataSource) AccountsCount ¶
func (c *ChainDataSource) AccountsCount() int
func (*ChainDataSource) AddressCodec ¶
func (c *ChainDataSource) AddressCodec() address.Codec
func (*ChainDataSource) AllAccounts ¶
func (c *ChainDataSource) AllAccounts() []simtypes.Account
AllAccounts returns all accounts in legacy format
func (*ChainDataSource) AnyAccount ¶
func (c *ChainDataSource) AnyAccount(r SimulationReporter, filters ...SimAccountFilter) SimAccount
AnyAccount returns a random SimAccount matching the filter criteria. Module accounts are excluded. In case of an error or no matching account found, the reporter is set to skip and an empty value is returned.
func (ChainDataSource) GetAccount ¶
func (c ChainDataSource) GetAccount(reporter SimulationReporter, addr string) SimAccount
GetAccount return SimAccount with given bench32 address. Reporter skip flag is set when not found.
func (ChainDataSource) GetAccountbyAccAddr ¶
func (c ChainDataSource) GetAccountbyAccAddr(reporter SimulationReporter, addr sdk.AccAddress) SimAccount
GetAccountbyAccAddr return SimAccount with given binary address. Reporter skip flag is set when not found.
func (ChainDataSource) HasAccount ¶
func (c ChainDataSource) HasAccount(addr string) bool
func (*ChainDataSource) IsSendEnabledDenom ¶
func (c *ChainDataSource) IsSendEnabledDenom(denom string) bool
func (*ChainDataSource) ModuleAccountAddress ¶
func (c *ChainDataSource) ModuleAccountAddress(reporter SimulationReporter, moduleName string) string
func (*ChainDataSource) Rand ¶
func (c *ChainDataSource) Rand() *XRand
type CoinsFilter ¶
func WithSendEnabledCoins ¶
func WithSendEnabledCoins() CoinsFilter
type CoinsFilterFn ¶
type ExecutionSummary ¶
type ExecutionSummary struct {
// contains filtered or unexported fields
}
func NewExecutionSummary ¶
func NewExecutionSummary() *ExecutionSummary
func (*ExecutionSummary) Add ¶
func (s *ExecutionSummary) Add(module, url string, status ReporterStatus, comment string)
func (*ExecutionSummary) String ¶
func (s *ExecutionSummary) String() string
type FactoryMethod ¶
type FactoryMethod func(ctx context.Context, testData *ChainDataSource, reporter SimulationReporter) (signer []SimAccount, msg sdk.Msg)
FactoryMethod is a method signature implemented by concrete message factories for SimMsgFactoryX
This factory method is responsible for creating a new `sdk.Msg` instance and determining the proposed signers who are expected to successfully sign the message for delivery.
Parameters:
- ctx: The context for the operation
- testData: A pointer to a `ChainDataSource` which provides helper methods and simple access to accounts and balances within the chain.
- reporter: An instance of `SimulationReporter` used to report the results of the simulation. If no valid message can be provided, the factory method should call `reporter.Skip("some comment")` with both `signer` and `msg` set to nil.
Returns: - signer: A slice of `SimAccount` representing the proposed signers. - msg: An instance of `sdk.Msg` representing the message to be delivered.
type FactoryMethodWithDeliveryResultHandler ¶
type FactoryMethodWithDeliveryResultHandler[T sdk.Msg] func(ctx context.Context, testData *ChainDataSource, reporter SimulationReporter) (signer []SimAccount, msg T, handler SimDeliveryResultHandler)
FactoryMethodWithDeliveryResultHandler extended factory method that can return a result handler, that is executed on the delivery tx error result. This is used in staking for example to validate negative execution results.
type FactoryMethodWithFutureOps ¶
type FactoryMethodWithFutureOps[T sdk.Msg] func(ctx context.Context, testData *ChainDataSource, reporter SimulationReporter, fOpsReg FutureOpsRegistry) ([]SimAccount, T)
FactoryMethodWithFutureOps extended message factory method for the gov module or others that have to schedule operations for a future block.
type FutureOperationRegistryAdapter ¶
type FutureOperationRegistryAdapter AbstractRegistry[simtypes.FutureOperation]
func NewFutureOpsRegistry ¶
func NewFutureOpsRegistry(l regCommon) *FutureOperationRegistryAdapter
func (*FutureOperationRegistryAdapter) Add ¶
func (l *FutureOperationRegistryAdapter) Add(blockTime time.Time, fx SimMsgFactoryX)
type FutureOpsRegistry ¶
type FutureOpsRegistry interface {
Add(blockTime time.Time, f SimMsgFactoryX)
}
FutureOpsRegistry register message factories for future blocks
type HasFutureOpsRegistry ¶
type HasFutureOpsRegistry interface {
SetFutureOpsRegistry(FutureOpsRegistry)
}
type HasLegacyProposalContents ¶
type HasLegacyProposalContents interface { // ProposalContents content functions used to simulate governance proposals ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent //nolint:staticcheck // legacy v1beta1 governance }
HasLegacyProposalContents defines the contents that can be used to simulate legacy governance (v1beta1) proposals Deprecated replaced by HasProposalMsgsX
type HasLegacyProposalMsgs ¶
type HasLegacyProposalMsgs interface { // ProposalMsgs msg fu nctions used to simulate governance proposals ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg }
HasLegacyProposalMsgs defines the messages that can be used to simulate governance (v1) proposals Deprecated replaced by HasProposalMsgsX
type HasLegacyWeightedOperations ¶
type HasLegacyWeightedOperations interface { // WeightedOperations simulation operations (i.e msgs) with their respective weight WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation }
type HasProposalMsgsX ¶
type HasProposalMsgsX interface {
ProposalMsgsX(weights WeightSource, reg Registry)
}
type HasWeightedOperationsX ¶
type HasWeightedOperationsX interface {
WeightedOperationsX(weight WeightSource, reg Registry)
}
type HasWeightedOperationsXWithProposals ¶
type HasWeightedOperationsXWithProposals interface { WeightedOperationsX(weights WeightSource, reg Registry, proposals WeightedProposalMsgIter, legacyProposals []simtypes.WeightedProposalContent) //nolint: staticcheck // used for legacy proposal types }
type LazyStateSimMsgFactory ¶
type LazyStateSimMsgFactory[T sdk.Msg] struct { SimMsgFactoryFn[T] // contains filtered or unexported fields }
LazyStateSimMsgFactory stateful message factory with weighted proposals and future operation registry initialized lazy before execution.
func NewSimMsgFactoryWithFutureOps ¶
func NewSimMsgFactoryWithFutureOps[T sdk.Msg](f FactoryMethodWithFutureOps[T]) *LazyStateSimMsgFactory[T]
func (*LazyStateSimMsgFactory[T]) SetFutureOpsRegistry ¶
func (c *LazyStateSimMsgFactory[T]) SetFutureOpsRegistry(registry FutureOpsRegistry)
type ModuleAccountSource ¶
type ModuleAccountSource interface {
GetModuleAddress(moduleName string) sdk.AccAddress
}
type Registry ¶
type Registry interface {
Add(weight uint32, f SimMsgFactoryX)
}
Registry is an abstract entry point to register message factories with weights
type ReporterStatus ¶
type ReporterStatus uint8
func (ReporterStatus) String ¶
func (s ReporterStatus) String() string
type ResultHandlingSimMsgFactory ¶
type ResultHandlingSimMsgFactory[T sdk.Msg] struct { SimMsgFactoryFn[T] // contains filtered or unexported fields }
ResultHandlingSimMsgFactory message factory with a delivery error result handler configured.
func NewSimMsgFactoryWithDeliveryResultHandler ¶
func NewSimMsgFactoryWithDeliveryResultHandler[T sdk.Msg](f FactoryMethodWithDeliveryResultHandler[T]) *ResultHandlingSimMsgFactory[T]
NewSimMsgFactoryWithDeliveryResultHandler constructor
func (ResultHandlingSimMsgFactory[T]) DeliveryResultHandler ¶
func (f ResultHandlingSimMsgFactory[T]) DeliveryResultHandler() SimDeliveryResultHandler
type SimAccount ¶
SimAccount is an extended simtypes.Account
func SafeRunFactoryMethod ¶
func SafeRunFactoryMethod( ctx context.Context, data *ChainDataSource, reporter SimulationReporter, f FactoryMethod, ) (signer []SimAccount, msg sdk.Msg)
SafeRunFactoryMethod runs the factory method on a separate goroutine to abort early when the context is canceled via reporter skip
func (*SimAccount) LiquidBalance ¶
func (a *SimAccount) LiquidBalance() *SimsAccountBalance
LiquidBalance spendable balance. This excludes not spendable amounts like staked or vested amounts.
type SimAccountFilter ¶
type SimAccountFilter interface { // Accept returns true to accept the account or false to reject Accept(a SimAccount) bool }
func ExcludeAccounts ¶
func ExcludeAccounts(others ...SimAccount) SimAccountFilter
func ExcludeAddresses ¶
func ExcludeAddresses(addrs ...string) SimAccountFilter
func UniqueAccounts ¶
func UniqueAccounts() SimAccountFilter
UniqueAccounts returns a stateful filter that rejects duplicate accounts. It uses a map to keep track of accounts that have been processed. If an account exists in the map, the filter function returns false to reject a duplicate, else it adds the account to the map and returns true.
Example usage:
uniqueAccountsFilter := simsx.UniqueAccounts() for { from := testData.AnyAccount(reporter, uniqueAccountsFilter) //... rest of the loop }
func WithDenomBalance ¶
func WithDenomBalance(denom string) SimAccountFilter
func WithLiquidBalanceGTE ¶
func WithLiquidBalanceGTE(amount ...sdk.Coin) SimAccountFilter
func WithSpendableBalance ¶
func WithSpendableBalance() SimAccountFilter
WithSpendableBalance Filters for liquid token but send may not be enabled for all or any
type SimAccountFilterFn ¶
type SimAccountFilterFn func(a SimAccount) bool
func (SimAccountFilterFn) Accept ¶
func (s SimAccountFilterFn) Accept(a SimAccount) bool
type SimDeliveryResultHandler ¶
SimDeliveryResultHandler processes the delivery response error. Some sims are supposed to fail and expect an error. An unhandled error returned indicates a failure
type SimMsgFactoryFn ¶
type SimMsgFactoryFn[T sdk.Msg] func(ctx context.Context, testData *ChainDataSource, reporter SimulationReporter) (signer []SimAccount, msg T)
SimMsgFactoryFn is the default factory for most cases. It does not create future operations but ensures successful message delivery.
func (SimMsgFactoryFn[T]) Cast ¶
func (f SimMsgFactoryFn[T]) Cast(msg sdk.Msg) T
func (SimMsgFactoryFn[T]) Create ¶
func (f SimMsgFactoryFn[T]) Create() FactoryMethod
func (SimMsgFactoryFn[T]) DeliveryResultHandler ¶
func (f SimMsgFactoryFn[T]) DeliveryResultHandler() SimDeliveryResultHandler
func (SimMsgFactoryFn[T]) MsgType ¶
func (f SimMsgFactoryFn[T]) MsgType() sdk.Msg
MsgType returns an empty instance of type T, which implements `sdk.Msg`.
type SimMsgFactoryX ¶
type SimMsgFactoryX interface { // MsgType returns an empty instance of the concrete message type that the factory provides. // This instance is primarily used for deduplication and reporting purposes. // The result must not be nil MsgType() sdk.Msg // Create returns a FactoryMethod implementation which is responsible for constructing new instances of the message // on each invocation. Create() FactoryMethod // DeliveryResultHandler returns a SimDeliveryResultHandler instance which processes the delivery // response error object. While most simulation factories anticipate successful message delivery, // certain factories employ this handler to validate execution errors, thereby covering negative // test scenarios. DeliveryResultHandler() SimDeliveryResultHandler }
SimMsgFactoryX is an interface for creating and handling fuzz test-like simulation messages in the system.
type SimStateFactory ¶
type SimStateFactory struct { Codec codec.Codec AppStateFn simtypes.AppStateFn BlockedAddr map[string]bool AccountSource AccountSourceX BalanceSource BalanceSource }
SimStateFactory is a factory type that provides a convenient way to create a simulation state for testing. It contains the following fields: - Codec: a codec used for serializing other objects - AppStateFn: a function that returns the app state JSON bytes and the genesis accounts - BlockedAddr: a map of blocked addresses - AccountSource: an interface for retrieving accounts - BalanceSource: an interface for retrieving balance-related information
type SimsAccountBalance ¶
SimsAccountBalance is a helper type for common access methods to balance amounts.
func NewSimsAccountBalance ¶
func NewSimsAccountBalance(o *SimAccount, r *rand.Rand, coins sdk.Coins) *SimsAccountBalance
NewSimsAccountBalance constructor
func (*SimsAccountBalance) BlockAmount ¶
func (b *SimsAccountBalance) BlockAmount(amount sdk.Coin) bool
BlockAmount returns true when balance is > requested amount and subtracts the amount from the liquid balance
func (*SimsAccountBalance) RandFees ¶
func (b *SimsAccountBalance) RandFees() sdk.Coins
func (*SimsAccountBalance) RandSubsetCoin ¶
func (b *SimsAccountBalance) RandSubsetCoin(reporter SimulationReporter, denom string, filters ...CoinsFilter) sdk.Coin
RandSubsetCoin return random amount from the current balance. When the coins are empty, skip is called on the reporter. The amount is removed from the liquid balance.
func (*SimsAccountBalance) RandSubsetCoins ¶
func (b *SimsAccountBalance) RandSubsetCoins(reporter SimulationReporter, filters ...CoinsFilter) sdk.Coins
RandSubsetCoins return random amounts from the current balance. When the coins are empty, skip is called on the reporter. The amounts are removed from the liquid balance.
type SimulationApp ¶
type SimulationApp interface { runtime.AppSimI SetNotSigverifyTx() GetBaseApp() *baseapp.BaseApp TxConfig() client.TxConfig Close() error }
SimulationApp abstract app that is used by sims
type SimulationReporter ¶
type SimulationReporter interface { WithScope(msg sdk.Msg, optionalSkipHook ...SkipHook) SimulationReporter Skip(comment string) Skipf(comment string, args ...any) // IsSkipped returns true when skipped or completed IsSkipped() bool ToLegacyOperationMsg() simtypes.OperationMsg // Fail complete with failure Fail(err error, comments ...string) // Success complete with success Success(msg sdk.Msg, comments ...string) // Close returns error captured on fail Close() error Comment() string }
SimulationReporter is an interface for reporting the result of a simulation run.
type SkipHook ¶
type SkipHook interface {
Skip(args ...any)
}
SkipHook is an interface that represents a callback hook used triggered on skip operations. It provides a single method `Skip` that accepts variadic arguments. This interface is implemented by Go stdlib testing.T and testing.B
type SkipHookFn ¶
type SkipHookFn func(args ...any)
func (SkipHookFn) Skip ¶
func (s SkipHookFn) Skip(args ...any)
type TestInstance ¶
type TestInstance[T SimulationApp] struct { App T DB corestore.KVStoreWithBatch 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]( tb testing.TB, tCfg simtypes.Config, appFactory func(logger log.Logger, db corestore.KVStoreWithBatch, 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.
type UniqueTypeRegistry ¶
type UniqueTypeRegistry map[string]WeightedFactory
func NewUniqueTypeRegistry ¶
func NewUniqueTypeRegistry() UniqueTypeRegistry
func (UniqueTypeRegistry) Add ¶
func (s UniqueTypeRegistry) Add(weight uint32, f SimMsgFactoryX)
func (UniqueTypeRegistry) Iterator ¶
func (s UniqueTypeRegistry) Iterator() WeightedProposalMsgIter
Iterator returns an iterator function for a Go for loop sorted by weight desc.
type WeightSource ¶
WeightSource interface for retrieving weights based on a name and a default value.
func ParamWeightSource ¶
func ParamWeightSource(p simtypes.AppParams) WeightSource
ParamWeightSource is an adapter to the simtypes.AppParams object. This function returns a WeightSource implementation that retrieves weights based on a name and a default value. The implementation uses the provided AppParams to get or generate the weight value. If the weight value exists in the AppParams, it is decoded and returned. Otherwise, the provided ParamSimulator is used to generate a random value or default value.
The WeightSource implementation is a WeightSourceFn function adapter that implements the WeightSource interface. It takes in a name string and a defaultValue uint32 as parameters and returns the weight value as a uint32.
Example Usage:
appParams := simtypes.AppParams{} // add parameters to appParams weightSource := ParamWeightSource(appParams) weightSource.Get("some_weight", 100)
type WeightSourceFn ¶
WeightSourceFn function adapter that implements WeightSource. Example:
weightSource := WeightSourceFn(func(name string, defaultValue uint32) uint32 { // implementation code... })
type WeightedFactory ¶
type WeightedFactory struct { Weight uint32 Factory SimMsgFactoryX }
WeightedFactory is a Weight Factory tuple
func (WeightedFactory) Compare ¶
func (f WeightedFactory) Compare(b WeightedFactory) int
Compare compares the WeightedFactory f with another WeightedFactory b. The comparison is done by comparing the weight of f with the weight of b. If the weight of f is greater than the weight of b, it returns 1. If the weight of f is less than the weight of b, it returns -1. If the weights are equal, it compares the TypeURL of the factories using strings.Compare. Returns an integer indicating the comparison result.
type WeightedFactoryMethod ¶
type WeightedFactoryMethod struct { Weight uint32 Factory FactoryMethod }
WeightedFactoryMethod is a data tuple used for registering legacy proposal operations
type WeightedFactoryMethods ¶
type WeightedFactoryMethods []WeightedFactoryMethod
func NewWeightedFactoryMethods ¶
func NewWeightedFactoryMethods() WeightedFactoryMethods
NewWeightedFactoryMethods constructor
func (*WeightedFactoryMethods) Add ¶
func (s *WeightedFactoryMethods) Add(weight uint32, f FactoryMethod)
Add adds a new WeightedFactoryMethod to the WeightedFactoryMethods slice. If weight is zero or f is nil, it returns without making any changes.
func (WeightedFactoryMethods) Iterator ¶
func (s WeightedFactoryMethods) Iterator() WeightedProposalMsgIter
Iterator returns an iterator function for a Go for loop sorted by weight desc.
type WeightedOperationRegistryAdapter ¶
type WeightedOperationRegistryAdapter struct { AbstractRegistry[simtypes.WeightedOperation] }
WeightedOperationRegistryAdapter is an implementation of the Registry interface that provides adapters to use the new message factories with the legacy simulation system
func NewSimsMsgRegistryAdapter ¶
func NewSimsMsgRegistryAdapter( reporter SimulationReporter, ak AccountSourceX, bk BalanceSource, txConfig client.TxConfig, logger log.Logger, ) *WeightedOperationRegistryAdapter
NewSimsMsgRegistryAdapter creates a new instance of SimsRegistryAdapter for WeightedOperation types.
func (*WeightedOperationRegistryAdapter) Add ¶
func (l *WeightedOperationRegistryAdapter) Add(weight uint32, fx SimMsgFactoryX)
Add adds a new weighted operation to the collection
type WeightedProposalMsgIter ¶
type WeightedProposalMsgIter = iter.Seq2[uint32, FactoryMethod]
WeightedProposalMsgIter iterator for weighted gov proposal payload messages
func AppendIterators ¶
func AppendIterators(iterators ...WeightedProposalMsgIter) WeightedProposalMsgIter
AppendIterators takes multiple WeightedProposalMsgIter and returns a single iterator that sequentially yields items after each one.
type XRand ¶
func (*XRand) IntInRange ¶
func (*XRand) PositiveSDKIntInRange ¶
func (*XRand) Uint32InRange ¶
Uint32InRange returns a pseudo-random uint32 number in the range [min, max]. It panics when min >= max
func (*XRand) Uint64InRange ¶
Uint64InRange returns a pseudo-random uint64 number in the range [min, max]. It panics when min >= max