From affe7265cb3b6bc8aa5050c5c740468b715d5d7d Mon Sep 17 00:00:00 2001 From: colin axner <25233464+colin-axner@users.noreply.github.com> Date: Wed, 10 Jun 2020 17:31:54 -0700 Subject: [PATCH] Update connection and channel to use types_test package name (#6395) * convert connection types test pacakge name * convert channel types test package name Co-authored-by: Alexander Bezobchuk --- x/ibc/03-connection/types/connection_test.go | 27 +-- x/ibc/03-connection/types/genesis_test.go | 39 ++-- x/ibc/03-connection/types/msgs_test.go | 83 +++---- x/ibc/04-channel/types/channel_test.go | 12 +- x/ibc/04-channel/types/genesis_test.go | 96 +++++---- x/ibc/04-channel/types/msgs_test.go | 215 ++++++++++--------- x/ibc/04-channel/types/packet_test.go | 26 +-- 7 files changed, 254 insertions(+), 244 deletions(-) diff --git a/x/ibc/03-connection/types/connection_test.go b/x/ibc/03-connection/types/connection_test.go index 33478e3d7..0a6e63206 100644 --- a/x/ibc/03-connection/types/connection_test.go +++ b/x/ibc/03-connection/types/connection_test.go @@ -1,10 +1,11 @@ -package types +package types_test import ( "testing" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) @@ -18,37 +19,37 @@ var ( func TestConnectionValidateBasic(t *testing.T) { testCases := []struct { name string - connection ConnectionEnd + connection types.ConnectionEnd expPass bool }{ { "valid connection", - ConnectionEnd{connectionID, clientID, []string{"1.0.0"}, INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + types.ConnectionEnd{connectionID, clientID, []string{"1.0.0"}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, true, }, { "invalid connection id", - ConnectionEnd{"(connectionIDONE)", clientID, []string{"1.0.0"}, INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + types.ConnectionEnd{"(connectionIDONE)", clientID, []string{"1.0.0"}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, false, }, { "invalid client id", - ConnectionEnd{connectionID, "(clientID1)", []string{"1.0.0"}, INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + types.ConnectionEnd{connectionID, "(clientID1)", []string{"1.0.0"}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, false, }, { "empty versions", - ConnectionEnd{connectionID, clientID, nil, INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + types.ConnectionEnd{connectionID, clientID, nil, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, false, }, { "invalid version", - ConnectionEnd{connectionID, clientID, []string{""}, INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + types.ConnectionEnd{connectionID, clientID, []string{""}, types.INIT, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, false, }, { "invalid counterparty", - ConnectionEnd{connectionID, clientID, []string{"1.0.0"}, INIT, Counterparty{clientID2, connectionID2, emptyPrefix}}, + types.ConnectionEnd{connectionID, clientID, []string{"1.0.0"}, types.INIT, types.Counterparty{clientID2, connectionID2, emptyPrefix}}, false, }, } @@ -68,13 +69,13 @@ func TestConnectionValidateBasic(t *testing.T) { func TestCounterpartyValidateBasic(t *testing.T) { testCases := []struct { name string - counterparty Counterparty + counterparty types.Counterparty expPass bool }{ - {"valid counterparty", Counterparty{clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, true}, - {"invalid client id", Counterparty{"(InvalidClient)", connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, false}, - {"invalid connection id", Counterparty{clientID, "(InvalidConnection)", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, false}, - {"invalid prefix", Counterparty{clientID, connectionID2, emptyPrefix}, false}, + {"valid counterparty", types.Counterparty{clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, true}, + {"invalid client id", types.Counterparty{"(InvalidClient)", connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, false}, + {"invalid connection id", types.Counterparty{clientID, "(InvalidConnection)", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, false}, + {"invalid prefix", types.Counterparty{clientID, connectionID2, emptyPrefix}, false}, } for i, tc := range testCases { diff --git a/x/ibc/03-connection/types/genesis_test.go b/x/ibc/03-connection/types/genesis_test.go index b37f507cb..a617dcd1d 100644 --- a/x/ibc/03-connection/types/genesis_test.go +++ b/x/ibc/03-connection/types/genesis_test.go @@ -1,10 +1,11 @@ -package types +package types_test import ( "testing" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) @@ -13,21 +14,21 @@ func TestValidateGenesis(t *testing.T) { testCases := []struct { name string - genState GenesisState + genState types.GenesisState expPass bool }{ { name: "default", - genState: DefaultGenesisState(), + genState: types.DefaultGenesisState(), expPass: true, }, { name: "valid genesis", - genState: NewGenesisState( - []ConnectionEnd{ - NewConnectionEnd(INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), + genState: types.NewGenesisState( + []types.ConnectionEnd{ + types.NewConnectionEnd(types.INIT, connectionID, clientID, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), }, - []ConnectionPaths{ + []types.ConnectionPaths{ {clientID, []string{host.ConnectionPath(connectionID)}}, }, ), @@ -35,11 +36,11 @@ func TestValidateGenesis(t *testing.T) { }, { name: "invalid connection", - genState: NewGenesisState( - []ConnectionEnd{ - NewConnectionEnd(INIT, connectionID, "(CLIENTIDONE)", Counterparty{clientID, connectionID, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), + genState: types.NewGenesisState( + []types.ConnectionEnd{ + types.NewConnectionEnd(types.INIT, connectionID, "(CLIENTIDONE)", types.Counterparty{clientID, connectionID, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), }, - []ConnectionPaths{ + []types.ConnectionPaths{ {clientID, []string{host.ConnectionPath(connectionID)}}, }, ), @@ -47,11 +48,11 @@ func TestValidateGenesis(t *testing.T) { }, { name: "invalid client id", - genState: NewGenesisState( - []ConnectionEnd{ - NewConnectionEnd(INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), + genState: types.NewGenesisState( + []types.ConnectionEnd{ + types.NewConnectionEnd(types.INIT, connectionID, clientID, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), }, - []ConnectionPaths{ + []types.ConnectionPaths{ {"(CLIENTIDONE)", []string{host.ConnectionPath(connectionID)}}, }, ), @@ -59,11 +60,11 @@ func TestValidateGenesis(t *testing.T) { }, { name: "invalid path", - genState: NewGenesisState( - []ConnectionEnd{ - NewConnectionEnd(INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), + genState: types.NewGenesisState( + []types.ConnectionEnd{ + types.NewConnectionEnd(types.INIT, connectionID, clientID, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), }, - []ConnectionPaths{ + []types.ConnectionPaths{ {clientID, []string{connectionID}}, }, ), diff --git a/x/ibc/03-connection/types/msgs_test.go b/x/ibc/03-connection/types/msgs_test.go index 50dccb40a..3f35e6108 100644 --- a/x/ibc/03-connection/types/msgs_test.go +++ b/x/ibc/03-connection/types/msgs_test.go @@ -1,4 +1,4 @@ -package types +package types_test import ( "fmt" @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/rootmulti" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) @@ -56,18 +57,18 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenInit() { prefix := commitmenttypes.NewMerklePrefix([]byte("storePrefixKey")) signer, _ := sdk.AccAddressFromBech32("cosmos1ckgw5d7jfj7wwxjzs9fdrdev9vc8dzcw3n2lht") - testMsgs := []*MsgConnectionOpenInit{ - NewMsgConnectionOpenInit("test/conn1", "clienttotesta", "connectiontotest", "clienttotest", prefix, signer), - NewMsgConnectionOpenInit("ibcconntest", "test/iris", "connectiontotest", "clienttotest", prefix, signer), - NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "test/conn1", "clienttotest", prefix, signer), - NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "test/conn1", prefix, signer), - NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", emptyPrefix, signer), - NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", prefix, nil), - NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", prefix, signer), + testMsgs := []*types.MsgConnectionOpenInit{ + types.NewMsgConnectionOpenInit("test/conn1", "clienttotesta", "connectiontotest", "clienttotest", prefix, signer), + types.NewMsgConnectionOpenInit("ibcconntest", "test/iris", "connectiontotest", "clienttotest", prefix, signer), + types.NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "test/conn1", "clienttotest", prefix, signer), + types.NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "test/conn1", prefix, signer), + types.NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", emptyPrefix, signer), + types.NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", prefix, nil), + types.NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", prefix, signer), } var testCases = []struct { - msg *MsgConnectionOpenInit + msg *types.MsgConnectionOpenInit expPass bool errMsg string }{ @@ -94,23 +95,23 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { prefix := commitmenttypes.NewMerklePrefix([]byte("storePrefixKey")) signer, _ := sdk.AccAddressFromBech32("cosmos1ckgw5d7jfj7wwxjzs9fdrdev9vc8dzcw3n2lht") - testMsgs := []*MsgConnectionOpenTry{ - NewMsgConnectionOpenTry("test/conn1", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), - NewMsgConnectionOpenTry("ibcconntest", "test/iris", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), - NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "ibc/test", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), - NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "test/conn1", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), - NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", emptyPrefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), - NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{}, suite.proof, suite.proof, 10, 10, signer), - NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, emptyProof, suite.proof, 10, 10, signer), - NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, emptyProof, 10, 10, signer), - NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 0, 10, signer), - NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 0, signer), - NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, nil), - NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), + testMsgs := []*types.MsgConnectionOpenTry{ + types.NewMsgConnectionOpenTry("test/conn1", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), + types.NewMsgConnectionOpenTry("ibcconntest", "test/iris", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), + types.NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "ibc/test", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), + types.NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "test/conn1", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), + types.NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", emptyPrefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), + types.NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{}, suite.proof, suite.proof, 10, 10, signer), + types.NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, emptyProof, suite.proof, 10, 10, signer), + types.NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, emptyProof, 10, 10, signer), + types.NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 0, 10, signer), + types.NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 0, signer), + types.NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, nil), + types.NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), } var testCases = []struct { - msg *MsgConnectionOpenTry + msg *types.MsgConnectionOpenTry expPass bool errMsg string }{ @@ -141,18 +142,18 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() { signer, _ := sdk.AccAddressFromBech32("cosmos1ckgw5d7jfj7wwxjzs9fdrdev9vc8dzcw3n2lht") - testMsgs := []*MsgConnectionOpenAck{ - NewMsgConnectionOpenAck("test/conn1", suite.proof, suite.proof, 10, 10, "1.0.0", signer), - NewMsgConnectionOpenAck("ibcconntest", emptyProof, suite.proof, 10, 10, "1.0.0", signer), - NewMsgConnectionOpenAck("ibcconntest", suite.proof, emptyProof, 10, 10, "1.0.0", signer), - NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 0, 10, "1.0.0", signer), - NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 0, "1.0.0", signer), - NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 10, "", signer), - NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 10, "1.0.0", nil), - NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 10, "1.0.0", signer), + testMsgs := []*types.MsgConnectionOpenAck{ + types.NewMsgConnectionOpenAck("test/conn1", suite.proof, suite.proof, 10, 10, "1.0.0", signer), + types.NewMsgConnectionOpenAck("ibcconntest", emptyProof, suite.proof, 10, 10, "1.0.0", signer), + types.NewMsgConnectionOpenAck("ibcconntest", suite.proof, emptyProof, 10, 10, "1.0.0", signer), + types.NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 0, 10, "1.0.0", signer), + types.NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 0, "1.0.0", signer), + types.NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 10, "", signer), + types.NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 10, "1.0.0", nil), + types.NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 10, "1.0.0", signer), } var testCases = []struct { - msg *MsgConnectionOpenAck + msg *types.MsgConnectionOpenAck expPass bool errMsg string }{ @@ -179,16 +180,16 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() { func (suite *MsgTestSuite) TestNewMsgConnectionOpenConfirm() { signer, _ := sdk.AccAddressFromBech32("cosmos1ckgw5d7jfj7wwxjzs9fdrdev9vc8dzcw3n2lht") - testMsgs := []*MsgConnectionOpenConfirm{ - NewMsgConnectionOpenConfirm("test/conn1", suite.proof, 10, signer), - NewMsgConnectionOpenConfirm("ibcconntest", emptyProof, 10, signer), - NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 0, signer), - NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 10, nil), - NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 10, signer), + testMsgs := []*types.MsgConnectionOpenConfirm{ + types.NewMsgConnectionOpenConfirm("test/conn1", suite.proof, 10, signer), + types.NewMsgConnectionOpenConfirm("ibcconntest", emptyProof, 10, signer), + types.NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 0, signer), + types.NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 10, nil), + types.NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 10, signer), } var testCases = []struct { - msg *MsgConnectionOpenConfirm + msg *types.MsgConnectionOpenConfirm expPass bool errMsg string }{ diff --git a/x/ibc/04-channel/types/channel_test.go b/x/ibc/04-channel/types/channel_test.go index f0c0b3a3b..c02114672 100644 --- a/x/ibc/04-channel/types/channel_test.go +++ b/x/ibc/04-channel/types/channel_test.go @@ -1,20 +1,22 @@ -package types +package types_test import ( "testing" "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" ) func TestCounterpartyValidateBasic(t *testing.T) { testCases := []struct { name string - counterparty Counterparty + counterparty types.Counterparty expPass bool }{ - {"valid counterparty", Counterparty{"portidone", "channelidone"}, true}, - {"invalid port id", Counterparty{"(InvalidPort)", "channelidone"}, false}, - {"invalid channel id", Counterparty{"portidone", "(InvalidChannel)"}, false}, + {"valid counterparty", types.Counterparty{"portidone", "channelidone"}, true}, + {"invalid port id", types.Counterparty{"(InvalidPort)", "channelidone"}, false}, + {"invalid channel id", types.Counterparty{"portidone", "(InvalidChannel)"}, false}, } for i, tc := range testCases { diff --git a/x/ibc/04-channel/types/genesis_test.go b/x/ibc/04-channel/types/genesis_test.go index 0228066f5..28e5cf67b 100644 --- a/x/ibc/04-channel/types/genesis_test.go +++ b/x/ibc/04-channel/types/genesis_test.go @@ -1,9 +1,11 @@ -package types +package types_test import ( "testing" "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" ) const ( @@ -14,63 +16,63 @@ const ( testChannel1 = "firstchannel" testChannel2 = "secondchannel" - testChannelOrder = ORDERED + testChannelOrder = types.ORDERED testChannelVersion = "1.0" ) func TestValidateGenesis(t *testing.T) { - counterparty1 := NewCounterparty(testPort1, testChannel1) - counterparty2 := NewCounterparty(testPort2, testChannel2) + counterparty1 := types.NewCounterparty(testPort1, testChannel1) + counterparty2 := types.NewCounterparty(testPort2, testChannel2) testCases := []struct { name string - genState GenesisState + genState types.GenesisState expPass bool }{ { name: "default", - genState: DefaultGenesisState(), + genState: types.DefaultGenesisState(), expPass: true, }, { name: "valid genesis", - genState: NewGenesisState( - []IdentifiedChannel{ - NewIdentifiedChannel( - testPort1, testChannel1, NewChannel( - INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion, + genState: types.NewGenesisState( + []types.IdentifiedChannel{ + types.NewIdentifiedChannel( + testPort1, testChannel1, types.NewChannel( + types.INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion, ), ), - NewIdentifiedChannel( - testPort2, testChannel2, NewChannel( - INIT, testChannelOrder, counterparty1, []string{testConnectionIDA}, testChannelVersion, + types.NewIdentifiedChannel( + testPort2, testChannel2, types.NewChannel( + types.INIT, testChannelOrder, counterparty1, []string{testConnectionIDA}, testChannelVersion, ), ), }, - []PacketAckCommitment{ - NewPacketAckCommitment(testPort2, testChannel2, 1, []byte("ack")), + []types.PacketAckCommitment{ + types.NewPacketAckCommitment(testPort2, testChannel2, 1, []byte("ack")), }, - []PacketAckCommitment{ - NewPacketAckCommitment(testPort1, testChannel1, 1, []byte("commit_hash")), + []types.PacketAckCommitment{ + types.NewPacketAckCommitment(testPort1, testChannel1, 1, []byte("commit_hash")), }, - []PacketSequence{ - NewPacketSequence(testPort1, testChannel1, 1), + []types.PacketSequence{ + types.NewPacketSequence(testPort1, testChannel1, 1), }, - []PacketSequence{ - NewPacketSequence(testPort2, testChannel2, 1), + []types.PacketSequence{ + types.NewPacketSequence(testPort2, testChannel2, 1), }, - []PacketSequence{ - NewPacketSequence(testPort2, testChannel2, 1), + []types.PacketSequence{ + types.NewPacketSequence(testPort2, testChannel2, 1), }, ), expPass: true, }, { name: "invalid channel", - genState: GenesisState{ - Channels: []IdentifiedChannel{ - NewIdentifiedChannel( - testPort1, "(testChannel1)", NewChannel( - INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion, + genState: types.GenesisState{ + Channels: []types.IdentifiedChannel{ + types.NewIdentifiedChannel( + testPort1, "(testChannel1)", types.NewChannel( + types.INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion, ), ), }, @@ -79,54 +81,54 @@ func TestValidateGenesis(t *testing.T) { }, { name: "invalid ack", - genState: GenesisState{ - Acknowledgements: []PacketAckCommitment{ - NewPacketAckCommitment(testPort2, testChannel2, 1, nil), + genState: types.GenesisState{ + Acknowledgements: []types.PacketAckCommitment{ + types.NewPacketAckCommitment(testPort2, testChannel2, 1, nil), }, }, expPass: false, }, { name: "invalid commitment", - genState: GenesisState{ - Commitments: []PacketAckCommitment{ - NewPacketAckCommitment(testPort1, testChannel1, 1, nil), + genState: types.GenesisState{ + Commitments: []types.PacketAckCommitment{ + types.NewPacketAckCommitment(testPort1, testChannel1, 1, nil), }, }, expPass: false, }, { name: "invalid send seq", - genState: GenesisState{ - SendSequences: []PacketSequence{ - NewPacketSequence(testPort1, testChannel1, 0), + genState: types.GenesisState{ + SendSequences: []types.PacketSequence{ + types.NewPacketSequence(testPort1, testChannel1, 0), }, }, expPass: false, }, { name: "invalid recv seq", - genState: GenesisState{ - RecvSequences: []PacketSequence{ - NewPacketSequence(testPort1, "(testChannel1)", 1), + genState: types.GenesisState{ + RecvSequences: []types.PacketSequence{ + types.NewPacketSequence(testPort1, "(testChannel1)", 1), }, }, expPass: false, }, { name: "invalid recv seq 2", - genState: GenesisState{ - RecvSequences: []PacketSequence{ - NewPacketSequence("(testPort1)", testChannel1, 1), + genState: types.GenesisState{ + RecvSequences: []types.PacketSequence{ + types.NewPacketSequence("(testPort1)", testChannel1, 1), }, }, expPass: false, }, { name: "invalid ack seq", - genState: GenesisState{ - AckSequences: []PacketSequence{ - NewPacketSequence(testPort1, "(testChannel1)", 1), + genState: types.GenesisState{ + AckSequences: []types.PacketSequence{ + types.NewPacketSequence(testPort1, "(testChannel1)", 1), }, }, expPass: false, diff --git a/x/ibc/04-channel/types/msgs_test.go b/x/ibc/04-channel/types/msgs_test.go index beaa9645b..7dcc4a62f 100644 --- a/x/ibc/04-channel/types/msgs_test.go +++ b/x/ibc/04-channel/types/msgs_test.go @@ -1,4 +1,4 @@ -package types +package types_test import ( "fmt" @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/rootmulti" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) @@ -79,26 +80,26 @@ func TestMsgTestSuite(t *testing.T) { // TestMsgChannelOpenInit tests ValidateBasic for MsgChannelOpenInit func (suite *MsgTestSuite) TestMsgChannelOpenInit() { - testMsgs := []*MsgChannelOpenInit{ - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // valid msg - NewMsgChannelOpenInit(invalidShortPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short port id - NewMsgChannelOpenInit(invalidLongPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long port id - NewMsgChannelOpenInit(invalidPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // port id contains non-alpha - NewMsgChannelOpenInit("testportid", invalidShortChannel, "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short channel id - NewMsgChannelOpenInit("testportid", invalidLongChannel, "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long channel id - NewMsgChannelOpenInit("testportid", invalidChannel, "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // channel id contains non-alpha - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", Order(3), connHops, "testcpport", "testcpchannel", addr), // invalid channel order - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ORDERED, invalidConnHops, "testcpport", "testcpchannel", addr), // connection hops more than 1 - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", UNORDERED, invalidShortConnHops, "testcpport", "testcpchannel", addr), // too short connection id - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", UNORDERED, invalidLongConnHops, "testcpport", "testcpchannel", addr), // too long connection id - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", UNORDERED, []string{invalidConnection}, "testcpport", "testcpchannel", addr), // connection id contains non-alpha - NewMsgChannelOpenInit("testportid", "testchannel", "", UNORDERED, connHops, "testcpport", "testcpchannel", addr), // empty channel version - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", UNORDERED, connHops, invalidPort, "testcpchannel", addr), // invalid counterparty port id - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", UNORDERED, connHops, "testcpport", invalidChannel, addr), // invalid counterparty channel id + testMsgs := []*types.MsgChannelOpenInit{ + types.NewMsgChannelOpenInit("testportid", "testchannel", "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", addr), // valid msg + types.NewMsgChannelOpenInit(invalidShortPort, "testchannel", "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short port id + types.NewMsgChannelOpenInit(invalidLongPort, "testchannel", "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long port id + types.NewMsgChannelOpenInit(invalidPort, "testchannel", "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", addr), // port id contains non-alpha + types.NewMsgChannelOpenInit("testportid", invalidShortChannel, "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short channel id + types.NewMsgChannelOpenInit("testportid", invalidLongChannel, "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long channel id + types.NewMsgChannelOpenInit("testportid", invalidChannel, "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", addr), // channel id contains non-alpha + types.NewMsgChannelOpenInit("testportid", "testchannel", "1.0", types.Order(3), connHops, "testcpport", "testcpchannel", addr), // invalid channel order + types.NewMsgChannelOpenInit("testportid", "testchannel", "1.0", types.ORDERED, invalidConnHops, "testcpport", "testcpchannel", addr), // connection hops more than 1 + types.NewMsgChannelOpenInit("testportid", "testchannel", "1.0", types.UNORDERED, invalidShortConnHops, "testcpport", "testcpchannel", addr), // too short connection id + types.NewMsgChannelOpenInit("testportid", "testchannel", "1.0", types.UNORDERED, invalidLongConnHops, "testcpport", "testcpchannel", addr), // too long connection id + types.NewMsgChannelOpenInit("testportid", "testchannel", "1.0", types.UNORDERED, []string{invalidConnection}, "testcpport", "testcpchannel", addr), // connection id contains non-alpha + types.NewMsgChannelOpenInit("testportid", "testchannel", "", types.UNORDERED, connHops, "testcpport", "testcpchannel", addr), // empty channel version + types.NewMsgChannelOpenInit("testportid", "testchannel", "1.0", types.UNORDERED, connHops, invalidPort, "testcpchannel", addr), // invalid counterparty port id + types.NewMsgChannelOpenInit("testportid", "testchannel", "1.0", types.UNORDERED, connHops, "testcpport", invalidChannel, addr), // invalid counterparty channel id } testCases := []struct { - msg *MsgChannelOpenInit + msg *types.MsgChannelOpenInit expPass bool errMsg string }{ @@ -131,28 +132,28 @@ func (suite *MsgTestSuite) TestMsgChannelOpenInit() { // TestMsgChannelOpenTry tests ValidateBasic for MsgChannelOpenTry func (suite *MsgTestSuite) TestMsgChannelOpenTry() { - testMsgs := []*MsgChannelOpenTry{ - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // valid msg - NewMsgChannelOpenTry(invalidShortPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short port id - NewMsgChannelOpenTry(invalidLongPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long port id - NewMsgChannelOpenTry(invalidPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // port id contains non-alpha - NewMsgChannelOpenTry("testportid", invalidShortChannel, "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short channel id - NewMsgChannelOpenTry("testportid", invalidLongChannel, "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long channel id - NewMsgChannelOpenTry("testportid", invalidChannel, "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // channel id contains non-alpha - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "", suite.proof, 1, addr), // empty counterparty version - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 0, addr), // suite.proof height is zero - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", Order(4), connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // invalid channel order - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", UNORDERED, invalidConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // connection hops more than 1 - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", UNORDERED, invalidShortConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short connection id - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", UNORDERED, invalidLongConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long connection id - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", UNORDERED, []string{invalidConnection}, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // connection id contains non-alpha - NewMsgChannelOpenTry("testportid", "testchannel", "", UNORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // empty channel version - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", UNORDERED, connHops, invalidPort, "testcpchannel", "1.0", suite.proof, 1, addr), // invalid counterparty port id - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", UNORDERED, connHops, "testcpport", invalidChannel, "1.0", suite.proof, 1, addr), // invalid counterparty channel id + testMsgs := []*types.MsgChannelOpenTry{ + types.NewMsgChannelOpenTry("testportid", "testchannel", "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // valid msg + types.NewMsgChannelOpenTry(invalidShortPort, "testchannel", "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short port id + types.NewMsgChannelOpenTry(invalidLongPort, "testchannel", "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long port id + types.NewMsgChannelOpenTry(invalidPort, "testchannel", "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // port id contains non-alpha + types.NewMsgChannelOpenTry("testportid", invalidShortChannel, "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short channel id + types.NewMsgChannelOpenTry("testportid", invalidLongChannel, "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long channel id + types.NewMsgChannelOpenTry("testportid", invalidChannel, "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // channel id contains non-alpha + types.NewMsgChannelOpenTry("testportid", "testchannel", "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", "", suite.proof, 1, addr), // empty counterparty version + types.NewMsgChannelOpenTry("testportid", "testchannel", "1.0", types.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 0, addr), // suite.proof height is zero + types.NewMsgChannelOpenTry("testportid", "testchannel", "1.0", types.Order(4), connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // invalid channel order + types.NewMsgChannelOpenTry("testportid", "testchannel", "1.0", types.UNORDERED, invalidConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // connection hops more than 1 + types.NewMsgChannelOpenTry("testportid", "testchannel", "1.0", types.UNORDERED, invalidShortConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short connection id + types.NewMsgChannelOpenTry("testportid", "testchannel", "1.0", types.UNORDERED, invalidLongConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long connection id + types.NewMsgChannelOpenTry("testportid", "testchannel", "1.0", types.UNORDERED, []string{invalidConnection}, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // connection id contains non-alpha + types.NewMsgChannelOpenTry("testportid", "testchannel", "", types.UNORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // empty channel version + types.NewMsgChannelOpenTry("testportid", "testchannel", "1.0", types.UNORDERED, connHops, invalidPort, "testcpchannel", "1.0", suite.proof, 1, addr), // invalid counterparty port id + types.NewMsgChannelOpenTry("testportid", "testchannel", "1.0", types.UNORDERED, connHops, "testcpport", invalidChannel, "1.0", suite.proof, 1, addr), // invalid counterparty channel id } testCases := []struct { - msg *MsgChannelOpenTry + msg *types.MsgChannelOpenTry expPass bool errMsg string }{ @@ -187,21 +188,21 @@ func (suite *MsgTestSuite) TestMsgChannelOpenTry() { // TestMsgChannelOpenAck tests ValidateBasic for MsgChannelOpenAck func (suite *MsgTestSuite) TestMsgChannelOpenAck() { - testMsgs := []*MsgChannelOpenAck{ - NewMsgChannelOpenAck("testportid", "testchannel", "1.0", suite.proof, 1, addr), // valid msg - NewMsgChannelOpenAck(invalidShortPort, "testchannel", "1.0", suite.proof, 1, addr), // too short port id - NewMsgChannelOpenAck(invalidLongPort, "testchannel", "1.0", suite.proof, 1, addr), // too long port id - NewMsgChannelOpenAck(invalidPort, "testchannel", "1.0", suite.proof, 1, addr), // port id contains non-alpha - NewMsgChannelOpenAck("testportid", invalidShortChannel, "1.0", suite.proof, 1, addr), // too short channel id - NewMsgChannelOpenAck("testportid", invalidLongChannel, "1.0", suite.proof, 1, addr), // too long channel id - NewMsgChannelOpenAck("testportid", invalidChannel, "1.0", suite.proof, 1, addr), // channel id contains non-alpha - NewMsgChannelOpenAck("testportid", "testchannel", "", suite.proof, 1, addr), // empty counterparty version - NewMsgChannelOpenAck("testportid", "testchannel", "1.0", commitmenttypes.MerkleProof{Proof: nil}, 1, addr), // empty proof - NewMsgChannelOpenAck("testportid", "testchannel", "1.0", suite.proof, 0, addr), // proof height is zero + testMsgs := []*types.MsgChannelOpenAck{ + types.NewMsgChannelOpenAck("testportid", "testchannel", "1.0", suite.proof, 1, addr), // valid msg + types.NewMsgChannelOpenAck(invalidShortPort, "testchannel", "1.0", suite.proof, 1, addr), // too short port id + types.NewMsgChannelOpenAck(invalidLongPort, "testchannel", "1.0", suite.proof, 1, addr), // too long port id + types.NewMsgChannelOpenAck(invalidPort, "testchannel", "1.0", suite.proof, 1, addr), // port id contains non-alpha + types.NewMsgChannelOpenAck("testportid", invalidShortChannel, "1.0", suite.proof, 1, addr), // too short channel id + types.NewMsgChannelOpenAck("testportid", invalidLongChannel, "1.0", suite.proof, 1, addr), // too long channel id + types.NewMsgChannelOpenAck("testportid", invalidChannel, "1.0", suite.proof, 1, addr), // channel id contains non-alpha + types.NewMsgChannelOpenAck("testportid", "testchannel", "", suite.proof, 1, addr), // empty counterparty version + types.NewMsgChannelOpenAck("testportid", "testchannel", "1.0", commitmenttypes.MerkleProof{Proof: nil}, 1, addr), // empty proof + types.NewMsgChannelOpenAck("testportid", "testchannel", "1.0", suite.proof, 0, addr), // proof height is zero } testCases := []struct { - msg *MsgChannelOpenAck + msg *types.MsgChannelOpenAck expPass bool errMsg string }{ @@ -229,20 +230,20 @@ func (suite *MsgTestSuite) TestMsgChannelOpenAck() { // TestMsgChannelOpenConfirm tests ValidateBasic for MsgChannelOpenConfirm func (suite *MsgTestSuite) TestMsgChannelOpenConfirm() { - testMsgs := []*MsgChannelOpenConfirm{ - NewMsgChannelOpenConfirm("testportid", "testchannel", suite.proof, 1, addr), // valid msg - NewMsgChannelOpenConfirm(invalidShortPort, "testchannel", suite.proof, 1, addr), // too short port id - NewMsgChannelOpenConfirm(invalidLongPort, "testchannel", suite.proof, 1, addr), // too long port id - NewMsgChannelOpenConfirm(invalidPort, "testchannel", suite.proof, 1, addr), // port id contains non-alpha - NewMsgChannelOpenConfirm("testportid", invalidShortChannel, suite.proof, 1, addr), // too short channel id - NewMsgChannelOpenConfirm("testportid", invalidLongChannel, suite.proof, 1, addr), // too long channel id - NewMsgChannelOpenConfirm("testportid", invalidChannel, suite.proof, 1, addr), // channel id contains non-alpha - NewMsgChannelOpenConfirm("testportid", "testchannel", commitmenttypes.MerkleProof{Proof: nil}, 1, addr), // empty proof - NewMsgChannelOpenConfirm("testportid", "testchannel", suite.proof, 0, addr), // proof height is zero + testMsgs := []*types.MsgChannelOpenConfirm{ + types.NewMsgChannelOpenConfirm("testportid", "testchannel", suite.proof, 1, addr), // valid msg + types.NewMsgChannelOpenConfirm(invalidShortPort, "testchannel", suite.proof, 1, addr), // too short port id + types.NewMsgChannelOpenConfirm(invalidLongPort, "testchannel", suite.proof, 1, addr), // too long port id + types.NewMsgChannelOpenConfirm(invalidPort, "testchannel", suite.proof, 1, addr), // port id contains non-alpha + types.NewMsgChannelOpenConfirm("testportid", invalidShortChannel, suite.proof, 1, addr), // too short channel id + types.NewMsgChannelOpenConfirm("testportid", invalidLongChannel, suite.proof, 1, addr), // too long channel id + types.NewMsgChannelOpenConfirm("testportid", invalidChannel, suite.proof, 1, addr), // channel id contains non-alpha + types.NewMsgChannelOpenConfirm("testportid", "testchannel", commitmenttypes.MerkleProof{Proof: nil}, 1, addr), // empty proof + types.NewMsgChannelOpenConfirm("testportid", "testchannel", suite.proof, 0, addr), // proof height is zero } testCases := []struct { - msg *MsgChannelOpenConfirm + msg *types.MsgChannelOpenConfirm expPass bool errMsg string }{ @@ -269,18 +270,18 @@ func (suite *MsgTestSuite) TestMsgChannelOpenConfirm() { // TestMsgChannelCloseInit tests ValidateBasic for MsgChannelCloseInit func (suite *MsgTestSuite) TestMsgChannelCloseInit() { - testMsgs := []*MsgChannelCloseInit{ - NewMsgChannelCloseInit("testportid", "testchannel", addr), // valid msg - NewMsgChannelCloseInit(invalidShortPort, "testchannel", addr), // too short port id - NewMsgChannelCloseInit(invalidLongPort, "testchannel", addr), // too long port id - NewMsgChannelCloseInit(invalidPort, "testchannel", addr), // port id contains non-alpha - NewMsgChannelCloseInit("testportid", invalidShortChannel, addr), // too short channel id - NewMsgChannelCloseInit("testportid", invalidLongChannel, addr), // too long channel id - NewMsgChannelCloseInit("testportid", invalidChannel, addr), // channel id contains non-alpha + testMsgs := []*types.MsgChannelCloseInit{ + types.NewMsgChannelCloseInit("testportid", "testchannel", addr), // valid msg + types.NewMsgChannelCloseInit(invalidShortPort, "testchannel", addr), // too short port id + types.NewMsgChannelCloseInit(invalidLongPort, "testchannel", addr), // too long port id + types.NewMsgChannelCloseInit(invalidPort, "testchannel", addr), // port id contains non-alpha + types.NewMsgChannelCloseInit("testportid", invalidShortChannel, addr), // too short channel id + types.NewMsgChannelCloseInit("testportid", invalidLongChannel, addr), // too long channel id + types.NewMsgChannelCloseInit("testportid", invalidChannel, addr), // channel id contains non-alpha } testCases := []struct { - msg *MsgChannelCloseInit + msg *types.MsgChannelCloseInit expPass bool errMsg string }{ @@ -305,20 +306,20 @@ func (suite *MsgTestSuite) TestMsgChannelCloseInit() { // TestMsgChannelCloseConfirm tests ValidateBasic for MsgChannelCloseConfirm func (suite *MsgTestSuite) TestMsgChannelCloseConfirm() { - testMsgs := []*MsgChannelCloseConfirm{ - NewMsgChannelCloseConfirm("testportid", "testchannel", suite.proof, 1, addr), // valid msg - NewMsgChannelCloseConfirm(invalidShortPort, "testchannel", suite.proof, 1, addr), // too short port id - NewMsgChannelCloseConfirm(invalidLongPort, "testchannel", suite.proof, 1, addr), // too long port id - NewMsgChannelCloseConfirm(invalidPort, "testchannel", suite.proof, 1, addr), // port id contains non-alpha - NewMsgChannelCloseConfirm("testportid", invalidShortChannel, suite.proof, 1, addr), // too short channel id - NewMsgChannelCloseConfirm("testportid", invalidLongChannel, suite.proof, 1, addr), // too long channel id - NewMsgChannelCloseConfirm("testportid", invalidChannel, suite.proof, 1, addr), // channel id contains non-alpha - NewMsgChannelCloseConfirm("testportid", "testchannel", commitmenttypes.MerkleProof{Proof: nil}, 1, addr), // empty proof - NewMsgChannelCloseConfirm("testportid", "testchannel", suite.proof, 0, addr), // proof height is zero + testMsgs := []*types.MsgChannelCloseConfirm{ + types.NewMsgChannelCloseConfirm("testportid", "testchannel", suite.proof, 1, addr), // valid msg + types.NewMsgChannelCloseConfirm(invalidShortPort, "testchannel", suite.proof, 1, addr), // too short port id + types.NewMsgChannelCloseConfirm(invalidLongPort, "testchannel", suite.proof, 1, addr), // too long port id + types.NewMsgChannelCloseConfirm(invalidPort, "testchannel", suite.proof, 1, addr), // port id contains non-alpha + types.NewMsgChannelCloseConfirm("testportid", invalidShortChannel, suite.proof, 1, addr), // too short channel id + types.NewMsgChannelCloseConfirm("testportid", invalidLongChannel, suite.proof, 1, addr), // too long channel id + types.NewMsgChannelCloseConfirm("testportid", invalidChannel, suite.proof, 1, addr), // channel id contains non-alpha + types.NewMsgChannelCloseConfirm("testportid", "testchannel", commitmenttypes.MerkleProof{Proof: nil}, 1, addr), // empty proof + types.NewMsgChannelCloseConfirm("testportid", "testchannel", suite.proof, 0, addr), // proof height is zero } testCases := []struct { - msg *MsgChannelCloseConfirm + msg *types.MsgChannelCloseConfirm expPass bool errMsg string }{ @@ -352,8 +353,8 @@ var ( unknownPacketData = []byte("unknown") invalidAckData = []byte("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890") - packet = NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp) - unknownPacket = NewPacket(unknownPacketData, 0, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp) + packet = types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp) + unknownPacket = types.NewPacket(unknownPacketData, 0, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp) invalidAck = invalidAckData emptyProof = commitmenttypes.MerkleProof{Proof: nil} @@ -371,23 +372,23 @@ var ( // TestMsgPacketType tests Type for MsgPacket func TestMsgPacketType(t *testing.T) { - msg := NewMsgPacket(packet, proof, 1, addr1) + msg := types.NewMsgPacket(packet, proof, 1, addr1) require.Equal(t, []byte("testdata"), msg.Packet.GetData()) } // TestMsgPacketValidation tests ValidateBasic for MsgPacket func TestMsgPacketValidation(t *testing.T) { - testMsgs := []*MsgPacket{ - NewMsgPacket(packet, proof, 1, addr1), // valid msg - NewMsgPacket(packet, proof, 0, addr1), // proof height is zero - NewMsgPacket(packet, invalidProofs2, 1, addr1), // proof contain empty proof - NewMsgPacket(packet, proof, 1, emptyAddr), // missing signer address - NewMsgPacket(unknownPacket, proof, 1, addr1), // unknown packet + testMsgs := []*types.MsgPacket{ + types.NewMsgPacket(packet, proof, 1, addr1), // valid msg + types.NewMsgPacket(packet, proof, 0, addr1), // proof height is zero + types.NewMsgPacket(packet, invalidProofs2, 1, addr1), // proof contain empty proof + types.NewMsgPacket(packet, proof, 1, emptyAddr), // missing signer address + types.NewMsgPacket(unknownPacket, proof, 1, addr1), // unknown packet } testCases := []struct { - msg *MsgPacket + msg *types.MsgPacket expPass bool errMsg string }{ @@ -410,7 +411,7 @@ func TestMsgPacketValidation(t *testing.T) { // TestMsgPacketGetSignBytes tests GetSignBytes for MsgPacket func TestMsgPacketGetSignBytes(t *testing.T) { - msg := NewMsgPacket(packet, proof, 1, addr1) + msg := types.NewMsgPacket(packet, proof, 1, addr1) res := msg.GetSignBytes() expected := fmt.Sprintf( @@ -422,7 +423,7 @@ func TestMsgPacketGetSignBytes(t *testing.T) { // TestMsgPacketGetSigners tests GetSigners for MsgPacket func TestMsgPacketGetSigners(t *testing.T) { - msg := NewMsgPacket(packet, proof, 1, addr1) + msg := types.NewMsgPacket(packet, proof, 1, addr1) res := msg.GetSigners() expected := "[746573746164647231]" @@ -431,16 +432,16 @@ func TestMsgPacketGetSigners(t *testing.T) { // TestMsgTimeout tests ValidateBasic for MsgTimeout func (suite *MsgTestSuite) TestMsgTimeout() { - testMsgs := []*MsgTimeout{ - NewMsgTimeout(packet, 1, proof, 1, addr), - NewMsgTimeout(packet, 1, proof, 0, addr), - NewMsgTimeout(packet, 1, proof, 1, emptyAddr), - NewMsgTimeout(packet, 1, emptyProof, 1, addr), - NewMsgTimeout(unknownPacket, 1, proof, 1, addr), + testMsgs := []*types.MsgTimeout{ + types.NewMsgTimeout(packet, 1, proof, 1, addr), + types.NewMsgTimeout(packet, 1, proof, 0, addr), + types.NewMsgTimeout(packet, 1, proof, 1, emptyAddr), + types.NewMsgTimeout(packet, 1, emptyProof, 1, addr), + types.NewMsgTimeout(unknownPacket, 1, proof, 1, addr), } testCases := []struct { - msg *MsgTimeout + msg *types.MsgTimeout expPass bool errMsg string }{ @@ -463,17 +464,17 @@ func (suite *MsgTestSuite) TestMsgTimeout() { // TestMsgAcknowledgement tests ValidateBasic for MsgAcknowledgement func (suite *MsgTestSuite) TestMsgAcknowledgement() { - testMsgs := []*MsgAcknowledgement{ - NewMsgAcknowledgement(packet, packet.GetData(), proof, 1, addr), - NewMsgAcknowledgement(packet, packet.GetData(), proof, 0, addr), - NewMsgAcknowledgement(packet, packet.GetData(), proof, 1, emptyAddr), - NewMsgAcknowledgement(packet, packet.GetData(), emptyProof, 1, addr), - NewMsgAcknowledgement(unknownPacket, packet.GetData(), proof, 1, addr), - NewMsgAcknowledgement(packet, invalidAck, proof, 1, addr), + testMsgs := []*types.MsgAcknowledgement{ + types.NewMsgAcknowledgement(packet, packet.GetData(), proof, 1, addr), + types.NewMsgAcknowledgement(packet, packet.GetData(), proof, 0, addr), + types.NewMsgAcknowledgement(packet, packet.GetData(), proof, 1, emptyAddr), + types.NewMsgAcknowledgement(packet, packet.GetData(), emptyProof, 1, addr), + types.NewMsgAcknowledgement(unknownPacket, packet.GetData(), proof, 1, addr), + types.NewMsgAcknowledgement(packet, invalidAck, proof, 1, addr), } testCases := []struct { - msg *MsgAcknowledgement + msg *types.MsgAcknowledgement expPass bool errMsg string }{ diff --git a/x/ibc/04-channel/types/packet_test.go b/x/ibc/04-channel/types/packet_test.go index 12c2e16a7..7d18373c6 100644 --- a/x/ibc/04-channel/types/packet_test.go +++ b/x/ibc/04-channel/types/packet_test.go @@ -1,27 +1,29 @@ -package types +package types_test import ( "testing" "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" ) func TestPacketValidateBasic(t *testing.T) { testCases := []struct { - packet Packet + packet types.Packet expPass bool errMsg string }{ - {NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), true, ""}, - {NewPacket(validPacketData, 0, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid sequence"}, - {NewPacket(validPacketData, 1, invalidPort, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid source port"}, - {NewPacket(validPacketData, 1, portid, invalidChannel, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid source channel"}, - {NewPacket(validPacketData, 1, portid, chanid, invalidPort, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid destination port"}, - {NewPacket(validPacketData, 1, portid, chanid, cpportid, invalidChannel, timeoutHeight, timeoutTimestamp), false, "invalid destination channel"}, - {NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, disabledTimeout, disabledTimeout), false, "disabled both timeout height and timestamp"}, - {NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, disabledTimeout, timeoutTimestamp), true, "disabled timeout height, valid timeout timestamp"}, - {NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, disabledTimeout), true, "disabled timeout timestamp, valid timeout height"}, - {NewPacket(unknownPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), true, ""}, + {types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), true, ""}, + {types.NewPacket(validPacketData, 0, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid sequence"}, + {types.NewPacket(validPacketData, 1, invalidPort, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid source port"}, + {types.NewPacket(validPacketData, 1, portid, invalidChannel, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid source channel"}, + {types.NewPacket(validPacketData, 1, portid, chanid, invalidPort, cpchanid, timeoutHeight, timeoutTimestamp), false, "invalid destination port"}, + {types.NewPacket(validPacketData, 1, portid, chanid, cpportid, invalidChannel, timeoutHeight, timeoutTimestamp), false, "invalid destination channel"}, + {types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, disabledTimeout, disabledTimeout), false, "disabled both timeout height and timestamp"}, + {types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, disabledTimeout, timeoutTimestamp), true, "disabled timeout height, valid timeout timestamp"}, + {types.NewPacket(validPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, disabledTimeout), true, "disabled timeout timestamp, valid timeout height"}, + {types.NewPacket(unknownPacketData, 1, portid, chanid, cpportid, cpchanid, timeoutHeight, timeoutTimestamp), true, ""}, } for i, tc := range testCases {