ibctesting

package
v0.0.0-...-201aeb4 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: Apache-2.0 Imports: 51 Imported by: 0

README

IBC Testing Package

Components

The testing package comprises of four parts constructed as a stack.

  • coordinator
  • chain
  • path
  • endpoint

A coordinator sits at the highest level and contains all the chains which have been initialized. It also stores and updates the current global time. The time is manually incremented by a TimeIncrement. This allows all the chains to remain in synchrony avoiding the issue of a counterparty being perceived to be in the future. The coordinator also contains functions to do basic setup of clients, connections, and channels between two chains.

A chain is an SDK application (as represented by an app.go file). Inside the chain is an TestingApp which allows the chain to simulate block production and transaction processing. The chain contains by default a single tendermint validator. A chain is used to process SDK messages.

A path connects two channel endpoints. It contains all the information needed to relay between two endpoints.

An endpoint represents a channel (and its associated client and connections) on some specific chain. It contains references to the chain it is on and the counterparty endpoint it is connected to. The endpoint contains functions to interact with initialization and updates of its associated clients, connections, and channels. It can send, receive, and acknowledge packets.

In general:

  • endpoints are used for initialization and execution of IBC logic on one side of an IBC connection
  • paths are used to relay packets
  • chains are used to commit SDK messages
  • coordinator is used to setup a path between two chains

Integration

To integrate the testing package into your tests, you will need to define:

  • a testing application
  • a function to initialize the testing application
TestingApp

Your project will likely already have an application defined. This application will need to be extended to fulfill the TestingApp interface.

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
}

To begin, you will need to extend your application by adding the following functions:

// TestingApp functions
// Example using SimApp to implement TestingApp

// GetBaseApp implements the TestingApp interface.
func (app *SimApp) GetBaseApp() *baseapp.BaseApp {
	return app.BaseApp
}

// GetStakingKeeper implements the TestingApp interface.
func (app *SimApp) GetStakingKeeper() stakingkeeper.Keeper {
	return app.StakingKeeper
}

// GetIBCKeeper implements the TestingApp interface.
func (app *SimApp) GetIBCKeeper() *ibckeeper.Keeper {
	return app.IBCKeeper
}

// GetScopedIBCKeeper implements the TestingApp interface.
func (app *SimApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
	return app.ScopedIBCKeeper
}

// GetTxConfig implements the TestingApp interface.
func (app *SimApp) GetTxConfig() client.TxConfig {
	return MakeTestEncodingConfig().TxConfig
}

Your application may need to define AppCodec() if it does not already exist:

// 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 (app *SimApp) AppCodec() codec.Codec {
	return app.appCodec
}

It is assumed your application contains an embedded BaseApp and thus implements the abci.Application interface, LastCommitID() and LastBlockHeight()

Initialize TestingApp

The testing package requires that you provide a function to initialize your TestingApp. This is how ibc-go implements the initialize function with its SimApp:

func SetupTestingApp() (TestingApp, map[string]json.RawMessage) {
	db := dbm.NewMemDB()
	encCdc := simapp.MakeTestEncodingConfig()
	app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{})
	return app, simapp.NewDefaultGenesisState(encCdc.Marshaler)
}

This function returns the TestingApp and the default genesis state used to initialize the testing app.

Change the value of DefaultTestingAppInit to use your function:

func init() {
    ibctesting.DefaultTestingAppInit = MySetupTestingAppFunction
}

Example

Here is an example of how to setup your testing environment in every package you are testing:

// KeeperTestSuite is a testing suite to test keeper functions.
type KeeperTestSuite struct {
	suite.Suite

	coordinator *ibctesting.Coordinator

	// testing chains used for convenience and readability
	chainA *ibctesting.TestChain
	chainB *ibctesting.TestChain
}

// TestKeeperTestSuite runs all the tests within this package.
func TestKeeperTestSuite(t *testing.T) {
	suite.Run(t, new(KeeperTestSuite))
}

// SetupTest creates a coordinator with 2 test chains.
func (suite *KeeperTestSuite) SetupTest() {
	suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) // initializes 2 test chains
	suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(0)) // convenience and readability
	suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1)) // convenience and readability
}

To create interaction between chainA and chainB, we need to contruct a Path these chains will use. A path contains two endpoints, EndpointA and EndpointB (corresponding to the order of the chains passed into the NewPath function). A path is a pointer and its values will be filled in as necessary during the setup portion of testing.

Endpoint Struct:

