2020-04-27 11:04:26 -07:00
|
|
|
package ibc_test
|
2020-04-24 08:52:07 -07:00
|
|
|
|
|
|
|
import (
|
2020-04-27 11:04:26 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/ibc"
|
|
|
|
client "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
2020-04-24 08:52:07 -07:00
|
|
|
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
|
|
|
|
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
|
2020-04-27 11:04:26 -07:00
|
|
|
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
|
|
|
localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"
|
2020-04-24 08:52:07 -07:00
|
|
|
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
|
|
|
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
|
|
|
|
)
|
|
|
|
|
2020-04-27 11:04:26 -07:00
|
|
|
func (suite *IBCTestSuite) TestValidateGenesis() {
|
2020-04-24 08:52:07 -07:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
2020-04-27 11:04:26 -07:00
|
|
|
genState ibc.GenesisState
|
2020-04-24 08:52:07 -07:00
|
|
|
expPass bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "default",
|
2020-04-27 11:04:26 -07:00
|
|
|
genState: ibc.DefaultGenesisState(),
|
2020-04-24 08:52:07 -07:00
|
|
|
expPass: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "valid genesis",
|
2020-04-27 11:04:26 -07:00
|
|
|
genState: ibc.GenesisState{
|
|
|
|
ClientGenesis: client.NewGenesisState(
|
|
|
|
[]exported.ClientState{
|
|
|
|
ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header),
|
|
|
|
localhosttypes.NewClientState(suite.store, "chaindID", 10),
|
|
|
|
},
|
|
|
|
[]client.ClientConsensusStates{
|
|
|
|
client.NewClientConsensusStates(
|
|
|
|
clientID,
|
|
|
|
[]exported.ConsensusState{
|
|
|
|
ibctmtypes.NewConsensusState(
|
|
|
|
suite.header.Time, commitmenttypes.NewMerkleRoot(suite.header.AppHash), suite.header.GetHeight(), suite.header.ValidatorSet,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
),
|
2020-04-24 08:52:07 -07:00
|
|
|
ConnectionGenesis: connection.NewGenesisState(
|
|
|
|
[]connection.ConnectionEnd{
|
|
|
|
connection.NewConnectionEnd(connectionexported.INIT, connectionID, clientID, connection.NewCounterparty(clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{"1.0.0"}),
|
|
|
|
},
|
|
|
|
[]connection.ConnectionPaths{
|
|
|
|
connection.NewConnectionPaths(clientID, []string{ibctypes.ConnectionPath(connectionID)}),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
expPass: true,
|
|
|
|
},
|
2020-04-27 11:04:26 -07:00
|
|
|
{
|
|
|
|
name: "invalid client genesis",
|
|
|
|
genState: ibc.GenesisState{
|
|
|
|
ClientGenesis: client.NewGenesisState(
|
|
|
|
[]exported.ClientState{
|
|
|
|
ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header),
|
|
|
|
localhosttypes.NewClientState(suite.store, "chaindID", 0),
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
ConnectionGenesis: connection.DefaultGenesisState(),
|
|
|
|
},
|
|
|
|
expPass: false,
|
|
|
|
},
|
2020-04-24 08:52:07 -07:00
|
|
|
{
|
|
|
|
name: "invalid connection genesis",
|
2020-04-27 11:04:26 -07:00
|
|
|
genState: ibc.GenesisState{
|
|
|
|
ClientGenesis: client.DefaultGenesisState(),
|
2020-04-24 08:52:07 -07:00
|
|
|
ConnectionGenesis: connection.NewGenesisState(
|
|
|
|
[]connection.ConnectionEnd{
|
|
|
|
connection.NewConnectionEnd(connectionexported.INIT, connectionID, "CLIENTIDONE", connection.NewCounterparty(clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{"1.0.0"}),
|
|
|
|
},
|
2020-04-27 11:04:26 -07:00
|
|
|
[]connection.ConnectionPaths{
|
|
|
|
connection.NewConnectionPaths(clientID, []string{ibctypes.ConnectionPath(connectionID)}),
|
|
|
|
},
|
2020-04-24 08:52:07 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
expPass: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
tc := tc
|
|
|
|
err := tc.genState.Validate()
|
|
|
|
if tc.expPass {
|
2020-04-27 11:04:26 -07:00
|
|
|
suite.Require().NoError(err, tc.name)
|
2020-04-24 08:52:07 -07:00
|
|
|
} else {
|
2020-04-27 11:04:26 -07:00
|
|
|
suite.Require().Error(err, tc.name)
|
2020-04-24 08:52:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|