testing

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultChannelVersion        = "ics20-1"
	BlockTime             uint64 = 1000 * 1000 * 1000 // 1[sec]
	DefaultDelayPeriod    uint64 = 3 * BlockTime
	DefaultPrefix                = "ibc"
	TransferPort                 = "transfer"

	RelayerKeyIndex uint32 = 0
)

Variables

This section is empty.

Functions

func MarshalWithAny

func MarshalWithAny(msg proto.Message) ([]byte, error)

func PackAny

func PackAny(msg proto.Message) (*types.Any, error)

func UnmarshalWithAny

func UnmarshalWithAny(bz []byte, msg proto.Message) error

func UnpackAny

func UnpackAny(bz []byte) (*types.Any, error)

Types

type BroadcastLog added in v0.3.5

type BroadcastLog struct {
	Transactions []Transaction `json:"transactions"`
}

type Chain

type Chain struct {
	ContractConfig ContractConfig

	// Core Modules
	IBCHandler    ibchandler.Ibchandler
	IBCCommitment ibccommitment.Ibccommitmenttesthelper

	// App Modules
	ERC20         erc20.Erc20
	ICS20Transfer ics20transferbank.Ics20transferbank
	ICS20Bank     ics20bank.Ics20bank

	// State
	LastLCState LightClientState

	// 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
}

func NewChain

func NewChain(t *testing.T, client *client.ETHClient, lc *LightClient) *Chain

func (*Chain) AddTestChannel

func (chain *Chain) 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 (*Chain) AddTestConnection

func (chain *Chain) AddTestConnection(clientID, counterpartyClientID string) *TestConnection

AddTestConnection appends a new TestConnection which contains references to the connection id, client id and counterparty client id.

func (*Chain) CallOpts

func (chain *Chain) CallOpts(ctx context.Context, index uint32) *bind.CallOpts

func (*Chain) ChainID

func (chain *Chain) ChainID() int64

func (*Chain) ChainIDString

func (chain *Chain) ChainIDString() string

func (*Chain) ChannelCloseConfirm

func (chain *Chain) ChannelCloseConfirm(
	ctx context.Context,
	counterparty *Chain,
	ch, counterpartyCh TestChannel,
) error

func (*Chain) ChannelCloseInit

func (chain *Chain) ChannelCloseInit(
	ctx context.Context,
	ch TestChannel,
) error

func (*Chain) ChannelOpenAck

func (chain *Chain) ChannelOpenAck(
	ctx context.Context,
	counterparty *Chain,
	ch, counterpartyCh TestChannel,
) error

func (*Chain) ChannelOpenConfirm

func (chain *Chain) ChannelOpenConfirm(
	ctx context.Context,
	counterparty *Chain,
	ch, counterpartyCh TestChannel,
) error

func (*Chain) ChannelOpenInit

func (chain *Chain) ChannelOpenInit(
	ctx context.Context,
	ch, counterparty TestChannel,
	order channeltypes.Channel_Order,
	connectionID string,
) (string, error)

func (*Chain) ChannelOpenTry

func (chain *Chain) ChannelOpenTry(
	ctx context.Context,
	counterparty *Chain,
	ch, counterpartyCh TestChannel,
	order channeltypes.Channel_Order,
	connectionID string,
) (string, error)

func (*Chain) Client

func (chain *Chain) Client() *client.ETHClient

func (*Chain) ClientType

func (chain *Chain) ClientType() string

func (*Chain) ConnectionOpenAck

func (chain *Chain) ConnectionOpenAck(
	ctx context.Context,
	counterparty *Chain,
	connection, counterpartyConnection *TestConnection,
) error

ConnectionOpenAck will construct and execute a MsgConnectionOpenAck.

func (*Chain) ConnectionOpenConfirm

func (chain *Chain) ConnectionOpenConfirm(
	ctx context.Context,
	counterparty *Chain,
	connection, counterpartyConnection *TestConnection,
) error

func (*Chain) ConnectionOpenInit

func (chain *Chain) ConnectionOpenInit(ctx context.Context, counterparty *Chain, connection, counterpartyConnection *TestConnection) (string, error)

func (*Chain) ConnectionOpenTry

func (chain *Chain) ConnectionOpenTry(ctx context.Context, counterparty *Chain, connection, counterpartyConnection *TestConnection) (string, error)

func (*Chain) ConstructIBFT2MsgCreateClient