// 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.
type Endpoint struct {
	Chain        *TestChain
	Counterparty *Endpoint
	ClientID     string
	ConnectionID string
	ChannelID    string

	ClientConfig     ClientConfig
	ConnectionConfig *ConnectionConfig
	ChannelConfig    *ChannelConfig
}

The fields empty after NewPath is called are ClientID, ConnectionID and ChannelID as the clients, connections, and channels for these endpoints have not yet been created. The ClientConfig, ConnectionConfig and ChannelConfig contain all the necessary information for clients, connections, and channels to be initialized. If you would like to use endpoints which are intitialized to use your Port IDs, you might add a helper function similar to the one found in transfer:

func NewTransferPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
	path := ibctesting.NewPath(chainA, chainB)
	path.EndpointA.ChannelConfig.PortID = ibctesting.TransferPort
	path.EndpointB.ChannelConfig.PortID = ibctesting.TransferPort

	return path
}

Path configurations should be set to the desired values before calling any Setup coordinator functions.

To initialize the clients, connections, and channels for a path we can call the Setup functions of the coordinator:

  • Setup() -> setup clients, connections, channels
  • SetupClients() -> setup clients only
  • SetupConnections() -> setup clients and connections only

Here is a basic example of the testing package being used to simulate IBC functionality:

    path := ibctesting.NewPath(suite.chainA, suite.chainB) // clientID, connectionID, channelID empty
    suite.coordinator.Setup(path) // clientID, connectionID, channelID filled
    suite.Require().Equal("07-tendermint-0", path.EndpointA.ClientID)
    suite.Require().Equal("connection-0", path.EndpointA.ClientID)
    suite.Require().Equal("channel-0", path.EndpointA.ClientID)

    // create packet 1 
    packet1 := NewPacket() // NewPacket would construct your packet

    // send on endpointA
    path.EndpointA.SendPacket(packet1)

    // receive on endpointB
    path.EndpointB.RecvPacket(packet1)

    // acknowledge the receipt of the packet
    path.EndpointA.AcknowledgePacket(packet1, ack)

    // we can also relay
    packet2 := NewPacket()

    path.EndpointA.SendPacket(packet2)

    path.Relay(packet2, expectedAck)

    // if needed we can update our clients
    path.EndpointB.UpdateClient()    
Transfer Testing Example

If ICS 20 had its own simapp, its testing setup might include a testing/app.go file with the following contents:

package transfertesting

import (
	"encoding/json"

	"github.com/tendermint/tendermint/libs/log"
	dbm "github.com/tendermint/tm-db"

	"github.com/cosmos/ibc-go/modules/apps/transfer/simapp"
	ibctesting "github.com/datachainlab/ibc-proxy/testing"
)

func SetupTransferTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) {
	db := dbm.NewMemDB()
	encCdc := simapp.MakeTestEncodingConfig()
	app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{})
	return app, simapp.NewDefaultGenesisState(encCdc.Marshaler)
}

func init() {
	ibctesting.DefaultTestingAppInit = SetupTransferTestingApp
}

func NewTransferPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
	path := ibctesting.NewPath(chainA, chainB)
	path.EndpointA.ChannelConfig.PortID = ibctesting.TransferPort
	path.EndpointB.ChannelConfig.PortID = ibctesting.TransferPort

	return path
}

func GetTransferSimApp(chain *ibctesting.TestChain) *simapp.SimApp {
	app, ok := chain.App.(*simapp.SimApp)
	if !ok {
		panic("not transfer app")
	}

	return app
}

Documentation

Index

Constants

View Source
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.Minute * 10
	DefaultDelayPeriod uint64        = 0

	TransferVersion = ibctransfertypes.Version
	InvalidID       = "IDisInvalid"

	ConnectionIDPrefix = "conn"
	ChannelIDPrefix    = "chan"

	TransferPort = ibctransfertypes.ModuleName
	MockPort     = mock.ModuleName

	// used for testing UpdateClientProposal
	Title       = "title"
	Description = "description"
)

Variables

View Source
var (
	DefaultOpenInitVersion *connectiontypes.Version

	// Default params variables used to create a TM client
	DefaultTrustLevel ibctmtypes.Fraction = ibctmtypes.DefaultTrustLevel
	TestHash                              = tmhash.Sum([]byte("TESTING HASH"))
	TestCoin                              = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))

	UpgradePath = []string{"upgrade", "upgradedIBCState"}

	ConnectionVersion = connectiontypes.ExportedVersionsToProto(connectiontypes.GetCompatibleVersions())[0]

	MockAcknowledgement = mock.MockAcknowledgement
)
View Source
var (
	ChainIDPrefix = "testchain"

	TimeIncrement = time.Second * 5
)
View Source
var DefaultTestingAppInit func() (TestingApp, map[string]json.RawMessage) = SetupTestingApp

