e2eTesting

package
v1.0.0-rc06 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Overview

DONTCOVER

Index

Constants

This section is empty.

Variables

View Source
var (
	TestAccountAddr = sdk.AccAddress("test")
	ProposerPK      = simapp.CreateTestPubKeys(1)[0]
	OperatorPK      = secp256k1.GenPrivKey().PubKey()
)

Functions

func GenAccounts

func GenAccounts(num uint) ([]sdk.AccAddress, []cryptotypes.PrivKey)

GenAccounts generates a list of accounts and private keys for them.

func GenContractAddresses

func GenContractAddresses(num uint) []sdk.AccAddress

GenContractAddresses generates a list of contract addresses (codeID and instanceID are sequential).

func GetStringEventAttribute

func GetStringEventAttribute(events []abci.Event, eventType, attrKey string) string

GetStringEventAttribute returns TX response event attribute string value by type and attribute key.

func HumanizeCoins

func HumanizeCoins(decimals uint8, coins ...sdk.Coin) string

HumanizeCoins returns the sdk.Coins string representation with a number of decimals specified. 1123000stake -> 1.123stake with 6 decimals (3 numbers after the dot is hardcoded).

func HumanizeDecCoins

func HumanizeDecCoins(decimals uint8, coins ...sdk.DecCoin) string

HumanizeDecCoins returns the sdk.DecCoins string representation. 1000.123456789stake -> 1.123456stake with 3 decimals (6 numbers after the dot is hardcoded).

Types

type Account

type Account struct {
	Address sdk.AccAddress
	PrivKey cryptotypes.PrivKey
}

Account keeps a genesis account data.

type IBCEndpoint

type IBCEndpoint struct {
	// contains filtered or unexported fields
}

func (*IBCEndpoint) ChannelID

func (e *IBCEndpoint) ChannelID() string

ChannelID returns the endpoint IBC channel ID.

type IBCPath

type IBCPath struct {
	// contains filtered or unexported fields
}