func (chain *Chain) ConstructIBFT2MsgCreateClient(counterparty *Chain) ibchandler.IBCMsgsMsgCreateClient

func (*Chain) ConstructIBFT2MsgUpdateClient

func (chain *Chain) ConstructIBFT2MsgUpdateClient(counterparty *Chain, clientID string) ibchandler.IBCMsgsMsgUpdateClient

func (*Chain) ConstructMockMsgCreateClient

func (chain *Chain) ConstructMockMsgCreateClient(counterparty *Chain) ibchandler.IBCMsgsMsgCreateClient

func (*Chain) ConstructMockMsgUpdateClient

func (chain *Chain) ConstructMockMsgUpdateClient(counterparty *Chain, clientID string) ibchandler.IBCMsgsMsgUpdateClient

func (*Chain) ConstructNextTestConnection

func (chain *Chain) ConstructNextTestConnection(clientID, counterpartyClientID string) *TestConnection

ConstructNextTestConnection constructs the next test connection to be created given a clientID and counterparty clientID.

func (*Chain) CreateIBFT2Client

func (chain *Chain) CreateIBFT2Client(ctx context.Context, counterparty *Chain) (string, error)

func (*Chain) CreateMockClient

func (chain *Chain) CreateMockClient(ctx context.Context, counterparty *Chain) (string, error)

func (*Chain) FindPacket

func (chain *Chain) FindPacket(
	ctx context.Context,
	sourcePortID string,
	sourceChannel string,
	sequence uint64,
) (*channeltypes.Packet, error)

func (*Chain) GetCommitmentPrefix

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

func (*Chain) GetIBFT2ClientState

func (chain *Chain) GetIBFT2ClientState(clientID string) *ibft2clienttypes.ClientState

func (*Chain) GetIBFT2ConsensusState added in v0.3.0

func (chain *Chain) GetIBFT2ConsensusState(clientID string, height ibcclient.Height) *ibft2clienttypes.ConsensusState

func (*Chain) GetLastGeneratedChannelID

func (chain *Chain) GetLastGeneratedChannelID(
	ctx context.Context,
) (string, error)

func (*Chain) GetLastGeneratedClientID

func (chain *Chain) GetLastGeneratedClientID(
	ctx context.Context,
) (string, error)

func (*Chain) GetLastGeneratedConnectionID

func (chain *Chain) GetLastGeneratedConnectionID(
	ctx context.Context,
) (string, error)

func (*Chain) GetLastSentPacket

func (chain *Chain) GetLastSentPacket(
	ctx context.Context,
	sourcePortID string,
	sourceChannel string,
) (*channeltypes.Packet, error)

func (*Chain) GetLightClientState added in v0.2.0

func (chain *Chain) GetLightClientState(counterparty *Chain, counterpartyClientID string, storageKeys [][]byte, height *big.Int) (LightClientState, error)

func (*Chain) GetMockClientState

func (chain *Chain) GetMockClientState(clientID string) *mockclienttypes.ClientState

func (*Chain) HandlePacketAcknowledgement

func (chain *Chain) HandlePacketAcknowledgement(
	ctx context.Context,
	counterparty *Chain,
	ch, counterpartyCh TestChannel,
	packet channeltypes.Packet,
	acknowledgement []byte,
) error

func (*Chain) HandlePacketRecv

func (chain *Chain) HandlePacketRecv(
	ctx context.Context,
	counterparty *Chain,
	ch, counterpartyCh TestChannel,
	packet channeltypes.Packet,
) error

func (*Chain) LastHeader

func (chain *Chain) LastHeader() *gethtypes.Header

func (*Chain) NextTestChannel

func (chain *Chain) 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.

The port is passed in by the caller.

func (*Chain) QueryChannelProof

func (counterparty *Chain) QueryChannelProof(chain *Chain, counterpartyClientID string, channel TestChannel, height *big.Int) (*Proof, error)

func (*Chain) QueryClientProof

func (counterparty *Chain) QueryClientProof(chain *Chain, counterpartyClientID string, height *big.Int) ([]byte, *Proof, error)

func (*Chain) QueryConnectionProof

func (counterparty *Chain) QueryConnectionProof(chain *Chain, counterpartyClientID string, counterpartyConnectionID string, height *big.Int) (*Proof, error)

func (*Chain) QueryProof

func (chain *Chain) QueryProof(counterparty *Chain, counterpartyClientID string, storageKey string, height *big.Int) (*Proof, error)