Functions

func CreateSortedSignerArray

func CreateSortedSignerArray(altPrivVal, suitePrivVal tmtypes.PrivValidator,
	altVal, suiteVal *tmtypes.Validator) []tmtypes.PrivValidator

CreateSortedSignerArray takes two PrivValidators, and the corresponding Validator structs (including voting power). It returns a signer array of PrivValidators that matches the sorting of ValidatorSet. The sorting is first by .VotingPower (descending), with secondary index of .Address (ascending).

func GenerateKeys

GenerateKeys generates a new set of secp256k1 private keys and public keys. If the number of keys is greater than one then the public key returned represents a multisig public key. The private keys are used for signing, the public keys are used for generating the public key and the public key is used for solo machine verification. The usage of secp256k1 is entirely arbitrary. The key type can be swapped for any key type supported by the PublicKey interface, if needed. The same is true for the amino based Multisignature public key.

func GetChainID

func GetChainID(index int) string

GetChainID returns the chainID used for the provided index.

func MakeBlockID

func MakeBlockID(hash []byte, partSetSize uint32, partSetHash []byte) tmtypes.BlockID

MakeBlockID copied unimported test functions from tmtypes to use them here

func ParseChannelIDFromEvents

func ParseChannelIDFromEvents(events sdk.Events) (string, error)

ParseChannelIDFromEvents parses events emitted from a MsgChannelOpenInit or MsgChannelOpenTry and returns the channel identifier.

func ParseClientIDFromEvents

func ParseClientIDFromEvents(events sdk.Events) (string, error)

ParseClientIDFromEvents parses events emitted from a MsgCreateClient and returns the client identifier.

func ParseConnectionIDFromEvents

func ParseConnectionIDFromEvents(events sdk.Events) (string, error)

ParseConnectionIDFromEvents parses events emitted from a MsgConnectionOpenInit or MsgConnectionOpenTry and returns the connection identifier.

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

type Coordinator struct {
	Chains map[string]*TestChain
	// contains filtered or unexported fields
}

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

func (coord *Coordinator) AcknowledgePacket(
	source, counterparty *TestChain,
	counterpartyClient string,
	packet channeltypes.Packet, ack []byte,
) error

AcknowledgePacket acknowledges on the source chain the packet received on the counterparty chain and updates the client on the counterparty representing the source chain. TODO: add a query for the acknowledgement by events - https://github.com/cosmos/cosmos-sdk/issues/6509

func (*Coordinator) AcknowledgePacketWithProxy

func (coord *Coordinator) AcknowledgePacketWithProxy(
	source, counterparty *TestChain,
	sourceChannel, counterpartyChannel *TestChannel,
	sourceConnection, counterpartyConnection *TestConnection,
	packet channeltypes.Packet, ack []byte, proxies ProxyPair,
) error

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

func (coord *Coordinator) ChanOpenAckWithProxy(
	source, counterparty *TestChain,
	sourceChannel, counterpartyChannel TestChannel,
	sourceConnection, counterpartyConnection *TestConnection,
	order channeltypes.Order,
	proxies ProxyPair,
) error

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

func (coord *Coordinator) ChanOpenConfirmWithProxy(
	source, counterparty *TestChain,
	sourceChannel, counterpartyChannel TestChannel,
	sourceConnection, counterpartyConnection *TestConnection,
	order channeltypes.Order,
	proxies ProxyPair,
) error

func (*Coordinator) ChanOpenFinalizeWithProxy

func (coord *Coordinator) ChanOpenFinalizeWithProxy(
	source, counterparty *TestChain,
	sourceChannel, counterpartyChannel TestChannel,
	sourceConnection, counterpartyConnection *TestConnection,
	order channeltypes.Order,
	proxies ProxyPair,
) error

func (*Coordinator) ChanOpenInit

func (coord *Coordinator) ChanOpenInit(
	source, counterparty *TestChain,
	connection, counterpartyConnection *TestConnection,
	sourcePortID, counterpartyPortID string,
	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) ChanOpenInitOnBothChains

