Allow localhost to be created (#7148)
* revert localhost not being created * Update x/ibc/02-client/keeper/grpc_query_test.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
parent
3d969a1ffd
commit
49e4d059ae
|
@ -5,6 +5,8 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
client "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||||
ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing"
|
ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,26 +30,22 @@ func TestClientTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(ClientTestSuite))
|
suite.Run(t, new(ClientTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: uncomment once simapp is switched to proto
|
|
||||||
func (suite *ClientTestSuite) TestBeginBlocker() {
|
func (suite *ClientTestSuite) TestBeginBlocker() {
|
||||||
prevHeight := suite.ctx.BlockHeight()
|
prevHeight := suite.chainA.GetContext().BlockHeight()
|
||||||
|
|
||||||
localHostClient, found := suite.app.IBCKeeper.ClientKeeper.GetClientState(suite.ctx, exported.ClientTypeLocalHost)
|
localHostClient := suite.chainA.GetClientState(exported.ClientTypeLocalHost)
|
||||||
suite.Require().True(found)
|
|
||||||
suite.Require().Equal(prevHeight, int64(localHostClient.GetLatestHeight()))
|
suite.Require().Equal(prevHeight, int64(localHostClient.GetLatestHeight()))
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
// increment height
|
// increment height
|
||||||
suite.ctx = suite.ctx.WithBlockHeight(suite.ctx.BlockHeight() + 1)
|
suite.coordinator.CommitBlock(suite.chainA, suite.chainB)
|
||||||
|
|
||||||
suite.Require().NotPanics(func() {
|
suite.Require().NotPanics(func() {
|
||||||
client.BeginBlocker(suite.ctx, suite.app.IBCKeeper.ClientKeeper)
|
client.BeginBlocker(suite.chainA.GetContext(), suite.chainA.App.IBCKeeper.ClientKeeper)
|
||||||
}, "BeginBlocker shouldn't panic")
|
}, "BeginBlocker shouldn't panic")
|
||||||
|
|
||||||
localHostClient, found = suite.app.IBCKeeper.ClientKeeper.GetClientState(suite.ctx, exported.ClientTypeLocalHost)
|
localHostClient = suite.chainA.GetClientState(exported.ClientTypeLocalHost)
|
||||||
suite.Require().True(found)
|
|
||||||
suite.Require().Equal(prevHeight+1, int64(localHostClient.GetLatestHeight()))
|
suite.Require().Equal(prevHeight+1, int64(localHostClient.GetLatestHeight()))
|
||||||
prevHeight = int64(localHostClient.GetLatestHeight())
|
prevHeight = int64(localHostClient.GetLatestHeight())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
|
@ -52,6 +52,8 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExportGenesis returns the ibc client submodule's exported genesis.
|
// ExportGenesis returns the ibc client submodule's exported genesis.
|
||||||
|
// NOTE: CreateLocalhost should always be false on export since a
|
||||||
|
// created localhost will be included in the exported clients.
|
||||||
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
|
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
|
||||||
return types.GenesisState{
|
return types.GenesisState{
|
||||||
Clients: k.GetAllGenesisClients(ctx),
|
Clients: k.GetAllGenesisClients(ctx),
|
||||||
|
|
|
@ -13,12 +13,6 @@ func (suite *ClientTestSuite) TestHandleCreateClientLocalHost() {
|
||||||
msg exported.MsgCreateClient
|
msg exported.MsgCreateClient
|
||||||
expPass bool
|
expPass bool
|
||||||
}{
|
}{
|
||||||
{
|
|
||||||
"localhost",
|
|
||||||
exported.ClientTypeLocalHost,
|
|
||||||
&localhosttypes.MsgCreateClient{suite.chainA.SenderAccount.GetAddress()},
|
|
||||||
true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"tendermint client",
|
"tendermint client",
|
||||||
"gaiamainnet",
|
"gaiamainnet",
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||||
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||||
|
localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"
|
||||||
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -229,16 +230,15 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func (suite *KeeperTestSuite) TestUpdateClientLocalhost() {
|
func (suite *KeeperTestSuite) TestUpdateClientLocalhost() {
|
||||||
var localhostClient exported.ClientState = localhosttypes.NewClientState(suite.header.ChainID, suite.ctx.BlockHeight())
|
var localhostClient exported.ClientState = localhosttypes.NewClientState(suite.header.Header.GetChainID(), suite.ctx.BlockHeight())
|
||||||
|
|
||||||
suite.ctx = suite.ctx.WithBlockHeight(suite.ctx.BlockHeight() + 1)
|
suite.ctx = suite.ctx.WithBlockHeight(suite.ctx.BlockHeight() + 1)
|
||||||
|
|
||||||
updatedClientState, err := suite.keeper.UpdateClient(suite.ctx, exported.ClientTypeLocalHost, nil)
|
updatedClientState, err := suite.keeper.UpdateClient(suite.ctx, exported.ClientTypeLocalHost, nil)
|
||||||
suite.Require().NoError(err, err)
|
suite.Require().NoError(err, err)
|
||||||
suite.Require().Equal(localhostClient.GetLatestHeight()+1, updatedClientState.GetLatestHeight())
|
suite.Require().Equal(localhostClient.GetLatestHeight()+1, updatedClientState.GetLatestHeight())
|
||||||
}*/
|
}
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
|
func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
|
||||||
altPrivVal := tmtypes.NewMockPV()
|
altPrivVal := tmtypes.NewMockPV()
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/types/query"
|
"github.com/cosmos/cosmos-sdk/types/query"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||||
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||||
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
||||||
|
@ -110,19 +111,20 @@ func (suite *KeeperTestSuite) TestQueryClientStates() {
|
||||||
{
|
{
|
||||||
"success",
|
"success",
|
||||||
func() {
|
func() {
|
||||||
clientState := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs())
|
clientA1, _ := suite.coordinator.SetupClients(suite.chainA, suite.chainB, exported.Tendermint)
|
||||||
clientState2 := ibctmtypes.NewClientState(testChainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, 0, commitmenttypes.GetSDKSpecs())
|
clientA2, _ := suite.coordinator.CreateClient(suite.chainA, suite.chainB, exported.Tendermint)
|
||||||
suite.keeper.SetClientState(suite.ctx, testClientID, clientState)
|
|
||||||
suite.keeper.SetClientState(suite.ctx, testClientID2, clientState2)
|
|
||||||
|
|
||||||
idcs := types.NewIdentifiedClientState(testClientID, clientState)
|
clientStateA1 := suite.chainA.GetClientState(clientA1)
|
||||||
idcs2 := types.NewIdentifiedClientState(testClientID2, clientState2)
|
clientStateA2 := suite.chainA.GetClientState(clientA2)
|
||||||
|
|
||||||
// order is swapped because the res is sorted by client id
|
idcs := types.NewIdentifiedClientState(clientA1, clientStateA1)
|
||||||
expClientStates = []*types.IdentifiedClientState{&idcs2, &idcs}
|
idcs2 := types.NewIdentifiedClientState(clientA2, clientStateA2)
|
||||||
|
|
||||||
|
// order is sorted by client id, localhost is last
|
||||||
|
expClientStates = []*types.IdentifiedClientState{&idcs, &idcs2}
|
||||||
req = &types.QueryClientStatesRequest{
|
req = &types.QueryClientStatesRequest{
|
||||||
Pagination: &query.PageRequest{
|
Pagination: &query.PageRequest{
|
||||||
Limit: 3,
|
Limit: 7,
|
||||||
CountTotal: true,
|
CountTotal: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -134,11 +136,18 @@ func (suite *KeeperTestSuite) TestQueryClientStates() {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
|
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
|
||||||
suite.SetupTest() // reset
|
suite.SetupTest() // reset
|
||||||
|
expClientStates = nil
|
||||||
|
|
||||||
tc.malleate()
|
tc.malleate()
|
||||||
ctx := sdk.WrapSDKContext(suite.ctx)
|
|
||||||
|
|
||||||
res, err := suite.queryClient.ClientStates(ctx, req)
|
// always add localhost which is created by default in init genesis
|
||||||
|
localhostClientState := suite.chainA.GetClientState(exported.Localhost.String())
|
||||||
|
identifiedLocalhost := types.NewIdentifiedClientState(exported.Localhost.String(), localhostClientState)
|
||||||
|
expClientStates = append(expClientStates, &identifiedLocalhost)
|
||||||
|
|
||||||
|
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
|
||||||
|
|
||||||
|
res, err := suite.chainA.QueryServer.ClientStates(ctx, req)
|
||||||
|
|
||||||
if tc.expPass {
|
if tc.expPass {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
@ -147,7 +156,6 @@ func (suite *KeeperTestSuite) TestQueryClientStates() {
|
||||||
for i := range expClientStates {
|
for i := range expClientStates {
|
||||||
suite.Require().Equal(expClientStates[i].ClientId, res.ClientStates[i].ClientId)
|
suite.Require().Equal(expClientStates[i].ClientId, res.ClientStates[i].ClientId)
|
||||||
suite.Require().NotNil(res.ClientStates[i].ClientState)
|
suite.Require().NotNil(res.ClientStates[i].ClientState)
|
||||||
expClientStates[i].ClientState.ClearCachedValue()
|
|
||||||
suite.Require().Equal(expClientStates[i].ClientState, res.ClientStates[i].ClientState)
|
suite.Require().Equal(expClientStates[i].ClientState, res.ClientStates[i].ClientState)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||||
localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"
|
localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"
|
||||||
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
||||||
|
ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing"
|
||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,6 +42,11 @@ const (
|
||||||
type KeeperTestSuite struct {
|
type KeeperTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
|
coordinator *ibctesting.Coordinator
|
||||||
|
|
||||||
|
chainA *ibctesting.TestChain
|
||||||
|
chainB *ibctesting.TestChain
|
||||||
|
|
||||||
cdc codec.Marshaler
|
cdc codec.Marshaler
|
||||||
ctx sdk.Context
|
ctx sdk.Context
|
||||||
keeper *keeper.Keeper
|
keeper *keeper.Keeper
|
||||||
|
@ -56,6 +62,11 @@ type KeeperTestSuite struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) SetupTest() {
|
func (suite *KeeperTestSuite) SetupTest() {
|
||||||
|
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
|
||||||
|
|
||||||
|
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(0))
|
||||||
|
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1))
|
||||||
|
|
||||||
isCheckTx := false
|
isCheckTx := false
|
||||||
suite.now = time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC)
|
suite.now = time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC)
|
||||||
suite.past = time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
|
suite.past = time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||||
|
@ -207,10 +218,9 @@ func (suite KeeperTestSuite) TestGetAllClients() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add localhost client
|
// add localhost client
|
||||||
// TODO: uncomment after simapp is migrated to proto
|
localHostClient, found := suite.keeper.GetClientState(suite.ctx, exported.ClientTypeLocalHost)
|
||||||
// localHostClient, found := suite.keeper.GetClientState(suite.ctx, exported.ClientTypeLocalHost)
|
suite.Require().True(found)
|
||||||
// suite.Require().True(found)
|
expClients = append(expClients, localHostClient)
|
||||||
// expClients = append(expClients, localHostClient)
|
|
||||||
|
|
||||||
clients := suite.keeper.GetAllClients(suite.ctx)
|
clients := suite.keeper.GetAllClients(suite.ctx)
|
||||||
suite.Require().Len(clients, len(expClients))
|
suite.Require().Len(clients, len(expClients))
|
||||||
|
@ -235,10 +245,9 @@ func (suite KeeperTestSuite) TestGetAllGenesisClients() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add localhost client
|
// add localhost client
|
||||||
// TODO: uncomment after simapp is migrated to proto
|
localHostClient, found := suite.keeper.GetClientState(suite.ctx, exported.ClientTypeLocalHost)
|
||||||
// localHostClient, found := suite.keeper.GetClientState(suite.ctx, exported.ClientTypeLocalHost)
|
suite.Require().True(found)
|
||||||
// suite.Require().True(found)
|
expGenClients = append(expGenClients, types.NewIdentifiedClientState(exported.ClientTypeLocalHost, localHostClient))
|
||||||
// expGenClients = append(expGenClients, types.NewIdentifiedClientState(exported.ClientTypeLocalHost, localHostClient))
|
|
||||||
|
|
||||||
genClients := suite.keeper.GetAllGenesisClients(suite.ctx)
|
genClients := suite.keeper.GetAllGenesisClients(suite.ctx)
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ func DefaultGenesisState() GenesisState {
|
||||||
return GenesisState{
|
return GenesisState{
|
||||||
Clients: []IdentifiedClientState{},
|
Clients: []IdentifiedClientState{},
|
||||||
ClientsConsensus: ClientsConsensusStates{},
|
ClientsConsensus: ClientsConsensusStates{},
|
||||||
CreateLocalhost: false,
|
CreateLocalhost: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue