Documentation ¶
Index ¶
- Constants
- Variables
- func GetChainID(index int) string
- func MakeBlockID(hash []byte, partSetSize int, partSetHash []byte) tmtypes.BlockID
- type Coordinator
- func (coord *Coordinator) AcknowledgementExecuted(source, counterparty *TestChain, packet channelexported.PacketI, ...) error
- func (coord *Coordinator) ChanCloseInit(source, counterparty *TestChain, channel TestChannel) error
- func (coord *Coordinator) ChanOpenAck(source, counterparty *TestChain, ...) error
- func (coord *Coordinator) ChanOpenConfirm(source, counterparty *TestChain, ...) error
- func (coord *Coordinator) ChanOpenInit(source, counterparty *TestChain, ...) (TestChannel, TestChannel, error)
- func (coord *Coordinator) ChanOpenTry(source, counterparty *TestChain, ...) error
- func (coord *Coordinator) CommitBlock(chains ...*TestChain)
- func (coord *Coordinator) CommitNBlocks(chain *TestChain, n uint64)
- func (coord *Coordinator) ConnOpenAck(source, counterparty *TestChain, ...) error
- func (coord *Coordinator) ConnOpenConfirm(source, counterparty *TestChain, ...) error
- func (coord *Coordinator) ConnOpenInit(source, counterparty *TestChain, clientID, counterpartyClientID string) (*TestConnection, *TestConnection, error)
- func (coord *Coordinator) ConnOpenTry(source, counterparty *TestChain, ...) error
- func (coord *Coordinator) CreateChannel(chainA, chainB *TestChain, connA, connB *TestConnection, ...) (TestChannel, TestChannel)
- func (coord *Coordinator) CreateClient(source, counterparty *TestChain, clientType clientexported.ClientType) (clientID string, err error)
- func (coord *Coordinator) CreateConnection(chainA, chainB *TestChain, clientA, clientB string) (*TestConnection, *TestConnection)
- func (coord *Coordinator) GetChain(chainID string) *TestChain
- func (coord *Coordinator) IncrementTime()
- func (coord *Coordinator) PacketExecuted(source, counterparty *TestChain, packet channelexported.PacketI, ...) error
- func (coord *Coordinator) SendPacket(source, counterparty *TestChain, packet channelexported.PacketI, ...) error
- func (coord *Coordinator) SetChannelClosed(source, counterparty *TestChain, testChannel TestChannel) error
- func (coord *Coordinator) Setup(chainA, chainB *TestChain) (string, string, *TestConnection, *TestConnection, TestChannel, TestChannel)
- func (coord *Coordinator) SetupClientConnections(chainA, chainB *TestChain, clientType clientexported.ClientType) (string, string, *TestConnection, *TestConnection)
- func (coord *Coordinator) SetupClients(chainA, chainB *TestChain, clientType clientexported.ClientType) (string, string)
- func (coord *Coordinator) UpdateClient(source, counterparty *TestChain, clientID string, ...) (err error)
- type TestChain
- func (chain *TestChain) AcknowledgementExecuted(packet channelexported.PacketI) error
- func (chain *TestChain) AddTestConnection(clientID, counterpartyClientID string) *TestConnection
- func (chain *TestChain) ChanCloseInit(counterparty *TestChain, channel TestChannel) error
- func (chain *TestChain) ChanOpenAck(counterparty *TestChain, ch, counterpartyCh TestChannel) error
- func (chain *TestChain) ChanOpenConfirm(counterparty *TestChain, ch, counterpartyCh TestChannel) error
- func (chain *TestChain) ChanOpenInit(ch, counterparty TestChannel, order channeltypes.Order, connectionID string) error
- func (chain *TestChain) ChanOpenTry(counterparty *TestChain, ch, counterpartyCh TestChannel, ...) error
- func (chain *TestChain) ConnectionOpenAck(counterparty *TestChain, connection, counterpartyConnection *TestConnection) error
- func (chain *TestChain) ConnectionOpenConfirm(counterparty *TestChain, connection, counterpartyConnection *TestConnection) error
- func (chain *TestChain) ConnectionOpenInit(counterparty *TestChain, connection, counterpartyConnection *TestConnection) error
- func (chain *TestChain) ConnectionOpenTry(counterparty *TestChain, connection, counterpartyConnection *TestConnection) error
- func (chain *TestChain) ConstructNextTestConnection(clientID, counterpartyClientID string) *TestConnection
- func (chain *TestChain) CreateChannelCapability(portID, channelID string)
- func (chain *TestChain) CreatePortCapability(portID string)
- func (chain *TestChain) CreateTMClient(counterparty *TestChain, clientID string) error
- func (chain *TestChain) CreateTMClientHeader() ibctmtypes.Header
- func (chain *TestChain) GetAcknowledgement(packet channelexported.PacketI) []byte
- func (chain *TestChain) GetChannel(testChannel TestChannel) channeltypes.Channel
- func (chain *TestChain) GetChannelCapability(portID, channelID string) *capabilitytypes.Capability
- func (chain *TestChain) GetClientState(clientID string) clientexported.ClientState
- func (chain *TestChain) GetConnection(testConnection *TestConnection) connectiontypes.ConnectionEnd
- func (chain *TestChain) GetContext() sdk.Context
- func (chain *TestChain) GetFirstTestConnection(clientID, counterpartyClientID string) *TestConnection
- func (chain *TestChain) GetPacketData(counterparty *TestChain) []byte
- func (chain *TestChain) GetPortCapability(portID string) *capabilitytypes.Capability
- func (chain *TestChain) GetPrefix() commitmenttypes.MerklePrefix
- func (chain *TestChain) NewClientID(counterpartyChainID string) string
- func (chain *TestChain) NextBlock()
- func (chain *TestChain) PacketExecuted(packet channelexported.PacketI) error
- func (chain *TestChain) QueryConsensusStateProof(clientID string) ([]byte, uint64)
- func (chain *TestChain) QueryProof(key []byte) ([]byte, uint64)
- func (chain *TestChain) SendMsg(msg sdk.Msg) error
- func (chain *TestChain) SendPacket(packet channelexported.PacketI) error
- func (chain *TestChain) UpdateTMClient(counterparty *TestChain, clientID string) error
- type TestChannel
- type TestConnection
Constants ¶
const ( // Default params 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 ChannelVersion = ibctransfertypes.Version InvalidID = "IDisInvalid" ConnectionIDPrefix = "connectionid" )
Variables ¶
var ( DefaultTrustLevel tmmath.Fraction = lite.DefaultTrustLevel TestHash = []byte("TESTING HASH") ConnectionVersion = connectiontypes.GetCompatibleEncodedVersions()[0] )
var (
ChainIDPrefix = "testchain"
)
Functions ¶
func GetChainID ¶
GetChainID returns the chainID used for the provided index.
Types ¶
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, n int) *Coordinator
NewCoordinator initializes Coordinator with N TestChain's
func (*Coordinator) AcknowledgementExecuted ¶
func (coord *Coordinator) AcknowledgementExecuted( source, counterparty *TestChain, packet channelexported.PacketI, counterpartyClientID string, ) error
AcknowledgementExecuted deletes the packet commitment with the given packet sequence since the acknowledgement has been verified.
func (*Coordinator) ChanCloseInit ¶
func (coord *Coordinator) ChanCloseInit( source, counterparty *TestChain, channel TestChannel, ) error
ChanCloseInit closes a channel on the source chain resulting in the channels state being set to CLOSED.
NOTE: does not work with ibc-transfer module
func (*Coordinator) ChanOpenAck ¶
func (coord *Coordinator) ChanOpenAck( source, counterparty *TestChain, sourceChannel, counterpartyChannel TestChannel, ) error
ChanOpenAck initializes a channel on the source chain with the state OPEN using the OpenAck handshake call.
func (*Coordinator) ChanOpenConfirm ¶
func (coord *Coordinator) ChanOpenConfirm( source, counterparty *TestChain, sourceChannel, counterpartyChannel TestChannel, ) error
ChanOpenConfirm initializes a channel on the source chain with the state OPEN using the OpenConfirm handshake call.
func (*Coordinator) ChanOpenInit ¶
func (coord *Coordinator) ChanOpenInit( source, counterparty *TestChain, connection, counterpartyConnection *TestConnection, order channeltypes.Order, ) (TestChannel, TestChannel, error)
ChanOpenInit initializes a channel on the source chain with the state INIT using the OpenInit handshake call.
NOTE: The counterparty testing channel will be created even if it is not created in the application state.
func (*Coordinator) ChanOpenTry ¶
func (coord *Coordinator) ChanOpenTry( source, counterparty *TestChain, sourceChannel, counterpartyChannel TestChannel, connection *TestConnection, order channeltypes.Order, ) error
ChanOpenTry initializes a channel on the source chain with the state TRYOPEN using the OpenTry handshake call.
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) CommitNBlocks ¶
func (coord *Coordinator) CommitNBlocks(chain *TestChain, n uint64)
CommitNBlocks commits n blocks to state and updates the block height by 1 for each commit.
func (*Coordinator) ConnOpenAck ¶
func (coord *Coordinator) ConnOpenAck( source, counterparty *TestChain, sourceConnection, counterpartyConnection *TestConnection, ) error
ConnOpenAck initializes a connection on the source chain with the state OPEN using the OpenAck handshake call.
func (*Coordinator) ConnOpenConfirm ¶
func (coord *Coordinator) ConnOpenConfirm( source, counterparty *TestChain, sourceConnection, counterpartyConnection *TestConnection, ) error
ConnOpenConfirm initializes a connection on the source chain with the state OPEN using the OpenConfirm handshake call.
func (*Coordinator) ConnOpenInit ¶
func (coord *Coordinator) ConnOpenInit( source, counterparty *TestChain, clientID, counterpartyClientID string, ) (*TestConnection, *TestConnection, error)
ConnOpenInit initializes a connection on the source chain with the state INIT using the OpenInit handshake call.
NOTE: The counterparty testing connection will be created even if it is not created in the application state.
func (*Coordinator) ConnOpenTry ¶
func (coord *Coordinator) ConnOpenTry( source, counterparty *TestChain, sourceConnection, counterpartyConnection *TestConnection, ) error
ConnOpenTry initializes a connection on the source chain with the state TRYOPEN using the OpenTry handshake call.
func (*Coordinator) CreateChannel ¶
func (coord *Coordinator) CreateChannel( chainA, chainB *TestChain, connA, connB *TestConnection, order channeltypes.Order, ) (TestChannel, TestChannel)
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) CreateClient ¶
func (coord *Coordinator) CreateClient( source, counterparty *TestChain, clientType clientexported.ClientType, ) (clientID string, err error)
CreateClient creates a counterparty client on the source chain and returns the clientID.
func (*Coordinator) CreateConnection ¶
func (coord *Coordinator) CreateConnection( chainA, chainB *TestChain, clientA, clientB string, ) (*TestConnection, *TestConnection)
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) PacketExecuted ¶
func (coord *Coordinator) PacketExecuted( source, counterparty *TestChain, packet channelexported.PacketI, counterpartyClientID string, ) error
PacketExecuted receives a packet through the channel keeper on the source chain and updates the counterparty client for the source chain.
func (*Coordinator) SendPacket ¶
func (coord *Coordinator) SendPacket( source, counterparty *TestChain, packet channelexported.PacketI, counterpartyClientID string, ) error
SendPacket sends a packet through the channel keeper on the source chain and updates the counterparty client for the source chain.
func (*Coordinator) SetChannelClosed ¶
func (coord *Coordinator) SetChannelClosed( source, counterparty *TestChain, testChannel TestChannel, ) error
SetChannelClosed sets a channel state to CLOSED.
func (*Coordinator) Setup ¶
func (coord *Coordinator) Setup( chainA, chainB *TestChain, ) (string, string, *TestConnection, *TestConnection, TestChannel, TestChannel)
Setup constructs a TM client, connection, and channel on both chains provided. It will fails if any error occurs. The clientID's, TestConnections, and TestChannels are returned for both chains.
func (*Coordinator) SetupClientConnections ¶
func (coord *Coordinator) SetupClientConnections( chainA, chainB *TestChain, clientType clientexported.ClientType, ) (string, string, *TestConnection, *TestConnection)
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) SetupClients ¶
func (coord *Coordinator) SetupClients( chainA, chainB *TestChain, clientType clientexported.ClientType, ) (string, string)
SetupClients is a helper function to create clients on both chains. It assumes the caller does not anticipate any errors.
func (*Coordinator) UpdateClient ¶
func (coord *Coordinator) UpdateClient( source, counterparty *TestChain, clientID string, clientType clientexported.ClientType, ) (err error)
UpdateClient updates a counterparty client on the source chain.
type TestChain ¶
type TestChain struct { App *simapp.SimApp ChainID string LastHeader ibctmtypes.Header // header for last block height committed CurrentHeader abci.Header // header for current block height Querier sdk.Querier // TODO: deprecate once clients are migrated to gRPC QueryServer types.QueryServer TxConfig client.TxConfig Vals *tmtypes.ValidatorSet Signers []tmtypes.PrivValidator SenderAccount authtypes.AccountI // IBC specific helpers ClientIDs []string // ClientID's used on this chain Connections []*TestConnection // track connectionID's created for this chain // contains filtered or unexported fields }
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 ¶
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 (*TestChain) AcknowledgementExecuted ¶
func (chain *TestChain) AcknowledgementExecuted( packet channelexported.PacketI, ) error
AcknowledgementExecuted simulates deleting a packet commitment with the given packet sequence.
func (*TestChain) AddTestConnection ¶
func (chain *TestChain) AddTestConnection(clientID, counterpartyClientID string) *TestConnection
AddTestConnection appends a new TestConnection which contains references to the connection id, client id and counterparty client id.
func (*TestChain) ChanCloseInit ¶
func (chain *TestChain) ChanCloseInit( counterparty *TestChain, channel TestChannel, ) error
ChanCloseInit will construct and execute a MsgChannelCloseInit.
NOTE: does not work with ibc-transfer module
func (*TestChain) ChanOpenAck ¶
func (chain *TestChain) ChanOpenAck( counterparty *TestChain, ch, counterpartyCh TestChannel, ) error
ChanOpenAck will construct and execute a MsgChannelOpenAck.
func (*TestChain) ChanOpenConfirm ¶
func (chain *TestChain) ChanOpenConfirm( counterparty *TestChain, ch, counterpartyCh TestChannel, ) error
ChanOpenConfirm will construct and execute a MsgChannelOpenConfirm.
func (*TestChain) ChanOpenInit ¶
func (chain *TestChain) ChanOpenInit( ch, counterparty TestChannel, order channeltypes.Order, connectionID string, ) error
ChanOpenInit will construct and execute a MsgChannelOpenInit.
func (*TestChain) ChanOpenTry ¶
func (chain *TestChain) ChanOpenTry( counterparty *TestChain, ch, counterpartyCh TestChannel, order channeltypes.Order, connectionID string, ) error
ChanOpenTry will construct and execute a MsgChannelOpenTry.
func (*TestChain) ConnectionOpenAck ¶
func (chain *TestChain) ConnectionOpenAck( counterparty *TestChain, connection, counterpartyConnection *TestConnection, ) error
ConnectionOpenAck will construct and execute a MsgConnectionOpenAck.
func (*TestChain) ConnectionOpenConfirm ¶
func (chain *TestChain) ConnectionOpenConfirm( counterparty *TestChain, connection, counterpartyConnection *TestConnection, ) error
ConnectionOpenConfirm will construct and execute a MsgConnectionOpenConfirm.
func (*TestChain) ConnectionOpenInit ¶
func (chain *TestChain) ConnectionOpenInit( counterparty *TestChain, connection, counterpartyConnection *TestConnection, ) error
ConnectionOpenInit will construct and execute a MsgConnectionOpenInit.
func (*TestChain) ConnectionOpenTry ¶
func (chain *TestChain) ConnectionOpenTry( counterparty *TestChain, connection, counterpartyConnection *TestConnection, ) error
ConnectionOpenTry will construct and execute a MsgConnectionOpenTry.
func (*TestChain) ConstructNextTestConnection ¶
func (chain *TestChain) ConstructNextTestConnection(clientID, counterpartyClientID string) *TestConnection
ConstructNextTestConnection constructs the next test connection to be created given a clientID and counterparty clientID. The connection id format: connectionid<index>
func (*TestChain) CreateChannelCapability ¶
CreateChannelCapability binds and claims a capability for the given portID and channelID if it does not already exist. This function will fail testing on any resulting error.
func (*TestChain) CreatePortCapability ¶
CreatePortCapability binds and claims a capability for the given portID if it does not already exist. This function will fail testing on any resulting error.
func (*TestChain) CreateTMClient ¶
CreateTMClient will construct and execute a 07-tendermint MsgCreateClient. A counterparty client will be created on the (target) chain.
func (*TestChain) CreateTMClientHeader ¶
func (chain *TestChain) CreateTMClientHeader() ibctmtypes.Header
CreateTMClientHeader creates a TM header to update the TM client.
func (*TestChain) GetAcknowledgement ¶
func (chain *TestChain) GetAcknowledgement(packet channelexported.PacketI) []byte
GetAcknowledgement retrieves an acknowledgement for the provided packet. If the acknowledgement does not exist then testing will fail.
func (*TestChain) GetChannel ¶
func (chain *TestChain) GetChannel(testChannel TestChannel) channeltypes.Channel
GetChannel retrieves an IBC Channel for the provided TestChannel. The channel is expected to exist otherwise testing will fail.
func (*TestChain) GetChannelCapability ¶
func (chain *TestChain) GetChannelCapability(portID, channelID string) *capabilitytypes.Capability
GetChannelCapability returns the channel capability for the given portID and channelID. The capability must exist, otherwise testing will fail.
func (*TestChain) GetClientState ¶
func (chain *TestChain) GetClientState(clientID string) clientexported.ClientState
GetClientState retrieves the client state for the provided clientID. The client is expected to exist otherwise testing will fail.
func (*TestChain) GetConnection ¶
func (chain *TestChain) GetConnection(testConnection *TestConnection) connectiontypes.ConnectionEnd
GetConnection retrieves an IBC Connection for the provided TestConnection. The connection is expected to exist otherwise testing will fail.
func (*TestChain) GetContext ¶
GetContext returns the current context for the application.
func (*TestChain) GetFirstTestConnection ¶
func (chain *TestChain) GetFirstTestConnection(clientID, counterpartyClientID string) *TestConnection
FirstTestConnection returns the first test connection for a given clientID. The connection may or may not exist in the chain state.
func (*TestChain) GetPacketData ¶
GetPacketData returns a ibc-transfer marshalled packet to be used for callback testing
func (*TestChain) GetPortCapability ¶
func (chain *TestChain) GetPortCapability(portID string) *capabilitytypes.Capability
GetPortCapability returns the port capability for the given portID. The capability must exist, otherwise testing will fail.
func (*TestChain) GetPrefix ¶
func (chain *TestChain) GetPrefix() commitmenttypes.MerklePrefix
GetPrefix returns the prefix for used by a chain in connection creation
func (*TestChain) NewClientID ¶
NewClientID appends a new clientID string in the format: ClientFor<counterparty-chain-id><index>
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) PacketExecuted ¶
func (chain *TestChain) PacketExecuted( packet channelexported.PacketI, ) error
PacketExecuted simulates receiving and writing an acknowledgement to the chain.
func (*TestChain) QueryConsensusStateProof ¶
QueryConsensusStateProof performs an abci query for a consensus state stored on the given clientID. The proof and consensusHeight are returned.
func (*TestChain) QueryProof ¶
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) SendMsg ¶
SendMsg delivers a transaction through the application. It updates the senders sequence number and updates the TestChain's headers.
func (*TestChain) SendPacket ¶
func (chain *TestChain) SendPacket( packet channelexported.PacketI, ) error
SendPacket simulates sending a packet through the channel keeper. No message needs to be passed since this call is made from a module.
type TestChannel ¶
TestChannel is a testing helper struct to keep track of the portID and channelID used in creating and interacting with a channel. The clientID and counterparty client ID are also tracked to cut down on querying and argument passing.
type TestConnection ¶
type TestConnection struct { ID string ClientID string CounterpartyClientID string Channels []TestChannel }
TestConnections is a testing helper struct to keep track of the connectionID, source clientID, and counterparty clientID used in creating and interacting with a connection.
func (*TestConnection) AddTestChannel ¶
func (conn *TestConnection) AddTestChannel() TestChannel
AddTestChannel appends a new TestChannel which contains references to the port and channel ID used for channel creation and interaction.
channel ID format: connectionid-<channel-index> the port is set to "transfer" to be compatible with the ICS-transfer module, this should eventually be updated as described in the issue: https://github.com/cosmos/cosmos-sdk/issues/6509
func (*TestConnection) FirstOrNextTestChannel ¶
func (conn *TestConnection) FirstOrNextTestChannel() TestChannel
FirstOrNextTestChannel returns the first test channel if it exists, otherwise it returns the next test channel to be created. This function is expected to be used when the caller does not know if the channel has or has not been created in app state, but would still like to refer to it to test existence or non-existence.
func (*TestConnection) NextTestChannel ¶
func (conn *TestConnection) NextTestChannel() TestChannel
NextTestChannel returns the next test channel to be created on this connection, but does not add it to the list of created channels. This function is expected to be used when the caller has not created the associated channel in app state, but would still like to refer to the non-existent channel usually to test for its non-existence.