func (coord *Coordinator) ChanOpenInitOnBothChains(
	source, counterparty *TestChain,
	connection, counterpartyConnection *TestConnection,
	sourcePortID, counterpartyPortID string,
	order channeltypes.Order,
) (TestChannel, TestChannel, error)

ChanOpenInitOnBothChains initializes a channel on the source chain and counterparty chain with the state INIT using the OpenInit handshake call.

func (*Coordinator) ChanOpenInitWithProxy

func (coord *Coordinator) ChanOpenInitWithProxy(
	source, counterparty *TestChain,
	connection, counterpartyConnection *TestConnection,
	sourcePortID, counterpartyPortID string,
	order channeltypes.Order,
	proxies ProxyPair,
) (TestChannel, TestChannel, error)

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

func (coord *Coordinator) ChanOpenTryWithProxy(
	source, counterparty *TestChain,
	sourceChannel, counterpartyChannel TestChannel,
	sourceConnection, counterpartyConnection *TestConnection,
	order channeltypes.Order,
	proxies ProxyPair,
) error

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

func (coord *Coordinator) ConnOpenAckWithProxy(
	source, counterparty *TestChain,
	sourceConnection, counterpartyConnection *TestConnection,
	proxies ProxyPair,
) error

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

func (coord *Coordinator) ConnOpenConfirmWithProxy(
	source, counterparty *TestChain,
	sourceConnection, counterpartyConnection *TestConnection,
	proxies ProxyPair,
) error

func (*Coordinator) ConnOpenFinalizeWithProxy

func (coord *Coordinator) ConnOpenFinalizeWithProxy(
	source, counterparty *TestChain,
	sourceConnection, counterpartyConnection *TestConnection,
	proxies ProxyPair,
) error

func (*Coordinator) ConnOpenInit

func (coord *Coordinator) ConnOpenInit(
	source, counterparty *TestChain,
	clientID, counterpartyClientID, nextChannelVersion 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) ConnOpenInitOnBothChains

func (coord *Coordinator) ConnOpenInitOnBothChains(
	source, counterparty *TestChain,
	clientID, counterpartyClientID, nextChannelVersion string,
) (*TestConnection, *TestConnection, error)

ConnOpenInitOnBothChains initializes a connection on the source chain with the state INIT using the OpenInit handshake call.

func (*Coordinator) ConnOpenInitWithProxy

func (coord *Coordinator) ConnOpenInitWithProxy(
	source, counterparty *TestChain,
	clientID, counterpartyClientID, nextChannelVersion string, proxies ProxyPair,
) (*TestConnection, *TestConnection, error)

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

func (coord *Coordinator) ConnOpenTryWithProxy(
	source, counterparty *TestChain,
	sourceConnection, counterpartyConnection *TestConnection,
	proxies ProxyPair,
) error

func (*Coordinator) CreateChannel

func (coord *Coordinator) CreateChannel(
	chainA, chainB *TestChain,
	connA, connB *TestConnection,
	sourcePortID, counterpartyPortID string,
	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) CreateChannelWithProxy

func (coord *Coordinator) CreateChannelWithProxy(
	chainA, chainB *TestChain,
	connA, connB *TestConnection,
	sourcePortID, counterpartyPortID string,
	order channeltypes.Order,
	proxies ProxyPair,
) (*TestChannel, *TestChannel)

func (*Coordinator) CreateClient

func (coord *Coordinator) CreateClient(
	source, counterparty *TestChain,
	clientType string,
) (clientID string, err error)

CreateClient creates a counterparty client on the source chain and returns the clientID.

func (*Coordinator) CreateClient2

func (coord *Coordinator) CreateClient2(
	source, counterparty *TestChain,
	clientType string, useMultiV bool, depth uint32,
) (clientID string, err error)

func (*Coordinator) CreateConnection

func (coord *Coordinator) CreateConnection(
	chainA, chainB *TestChain,
	clientA, clientB string,
	nextChannelVersion 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) CreateConnectionWithProxy

func (coord *Coordinator) CreateConnectionWithProxy(
	chainA, chainB *TestChain,
	clientA, clientB string,
	nextChannelVersion string,
	proxies ProxyPair,
) (*TestConnection, *TestConnection)

func (*Coordinator) CreateMockChannels

func (coord *Coordinator) CreateMockChannels(
	chainA, chainB *TestChain,
	connA, connB *TestConnection,
	order channeltypes.Order,
) (TestChannel, TestChannel)

