Documentation ¶
Overview ¶
DONTCOVER
Index ¶
- Variables
- func GenAccounts(num uint) ([]sdk.AccAddress, []cryptotypes.PrivKey)
- func GenContractAddresses(num uint) []sdk.AccAddress
- func GetStringEventAttribute(events []abci.Event, eventType, attrKey string) string
- func HumanizeCoins(decimals uint8, coins ...sdk.Coin) string
- func HumanizeDecCoins(decimals uint8, coins ...sdk.DecCoin) string
- type Account
- type IBCEndpoint
- type IBCPath
- func (p *IBCPath) EndpointA() *IBCEndpoint
- func (p *IBCPath) EndpointB() *IBCEndpoint
- func (p *IBCPath) RelayPacket(packet channelTypes.Packet, ack []byte)
- func (p *IBCPath) SkipBlocks(n int64)
- func (p *IBCPath) SkipTime(endpoint *IBCEndpoint, dur time.Duration)
- func (p *IBCPath) TimeoutPacket(packet channelTypes.Packet, endpoint *IBCEndpoint)
- type SendMsgOption
- type TestChain
- func (chain *TestChain) BeginBlock() []abci.Event
- func (chain *TestChain) Client() grpc.ClientConnInterface
- func (chain *TestChain) EndBlock() []abci.Event
- func (chain *TestChain) ExecuteGovProposal(proposerAcc Account, expPass bool, proposals []sdk.Msg, title string, ...)
- func (chain *TestChain) GetAccount(idx int) Account
- func (chain *TestChain) GetApp() *app.App
- func (chain *TestChain) GetAppCodec() codec.Codec
- func (chain *TestChain) GetBalance(accAddr sdk.AccAddress) sdk.Coins
- func (chain *TestChain) GetBlockHeight() int64
- func (chain *TestChain) GetBlockTime() time.Time
- func (chain *TestChain) GetChainID() string
- func (chain *TestChain) GetClientState(clientID string) exported.ClientState
- func (chain *TestChain) GetContext() sdk.Context
- func (chain *TestChain) GetContractInfo(contractAddr sdk.AccAddress) wasmdTypes.ContractInfo
- func (chain *TestChain) GetCurrentValSet() tmTypes.ValidatorSet
- func (chain *TestChain) GetDefaultTxFee() sdk.Coins
- func (chain *TestChain) GetIBCPacketCommitment(packet channelTypes.Packet) []byte
- func (chain *TestChain) GetMerklePrefix() commitmentTypes.MerklePrefix
- func (chain *TestChain) GetModuleBalance(moduleName string) sdk.Coins
- func (chain *TestChain) GetNextIBCPacketSequence(portID, channelID string) uint64
- func (chain *TestChain) GetProofAtHeight(key []byte, height uint64) ([]byte, clientTypes.Height)
- func (chain *TestChain) GetTMClientHeaderUpdate(counterpartyChain *TestChain, clientID string, ...) ibcTmTypes.Header
- func (chain *TestChain) GetTMClientLastHeader() ibcTmTypes.Header
- func (chain *TestChain) GetUnbondingTime() time.Duration
- func (chain *TestChain) GetValSetAtHeight(height int64) tmTypes.ValidatorSet
- func (chain *TestChain) GoToHeight(height int64, skipTime time.Duration)
- func (chain *TestChain) InstantiateContract(sender Account, codeID uint64, adminAddr, label string, funds sdk.Coins, ...) (contractAddr sdk.AccAddress, instResp []byte)
- func (chain *TestChain) NextBlock(skipTime time.Duration) []abci.Event
- func (chain *TestChain) ParseSDKResultData(r *sdk.Result) sdk.TxMsgData
- func (chain *TestChain) SendIBCPacket(packet exported.PacketI)
- func (chain *TestChain) SendMsgs(senderAcc Account, expPass bool, msgs []sdk.Msg, opts ...SendMsgOption) (sdk.GasInfo, *sdk.Result, []abci.Event, error)
- func (chain *TestChain) SendMsgsRaw(senderAcc Account, msgs []sdk.Msg, opts ...SendMsgOption) (sdk.GasInfo, *sdk.Result, error)
- func (chain *TestChain) SmartQueryContract(contractAddr sdk.AccAddress, expPass bool, msg json.Marshaler) ([]byte, error)
- func (chain *TestChain) UploadContract(sender Account, wasmPath string, instantiatePerms wasmdTypes.AccessConfig) (codeID uint64)
- type TestChainConfigOption
- func WithBondAmount(amount string) TestChainConfigOption
- func WithDefaultFeeAmount(amount string) TestChainConfigOption
- func WithDummyTestAddress() TestChainConfigOption
- func WithGenAccounts(num int) TestChainConfigOption
- func WithGenDefaultCoinBalance(amount string) TestChainConfigOption
- func WithLogger() TestChainConfigOption
- func WithValidatorsNum(num int) TestChainConfigOption
- type TestChainConsensusParamsOption
- type TestChainGenesisOption
Constants ¶
This section is empty.
Variables ¶
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 ¶
GetStringEventAttribute returns TX response event attribute string value by type and attribute key.
func HumanizeCoins ¶
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).
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 ¶
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 ¶
NewTestChain creates a new TestChain with the default amount of genesis accounts and validators.
func (*TestChain) BeginBlock ¶
BeginBlock begins a new block.
func (*TestChain) Client ¶
func (chain *TestChain) Client() grpc.ClientConnInterface
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 ¶
GetAccount returns account address and private key with the given index.
func (*TestChain) GetAppCodec ¶
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 ¶
GetBlockHeight returns the current block height.
func (*TestChain) GetBlockTime ¶
GetBlockTime returns the current block time.
func (*TestChain) GetChainID ¶
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 ¶
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 ¶
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 ¶
GetModuleBalance returns the balance of the given module.
func (*TestChain) GetNextIBCPacketSequence ¶
GetNextIBCPacketSequence returns the next IBC packet sequence.
func (*TestChain) GetProofAtHeight ¶
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 ¶
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 (*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) ParseSDKResultData ¶
ParseSDKResultData converts TX result data into a slice of Msgs.
func (*TestChain) SendIBCPacket ¶
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.