simapp

package
v0.0.0-...-038b244 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 130 Imported by: 0

README

Callbacks Testing SimApp

This testing directory is a duplicate of the ibc-go testing directory. It is only here as a way of creating a separate SimApp binary to avoid introducing a dependency on the callbacks module from within ibc-go.

The simapp can be built with the workflow found here.

Documentation

Index

Constants

View Source
const (
	// OogPanicContract is a contract address that will panic out of gas
	OogPanicContract = "panics out of gas"
	// OogErrorContract is a contract address that will error out of gas
	OogErrorContract = "errors out of gas"
	// PanicContract is a contract address that will panic
	PanicContract = "panics"
	// ErrorContract is a contract address that will return an error
	ErrorContract = "errors"
	// SuccessContract is a contract address that will return nil
	SuccessContract = "success"
)

IBC application testing ports

Variables

View Source
var (
	// DefaultNodeHome default home directories for the application daemon
	DefaultNodeHome string
)
View Source
var StatefulCounterKey = "stateful-callback-counter"

Functions

func BlockedAddresses

func BlockedAddresses() map[string]bool

BlockedAddresses returns all the app's blocked account addresses.

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.

Types

type ContractKeeper

type ContractKeeper struct {
	Counters map[callbacktypes.CallbackType]int

	IBCSendPacketCallbackFn func(
		cachedCtx sdk.Context,
		sourcePort string,
		sourceChannel string,
		timeoutHeight clienttypes.Height,
		timeoutTimestamp uint64,
		packetData []byte,
		contractAddress,
		packetSenderAddress string,
	) error

	IBCOnAcknowledgementPacketCallbackFn func(
		cachedCtx sdk.Context,
		packet channeltypes.Packet,
		acknowledgement []byte,
		relayer sdk.AccAddress,
		contractAddress,
		packetSenderAddress string,
	) error

	IBCOnTimeoutPacketCallbackFn func(
		cachedCtx sdk.Context,
		packet channeltypes.Packet,
		relayer sdk.AccAddress,
		contractAddress,
		packetSenderAddress string,
	) error

	IBCReceivePacketCallbackFn func(
		cachedCtx sdk.Context,
		packet ibcexported.PacketI,
		ack ibcexported.Acknowledgement,
		contractAddress string,
	) error
	// contains filtered or unexported fields
}

This is a mock contract keeper used for testing. It is not wired up to any modules. It implements the interface functions expected by the ibccallbacks middleware so that it can be tested with simapp. The keeper is responsible for tracking two metrics:

  • number of callbacks called per callback type
  • stateful entry attempts

The counter for callbacks allows us to ensure the correct callbacks were routed to and the stateful entries allows us to track state reversals or reverted state upon contract execution failure or out of gas errors.

func NewContractKeeper

func NewContractKeeper(key storetypes.StoreKey) *ContractKeeper

NewKeeper creates a new mock ContractKeeper.

func (ContractKeeper) GetStateEntryCounter

func (k ContractKeeper) GetStateEntryCounter(ctx sdk.Context) uint8

GetStateEntryCounter returns the state entry counter stored in state.

func (ContractKeeper) IBCOnAcknowledgementPacketCallback

func (k ContractKeeper) IBCOnAcknowledgementPacketCallback(
	ctx sdk.Context,
	packet channeltypes.Packet,
	acknowledgement []byte,
	relayer sdk.AccAddress,
	contractAddress,
	packetSenderAddress string,
) error

IBCOnAcknowledgementPacketCallback increments the stateful entry counter and the acknowledgement_packet callback counter. This function:

  • returns MockApplicationCallbackError and consumes half the remaining gas if the contract address is ErrorContract
  • Oog panics and consumes all the remaining gas + 1 if the contract address is OogPanicContract
  • returns MockApplicationCallbackError and consumes all the remaining gas + 1 if the contract address is OogErrorContract
  • Panics and consumes half the remaining gas if the contract address is PanicContract
  • returns nil and consumes half the remaining gas if the contract address is SuccessContract or any other value

func (ContractKeeper) IBCOnTimeoutPacketCallback

func (k ContractKeeper) IBCOnTimeoutPacketCallback(
	ctx sdk.Context,
	packet channeltypes.Packet,
	relayer sdk.AccAddress,
	contractAddress,
	packetSenderAddress string,
) error

IBCOnTimeoutPacketCallback increments the stateful entry counter and the timeout_packet callback counter. This function:

  • returns MockApplicationCallbackError and consumes half the remaining gas if the contract address is ErrorContract
  • Oog panics and consumes all the remaining gas + 1 if the contract address is OogPanicContract
  • returns MockApplicationCallbackError and consumes all the remaining gas + 1 if the contract address is OogErrorContract
  • Panics and consumes half the remaining gas if the contract address is PanicContract
  • returns nil and consumes half the remaining gas if the contract address is SuccessContract or any other value

func (ContractKeeper) IBCReceivePacketCallback

func (k ContractKeeper) IBCReceivePacketCallback(
	ctx sdk.Context,
	packet ibcexported.PacketI,
	ack ibcexported.Acknowledgement,
	contractAddress string,
) error

IBCReceivePacketCallback increments the stateful entry counter and the receive_packet callback counter. This function:

  • returns MockApplicationCallbackError and consumes half the remaining gas if the contract address is ErrorContract
  • Oog panics and consumes all the remaining gas + 1 if the contract address is OogPanicContract
  • returns MockApplicationCallbackError and consumes all the remaining gas + 1 if the contract address is OogErrorContract
  • Panics and consumes half the remaining gas if the contract address is PanicContract
  • returns nil and consumes half the remaining gas if the contract address is SuccessContract or any other value

func (ContractKeeper) IBCSendPacketCallback

func (k ContractKeeper) IBCSendPacketCallback(
	ctx sdk.Context,
	sourcePort string,
	sourceChannel string,
	timeoutHeight clienttypes.Height,
	timeoutTimestamp uint64,
	packetData []byte,
	contractAddress,
	packetSenderAddress string,
) error

IBCPacketSendCallback increments the stateful entry counter and the send_packet callback counter. This function:

  • returns MockApplicationCallbackError and consumes half the remaining gas if the contract address is ErrorContract
  • Oog panics and consumes all the remaining gas + 1 if the contract address is OogPanicContract
  • returns MockApplicationCallbackError and consumes all the remaining gas + 1 if the contract address is OogErrorContract
  • Panics and consumes half the remaining gas if the contract address is PanicContract
  • returns nil and consumes half the remaining gas if the contract address is SuccessContract or any other value

func (ContractKeeper) IncrementStateEntryCounter

func (k ContractKeeper) IncrementStateEntryCounter(ctx sdk.Context)

IncrementStatefulCounter increments the stateful callback counter in state.

func (ContractKeeper) ProcessMockCallback

func (k ContractKeeper) ProcessMockCallback(
	ctx sdk.Context,
	callbackType callbacktypes.CallbackType,
	contractAddress string,
) (err error)

ProcessMockCallback processes a mock callback. It increments the stateful entry counter and the callback counter. This function:

  • returns MockApplicationCallbackError and consumes half the remaining gas if the contract address is ErrorContract
  • Oog panics and consumes all the remaining gas + 1 if the contract address is OogPanicContract
  • returns MockApplicationCallbackError and consumes all the remaining gas + 1 if the contract address is OogErrorContract
  • Panics and consumes half the remaining gas if the contract address is PanicContract
  • returns nil and consumes half the remaining gas if the contract address is SuccessContract or any other value

func (ContractKeeper) SetStateEntryCounter

func (k ContractKeeper) SetStateEntryCounter(ctx sdk.Context, count uint8)

SetStateEntryCounter sets state entry counter. The number of stateful entries is tracked as a uint8. This function is used to test state reversals.

type EncodingConfig

type EncodingConfig struct {
	InterfaceRegistry types.InterfaceRegistry
	Codec             codec.Codec
	TxConfig          client.TxConfig
	Amino             *codec.LegacyAmino
}

EncodingConfig specifies the concrete encoding types to use for a given app. This is provided for compatibility between protobuf and amino implementations.

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 ModuleBasicManager which populates json from each BasicModule object provided to it during init.

type HandlerOptions

type HandlerOptions struct {
	ante.HandlerOptions
	CircuitKeeper circuitante.CircuitBreaker
	IBCKeeper     *keeper.Keeper
}

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

type SimApp