CreateMockChannels constructs and executes channel handshake messages to create OPEN channels that use a mock application module that returns nil on all callbacks. This function is expects the channels to be successfully opened otherwise testing will fail.

func (*Coordinator) CreateMultiVClient

func (coord *Coordinator) CreateMultiVClient(
	source, counterparty *TestChain,
	clientType string, depth uint32,
) (string, error)

func (*Coordinator) CreateProxyClient

func (coord *Coordinator) CreateProxyClient(downstream, proxy *TestChain, clientType string, upstreamClientID string) (string, error)

func (*Coordinator) CreateTransferChannels

func (coord *Coordinator) CreateTransferChannels(
	chainA, chainB *TestChain,
	connA, connB *TestConnection,
	order channeltypes.Order,
) (TestChannel, TestChannel)

CreateTransferChannels constructs and executes channel handshake messages to create OPEN ibc-transfer channels on chainA and chainB. The function expects the channels 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) IncrementClientSequence

func (coord *Coordinator) IncrementClientSequence(
	source, counterparty *TestChain,
	clientType string, num int,
) error

IncrementClientSequence creates a given number of clients. It's useful if you want to use different clientIDs across chains for testing purposes.

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

func (coord *Coordinator) RecvPacket(
	source, counterparty *TestChain,
	sourceClient string,
	packet channeltypes.Packet,
) error

RecvPacket receives a channel packet on the counterparty chain and updates the client on the source chain representing the counterparty.

func (*Coordinator) RecvPacketWithProxy

func (coord *Coordinator) RecvPacketWithProxy(
	source, counterparty *TestChain,
	sourceConnection, counterpartyConnection *TestConnection,
	packet channeltypes.Packet, proxies ProxyPair,
) error

func (*Coordinator) RelayPacket

func (coord *Coordinator) RelayPacket(
	source, counterparty *TestChain,
	sourceClient, counterpartyClient string,
	packet channeltypes.Packet, ack []byte,
) error

RelayPacket receives a channel packet on counterparty, queries the ack and acknowledges the packet on source. The clients are updated as needed.

func (*Coordinator) SendMsg

func (coord *Coordinator) SendMsg(source, counterparty *TestChain, counterpartyClientID string, msg sdk.Msg) error

SendMsg delivers a single provided message to the chain. The counterparty client is update with the new source consensus state.

func (*Coordinator) SendMsgs

func (coord *Coordinator) SendMsgs(source, counterparty *TestChain, counterpartyClientID string, msgs []sdk.Msg) error

SendMsgs delivers the provided messages to the chain. The counterparty client is updated with the new source consensus state.

func (*Coordinator) SendPacket

func (coord *Coordinator) SendPacket(
	source, counterparty *TestChain,
	packet exported.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) SendPacketWithProxy

func (coord *Coordinator) SendPacketWithProxy(
	source, counterparty *TestChain,
	sourceConnection, counterpartyConnection *TestConnection,
	proxies ProxyPair,
	msgs ...sdk.Msg,
) error

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, order channeltypes.Order,
) (string, string, *TestConnection, *TestConnection, TestChannel, TestChannel)

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

func (coord *Coordinator) SetupClientConnections(
	chainA, chainB *TestChain,
	clientType string,
	nextChannelVersion string,
) (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 string,
) (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 string,
) (err error)

UpdateClient updates a counterparty client on the source chain.

func (*Coordinator) UpdateClients

func (coord *Coordinator) UpdateClients(chains []*TestChain, clientIDs []string, clientType string) error

func (*Coordinator) UpdateMultiVClient

func (coord *Coordinator) UpdateMultiVClient(
	source, counterparty *TestChain,
	clientID string,
) error

func (*Coordinator) WriteAcknowledgement

func (coord *Coordinator) WriteAcknowledgement(
	source, counterparty *TestChain,
	packet exported.PacketI,
	counterpartyClientID string,
) error

WriteAcknowledgement writes an acknowledgement to the channel keeper on the source chain and updates the counterparty client for the source chain.

type ProxyInfo

type ProxyInfo struct {
	Chain            *TestChain
	ClientID         string
	UpstreamClientID string
	UpstreamPrefix   exported.Prefix
}

type ProxyPair

type ProxyPair [2]*ProxyInfo

func (ProxyPair) Swap

func (pair ProxyPair) Swap() ProxyPair

type Solomachine

