simapp

package module
v0.0.0-...-150f2d6 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 134 Imported by: 80

README


sidebar_position: 1

SimApp

SimApp is a CLI application built using the Cosmos SDK for testing and educational purposes.

Running testnets with simd

Except stated otherwise, all participants in the testnet must follow through with each step.

1. Download and Setup

Download the Cosmos SDK and unzip it. You can do this manually (via the GitHub UI) or with the git clone command.

git clone github.com/cosmos/cosmos-sdk.git

Next, run this command to build the simd binary in the build directory.

make build

Use the following command and skip all the next steps to configure your SimApp node:

make init-simapp

If you’ve run simd in the past, you may need to reset your database before starting up a new testnet. You can do that with this command:

# you need to provide the moniker and chain ID
$ ./simd init [moniker] --chain-id [chain-id]

The command should initialize a new working directory at the ~simapp location.

The moniker and chain-id can be anything but you need to use the same chain-id subsequently.

2. Create a New Key

Execute this command to create a new key.

 ./simd keys add [key_name]

The command will create a new key with your chosen name.

⚠️ Save the output somewhere safe; you’ll need the address later.

3. Add Genesis Account

Add a genesis account to your testnet blockchain.

$ ./simd genesis add-genesis-account [key_name] [amount]

Where key_name is the same key name as before, and the amount is something like 10000000000000000000000000stake.

4. Add the Genesis Transaction

This creates the genesis transaction for your testnet chain.

$ ./simd genesis gentx [key_name] [amount] --chain-id [chain-id]

The amount should be at least 1000000000stake. When you start your node, providing too much or too little may result in errors.

5. Create the Genesis File

A participant must create the genesis file genesis.json with every participant's transaction.

You can do this by gathering all the Genesis transactions under config/gentx and then executing this command.

$ ./simd genesis collect-gentxs

The command will create a new genesis.json file that includes data from all the validators. The command will create a new genesis.json file, including data from all the validators

Once you've received the super genesis file, overwrite your original genesis.json file with the new super genesis.json.

Modify your config/config.toml (in the simapp working directory) to include the other participants as persistent peers:

# Comma-separated list of nodes to keep persistent connections to
persistent_peers = "[validator_address]@[ip_address]:[port],[validator_address]@[ip_address]:[port]"

You can find validator_address by executing:

$ ./simd comet show-node-id

The output will be the hex-encoded validator_address. The default port is 26656.

6. Start the Nodes

Finally, execute this command to start your nodes.

$ ./simd start

Now you have a small testnet that you can use to try out changes to the Cosmos SDK or CometBFT!

⚠️ NOTE: Sometimes, creating the network through the collect-gents will fail, and validators will start in a funny state (and then panic).

If this happens, you can try to create and start the network first with a single validator and then add additional validators using a create-validator transaction.

Documentation

Index

Constants

View Source
const UpgradeName = "v052-to-v054"

UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade from v0.52.x to v0.54.x

NOTE: This upgrade defines a reference implementation of what an upgrade could look like when an application is migrating from Cosmos SDK version v0.52.x to v0.54.x.

Variables

View Source
var DefaultNodeHome string

DefaultNodeHome default home directories for the application daemon

Functions

func AddTestAddrsIncremental

func AddTestAddrsIncremental(app *SimApp, ctx sdk.Context, accNum int, accAmt sdkmath.Int) []sdk.AccAddress

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

func AppConfig

func AppConfig() depinject.Config

AppConfig returns the default app config.

func BlockedAddresses

func BlockedAddresses(_ address.Codec) (map[string]bool, error)

BlockedAddresses returns all the app's blocked account addresses. This function takes an address.Codec parameter to maintain compatibility with the signature of the same function in appV1.

func GetMaccPerms

func GetMaccPerms() map[string][]string

GetMaccPerms returns a copy of the module account permissions

NOTE: This is solely to be used for testing purposes.

func NewAnteHandler

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error)

NewAnteHandler returns an AnteHandler that checks and increments sequence numbers, checks signatures & account numbers, and deducts fees from the first signer.

func ProvideExampleMintFn

func ProvideExampleMintFn(bankKeeper MintBankKeeper) minttypes.MintFn

ProvideExampleMintFn returns the function used in x/mint's endblocker to mint new tokens. Note that this function can not have the mint keeper as a parameter because it would create a cyclic dependency.

Types

type GenesisState

type GenesisState map[string]json.RawMessage

GenesisState of the blockchain is represented here as a map of raw json messages key'd by a identifier string. The identifier is used to determine which module genesis information belongs to so it may be appropriately routed during init chain. Within this application default genesis information is retrieved from the module manager which populates json from each module object provided to it during init.

func GenesisStateWithSingleValidator

func GenesisStateWithSingleValidator(t *testing.T, app *SimApp) GenesisState

GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts that also act as delegators.

type HandlerOptions

type HandlerOptions struct {
	ante.HandlerOptions
	CircuitKeeper circuitante.CircuitBreaker
}

HandlerOptions are the options required for constructing a default SDK AnteHandler.

type MintBankKeeper

type MintBankKeeper interface {
	MintCoins(ctx context.Context, moduleName string, coins sdk.Coins) error
	SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error
}

type SetupOptions

type SetupOptions struct {
	Logger  log.Logger
	DB      corestore.KVStoreWithBatch
	AppOpts servertypes.AppOptions
}

SetupOptions defines arguments that are passed into `Simapp` constructor.

type SimApp

