package
0.53.0-beta.2
Repository: https://github.com/cosmos/cosmos-sdk.git
Documentation: pkg.go.dev

# README

Simsx

This package introduces some new helper types to simplify message construction for simulations (sims). The focus is on better dev UX for new message factories. Technically, they are adapters that build upon the existing sims framework.

Message factory

Simple functions as factories for dedicated sdk.Msgs. They have access to the context, reporter and test data environment. For example:

func MsgSendFactory() simsx.SimMsgFactoryFn[*types.MsgSend] {
    return func(ctx context.Context, testData *simsx.ChainDataSource, reporter simsx.SimulationReporter) ([]simsx.SimAccount, *types.MsgSend) {
        from := testData.AnyAccount(reporter, simsx.WithSpendableBalance())
        to := testData.AnyAccount(reporter, simsx.ExcludeAccounts(from))
        coins := from.LiquidBalance().RandSubsetCoins(reporter, simsx.WithSendEnabledCoins())
        return []simsx.SimAccount{from}, types.NewMsgSend(from.AddressBech32, to.AddressBech32, coins)
    }
}

Sims registry

A new helper to register message factories with a default weight value. They can be overwritten by a parameters file as before. The registry is passed to the AppModule type. For example:

func (am AppModule) WeightedOperationsX(weights simsx.WeightSource, reg simsx.Registry) {
    reg.Add(weights.Get("msg_send", 100), simulation.MsgSendFactory())
    reg.Add(weights.Get("msg_multisend", 10), simulation.MsgMultiSendFactory())
}

Reporter

The reporter is a flow control structure that can be used in message factories to skip execution at any point. The idea is similar to the testing.T Skip in Go stdlib. Internally, it converts skip, success and failure events to legacy sim messages. The reporter also provides some capability to print an execution summary. It is also used to interact with the test data environment to not have errors checked all the time. Message factories may want to abort early via

if reporter.IsSkipped() {
    return nil, nil
}

Test data environment

The test data environment provides simple access to accounts and other test data used in most message factories. It also encapsulates some app internals like bank keeper or address codec.

# Packages

No description provided by the author

# Functions

AppendIterators takes multiple WeightedProposalMsgIter and returns a single iterator that sequentially yields items after each one.
BlockTime read header block time from sdk context or sims context key if not present.
Collect applies the function f to each element in the source slice, returning a new slice containing the results.
DeliverSimsMsg delivers a simulation message by creating and signing a mock transaction, then delivering it to the application through the specified entrypoint.
No description provided by the author
No description provided by the author
FauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of an IAVLStore for faster simulation speed.
First returns the first element in the slice that matches the condition.
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.
NewChainDataSource constructor.
No description provided by the author
No description provided by the author
NewSimMsgFactoryWithDeliveryResultHandler constructor.
No description provided by the author
NewSimsAccountBalance constructor.
NewSimsMsgRegistryAdapter creates a new instance of SimsRegistryAdapter for WeightedOperation types.
NewSimulationAppInstance initializes and returns a TestInstance of a SimulationApp.
No description provided by the author
No description provided by the author
NewWeightedFactoryMethods constructor.
NewXRand constructor.
OneOf returns a random element from the given slice using the provided random number generator.
ParamWeightSource is an adapter to the simtypes.AppParams object.
Run is a helper function that runs a simulation test with the given parameters.
RunWithSeed is a helper function that runs a simulation test with the given parameters.
RunWithSeedAndRandAcc calls RunWithSeed with randAccFn.
RunWithSeeds is a helper function that runs a simulation test with the given parameters.
RunWithSeedsAndRandAcc calls RunWithSeeds with randAccFn.
SafeRunFactoryMethod runs the factory method on a separate goroutine to abort early when the context is canceled via reporter skip.
UniqueAccounts returns a stateful filter that rejects duplicate accounts.
No description provided by the author
No description provided by the author
No description provided by the author
WithSpendableBalance Filters for liquid token but send may not be enabled for all or any.
WriteToDebugLog is an adapter to io.Writer interface.

# Constants

No description provided by the author

# Structs

No description provided by the author
No description provided by the author
ChainDataSource provides common sims test data and helper methods.
No description provided by the author
LazyStateSimMsgFactory stateful message factory with weighted proposals and future operation registry initialized lazy before execution.
ResultHandlingSimMsgFactory message factory with a delivery error result handler configured.
SimAccount is an extended simtypes.Account.
SimsAccountBalance is a helper type for common access methods to balance amounts.
SimStateFactory is a factory type that provides a convenient way to create a simulation state for testing.
TestInstance is a generic type that represents an instance of a SimulationApp used for testing simulations.
WeightedFactory is a Weight Factory tuple.
WeightedFactoryMethod is a data tuple used for registering legacy proposal operations.
WeightedOperationRegistryAdapter is an implementation of the Registry interface that provides adapters to use the new message factories with the legacy simulation system.
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
BalanceSource is an interface for retrieving balance-related information for a given account.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SimMsgFactoryX is an interface for creating and handling fuzz test-like simulation messages in the system.
SimulationApp abstract app that is used by sims.
SimulationReporter is an interface for reporting the result of a simulation run.
SkipHook is an interface that represents a callback hook used triggered on skip operations.
WeightSource interface for retrieving weights based on a name and a default value.

# Type aliases

No description provided by the author
AppOptionsFn is an adapter to the single method AppOptions interface.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SimMsgFactoryFn is the default factory for most cases.
No description provided by the author
No description provided by the author
UnorderedRegistry represents a collection of WeightedFactory elements without guaranteed order.
No description provided by the author
WeightSourceFn function adapter that implements WeightSource.