type Solomachine struct {
	ClientID    string
	PrivateKeys []cryptotypes.PrivKey // keys used for signing
	PublicKeys  []cryptotypes.PubKey  // keys used for generating solo machine pub key
	PublicKey   cryptotypes.PubKey    // key used for verification
	Sequence    uint64
	Time        uint64
	Diversifier string
	// contains filtered or unexported fields
}

Solomachine is a testing helper used to simulate a counterparty solo machine client.

func NewSolomachine

func NewSolomachine(t *testing.T, cdc codec.BinaryCodec, clientID, diversifier string, nKeys uint64) *Solomachine

NewSolomachine returns a new solomachine instance with an `nKeys` amount of generated private/public key pairs and a sequence starting at 1. If nKeys is greater than 1 then a multisig public key is used.

func (*Solomachine) ClientState

func (solo *Solomachine) ClientState() *solomachinetypes.ClientState

ClientState returns a new solo machine ClientState instance. Default usage does not allow update after governance proposal

func (*Solomachine) ConsensusState

func (solo *Solomachine) ConsensusState() *solomachinetypes.ConsensusState

ConsensusState returns a new solo machine ConsensusState instance

func (*Solomachine) CreateHeader

func (solo *Solomachine) CreateHeader() *solomachinetypes.Header

CreateHeader generates a new private/public key pair and creates the necessary signature to construct a valid solo machine header.

func (*Solomachine) CreateMisbehaviour

func (solo *Solomachine) CreateMisbehaviour() *solomachinetypes.Misbehaviour

CreateMisbehaviour constructs testing misbehaviour for the solo machine client by signing over two different data bytes at the same sequence.

func (*Solomachine) GenerateSignature

func (solo *Solomachine) GenerateSignature(signBytes []byte) []byte

GenerateSignature uses the stored private keys to generate a signature over the sign bytes with each key. If the amount of keys is greater than 1 then a multisig data type is returned.

func (*Solomachine) GetChannelStatePath

func (solo *Solomachine) GetChannelStatePath(portID, channelID string) commitmenttypes.MerklePath

GetChannelStatePath returns the commitment path for that channel state.

func (*Solomachine) GetClientStatePath

func (solo *Solomachine) GetClientStatePath(counterpartyClientIdentifier string) commitmenttypes.MerklePath

GetClientStatePath returns the commitment path for the client state.

func (*Solomachine) GetConnectionStatePath

func (solo *Solomachine) GetConnectionStatePath(connID string) commitmenttypes.MerklePath

GetConnectionStatePath returns the commitment path for the connection state.

func (*Solomachine) GetConsensusStatePath

func (solo *Solomachine) GetConsensusStatePath(counterpartyClientIdentifier string, consensusHeight exported.Height) commitmenttypes.MerklePath

GetConsensusStatePath returns the commitment path for the consensus state.

func (*Solomachine) GetHeight

func (solo *Solomachine) GetHeight() exported.Height

GetHeight returns an exported.Height with Sequence as RevisionHeight

func (*Solomachine) GetNextSequenceRecvPath

func (solo *Solomachine) GetNextSequenceRecvPath(portID, channelID string) commitmenttypes.MerklePath

GetNextSequenceRecvPath returns the commitment path for the next sequence recv counter.

func (*Solomachine) GetPacketAcknowledgementPath

func (solo *Solomachine) GetPacketAcknowledgementPath(portID, channelID string) commitmenttypes.MerklePath

GetPacketAcknowledgementPath returns the commitment path for a packet acknowledgement.

func (*Solomachine) GetPacketCommitmentPath

func (solo *Solomachine) GetPacketCommitmentPath(portID, channelID string) commitmenttypes.MerklePath

GetPacketCommitmentPath returns the commitment path for a packet commitment.

func (*Solomachine) GetPacketReceiptPath

func (solo *Solomachine) GetPacketReceiptPath(portID, channelID string) commitmenttypes.MerklePath

