diff --git a/testing/chain.go b/testing/chain.go index 58ec22b2e75..7eca368decd 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -35,9 +35,7 @@ import ( "github.com/cosmos/ibc-go/v3/testing/simapp" ) -var ( - MaxAccounts = 10 -) +var MaxAccounts = 10 type SenderAccount struct { SenderPrivKey cryptotypes.PrivKey @@ -50,7 +48,7 @@ type SenderAccount struct { // is used for delivering transactions through the application state. // NOTE: the actual application uses an empty chain-id for ease of testing. type TestChain struct { - t *testing.T + *testing.T Coordinator *Coordinator App TestingApp @@ -134,7 +132,7 @@ func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, va // create an account to send transactions from chain := &TestChain{ - t: t, + T: t, Coordinator: coord, ChainID: chainID, App: app, @@ -191,7 +189,7 @@ func (chain *TestChain) GetContext() sdk.Context { // their own SimApp. func (chain *TestChain) GetSimApp() *simapp.SimApp { app, ok := chain.App.(*simapp.SimApp) - require.True(chain.t, ok) + require.True(chain.T, ok) return app } @@ -213,10 +211,10 @@ func (chain *TestChain) QueryProofAtHeight(key []byte, height int64) ([]byte, cl }) merkleProof, err := commitmenttypes.ConvertProofs(res.ProofOps) - require.NoError(chain.t, err) + require.NoError(chain.T, err) proof, err := chain.App.AppCodec().Marshal(&merkleProof) - require.NoError(chain.t, err) + require.NoError(chain.T, err) revision := clienttypes.ParseChainID(chain.ChainID) @@ -237,10 +235,10 @@ func (chain *TestChain) QueryUpgradeProof(key []byte, height uint64) ([]byte, cl }) merkleProof, err := commitmenttypes.ConvertProofs(res.ProofOps) - require.NoError(chain.t, err) + require.NoError(chain.T, err) proof, err := chain.App.AppCodec().Marshal(&merkleProof) - require.NoError(chain.t, err) + require.NoError(chain.T, err) revision := clienttypes.ParseChainID(chain.ChainID) @@ -311,7 +309,7 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) { chain.Coordinator.UpdateTimeForChain(chain) _, r, err := simapp.SignAndDeliver( - chain.t, + chain.T, chain.TxConfig, chain.App.GetBaseApp(), chain.GetContext().BlockHeader(), @@ -340,7 +338,7 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) { // expected to exist otherwise testing will fail. func (chain *TestChain) GetClientState(clientID string) exported.ClientState { clientState, found := chain.App.GetIBCKeeper().ClientKeeper.GetClientState(chain.GetContext(), clientID) - require.True(chain.t, found) + require.True(chain.T, found) return clientState } @@ -372,7 +370,7 @@ func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bo // acknowledgement does not exist then testing will fail. func (chain *TestChain) GetAcknowledgement(packet exported.PacketI) []byte { ack, found := chain.App.GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(chain.GetContext(), packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) - require.True(chain.t, found) + require.True(chain.T, found) return ack } @@ -447,7 +445,7 @@ func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64, valSet *tmproto.ValidatorSet trustedVals *tmproto.ValidatorSet ) - require.NotNil(chain.t, tmValSet) + require.NotNil(chain.T, tmValSet) vsetHash := tmValSet.Hash() nextValHash := nextVals.Hash() @@ -533,11 +531,11 @@ func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.Scope if !ok { // create capability using the IBC capability keeper cap, err := chain.App.GetScopedIBCKeeper().NewCapability(chain.GetContext(), host.PortPath(portID)) - require.NoError(chain.t, err) + require.NoError(chain.T, err) // claim capability using the scopedKeeper err = scopedKeeper.ClaimCapability(chain.GetContext(), cap, host.PortPath(portID)) - require.NoError(chain.t, err) + require.NoError(chain.T, err) } chain.NextBlock() @@ -547,7 +545,7 @@ func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.Scope // exist, otherwise testing will fail. func (chain *TestChain) GetPortCapability(portID string) *capabilitytypes.Capability { cap, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), host.PortPath(portID)) - require.True(chain.t, ok) + require.True(chain.T, ok) return cap } @@ -561,9 +559,9 @@ func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.Sc _, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), capName) if !ok { cap, err := chain.App.GetScopedIBCKeeper().NewCapability(chain.GetContext(), capName) - require.NoError(chain.t, err) + require.NoError(chain.T, err) err = scopedKeeper.ClaimCapability(chain.GetContext(), cap, capName) - require.NoError(chain.t, err) + require.NoError(chain.T, err) } chain.NextBlock() @@ -573,7 +571,7 @@ func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.Sc // The capability must exist, otherwise testing will fail. func (chain *TestChain) GetChannelCapability(portID, channelID string) *capabilitytypes.Capability { cap, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), host.ChannelCapabilityPath(portID, channelID)) - require.True(chain.t, ok) + require.True(chain.T, ok) return cap } diff --git a/testing/coordinator.go b/testing/coordinator.go index a853cd9c077..af2ea5d5b43 100644 --- a/testing/coordinator.go +++ b/testing/coordinator.go @@ -19,7 +19,7 @@ var ( // Coordinator is a testing struct which contains N TestChain's. It handles keeping all chains // in sync with regards to time. type Coordinator struct { - t *testing.T + *testing.T CurrentTime time.Time Chains map[string]*TestChain @@ -29,7 +29,7 @@ type Coordinator struct { func NewCoordinator(t *testing.T, n int) *Coordinator { chains := make(map[string]*TestChain) coord := &Coordinator{ - t: t, + T: t, CurrentTime: globalStartTime, } @@ -84,10 +84,10 @@ func (coord *Coordinator) Setup(path *Path) { // caller does not anticipate any errors. func (coord *Coordinator) SetupClients(path *Path) { err := path.EndpointA.CreateClient() - require.NoError(coord.t, err) + require.NoError(coord.T, err) err = path.EndpointB.CreateClient() - require.NoError(coord.t, err) + require.NoError(coord.T, err) } // SetupClientConnections is a helper function to create clients and the appropriate @@ -105,16 +105,16 @@ func (coord *Coordinator) SetupConnections(path *Path) { // successfully opened otherwise testing will fail. func (coord *Coordinator) CreateConnections(path *Path) { err := path.EndpointA.ConnOpenInit() - require.NoError(coord.t, err) + require.NoError(coord.T, err) err = path.EndpointB.ConnOpenTry() - require.NoError(coord.t, err) + require.NoError(coord.T, err) err = path.EndpointA.ConnOpenAck() - require.NoError(coord.t, err) + require.NoError(coord.T, err) err = path.EndpointB.ConnOpenConfirm() - require.NoError(coord.t, err) + require.NoError(coord.T, err) // ensure counterparty is up to date path.EndpointA.UpdateClient() @@ -146,16 +146,16 @@ func (coord *Coordinator) CreateTransferChannels(path *Path) { // opened otherwise testing will fail. func (coord *Coordinator) CreateChannels(path *Path) { err := path.EndpointA.ChanOpenInit() - require.NoError(coord.t, err) + require.NoError(coord.T, err) err = path.EndpointB.ChanOpenTry() - require.NoError(coord.t, err) + require.NoError(coord.T, err) err = path.EndpointA.ChanOpenAck() - require.NoError(coord.t, err) + require.NoError(coord.T, err) err = path.EndpointB.ChanOpenConfirm() - require.NoError(coord.t, err) + require.NoError(coord.T, err) // ensure counterparty is up to date path.EndpointA.UpdateClient() @@ -165,7 +165,7 @@ func (coord *Coordinator) CreateChannels(path *Path) { // not exist. func (coord *Coordinator) GetChain(chainID string) *TestChain { chain, found := coord.Chains[chainID] - require.True(coord.t, found, fmt.Sprintf("%s chain does not exist", chainID)) + require.True(coord.T, found, fmt.Sprintf("%s chain does not exist", chainID)) return chain } diff --git a/testing/endpoint.go b/testing/endpoint.go index 962ecf5ef35..5d496494afc 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -88,7 +88,7 @@ func (endpoint *Endpoint) CreateClient() (err error) { switch endpoint.ClientConfig.GetClientType() { case exported.Tendermint: tmConfig, ok := endpoint.ClientConfig.(*TendermintConfig) - require.True(endpoint.Chain.t, ok) + require.True(endpoint.Chain.T, ok) height := endpoint.Counterparty.Chain.LastHeader.GetHeight().(clienttypes.Height) clientState = ibctmtypes.NewClientState( @@ -98,7 +98,7 @@ func (endpoint *Endpoint) CreateClient() (err error) { consensusState = endpoint.Counterparty.Chain.LastHeader.ConsensusState() case exported.Solomachine: // TODO - // solo := NewSolomachine(chain.t, endpoint.Chain.Codec, clientID, "", 1) + // solo := NewSolomachine(Chain.T, endpoint.Chain.Codec, clientID, "", 1) // clientState = solo.ClientState() // consensusState = solo.ConsensusState() @@ -113,7 +113,7 @@ func (endpoint *Endpoint) CreateClient() (err error) { msg, err := clienttypes.NewMsgCreateClient( clientState, consensusState, endpoint.Chain.SenderAccount.GetAddress().String(), ) - require.NoError(endpoint.Chain.t, err) + require.NoError(endpoint.Chain.T, err) res, err := endpoint.Chain.SendMsgs(msg) if err != nil { @@ -121,7 +121,7 @@ func (endpoint *Endpoint) CreateClient() (err error) { } endpoint.ClientID, err = ParseClientIDFromEvents(res.GetEvents()) - require.NoError(endpoint.Chain.t, err) + require.NoError(endpoint.Chain.T, err) return nil } @@ -131,9 +131,7 @@ func (endpoint *Endpoint) UpdateClient() (err error) { // ensure counterparty has committed state endpoint.Chain.Coordinator.CommitBlock(endpoint.Counterparty.Chain) - var ( - header exported.Header - ) + var header exported.Header switch endpoint.ClientConfig.GetClientType() { case exported.Tendermint: @@ -151,10 +149,9 @@ func (endpoint *Endpoint) UpdateClient() (err error) { endpoint.ClientID, header, endpoint.Chain.SenderAccount.GetAddress().String(), ) - require.NoError(endpoint.Chain.t, err) + require.NoError(endpoint.Chain.T, err) return endpoint.Chain.sendMsgs(msg) - } // ConnOpenInit will construct and execute a MsgConnectionOpenInit on the associated endpoint. @@ -171,7 +168,7 @@ func (endpoint *Endpoint) ConnOpenInit() error { } endpoint.ConnectionID, err = ParseConnectionIDFromEvents(res.GetEvents()) - require.NoError(endpoint.Chain.t, err) + require.NoError(endpoint.Chain.T, err) return nil } @@ -197,7 +194,7 @@ func (endpoint *Endpoint) ConnOpenTry() error { if endpoint.ConnectionID == "" { endpoint.ConnectionID, err = ParseConnectionIDFromEvents(res.GetEvents()) - require.NoError(endpoint.Chain.t, err) + require.NoError(endpoint.Chain.T, err) } return nil @@ -277,7 +274,7 @@ func (endpoint *Endpoint) ChanOpenInit() error { } endpoint.ChannelID, err = ParseChannelIDFromEvents(res.GetEvents()) - require.NoError(endpoint.Chain.t, err) + require.NoError(endpoint.Chain.T, err) return nil } @@ -303,7 +300,7 @@ func (endpoint *Endpoint) ChanOpenTry() error { if endpoint.ChannelID == "" { endpoint.ChannelID, err = ParseChannelIDFromEvents(res.GetEvents()) - require.NoError(endpoint.Chain.t, err) + require.NoError(endpoint.Chain.T, err) } // update version to selected app version @@ -449,7 +446,7 @@ func (endpoint *Endpoint) TimeoutPacket(packet channeltypes.Packet) error { proof, proofHeight := endpoint.Counterparty.QueryProof(packetKey) nextSeqRecv, found := endpoint.Counterparty.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextSequenceRecv(endpoint.Counterparty.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID) - require.True(endpoint.Chain.t, found) + require.True(endpoint.Chain.T, found) timeoutMsg := channeltypes.NewMsgTimeout( packet, nextSeqRecv, @@ -486,7 +483,7 @@ func (endpoint *Endpoint) SetClientState(clientState exported.ClientState) { // The consensus state is expected to exist otherwise testing will fail. func (endpoint *Endpoint) GetConsensusState(height exported.Height) exported.ConsensusState { consensusState, found := endpoint.Chain.GetConsensusState(endpoint.ClientID, height) - require.True(endpoint.Chain.t, found) + require.True(endpoint.Chain.T, found) return consensusState } @@ -500,7 +497,7 @@ func (endpoint *Endpoint) SetConsensusState(consensusState exported.ConsensusSta // connection is expected to exist otherwise testing will fail. func (endpoint *Endpoint) GetConnection() connectiontypes.ConnectionEnd { connection, found := endpoint.Chain.App.GetIBCKeeper().ConnectionKeeper.GetConnection(endpoint.Chain.GetContext(), endpoint.ConnectionID) - require.True(endpoint.Chain.t, found) + require.True(endpoint.Chain.T, found) return connection } @@ -514,7 +511,7 @@ func (endpoint *Endpoint) SetConnection(connection connectiontypes.ConnectionEnd // is expected to exist otherwise testing will fail. func (endpoint *Endpoint) GetChannel() channeltypes.Channel { channel, found := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.GetChannel(endpoint.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID) - require.True(endpoint.Chain.t, found) + require.True(endpoint.Chain.T, found) return channel }