func (*Chain) SendPacket

func (chain *Chain) SendPacket(
	ctx context.Context,
	packet channeltypes.Packet,
) error

func (*Chain) TxOpts

func (chain *Chain) TxOpts(ctx context.Context, index uint32) *bind.TransactOpts

func (*Chain) UpdateHeader

func (chain *Chain) UpdateHeader()

func (*Chain) UpdateIBFT2Client

func (chain *Chain) UpdateIBFT2Client(ctx context.Context, counterparty *Chain, clientID string) error

func (*Chain) UpdateMockClient

func (chain *Chain) UpdateMockClient(ctx context.Context, counterparty *Chain, clientID string) error

func (*Chain) WaitForReceiptAndGet

func (chain *Chain) WaitForReceiptAndGet(ctx context.Context, tx *gethtypes.Transaction) error

func (*Chain) WaitIfNoError

func (chain *Chain) WaitIfNoError(ctx context.Context) func(tx *gethtypes.Transaction, err error) error

type ContractConfig

type ContractConfig struct {
	IBCHandlerAddress              common.Address
	ICS20TransferBankAddress       common.Address
	ICS20BankAddress               common.Address
	IBCCommitmentTestHelperAddress common.Address
	ERC20TokenAddress              common.Address
}

func (*ContractConfig) Validate added in v0.3.5

func (cc *ContractConfig) Validate() error

type Coordinator

type Coordinator struct {
	// contains filtered or unexported fields
}

func NewCoordinator

func NewCoordinator(t *testing.T, chains ...*Chain) Coordinator

func (*Coordinator) ChanCloseConfirm

func (c *Coordinator) ChanCloseConfirm(
	ctx context.Context,
	source, counterparty *Chain,
	sourceChannel, counterpartyChannel TestChannel,
) error

ChanCloseConfirm confirms closing of a channel on chain A to chain B, after which the channel is closed on both chains (this code is executed on chain B).

func (*Coordinator) ChanCloseInit

func (c *Coordinator) ChanCloseInit(
	ctx context.Context,
	source, counterparty *Chain,
	sourceChannel TestChannel,
) error

ChanCloseInit closes a channel on chain A to chain B (this code is executed on chain A).

func (*Coordinator) ChanOpenAck

func (c *Coordinator) ChanOpenAck(
	ctx context.Context,
	source, counterparty *Chain,
	sourceChannel, counterpartyChannel TestChannel,
) error

ChanOpenAck relays acceptance of a channel open attempt from chain B back to chain A (this code is executed on chain A).

func (*Coordinator) ChanOpenConfirm

func (c *Coordinator) ChanOpenConfirm(
	ctx context.Context,
	source, counterparty *Chain,
	sourceChannel, counterpartyChannel TestChannel,
) error

ChanOpenConfirm confirms opening of a channel on chain A to chain B, after which the channel is open on both chains (this code is executed on chain B).

func (*Coordinator) ChanOpenInit

