sims

package
v0.52.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 54 Imported by: 821

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 AccountsFromAppState

func AccountsFromAppState(cdc codec.JSONCodec, appStateJSON json.RawMessage) ([]simtypes.Account, error)

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,
	addressCodec, validatorCodec address.Codec,
	modules []module.AppModuleSimulation,
	genesisState map[string]json.RawMessage,
) simtypes.AppStateFn

AppStateFn returns the initial application state using a genesis or the simulation parameters.

func AppStateFromGenesisFileFn

func AppStateFromGenesisFileFn(_ 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(
	modules []module.AppModuleSimulation,
	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 added in v0.50.0

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 added in v0.47.10

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

NextBlock starts a new block.

func PrintStats

func PrintStats(db DBStatsInterface, logLine func(args ...any))

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

func (AppOptionsMap) GetString

func (m AppOptionsMap) GetString(key string) string

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 DBStatsInterface

type DBStatsInterface interface {
	Stats() map[string]string
}

DBStatsInterface defines the interface for the app DB statistics.

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              corestore.KVStoreWithBatch
}

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