Documentation ¶
Overview ¶
This file contains the variables, constants, and default values used in the testing package and commonly defined in tests.
Index ¶
- Constants
- Variables
- func GetChainID(index int) string
- func GetChainIDAlthea(index int) string
- func MakeBlockID(hash []byte, partSetSize uint32, partSetHash []byte) tmtypes.BlockID
- func ParseAckFromEvents(events sdk.Events) ([]byte, error)
- func ParseChannelIDFromEvents(events sdk.Events) (string, error)
- func ParseClientIDFromEvents(events sdk.Events) (string, error)
- func ParseConnectionIDFromEvents(events sdk.Events) (string, error)
- func ParsePacketFromEvents(events sdk.Events) (channeltypes.Packet, error)
- func SignAndDeliver(t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, header tmproto.Header, ...) (sdk.GasInfo, *sdk.Result, error)
- type ChannelConfig
- type ClientConfig
- type ConnectionConfig
- type Coordinator
- func (coord *Coordinator) CommitBlock(chains ...*TestChain)
- func (coord *Coordinator) CreateChannels(path *Path)
- func (coord *Coordinator) CreateConnections(path *Path)
- func (coord *Coordinator) GetChain(chainID string) *TestChain
- func (coord *Coordinator) IncrementTime()
- func (coord *Coordinator) IncrementTimeBy(increment time.Duration)
- func (coord *Coordinator) Setup(path *Path)
- func (coord *Coordinator) SetupClients(path *Path)
- func (coord *Coordinator) SetupConnections(path *Path)
- func (coord *Coordinator) UpdateTime()
- func (coord *Coordinator) UpdateTimeForChain(chain *TestChain)
- type Endpoint
- func (endpoint *Endpoint) AcknowledgePacket(packet channeltypes.Packet, ack []byte) error
- func (endpoint *Endpoint) ChanOpenAck() error
- func (endpoint *Endpoint) ChanOpenConfirm() error
- func (endpoint *Endpoint) ChanOpenInit() error
- func (endpoint *Endpoint) ChanOpenTry() error
- func (endpoint *Endpoint) ConnOpenAck() error
- func (endpoint *Endpoint) ConnOpenConfirm() error
- func (endpoint *Endpoint) ConnOpenInit() error
- func (endpoint *Endpoint) ConnOpenTry() error
- func (endpoint *Endpoint) CreateClient() (err error)
- func (endpoint *Endpoint) GetChannel() channeltypes.Channel
- func (endpoint *Endpoint) QueryConnectionHandshakeProof() (clientState exported.ClientState, proofClient, proofConsensus []byte, ...)
- func (endpoint *Endpoint) QueryProof(key []byte) ([]byte, clienttypes.Height)
- func (endpoint *Endpoint) QueryProofAtHeight(key []byte, height uint64) ([]byte, clienttypes.Height)
- func (endpoint *Endpoint) RecvPacketWithResult(packet channeltypes.Packet) (*sdk.Result, error)
- func (endpoint *Endpoint) UpdateClient() (err error)
- type Path
- type SenderAccount
- type TendermintConfig
- type TestChain
- func (chain *TestChain) ConstructUpdateTMClientHeader(counterparty *TestChain, clientID string) (*ibctmtypes.Header, error)
- func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty *TestChain, clientID string, trustedHeight clienttypes.Height) (*ibctmtypes.Header, error)
- func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64, trustedHeight clienttypes.Height, ...) *ibctmtypes.Header
- func (chain *TestChain) CurrentTMClientHeader() *ibctmtypes.Header
- func (chain *TestChain) GetClientState(clientID string) exported.ClientState
- func (chain *TestChain) GetContext() sdk.Context
- func (chain *TestChain) GetPrefix() commitmenttypes.MerklePrefix
- func (chain *TestChain) GetSimApp() *simapp.SimApp
- func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bool)
- func (chain *TestChain) NextBlock()
- func (chain *TestChain) QueryProof(key []byte) ([]byte, clienttypes.Height)
- func (chain *TestChain) QueryProofAtHeight(key []byte, height int64) ([]byte, clienttypes.Height)
- func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error)
- type TestingApp
- func SetupTestingAltheaApp() (TestingApp, map[string]json.RawMessage)
- func SetupTestingApp() (TestingApp, map[string]json.RawMessage)
- func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, ...) TestingApp
- func SetupWithGenesisValSetAlthea(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, ...) TestingApp
Constants ¶
const ( // Default params constants used to create a TM client TrustingPeriod time.Duration = time.Hour * 24 * 7 * 2 UnbondingPeriod time.Duration = time.Hour * 24 * 7 * 3 MaxClockDrift time.Duration = time.Second * 10 DefaultDelayPeriod uint64 = 0 DefaultChannelVersion = mock.Version // Application Ports TransferPort = ibctransfertypes.ModuleName )
Variables ¶
var ( ChainIDPrefix = "testchain" TimeIncrement = time.Second * 5 )
var ( DefaultOpenInitVersion *connectiontypes.Version // Default params variables used to create a TM client DefaultTrustLevel ibctmtypes.Fraction = ibctmtypes.DefaultTrustLevel UpgradePath = []string{"upgrade", "upgradedIBCState"} ConnectionVersion = connectiontypes.ExportedVersionsToProto(connectiontypes.GetCompatibleVersions())[0] )
var AltheaTestingAppInit func() (TestingApp, map[string]json.RawMessage) = SetupTestingAltheaApp
var ChainIDPrefixAlthea = "althea_417834-"
ChainIDPrefix defines the default chain ID prefix for althea test chains
var DefaultTestingAppInit func() (TestingApp, map[string]json.RawMessage) = SetupTestingApp
var MaxAccounts = 10
Functions ¶
func GetChainID ¶
GetChainID returns the chainID used for the provided index.
func GetChainIDAlthea ¶
GetChainID returns the chainID used for the provided index.
func MakeBlockID ¶
MakeBlockID copied unimported test functions from tmtypes to use them here
func ParseAckFromEvents ¶
ParseAckFromEvents parses events emitted from a MsgRecvPacket and returns the acknowledgement.
func ParseChannelIDFromEvents ¶
ParseChannelIDFromEvents parses events emitted from a MsgChannelOpenInit or MsgChannelOpenTry and returns the channel identifier.
func ParseClientIDFromEvents ¶
ParseClientIDFromEvents parses events emitted from a MsgCreateClient and returns the client identifier.
func ParseConnectionIDFromEvents ¶
ParseConnectionIDFromEvents parses events emitted from a MsgConnectionOpenInit or MsgConnectionOpenTry and returns the connection identifier.
func ParsePacketFromEvents ¶
func ParsePacketFromEvents(events sdk.Events) (channeltypes.Packet, error)
ParsePacketFromEvents parses events emitted from a MsgRecvPacket and returns the acknowledgement.
func SignAndDeliver ¶
func SignAndDeliver( t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, header tmproto.Header, msgs []sdk.Msg, chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey, ) (sdk.GasInfo, *sdk.Result, error)
SignAndDeliver signs and delivers a transaction. No simulation occurs as the ibc testing package causes checkState and deliverState to diverge in block time.
Types ¶
type ChannelConfig ¶
type ChannelConfig struct { PortID string Version string Order channeltypes.Order }
func NewChannelConfig ¶
func NewChannelConfig() *ChannelConfig
type ClientConfig ¶
type ClientConfig interface {
GetClientType() string
}
type ConnectionConfig ¶
type ConnectionConfig struct { DelayPeriod uint64 Version *connectiontypes.Version }
func NewConnectionConfig ¶
func NewConnectionConfig() *ConnectionConfig
type Coordinator ¶
Coordinator is a testing struct which contains N TestChain's. It handles keeping all chains in sync with regards to time.
func NewCoordinator ¶
func NewCoordinator(t *testing.T, nEVMChains, mCosmosChains int) *Coordinator
NewCoordinator initializes Coordinator with N EVM TestChain's (althea apps) and M Cosmos chains (Simulation Apps)
func (*Coordinator) CommitBlock ¶
func (coord *Coordinator) CommitBlock(chains ...*TestChain)
CommitBlock commits a block on the provided indexes and then increments the global time.
CONTRACT: the passed in list of indexes must not contain duplicates
func (*Coordinator) CreateChannels ¶
func (coord *Coordinator) CreateChannels(path *Path)
CreateChannel constructs and executes channel handshake messages in order to create OPEN channels on chainA and chainB. The function expects the channels to be successfully opened otherwise testing will fail.
func (*Coordinator) CreateConnections ¶
func (coord *Coordinator) CreateConnections(path *Path)
CreateConnection constructs and executes connection handshake messages in order to create OPEN channels on chainA and chainB. The connection information of for chainA and chainB are returned within a TestConnection struct. The function expects the connections to be successfully opened otherwise testing will fail.
func (*Coordinator) GetChain ¶
func (coord *Coordinator) GetChain(chainID string) *TestChain
GetChain returns the TestChain using the given chainID and returns an error if it does not exist.
func (*Coordinator) IncrementTime ¶
func (coord *Coordinator) IncrementTime()
IncrementTime iterates through all the TestChain's and increments their current header time by 5 seconds.
CONTRACT: this function must be called after every Commit on any TestChain.
func (*Coordinator) IncrementTimeBy ¶
func (coord *Coordinator) IncrementTimeBy(increment time.Duration)
IncrementTimeBy iterates through all the TestChain's and increments their current header time by specified time.
func (*Coordinator) Setup ¶
func (coord *Coordinator) Setup(path *Path)
Setup constructs a TM client, connection, and channel on both chains provided. It will fail if any error occurs. The clientID's, TestConnections, and TestChannels are returned for both chains. The channels created are connected to the ibc-transfer application.
func (*Coordinator) SetupClients ¶
func (coord *Coordinator) SetupClients(path *Path)
SetupClients is a helper function to create clients on both chains. It assumes the caller does not anticipate any errors.
func (*Coordinator) SetupConnections ¶
func (coord *Coordinator) SetupConnections(path *Path)
SetupClientConnections is a helper function to create clients and the appropriate connections on both the source and counterparty chain. It assumes the caller does not anticipate any errors.
func (*Coordinator) UpdateTime ¶
func (coord *Coordinator) UpdateTime()
UpdateTime updates all clocks for the TestChains to the current global time.
func (*Coordinator) UpdateTimeForChain ¶
func (coord *Coordinator) UpdateTimeForChain(chain *TestChain)
UpdateTimeForChain updates the clock for a specific chain.
type Endpoint ¶
type Endpoint struct { Chain *TestChain Counterparty *Endpoint ClientID string ConnectionID string ChannelID string ClientConfig ClientConfig ConnectionConfig *ConnectionConfig ChannelConfig *ChannelConfig }
Endpoint is a which represents a channel endpoint and its associated client and connections. It contains client, connection, and channel configuration parameters. Endpoint functions will utilize the parameters set in the configuration structs when executing IBC messages.
func NewDefaultEndpoint ¶
NewDefaultEndpoint constructs a new endpoint using default values. CONTRACT: the counterparty endpoitn must be set by the caller.
func (*Endpoint) AcknowledgePacket ¶
func (endpoint *Endpoint) AcknowledgePacket(packet channeltypes.Packet, ack []byte) error
AcknowledgePacket sends a MsgAcknowledgement to the channel associated with the endpoint.
func (*Endpoint) ChanOpenAck ¶
ChanOpenAck will construct and execute a MsgChannelOpenAck on the associated endpoint.
func (*Endpoint) ChanOpenConfirm ¶
ChanOpenConfirm will construct and execute a MsgChannelOpenConfirm on the associated endpoint.
func (*Endpoint) ChanOpenInit ¶
ChanOpenInit will construct and execute a MsgChannelOpenInit on the associated endpoint.
func (*Endpoint) ChanOpenTry ¶
ChanOpenTry will construct and execute a MsgChannelOpenTry on the associated endpoint.
func (*Endpoint) ConnOpenAck ¶
ConnOpenAck will construct and execute a MsgConnectionOpenAck on the associated endpoint.
func (*Endpoint) ConnOpenConfirm ¶
ConnOpenConfirm will construct and execute a MsgConnectionOpenConfirm on the associated endpoint.
func (*Endpoint) ConnOpenInit ¶
ConnOpenInit will construct and execute a MsgConnectionOpenInit on the associated endpoint.
func (*Endpoint) ConnOpenTry ¶
ConnOpenTry will construct and execute a MsgConnectionOpenTry on the associated endpoint.
func (*Endpoint) CreateClient ¶
CreateClient creates an IBC client on the endpoint. It will update the clientID for the endpoint if the message is successfully executed. NOTE: a solo machine client will be created with an empty diversifier.
func (*Endpoint) GetChannel ¶
func (endpoint *Endpoint) GetChannel() channeltypes.Channel
GetChannel retrieves an IBC Channel for the endpoint. The channel is expected to exist otherwise testing will fail.
func (*Endpoint) QueryConnectionHandshakeProof ¶
func (endpoint *Endpoint) QueryConnectionHandshakeProof() ( clientState exported.ClientState, proofClient, proofConsensus []byte, consensusHeight clienttypes.Height, proofConnection []byte, proofHeight clienttypes.Height, )
QueryConnectionHandshakeProof returns all the proofs necessary to execute OpenTry or Open Ack of the connection handshakes. It returns the counterparty client state, proof of the counterparty client state, proof of the counterparty consensus state, the consensus state height, proof of the counterparty connection, and the proof height for all the proofs returned.
func (*Endpoint) QueryProof ¶
func (endpoint *Endpoint) QueryProof(key []byte) ([]byte, clienttypes.Height)
QueryProof queries proof associated with this endpoint using the lastest client state height on the counterparty chain.
func (*Endpoint) QueryProofAtHeight ¶
func (endpoint *Endpoint) QueryProofAtHeight(key []byte, height uint64) ([]byte, clienttypes.Height)
QueryProofAtHeight queries proof associated with this endpoint using the proof height provided
func (*Endpoint) RecvPacketWithResult ¶
RecvPacketWithResult receives a packet on the associated endpoint and the result of the transaction is returned. The counterparty client is updated.
func (*Endpoint) UpdateClient ¶
UpdateClient updates the IBC client associated with the endpoint.
type Path ¶
Path contains two endpoints representing two chains connected over IBC
func NewPath ¶
NewPath constructs an endpoint for each chain using the default values for the endpoints. Each endpoint is updated to have a pointer to the counterparty endpoint.
func (*Path) RelayPacket ¶
func (path *Path) RelayPacket(packet channeltypes.Packet) error
RelayPacket attempts to relay the packet first on EndpointA and then on EndpointB if EndpointA does not contain a packet commitment for that packet. An error is returned if a relay step fails or the packet commitment does not exist on either endpoint.
type SenderAccount ¶
type SenderAccount struct { SenderPrivKey cryptotypes.PrivKey SenderAccount authtypes.AccountI }
type TendermintConfig ¶
type TendermintConfig struct { TrustLevel ibctmtypes.Fraction TrustingPeriod time.Duration UnbondingPeriod time.Duration MaxClockDrift time.Duration AllowUpdateAfterExpiry bool AllowUpdateAfterMisbehaviour bool }
func NewTendermintConfig ¶
func NewTendermintConfig() *TendermintConfig
func (*TendermintConfig) GetClientType ¶
func (tmcfg *TendermintConfig) GetClientType() string
type TestChain ¶
type TestChain struct { *testing.T Coordinator *Coordinator App TestingApp ChainID string LastHeader *ibctmtypes.Header // header for last block height committed CurrentHeader tmproto.Header // header for current block height QueryServer types.QueryServer TxConfig client.TxConfig Codec codec.BinaryCodec Vals *tmtypes.ValidatorSet Signers []tmtypes.PrivValidator // autogenerated sender private key SenderPrivKey cryptotypes.PrivKey SenderAccount authtypes.AccountI SenderAccounts []SenderAccount }
TestChain is a testing struct that wraps a simapp with the last TM Header, the current ABCI header and the validators of the TestChain. It also contains a field called ChainID. This is the clientID that *other* chains use to refer to this TestChain. The SenderAccount is used for delivering transactions through the application state. NOTE: the actual application uses an empty chain-id for ease of testing.
func NewTestChain ¶
func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain
NewTestChain initializes a new test chain with a default of 4 validators Use this function if the tests do not need custom control over the validator set
func NewTestChainAlthea ¶
func NewTestChainAlthea(t *testing.T, coord *Coordinator, chainID string) *TestChain
NewTestChain initializes a new TestChain instance with a single validator set using a generated private key. It also creates a sender account to be used for delivering transactions.
The first block height is committed to state in order to allow for client creations on counterparty chains. The TestChain will return with a block height starting at 2.
Time management is handled by the Coordinator in order to ensure synchrony between chains. Each update of any chain increments the block header time for all chains by 5 seconds.
func NewTestChainWithValSet ¶
func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, valSet *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator) *TestChain
NewTestChainWithValSet initializes a new TestChain instance with the given validator set and signer array. It also initializes 10 Sender accounts with a balance of 10000000000000000000 coins of bond denom to use for tests.
The first block height is committed to state in order to allow for client creations on counterparty chains. The TestChain will return with a block height starting at 2.
Time management is handled by the Coordinator in order to ensure synchrony between chains. Each update of any chain increments the block header time for all chains by 5 seconds.
NOTE: to use a custom sender privkey and account for testing purposes, replace and modify this constructor function.
CONTRACT: Validator and signer array must be provided in the order expected by Tendermint. i.e. sorted first by power and then lexicographically by address.
func (*TestChain) ConstructUpdateTMClientHeader ¶
func (chain *TestChain) ConstructUpdateTMClientHeader(counterparty *TestChain, clientID string) (*ibctmtypes.Header, error)
ConstructUpdateTMClientHeader will construct a valid 07-tendermint Header to update the light client on the source chain.
func (*TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight ¶
func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty *TestChain, clientID string, trustedHeight clienttypes.Height) (*ibctmtypes.Header, error)
ConstructUpdateTMClientHeader will construct a valid 07-tendermint Header to update the light client on the source chain.
func (*TestChain) CreateTMClientHeader ¶
func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64, trustedHeight clienttypes.Height, timestamp time.Time, tmValSet, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator) *ibctmtypes.Header
CreateTMClientHeader creates a TM header to update the TM client. Args are passed in to allow caller flexibility to use params that differ from the chain.
func (*TestChain) CurrentTMClientHeader ¶
func (chain *TestChain) CurrentTMClientHeader() *ibctmtypes.Header
CurrentTMClientHeader creates a TM header using the current header parameters on the chain. The trusted fields in the header are set to nil.
func (*TestChain) GetClientState ¶
func (chain *TestChain) GetClientState(clientID string) exported.ClientState
GetClientState retrieves the client state for the provided clientID. The client is expected to exist otherwise testing will fail.
func (*TestChain) GetContext ¶
GetContext returns the current context for the application.
func (*TestChain) GetPrefix ¶
func (chain *TestChain) GetPrefix() commitmenttypes.MerklePrefix
GetPrefix returns the prefix for used by a chain in connection creation
func (*TestChain) GetSimApp ¶
GetSimApp returns the SimApp to allow usage ofnon-interface fields. CONTRACT: This function should not be called by third parties implementing their own SimApp.
func (*TestChain) GetValsAtHeight ¶
func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bool)
GetValsAtHeight will return the validator set of the chain at a given height. It will return a success boolean depending on if the validator set exists or not at that height.
func (*TestChain) NextBlock ¶
func (chain *TestChain) NextBlock()
NextBlock sets the last header to the current header and increments the current header to be at the next block height. It does not update the time as that is handled by the Coordinator.
CONTRACT: this function must only be called after app.Commit() occurs
func (*TestChain) QueryProof ¶
func (chain *TestChain) QueryProof(key []byte) ([]byte, clienttypes.Height)
QueryProof performs an abci query with the given key and returns the proto encoded merkle proof for the query and the height at which the proof will succeed on a tendermint verifier.
func (*TestChain) QueryProofAtHeight ¶
QueryProof performs an abci query with the given key and returns the proto encoded merkle proof for the query and the height at which the proof will succeed on a tendermint verifier.
type TestingApp ¶
type TestingApp interface { abci.Application // ibc-go additions GetBaseApp() *baseapp.BaseApp GetStakingKeeper() stakingkeeper.Keeper GetIBCKeeper() *keeper.Keeper GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper GetTxConfig() client.TxConfig // Implemented by SimApp AppCodec() codec.Codec // Implemented by BaseApp LastCommitID() sdk.CommitID LastBlockHeight() int64 }
func SetupTestingAltheaApp ¶
func SetupTestingAltheaApp() (TestingApp, map[string]json.RawMessage)
SetupTestingApp initializes the IBC-go testing application
func SetupTestingApp ¶
func SetupTestingApp() (TestingApp, map[string]json.RawMessage)
func SetupWithGenesisValSet ¶
func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, powerReduction sdk.Int, balances ...banktypes.Balance) TestingApp
func SetupWithGenesisValSetAlthea ¶
func SetupWithGenesisValSetAlthea(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, balances ...banktypes.Balance) TestingApp
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 (10^6) in the default token of the simapp from first genesis account. A Nop logger is set in SimApp.