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: 53 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StakePerAccount           = "stake_per_account"
	InitiallyBondedValidators = "initially_bonded_validators"
)

Simulation parameter constants

View Source
const DefaultGenTxGas = 10000000

Variables

View Source
var DefaultConsensusParams = &cmtproto.ConsensusParams{
	Version: &cmtproto.VersionParams{
		App: 1,
	},
	Block: &cmtproto.BlockParams{
		MaxBytes: 200000,
		MaxGas:   100_000_000,
	},
	Evidence: &cmtproto.EvidenceParams{
		MaxAgeNumBlocks: 302400,
		MaxAgeDuration:  504 * time.Hour,
		MaxBytes:        10000,
	},
	Validator: &cmtproto.ValidatorParams{
		PubKeyTypes: []string{
			cmttypes.ABCIPubKeyTypeEd25519,
			cmttypes.ABCIPubKeyTypeSecp256k1,
		},
	},
}

DefaultConsensusParams defines the default CometBFT consensus params used in SimApp testing.

Functions

func AddTestAddrs

func AddTestAddrs(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress

AddTestAddrs constructs and returns accNum amount of accounts with an initial balance of accAmt in random order

func AddTestAddrsFromPubKeys

func AddTestAddrsFromPubKeys(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx sdk.Context, pubKeys []cryptotypes.PubKey, accAmt math.Int)

AddTestAddrsFromPubKeys adds the addresses into the SimApp providing only the public keys.

func AddTestAddrsIncremental

func AddTestAddrsIncremental(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress

AddTestAddrsIncremental constructs and returns accNum amount of accounts with an initial balance of accAmt in random order

func AppStateFn

func AppStateFn(
	cdc codec.JSONCodec,
	addresCodec, validatorCodec address.Codec,
	simManager *module.SimulationManager,
	genesisState map[string]json.RawMessage,
) simtypes.AppStateFn

AppStateFn returns the initial application state using a genesis or the simulation parameters. It calls appStateFnWithExtendedCb with nil rawStateCb.

func AppStateFromGenesisFileFn

func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONCodec, genesisFile string) (genutiltypes.AppGenesis, []simtypes.Account, error)

AppStateFromGenesisFileFn util function to generate the genesis AppState from a genesis.json file.

func AppStateRandomizedFn

func AppStateRandomizedFn(
	simManager *module.SimulationManager,
	r *rand.Rand,
	cdc codec.JSONCodec,
	accs []simtypes.Account,
	genesisTimestamp time.Time,
	appParams simtypes.AppParams,
	genesisState map[string]json.RawMessage,
	addressCodec, validatorCodec address.Codec,
) (json.RawMessage, []simtypes.Account)

AppStateRandomizedFn creates calls each module's GenesisState generator function and creates the simulation params

func CheckExportSimulation

func CheckExportSimulation(app runtime.AppSimI, config simtypes.Config, params simtypes.Params) error

CheckExportSimulation exports the app state and simulation parameters to JSON if the export paths are defined.

func ConvertAddrsToValAddrs

func ConvertAddrsToValAddrs(addrs []sdk.AccAddress) []sdk.ValAddress

ConvertAddrsToValAddrs converts the provided addresses to ValAddress.

func CreateIncrementalAccounts

func CreateIncrementalAccounts(accNum int) []sdk.AccAddress

CreateIncrementalAccounts is a strategy used by addTestAddrs() in order to generated addresses in ascending order.

func CreateRandomAccounts

func CreateRandomAccounts(accNum int) []sdk.AccAddress

CreateRandomAccounts is a strategy used by addTestAddrs() in order to generated addresses in random order.

func CreateRandomValidatorSet

func CreateRandomValidatorSet() (*cmttypes.ValidatorSet, error)

CreateRandomValidatorSet creates a validator set with one random validator

func CreateTestPubKeys

func CreateTestPubKeys(numPubKeys int) []cryptotypes.PubKey

CreateTestPubKeys returns a total of numPubKeys public keys in ascending order.

func DiffKVStores

func DiffKVStores(a, b storetypes.KVStore, prefixesToSkip [][]byte) (diffA, diffB []kv.Pair)

DiffKVStores compares two KVstores and returns all the key/value pairs that differ from one another. It also skips value comparison for a set of provided prefixes.

func GenSignedMockTx

func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey) (sdk.Tx, error)

GenSignedMockTx generates a signed mock transaction.

func GenesisStateWithValSet

func GenesisStateWithValSet(
	codec codec.Codec,
	genesisState map[string]json.RawMessage,
	valSet *cmttypes.ValidatorSet,
	genAccs []authtypes.GenesisAccount,
	balances ...banktypes.Balance,
) (map[string]json.RawMessage, error)