GetPacketReceiptPath returns the commitment path for a packet receipt and an absent receipts.

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 {
	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

	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

func NewTestChain(t *testing.T, 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 (*TestChain) AddTestChannel

func (chain *TestChain) AddTestChannel(conn *TestConnection, portID string) TestChannel

AddTestChannel appends a new TestChannel which contains references to the port and channel ID used for channel creation and interaction. See 'NextTestChannel' for channel ID naming format.

func (*TestChain) AddTestConnection

func (chain *TestChain) AddTestConnection(clientID, counterpartyClientID, nextChannelVersion 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) ConnectionOpenAckWithProxy

func (chain *TestChain) ConnectionOpenAckWithProxy(
	counterparty *TestChain,
	connection, counterpartyConnection *TestConnection,
	counterpartyProxy ProxyInfo,
) error

chain: c0, counterparty: c1, counterpartyProxy: p1 verification:

c0 -> c1
c1 -> p1 -> c0

multi-proof: c0 -> c1 (head)-> p1 (leaf)-> c0

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

func (chain *TestChain) ConnectionOpenTryWithProxy(
	counterparty *TestChain,
	connection, counterpartyConnection *TestConnection,
	counterpartyProxy ProxyInfo,
) error

chain: c1, counterparty: c0, counterpartyProxy: p0 verification:

c0 -> p0 -> c1
c1 -> c0

multi-proof: c1 -> c0 (head)-> p0 (leaf)-> c1

func (*TestChain) ConstructMsgCreateClient

func (chain *TestChain) ConstructMsgCreateClient(counterparty *TestChain, clientID string, clientType string) *clienttypes.MsgCreateClient

ConstructMsgCreateClient constructs a message to create a new client state (tendermint or solomachine). NOTE: a solo machine client will be created with an empty diversifier.

func (*TestChain) ConstructNextTestConnection

func (chain *TestChain) ConstructNextTestConnection(clientID, counterpartyClientID, nextChannelVersion string) *TestConnection

ConstructNextTestConnection constructs the next test connection to be created given a clientID and counterparty clientID. The connection id format: <chainID>-conn<index>

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

func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.ScopedKeeper, portID, channelID string)

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

func (chain *TestChain) CreateMultiVClient(
	counterparty *TestChain,
	clientID string,
	clientType string,
	depth uint32,
) error

func (*TestChain) CreatePortCapability

func (chain *TestChain) CreatePortCapability(portID string)

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. NOTE: only creation of a capbility for a transfer or mock port is supported Other applications must bind to the port in InitGenesis or modify this code.

func (*TestChain) CreateProxyClient

func (chain *TestChain) CreateProxyClient(proxy *TestChain, clientType string, clientID string, upstreamClientID string) error

func (*TestChain) CreateTMClient

func (chain *TestChain) CreateTMClient(counterparty *TestChain, clientID string) error

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(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) ExpireClient

func (chain *TestChain) ExpireClient(amount time.Duration)

ExpireClient fast forwards the chain's block time by the provided amount of time which will expire any clients with a trusting period less than or equal to this amount of time.

func (*TestChain) GetAcknowledgement

func (chain *TestChain) GetAcknowledgement(packet exported.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) exported.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) GetConsensusState

func (chain *TestChain) GetConsensusState(clientID string, height exported.Height) (exported.ConsensusState, bool)

GetConsensusState retrieves the consensus state for the provided clientID and height. It will return a success boolean depending on if consensus state exists or not.

func (*TestChain) GetContext

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

GetContext returns the current context for the application.

func (*TestChain) GetPacketData

func (chain *TestChain) GetPacketData(counterparty *TestChain) []byte

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

func (chain *TestChain) GetProxyChannel(
	upstreamPrefix exported.Prefix,
	upstreamClientID string,
	portID, channelID string,
) channeltypes.Channel

func (*TestChain) GetProxyConnection

func (chain *TestChain) GetProxyConnection(
	upstreamPrefix exported.Prefix,
	upstreamClientID string,
	connectionID string,
) connectiontypes.ConnectionEnd

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

func (chain *TestChain) NewClientID(clientType string) string

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

func (chain *TestChain) NextTestChannel(conn *TestConnection, portID string) 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.

channel ID format: <connectionid>-chan<channel-index>

The port is passed in by the caller.

func (*TestChain) QueryAnyClientStateProof

func (chain *TestChain) QueryAnyClientStateProof(clientID string) (*codectypes.Any, exported.Height, []byte)

func (*TestChain) QueryAnyConsensusStateProof

func (chain *TestChain) QueryAnyConsensusStateProof(clientID string) (*codectypes.Any, []byte, clienttypes.Height)

func (*TestChain) QueryClientStateProof

func (chain *TestChain) QueryClientStateProof(clientID string) (exported.ClientState, []byte)

QueryClientStateProof performs and abci query for a client state stored with a given clientID and returns the ClientState along with the proof

func (*TestChain) QueryConsensusStateProof

func (chain *TestChain) QueryConsensusStateProof(clientID string) ([]byte, clienttypes.Height)