type SimApp struct {
	*baseapp.BaseApp

	// keepers
	AccountKeeper         authkeeper.AccountKeeper
	BankKeeper            bankkeeper.Keeper
	CapabilityKeeper      *capabilitykeeper.Keeper
	StakingKeeper         *stakingkeeper.Keeper
	SlashingKeeper        slashingkeeper.Keeper
	MintKeeper            mintkeeper.Keeper
	DistrKeeper           distrkeeper.Keeper
	GovKeeper             govkeeper.Keeper
	CrisisKeeper          *crisiskeeper.Keeper
	UpgradeKeeper         *upgradekeeper.Keeper
	ParamsKeeper          paramskeeper.Keeper
	AuthzKeeper           authzkeeper.Keeper
	IBCKeeper             *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
	IBCFeeKeeper          ibcfeekeeper.Keeper
	ICAControllerKeeper   icacontrollerkeeper.Keeper
	ICAHostKeeper         icahostkeeper.Keeper
	EvidenceKeeper        evidencekeeper.Keeper
	TransferKeeper        ibctransferkeeper.Keeper
	FeeGrantKeeper        feegrantkeeper.Keeper
	GroupKeeper           groupkeeper.Keeper
	ConsensusParamsKeeper consensusparamkeeper.Keeper
	CircuitKeeper         circuitkeeper.Keeper

	// make scoped keepers public for test purposes
	ScopedIBCKeeper           capabilitykeeper.ScopedKeeper
	ScopedTransferKeeper      capabilitykeeper.ScopedKeeper
	ScopedFeeMockKeeper       capabilitykeeper.ScopedKeeper
	ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
	ScopedICAHostKeeper       capabilitykeeper.ScopedKeeper
	ScopedIBCMockKeeper       capabilitykeeper.ScopedKeeper
	ScopedICAMockKeeper       capabilitykeeper.ScopedKeeper

	// mock contract keeper used for testing
	MockContractKeeper *ContractKeeper

	// make IBC modules public for test purposes
	// these modules are never directly routed to by the IBC Router
	ICAAuthModule ibcmock.IBCModule
	FeeMockModule ibcmock.IBCModule

	// the module manager
	ModuleManager      *module.Manager
	BasicModuleManager module.BasicManager
	// 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 dbm.DB,
	traceStore io.Writer,
	loadLatest bool,
	appOpts servertypes.AppOptions,
	baseAppOptions ...func(*baseapp.BaseApp),
) *SimApp

NewSimApp returns a reference to an initialized 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) AutoCliOpts

func (app *SimApp) AutoCliOpts() autocli.AppOptions

AutoCliOpts returns the autocli options for the app.

func (*SimApp) BeginBlocker

func (app *SimApp) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error)

BeginBlocker application updates every begin block

func (*SimApp) Configurator

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

Configurator returns the configurator for the app

func (*SimApp) DefaultGenesis

func (app *SimApp) DefaultGenesis() map[string]json.RawMessage

DefaultGenesis returns a default genesis from the registered AppModuleBasic's.

func (*SimApp) EndBlocker

func (app *SimApp) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error)

EndBlocker application updates every end block

func (*SimApp) ExportAppStateAndValidators

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

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

func (*SimApp) GetBaseApp

func (app *SimApp) GetBaseApp() *baseapp.BaseApp

GetBaseApp implements the TestingApp interface.

func (*SimApp) GetIBCKeeper

func (app *SimApp) GetIBCKeeper() *ibckeeper.Keeper

GetIBCKeeper implements the TestingApp interface.

func (*SimApp) GetKey

func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey

GetKey returns the KVStoreKey for the provided store key.

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

func (*SimApp) GetMemKey

func (app *SimApp) GetMemKey(storeKey string) *storetypes.MemoryStoreKey

GetMemKey returns the MemStoreKey for the provided mem key.

NOTE: This is solely used for testing purposes.

func (*SimApp) GetScopedIBCKeeper

func (app *SimApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper

GetScopedIBCKeeper implements the TestingApp interface.

func (*SimApp) GetStakingKeeper

func (app *SimApp) GetStakingKeeper() ibctestingtypes.StakingKeeper

GetStakingKeeper implements the TestingApp interface.

func (*SimApp) GetStoreKeys

func (app *SimApp) GetStoreKeys() []storetypes.StoreKey

GetStoreKeys returns all the stored store keys.

func (*SimApp) GetSubspace

func (app *SimApp) GetSubspace(moduleName string) paramstypes.Subspace

GetSubspace returns a param subspace for a given module name.

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

func (*SimApp) GetTxConfig

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

GetTxConfig implements the TestingApp interface.

func (*SimApp) InitChainer

func (app *SimApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error)

InitChainer application update at chain initialization

func (*SimApp) InterfaceRegistry

func (app *SimApp) InterfaceRegistry() types.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) LoadHeight

func (app *SimApp) LoadHeight(height int64) error

LoadHeight loads a particular height

func (*SimApp) Name

func (app *SimApp) Name() string

Name returns the name of the App

func (*SimApp) PreBlocker

func (app *SimApp) PreBlocker(ctx sdk.Context, _ *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error)

PreBlocker application updates every pre block

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) RegisterNodeService

func (app *SimApp) RegisterNodeService(clientCtx client.Context, cfg config.Config)

func (*SimApp) RegisterTendermintService

func (app *SimApp) RegisterTendermintService(clientCtx client.Context)

RegisterTendermintService implements the Application.RegisterTendermintService method.

func (*SimApp) RegisterTxService

func (app *SimApp) RegisterTxService(clientCtx client.Context)

RegisterTxService implements the Application.RegisterTxService method.

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

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