ibctesting

package
v0.0.0-...-5628e88 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

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

type TestChain struct {
	App TestingApp

	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
	// 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) *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) ChainID

func (chain *TestChain) ChainID() string

func (*TestChain) ChannelOpenAck

func (chain *TestChain) ChannelOpenAck(ctx context.Context, msg ibctestingtypes.MsgChannelOpenAck) error

func (*TestChain) ChannelOpenConfirm

func (chain *TestChain) ChannelOpenConfirm(ctx context.Context, msg ibctestingtypes.MsgChannelOpenConfirm) error

func (*TestChain) ChannelOpenInit

func (chain *TestChain) ChannelOpenInit(ctx context.Context, msg ibctestingtypes.MsgChannelOpenInit) (string, error)

func (*TestChain) ChannelOpenTry

func (chain *TestChain) ChannelOpenTry(ctx context.Context, msg ibctestingtypes.MsgChannelOpenTry) (string, error)

func (*TestChain) ChannelStateCommitmentKey

func (chain *TestChain) ChannelStateCommitmentKey(portID, channelID string) []byte

func (*TestChain) ClientStateCommitmentKey

func (chain *TestChain) ClientStateCommitmentKey(clientID string) []byte

func (*TestChain) ConnectionOpenAck

func (chain *TestChain) ConnectionOpenAck(ctx context.Context, msg ibctestingtypes.MsgConnectionOpenAck) error

func (*TestChain) ConnectionOpenConfirm

func (chain *TestChain) ConnectionOpenConfirm(ctx context.Context, msg ibctestingtypes.MsgConnectionOpenConfirm) error

func (*TestChain) ConnectionOpenInit

func (chain *TestChain) ConnectionOpenInit(ctx context.Context, msg ibctestingtypes.MsgConnectionOpenInit) (string, error)

func (*TestChain) ConnectionOpenTry

func (chain *TestChain) ConnectionOpenTry(ctx context.Context, msg ibctestingtypes.MsgConnectionOpenTry) (string, error)

func (*TestChain) ConnectionStateCommitmentKey

func (chain *TestChain) ConnectionStateCommitmentKey(connectionID string) []byte

func (*TestChain) ConsensusStateCommitmentKey

func (chain *TestChain) ConsensusStateCommitmentKey(clientID string, height exported.Height) []byte

func (*TestChain) ConstructMockMsgCreateClient

func (chain *TestChain) ConstructMockMsgCreateClient() ibctestingtypes.MsgCreateClient

func (*TestChain) ConstructMockMsgUpdateClient

func (chain *TestChain) ConstructMockMsgUpdateClient(clientID string) ibctestingtypes.MsgUpdateClient

func (*TestChain) ConstructTendermintMsgCreateClient

func (chain *TestChain) ConstructTendermintMsgCreateClient(
	trustLevel ibctmtypes.Fraction,
	trustingPeriod, unbondingPeriod, maxClockDrift time.Duration,
	upgradePath []string, allowUpdateAfterExpiry, allowUpdateAfterMisbehaviour bool) ibctestingtypes.MsgCreateClient

func (*TestChain) ConstructTendermintUpdateTMClientHeader

func (chain *TestChain) ConstructTendermintUpdateTMClientHeader(
	counterparty ibctestingtypes.TestChainI,
	clientID string,
) ibctestingtypes.MsgUpdateClient

func (*TestChain) ConstructTrustedEthereumMsgCreateClient

func (chain *TestChain) ConstructTrustedEthereumMsgCreateClient(
	publicKey cryptotypes.PubKey,
	diversifier string,
) ibctestingtypes.MsgCreateClient

func (*TestChain) ConstructTrustedEthereumMsgUpdateClient

func (chain *TestChain) ConstructTrustedEthereumMsgUpdateClient(
	clientID string,
	privateKey cryptotypes.PrivKey,
	divisifier string,
) ibctestingtypes.MsgUpdateClient

func (*TestChain) ConstructUpdateTMClientHeader

func (chain *TestChain) ConstructUpdateTMClientHeader(counterparty ibctestingtypes.TestChainI, 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 ibctestingtypes.TestChainI, 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) 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. The scoped keeper passed in will claim the new capability.

func (*TestChain) CreateClient

func (chain *TestChain) CreateClient(ctx context.Context, msg ibctestingtypes.MsgCreateClient) (string, error)

func (*TestChain) CreatePortCapability

func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.ScopedKeeper, 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) 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) 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) 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) GetClientStateBytes

func (chain *TestChain) GetClientStateBytes(clientID string) []byte

GetClientStateBytes retrieves the client state for the provided clientID. The client is expected to exist otherwise testing will fail.

func (*TestChain) GetCommitmentPrefix

func (chain *TestChain) GetCommitmentPrefix() []byte

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

func (chain *TestChain) GetLatestHeight(clientID string, clientType string) exported.Height

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

func (chain *TestChain) GetSenderAddress() string

func (*TestChain) GetSimApp

func (chain *TestChain) GetSimApp() *simapp.SimApp

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

func (chain *TestChain) HandlePacketAcknowledgement(ctx context.Context, packet exported.PacketI, acknowledgement []byte, proof *ibctestingtypes.Proof) error

func (*TestChain) HandlePacketRecv

func (chain *TestChain) HandlePacketRecv(ctx context.Context, packet exported.PacketI, proof *ibctestingtypes.Proof) error

func (*TestChain) Init

func (chain *TestChain) Init(chainID string) error

func (*TestChain) MockAcknowledgementProof

func (chain *TestChain) MockAcknowledgementProof(ack []byte, proof *ibctestingtypes.Proof) (*ibctestingtypes.Proof, error)

func (*TestChain) MockChannelProof

func (chain *TestChain) MockChannelProof(portID string, channelID string, proof *ibctestingtypes.Proof) (*ibctestingtypes.Proof, error)

func (*TestChain) MockConnectionProof

func (chain *TestChain) MockConnectionProof(connectionID string, proof *ibctestingtypes.Proof) (*ibctestingtypes.Proof, error)

func (*TestChain) MockPacketProof

func (chain *TestChain) MockPacketProof(packet exported.PacketI, proof *ibctestingtypes.Proof) (*ibctestingtypes.Proof, error)

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.

CONTRACT: this function must only be called after app.Commit() occurs

func (*TestChain) PacketAcknowledgementCommitmentKey

func (chain *TestChain) PacketAcknowledgementCommitmentKey(portID, channelID string, sequence uint64) []byte

func (*TestChain) PacketCommitmentKey

func (chain *TestChain) PacketCommitmentKey(portID, channelID string, sequence uint64) []byte

func (*TestChain) QueryProofAtHeight

func (chain *TestChain) QueryProofAtHeight(key []byte, height exported.Height, clientType string) (*ibctestingtypes.Proof, error)

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

func (chain *TestChain) T() *testing.T

func (*TestChain) UpdateClient

func (chain *TestChain) UpdateClient(ctx context.Context, msg ibctestingtypes.MsgUpdateClient) error

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