QueryConsensusStateProof performs an abci query for a consensus state stored on the given clientID. The proof and consensusHeight are returned.

func (*TestChain) QueryMultiVBranchProof

func (chain *TestChain) QueryMultiVBranchProof(clientID string) *multivtypes.Proof

func (*TestChain) QueryMultiVLeafClientProof

func (chain *TestChain) QueryMultiVLeafClientProof(head *multivtypes.Proof, upstreamClientID string) (exported.ClientState, []byte)

func (*TestChain) QueryMultiVLeafConsensusProof

func (chain *TestChain) QueryMultiVLeafConsensusProof(head *multivtypes.Proof, upstreamClientID string) (exported.ConsensusState, []byte, clienttypes.Height)

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

func (chain *TestChain) QueryProxyAcknowledgementProof(destPort, destChannel string, packetSequence uint64, upstreamPrefix exported.Prefix, upstreamClientID string) ([]byte, clienttypes.Height)

func (*TestChain) QueryProxyChannelStateProof

func (chain *TestChain) QueryProxyChannelStateProof(portID string, channelID string, upstreamPrefix exported.Prefix, upstreamClientID string) ([]byte, clienttypes.Height)

func (*TestChain) QueryProxyClientStateProof

func (chain *TestChain) QueryProxyClientStateProof(clientID string, upstreamPrefix exported.Prefix, upstreamClientID string) (exported.ClientState, []byte)

func (*TestChain) QueryProxyConnectionStateProof

func (chain *TestChain) QueryProxyConnectionStateProof(connectionID string, upstreamPrefix exported.Prefix, upstreamClientID string) ([]byte, clienttypes.Height)

func (*TestChain) QueryProxyConsensusStateProof

func (chain *TestChain) QueryProxyConsensusStateProof(clientID string, upstreamPrefix exported.Prefix, upstreamClientID string) ([]byte, clienttypes.Height)

func (*TestChain) QueryProxyPacketCommitmentProof

func (chain *TestChain) QueryProxyPacketCommitmentProof(sourcePort, sourceChannel string, packetSequence uint64, upstreamPrefix exported.Prefix, upstreamClientID string) ([]byte, clienttypes.Height)

func (*TestChain) QueryProxyProof

func (chain *TestChain) QueryProxyProof(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) QueryUpgradeProof

func (chain *TestChain) QueryUpgradeProof(key []byte, height uint64) ([]byte, clienttypes.Height)

QueryUpgradeProof 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) SendMsgs

func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error)

SendMsgs delivers a transaction through the application. It updates the senders sequence number and updates the TestChain's headers. It returns the result and error if one occurred.

func (*TestChain) SendPacket

func (chain *TestChain) SendPacket(
	packet exported.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.

func (*TestChain) UpdateMultiVClient

func (chain *TestChain) UpdateMultiVClient(
	counterparty *TestChain,
	clientID string,
) error

func (*TestChain) UpdateProxyClient

func (chain *TestChain) UpdateProxyClient(proxy *TestChain, proxyClientID string) error

func (*TestChain) UpdateTMClient

func (chain *TestChain) UpdateTMClient(counterparty *TestChain, clientID string) error

UpdateTMClient will construct and execute a 07-tendermint MsgUpdateClient. The counterparty client will be updated on the (target) chain. UpdateTMClient mocks the relayer flow necessary for updating a Tendermint client.

func (*TestChain) WriteAcknowledgement

func (chain *TestChain) WriteAcknowledgement(
	packet exported.PacketI,
) error

WriteAcknowledgement simulates writing an acknowledgement to the chain.

type TestChannel

type TestChannel struct {
	PortID               string
	ID                   string
	ClientID             string
	CounterpartyClientID string
	Version              string
}

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
	NextChannelVersion   string
	Channels             []TestChannel
}

TestConnection is a testing helper struct to keep track of the connectionID, source clientID, counterparty clientID, and the next channel version used in creating and interacting with a connection.

func (*TestConnection) FirstOrNextTestChannel

func (conn *TestConnection) FirstOrNextTestChannel(portID string) 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.

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 SetupTestingApp

func SetupTestingApp() (TestingApp, map[string]json.RawMessage)

func SetupWithGenesisValSet

func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, 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.

Directories

Path Synopsis
This package is only intended to be used for testing core IBC.
This package is only intended to be used for testing core IBC.
params
Package params defines the simulation parameters in the simapp.
Package params defines the simulation parameters in the simapp.

Jump to

Keyboard shortcuts

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