func (c *Coordinator) ChanOpenInit(
	ctx context.Context,
	source, counterparty *Chain,
	connection, counterpartyConnection *TestConnection,
	sourcePortID, counterpartyPortID string,
	order channeltypes.Channel_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 (c *Coordinator) ChanOpenTry(
	ctx context.Context,
	source, counterparty *Chain,
	sourceChannel, counterpartyChannel *TestChannel,
	connection *TestConnection,
	order channeltypes.Channel_Order,
) error

ChanOpenTry relays notice of a channel open attempt on chain A to chain B (this code is executed on chain B).

func (*Coordinator) CloseChannel

func (c *Coordinator) CloseChannel(
	ctx context.Context,
	chainA, chainB *Chain,
	chanA, chanB TestChannel,
)

CloseChannel constructs and executes channel closing messages in order to transition the channel to the CLOSED state on chainA and chainB. The function expects the channels to be successfully closed otherwise testing will fail.

func (*Coordinator) ConnOpenAck

func (c *Coordinator) ConnOpenAck(
	ctx context.Context,
	source, counterparty *Chain,
	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 (c *Coordinator) ConnOpenConfirm(
	ctx context.Context,
	source, counterparty *Chain,
	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 (c Coordinator) ConnOpenInit(
	ctx context.Context,
	source, counterparty *Chain,
	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 (c *Coordinator) ConnOpenTry(
	ctx context.Context,
	source, counterparty *Chain,
	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 (c *Coordinator) CreateChannel(
	ctx context.Context,
	chainA, chainB *Chain,
	connA, connB *TestConnection,
	sourcePortID, counterpartyPortID string,
	order channeltypes.Channel_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 (c Coordinator) CreateClient(
	ctx context.Context,
	source, counterparty *Chain,
	clientType string,
) (clientID string, err error)

func (*Coordinator) CreateConnection

func (c *Coordinator) CreateConnection(
	ctx context.Context,
	chainA, chainB *Chain,
	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 (c Coordinator) GetChain(idx int) *Chain

func (*Coordinator) HandlePacketAcknowledgement

func (c *Coordinator) HandlePacketAcknowledgement(
	ctx context.Context,
	source, counterparty *Chain,
	sourceChannel, counterpartyChannel TestChannel,
	packet channeltypes.Packet,
	acknowledgement []byte,
) error

func (*Coordinator) HandlePacketRecv

func (c *Coordinator) HandlePacketRecv(
	ctx context.Context,
	source, counterparty *Chain,
	sourceChannel, counterpartyChannel TestChannel,
	packet channeltypes.Packet,
) error

func (*Coordinator) SendPacket

func (c *Coordinator) SendPacket(
	ctx context.Context,
	source, counterparty *Chain,
	packet channeltypes.Packet,
	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) SetupClientConnections

func (coord *Coordinator) SetupClientConnections(
	ctx context.Context,
	chainA, chainB *Chain,
	clientType 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(
	ctx context.Context,
	chainA, chainB *Chain,
	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 (c Coordinator) UpdateClient(
	ctx context.Context,
	source, counterparty *Chain,
	clientID string,
) error

func (*Coordinator) UpdateHeaders

func (coord *Coordinator) UpdateHeaders()

type ETHState added in v0.2.0

type ETHState struct {
	StateProof *client.StateProof
	// contains filtered or unexported fields
}

func (ETHState) Header added in v0.2.0

func (cs ETHState) Header() *gethtypes.Header

func (ETHState) Proof added in v0.2.0

func (cs ETHState) Proof() *client.StateProof

type IBFT2State added in v0.2.0

type IBFT2State struct {
	ParsedHeader *chains.ParsedHeader
	StateProof   *client.StateProof
	CommitSeals  [][]byte
}

func (IBFT2State) ChainHeaderRLP added in v0.2.0

func (cs IBFT2State) ChainHeaderRLP() []byte

func (IBFT2State) GetCommitSeals added in v0.2.0

func (cs IBFT2State) GetCommitSeals() [][]byte

func (IBFT2State) Header added in v0.2.0

func (cs IBFT2State) Header() *gethtypes.Header

func (IBFT2State) Proof added in v0.2.0

func (cs IBFT2State) Proof() *client.StateProof

func (IBFT2State) SealingHeaderRLP added in v0.2.0

func (cs IBFT2State) SealingHeaderRLP() []byte

func (IBFT2State) Validators added in v0.2.0

func (cs IBFT2State) Validators() [][]byte

type LightClient added in v0.2.0

type LightClient struct {
	// contains filtered or unexported fields
}

func NewLightClient added in v0.2.0

func NewLightClient(cl *client.ETHClient, clientType string) *LightClient

func (LightClient) ClientType added in v0.2.0

func (lc LightClient) ClientType() string

func (LightClient) GetIBFT2State added in v0.2.0

func (lc LightClient) GetIBFT2State(ctx context.Context, address common.Address, storageKeys [][]byte, bn *big.Int) (LightClientState, error)

func (LightClient) GetMockContractState added in v0.2.0

func (lc LightClient) GetMockContractState(ctx context.Context, address common.Address, storageKeys [][]byte, bn *big.Int) (LightClientState, error)

func (LightClient) GetState added in v0.2.0

func (lc LightClient) GetState(ctx context.Context, address common.Address, storageKeys [][]byte, bn *big.Int) (LightClientState, error)

type LightClientState added in v0.2.0

type LightClientState interface {
	Header() *gethtypes.Header
	Proof() *client.StateProof
}

type Proof

type Proof struct {
	Height ibcclient.Height
	Data   []byte
}

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.

type Transaction added in v0.3.5

type Transaction struct {
	TransactionType string         `json:"transactionType"`
	ContractName    string         `json:"contractName"`
	ContractAddress common.Address `json:"contractAddress"`
}

Jump to

Keyboard shortcuts

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