IBCPath keeps IBC endpoints in sync and provides helper relayer functions. Heavily inspired by the Path from the ibc-go repo (https://github.com/cosmos/ibc-go/blob/main/testing/path.go). Reasons for no using the ibc-go's version are: simplify it, custom TestChain usage, hiding some public methods making it more usable without knowing how it works under the hood.

func NewIBCPath

func NewIBCPath(t *testing.T, srcChain, dstChain *TestChain, srcChPort, dstChPort, chVersion string, chOrder channelTypes.Order) *IBCPath

NewIBCPath builds a new IBCPath relayer creating a connection between two IBC endpoints.

func (*IBCPath) EndpointA

func (p *IBCPath) EndpointA() *IBCEndpoint

EndpointA returns the IBC endpoint A.

func (*IBCPath) EndpointB

func (p *IBCPath) EndpointB() *IBCEndpoint

EndpointB returns the IBC endpoint A.

func (*IBCPath) RelayPacket

func (p *IBCPath) RelayPacket(packet channelTypes.Packet, ack []byte)

RelayPacket attempts to relay a packet first on EndpointA and then on EndpointB. Packet must be committed.

func (*IBCPath) SkipBlocks

func (p *IBCPath) SkipBlocks(n int64)

SkipBlocks skips a number of blocks for both endpoints updating IBC clients.

func (*IBCPath) SkipTime

func (p *IBCPath) SkipTime(endpoint *IBCEndpoint, dur time.Duration)

SkipTime skips a period for both endpoints updating IBC clients.

func (*IBCPath) TimeoutPacket

func (p *IBCPath) TimeoutPacket(packet channelTypes.Packet, endpoint *IBCEndpoint)

TimeoutPacket timeouts a packet for the specified endpoint skipping block/time. Packet must be committed.

type SendMsgOption

type SendMsgOption func(opt *sendMsgOptions)

func WithGranter

func WithGranter(granter sdk.AccAddress) SendMsgOption

func WithMsgFees

func WithMsgFees(coins ...sdk.Coin) SendMsgOption

WithMsgFees option add fees to the transaction.

func WithSimulation

func WithSimulation() SendMsgOption

WithSimulation options estimates gas usage for the transaction.

func WithTxGasLimit

func WithTxGasLimit(limit uint64) SendMsgOption

WithTxGasLimit option overrides the default gas limit for the transaction.

func WithoutBlockChange

func WithoutBlockChange() SendMsgOption

WithoutBlockChange option disables EndBlocker and BeginBlocker after the transaction.

type TestChain

type TestChain struct {
	// contains filtered or unexported fields
}

TestChain keeps a test chain state and provides helper functions to simulate various operations. Heavily inspired by the TestChain from the ibc-go repo (https://github.com/cosmos/ibc-go/blob/main/testing/chain.go). Reasons for creating a custom TestChain rather than using the ibc-go's one are: to simplify it, add contract related helpers and fix errors caused by x/gastracker module (ibc-go version starts at block 2).

func NewTestChain

func NewTestChain(t *testing.T, chainIdx int, opts ...interface{}) *TestChain

NewTestChain creates a new TestChain with the default amount of genesis accounts and validators.

func (*TestChain) BeginBlock

func (chain *TestChain) BeginBlock() []abci.Event

BeginBlock begins a new block.

func (*TestChain) Client

func (chain *TestChain) Client() grpc.ClientConnInterface

func (*TestChain) EndBlock

func (chain *TestChain) EndBlock() []abci.Event

EndBlock finalizes the current block.

func (*TestChain) ExecuteGovProposal

func (chain *TestChain) ExecuteGovProposal(proposerAcc Account, expPass bool, proposals []sdk.Msg, title string, summary string, metadata string)

ExecuteGovProposal submits a new proposal and votes for it.

func (*TestChain) GetAccount

func (chain *TestChain) GetAccount(idx int) Account

GetAccount returns account address and private key with the given index.

func (*TestChain) GetApp

func (chain *TestChain) GetApp() *app.App

GetApp returns the application.

func (*TestChain) GetAppCodec

func (chain *TestChain) GetAppCodec() codec.Codec

GetAppCodec returns the application codec.

func (*TestChain) GetBalance

func (chain *TestChain) GetBalance(accAddr sdk.AccAddress) sdk.Coins

GetBalance returns the balance of the given account.

func (*TestChain) GetBlockHeight

func (chain *TestChain) GetBlockHeight() int64

GetBlockHeight returns the current block height.

func (*TestChain) GetBlockTime

func (chain *TestChain) GetBlockTime() time.Time

GetBlockTime returns the current block time.

func (*TestChain) GetChainID

func (chain *TestChain) GetChainID() string

GetChainID returns the chain ID.

func (*TestChain) GetClientState

func (chain *TestChain) GetClientState(clientID string) exported.ClientState

GetClientState returns an IBC client state for the provided clientID. Used to update an IBC TM client.

func (*TestChain) GetContext

func (chain *TestChain) GetContext() sdk.Context

GetContext returns a context for the current block.

func (*TestChain) GetContractInfo

func (chain *TestChain) GetContractInfo(contractAddr sdk.AccAddress) wasmdTypes.ContractInfo

GetContractInfo returns a contract info.

func (*TestChain) GetCurrentValSet

func (chain *TestChain) GetCurrentValSet() tmTypes.ValidatorSet

GetCurrentValSet returns a validator set for the current block height. Used to create an IBC TM client header.

func (*TestChain) GetDefaultTxFee

func (chain *TestChain) GetDefaultTxFee() sdk.Coins

GetDefaultTxFee returns the default transaction fee (that one is used if SendMsgs has no other options).

func (*TestChain) GetIBCPacketCommitment

func (chain *TestChain) GetIBCPacketCommitment(packet channelTypes.Packet) []byte

GetIBCPacketCommitment returns an IBC packet commitment hash (nil if not committed).

func (*TestChain) GetMerklePrefix

func (chain *TestChain) GetMerklePrefix() commitmentTypes.MerklePrefix

GetMerklePrefix returns a Merkle tree prefix. Used to send IBC ConnectionOpenInit msg.

func (*TestChain) GetModuleBalance

func (chain *TestChain) GetModuleBalance(moduleName string) sdk.Coins

GetModuleBalance returns the balance of the given module.

func (*TestChain) GetNextIBCPacketSequence

func (chain *TestChain) GetNextIBCPacketSequence(portID, channelID string) uint64

GetNextIBCPacketSequence returns the next IBC packet sequence.

func (*TestChain) GetProofAtHeight

func (chain *TestChain) GetProofAtHeight(key []byte, height uint64) ([]byte, clientTypes.Height)

GetProofAtHeight returns the proto encoded merkle proof by key for the specified height. Used to establish an IBC connection.

func (*TestChain) GetTMClientHeaderUpdate

func (chain *TestChain) GetTMClientHeaderUpdate(counterpartyChain *TestChain, clientID string, blockHeightTrusted clientTypes.Height) ibcTmTypes.Header

GetTMClientHeaderUpdate creates an IBC TM client header to update an existing client on the source chain.

func (*TestChain) GetTMClientLastHeader

func (chain *TestChain) GetTMClientLastHeader() ibcTmTypes.Header

GetTMClientLastHeader creates an IBC TM client header from the last committed block. Used to create a new client.

func (*TestChain) GetUnbondingTime

func (chain *TestChain) GetUnbondingTime() time.Duration

GetUnbondingTime returns x/staking validator unbonding time.

func (*TestChain) GetValSetAtHeight

func (chain *TestChain) GetValSetAtHeight(height int64) tmTypes.ValidatorSet

GetValSetAtHeight returns a validator set for the specified block height. Used to create an IBC TM client header.

func (*TestChain) GoToHeight

func (chain *TestChain) GoToHeight(height int64, skipTime time.Duration)

func (*TestChain) InstantiateContract

func (chain *TestChain) InstantiateContract(sender Account, codeID uint64, adminAddr, label string, funds sdk.Coins, msg json.Marshaler) (contractAddr sdk.AccAddress, instResp []byte)

InstantiateContract instantiates a contract and returns the contract address.

func (*TestChain) NextBlock

func (chain *TestChain) NextBlock(skipTime time.Duration) []abci.Event

NextBlock starts a new block with options time shift.

func (*TestChain) ParseSDKResultData

func (chain *TestChain) ParseSDKResultData(r *sdk.Result) sdk.TxMsgData

ParseSDKResultData converts TX result data into a slice of Msgs.

func (*TestChain) SendIBCPacket

func (chain *TestChain) SendIBCPacket(packet exported.PacketI)

SendIBCPacket send an IBC packet and commits chain state.

func (*TestChain) SendMsgs

func (chain *TestChain) SendMsgs(senderAcc Account, expPass bool, msgs []sdk.Msg, opts ...SendMsgOption) (sdk.GasInfo, *sdk.Result, []abci.Event, error)

SendMsgs sends a series of messages, checks for tx failure and starts a new block.

func (*TestChain) SendMsgsRaw

func (chain *TestChain) SendMsgsRaw(senderAcc Account, msgs []sdk.Msg, opts ...SendMsgOption) (sdk.GasInfo, *sdk.Result, error)

SendMsgsRaw sends a series of messages.

func (*TestChain) SmartQueryContract

func (chain *TestChain) SmartQueryContract(contractAddr sdk.AccAddress, expPass bool, msg json.Marshaler) ([]byte, error)

SmartQueryContract queries a contract and returns the result.

func (*TestChain) UploadContract

func (chain *TestChain) UploadContract(sender Account, wasmPath string, instantiatePerms wasmdTypes.AccessConfig) (codeID uint64)

UploadContract uploads a contract and returns the codeID.

type TestChainConfigOption

type TestChainConfigOption func(cfg *chainConfig)

func WithBondAmount

func WithBondAmount(amount string) TestChainConfigOption

WithBondAmount sets the amount of coins to bond for each validator.

func WithDefaultFeeAmount

func WithDefaultFeeAmount(amount string) TestChainConfigOption

WithDefaultFeeAmount sets the default fee amount which is used for sending Msgs with no fee specified.

func WithDummyTestAddress

func WithDummyTestAddress() TestChainConfigOption

func WithGenAccounts

func WithGenAccounts(num int) TestChainConfigOption

WithGenAccounts sets the number of genesis accounts

func WithGenDefaultCoinBalance

func WithGenDefaultCoinBalance(amount string) TestChainConfigOption

WithGenDefaultCoinBalance sets the genesis account balance for the default token (stake).

func WithLogger

func WithLogger() TestChainConfigOption

WithLogger enables the app console logger.

func WithValidatorsNum

func WithValidatorsNum(num int) TestChainConfigOption

type TestChainConsensusParamsOption

type TestChainConsensusParamsOption func(params *tmproto.ConsensusParams)

func WithBlockGasLimit

func WithBlockGasLimit(gasLimit int64) TestChainConsensusParamsOption

WithBlockGasLimit sets the block gas limit (not set by default).

type TestChainGenesisOption

type TestChainGenesisOption func(cdc codec.Codec, genesis app.GenesisState)

func WithMintParams

func WithMintParams(inflationMin, inflationMax sdk.Dec, blocksPerYear uint64) TestChainGenesisOption

WithMintParams sets x/mint inflation calculation parameters.

Jump to

Keyboard shortcuts

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