type SimApp struct {
	*runtime.App

	// required keepers during wiring
	// others keepers are all in the app
	AccountsKeeper        accounts.Keeper
	AuthKeeper            authkeeper.AccountKeeper
	BankKeeper            bankkeeper.Keeper
	StakingKeeper         *stakingkeeper.Keeper
	SlashingKeeper        slashingkeeper.Keeper
	DistrKeeper           distrkeeper.Keeper
	UpgradeKeeper         *upgradekeeper.Keeper
	FeeGrantKeeper        feegrantkeeper.Keeper
	ConsensusParamsKeeper consensuskeeper.Keeper
	CircuitBreakerKeeper  circuitkeeper.Keeper
	// contains filtered or unexported fields
}

SimApp extends an ABCI application, but with most of its parameters exported. They are exported for convenience in creating helper functions, as object capabilities aren't needed for testing.

func NewSimApp

func NewSimApp(
	logger log.Logger,
	db corestore.KVStoreWithBatch,
	traceStore io.Writer,
	loadLatest bool,
	appOpts servertypes.AppOptions,
	baseAppOptions ...func(*baseapp.BaseApp),
) *SimApp

NewSimApp returns a reference to an initialized SimApp.

func NewSimappWithCustomOptions

func NewSimappWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions) *SimApp

NewSimappWithCustomOptions initializes a new SimApp with custom options.

func Setup

func Setup(t *testing.T, isCheckTx bool) *SimApp

Setup initializes a new SimApp. A Nop logger is set in SimApp.

func SetupWithGenesisValSet

func SetupWithGenesisValSet(t *testing.T, valSet *cmttypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp

SetupWithGenesisValSet initializes a new SimApp with a validator set and genesis accounts that also act as delegators. For simplicity, each validator is bonded with a delegation of one consensus engine unit in the default token of the simapp from first genesis account. A Nop logger is set in SimApp.

func (*SimApp) AppCodec

func (app *SimApp) AppCodec() codec.Codec

AppCodec returns SimApp's app codec.

NOTE: This is solely to be used for testing purposes as it may be desirable for modules to register their own custom testing types.

func (*SimApp) ExportAppStateAndValidators

func (app *SimApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs, modulesToExport []string) (servertypes.ExportedApp, error)

ExportAppStateAndValidators exports the state of the application for a genesis file.

func (*SimApp) InterfaceRegistry

func (app *SimApp) InterfaceRegistry() codectypes.InterfaceRegistry

InterfaceRegistry returns SimApp's InterfaceRegistry.

func (*SimApp) LegacyAmino

func (app *SimApp) LegacyAmino() *codec.LegacyAmino

LegacyAmino returns SimApp's amino codec.

NOTE: This is solely to be used for testing purposes as it may be desirable for modules to register their own custom testing types.

func (*SimApp) RegisterAPIRoutes

func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig)

RegisterAPIRoutes registers all application module routes with the provided API server.

func (SimApp) RegisterUpgradeHandlers

func (app SimApp) RegisterUpgradeHandlers()

func (*SimApp) SimulationManager

func (app *SimApp) SimulationManager() *module.SimulationManager

SimulationManager implements the SimulationApp interface

func (*SimApp) TxConfig

func (app *SimApp) TxConfig() client.TxConfig

TxConfig returns SimApp's TxConfig

type SimGenesisAccount

type SimGenesisAccount struct {
	*authtypes.BaseAccount

	// vesting account fields
	OriginalVesting  sdk.Coins `json:"original_vesting" yaml:"original_vesting"`   // total vesting coins upon initialization
	DelegatedFree    sdk.Coins `json:"delegated_free" yaml:"delegated_free"`       // delegated vested coins at time of delegation
	DelegatedVesting sdk.Coins `json:"delegated_vesting" yaml:"delegated_vesting"` // delegated vesting coins at time of delegation
	StartTime        int64     `json:"start_time" yaml:"start_time"`               // vesting start time (UNIX Epoch time)
	EndTime          int64     `json:"end_time" yaml:"end_time"`                   // vesting end time (UNIX Epoch time)

	// module account fields
	ModuleName        string   `json:"module_name" yaml:"module_name"`               // name of the module account
	ModulePermissions []string `json:"module_permissions" yaml:"module_permissions"` // permissions of module account
}

SimGenesisAccount defines a type that implements the GenesisAccount interface to be used for simulation accounts in the genesis state.

func (SimGenesisAccount) Validate

func (sga SimGenesisAccount) Validate() error

Validate checks for errors on the vesting and module account parameters

type VoteExtension

type VoteExtension struct {
	Hash   []byte
	Height int64
	Data   []byte
}

VoteExtension defines the structure used to create a dummy vote extension.

type VoteExtensionHandler

type VoteExtensionHandler struct{}

VoteExtensionHandler defines a dummy vote extension handler for SimApp.

NOTE: This implementation is solely used for testing purposes. DO NOT use in a production application!

func NewVoteExtensionHandler

func NewVoteExtensionHandler() *VoteExtensionHandler

func (*VoteExtensionHandler) ExtendVote

func (h *VoteExtensionHandler) ExtendVote() sdk.ExtendVoteHandler

func (*VoteExtensionHandler) SetHandlers

func (h *VoteExtensionHandler) SetHandlers(bApp *baseapp.BaseApp)

func (*VoteExtensionHandler) VerifyVoteExtension

func (h *VoteExtensionHandler) VerifyVoteExtension() sdk.VerifyVoteExtensionHandler

Directories

Path Synopsis
Package params defines the simulation parameters in the simapp.
Package params defines the simulation parameters in the simapp.
cmd

Jump to

Keyboard shortcuts

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