GenesisStateWithValSet returns a new genesis state with the validator set

func GetSimulationLog

func GetSimulationLog(storeName string, sdr simtypes.StoreDecoderRegistry, kvAs, kvBs []kv.Pair) (log string)

GetSimulationLog unmarshals the KVPair's Value to the corresponding type based on the each's module store key and the prefix bytes of the KVPair's key.

func NewAppOptionsWithFlagHome

func NewAppOptionsWithFlagHome(homePath string) servertypes.AppOptions

func NewPubKeyFromHex

func NewPubKeyFromHex(pk string) (res cryptotypes.PubKey)

NewPubKeyFromHex returns a PubKey from a hex string.

func NextBlock

func NextBlock(app *runtime.App, ctx sdk.Context, jumpTime time.Duration) (sdk.Context, error)

NextBlock starts a new block.

func PrintStats

func PrintStats(db dbm.DB)

PrintStats prints the corresponding statistics from the app DB.

func Setup

func Setup(appConfig depinject.Config, extraOutputs ...interface{}) (*runtime.App, error)

Setup initializes a new runtime.App and can inject values into extraOutputs. It uses SetupWithConfiguration under the hood.

func SetupAtGenesis

func SetupAtGenesis(appConfig depinject.Config, extraOutputs ...interface{}) (*runtime.App, error)

SetupAtGenesis initializes a new runtime.App at genesis and can inject values into extraOutputs. It uses SetupWithConfiguration under the hood.

func SetupSimulation

func SetupSimulation(config simtypes.Config, dirPrefix, dbName string, verbose, skip bool) (dbm.DB, string, log.Logger, bool, error)

SetupSimulation creates the config, db (levelDB), temporary directory and logger for the simulation tests. If `skip` is false it skips the current test. `skip` should be set using the `FlagEnabledValue` flag. Returns error on an invalid db instantiation or temp dir creation.

func SetupWithConfiguration

func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupConfig, extraOutputs ...interface{}) (*runtime.App, error)

SetupWithConfiguration initializes a new runtime.App. A Nop logger is set in runtime.App. appConfig defines the application configuration (f.e. app_config.go). extraOutputs defines the extra outputs to be assigned by the dependency injector (depinject).

func SignCheckDeliver

func SignCheckDeliver(
	t *testing.T, txCfg client.TxConfig, app *baseapp.BaseApp, header header.Info, msgs []sdk.Msg,
	chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey,
) (sdk.GasInfo, *sdk.Result, error)

SignCheckDeliver checks a generated signed transaction and simulates a block commitment with the given transaction. A test assertion is made using the parameter 'expPass' against the result. A corresponding result is returned.

func SimulationOperations

func SimulationOperations(app runtime.AppSimI, cdc codec.Codec, config simtypes.Config, txConfig client.TxConfig) []simtypes.WeightedOperation

SimulationOperations retrieves the simulation params from the provided file path and returns all the modules weighted operations

func TestAddr

func TestAddr(addr, bech string) (sdk.AccAddress, error)

Types

type AppOptionsMap

type AppOptionsMap map[string]interface{}

AppOptionsMap is a stub implementing AppOptions which can get data from a map

func (AppOptionsMap) Get

func (m AppOptionsMap) Get(key string) interface{}

type BankKeeper

type BankKeeper interface {
	SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
	MintCoins(ctx context.Context, moduleName string, amt sdk.Coins) error
}

type EmptyAppOptions

type EmptyAppOptions struct{}

EmptyAppOptions is a stub implementing AppOptions

func (EmptyAppOptions) Get

func (ao EmptyAppOptions) Get(o string) interface{}

Get implements AppOptions

type GenerateAccountStrategy

type GenerateAccountStrategy func(int) []sdk.AccAddress

type GenesisAccount

type GenesisAccount struct {
	authtypes.GenesisAccount
	Coins sdk.Coins
}

type StakingKeeper

type StakingKeeper interface {
	BondDenom(ctx context.Context) (string, error)
}

StakingKeeper is a subset of the staking keeper's public interface that provides the staking bond denom. It is used in arguments in this package's functions so that a mock staking keeper can be passed instead of the real one.

type StartupConfig

type StartupConfig struct {
	ValidatorSet    func() (*cmttypes.ValidatorSet, error)
	BaseAppOption   runtime.BaseAppOption
	AtGenesis       bool
	GenesisAccounts []GenesisAccount
	DB              dbm.DB
}

StartupConfig defines the startup configuration new a test application.

ValidatorSet defines a custom validator set to be validating the app. BaseAppOption defines the additional operations that must be run on baseapp before app start. AtGenesis defines if the app started should already have produced block or not.

func DefaultStartUpConfig

func DefaultStartUpConfig() StartupConfig

Jump to

Keyboard shortcuts

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