diff --git a/tests/e2e/channel_init.go b/tests/e2e/channel_init.go index 7459f803d1..044b6e5272 100644 --- a/tests/e2e/channel_init.go +++ b/tests/e2e/channel_init.go @@ -21,8 +21,10 @@ func (suite *CCVTestSuite) TestConsumerGenesis() { genesis := consumerKeeper.ExportGenesis(suite.consumerChain.GetContext()) - suite.Require().Equal(suite.providerClient, genesis.ProviderClientState) - suite.Require().Equal(suite.providerConsState, genesis.ProviderConsensusState) + // Confirm that client and cons state are exported from consumer keeper properly + consumerEndpointClientState, consumerEndpointConsState := suite.GetConsumerEndpointClientAndConsState() + suite.Require().Equal(consumerEndpointClientState, genesis.ProviderClientState) + suite.Require().Equal(consumerEndpointConsState, genesis.ProviderConsensusState) suite.Require().NotPanics(func() { consumerKeeper.InitGenesis(suite.consumerChain.GetContext(), genesis) @@ -85,15 +87,6 @@ func (suite *CCVTestSuite) TestConsumerGenesis() { }) } -// TestProviderClientMatches tests that the provider client managed by the consumer keeper matches the client keeper's client state -func (suite *CCVTestSuite) TestProviderClientMatches() { - providerClientID, ok := suite.consumerApp.GetConsumerKeeper().GetProviderClientID(suite.consumerCtx()) - suite.Require().True(ok) - - clientState, _ := suite.consumerApp.GetIBCKeeper().ClientKeeper.GetClientState(suite.consumerCtx(), providerClientID) - suite.Require().Equal(suite.providerClient, clientState, "stored client state does not match genesis provider client") -} - // TestInitTimeout tests the init timeout func (suite *CCVTestSuite) TestInitTimeout() { testCases := []struct { diff --git a/tests/e2e/common.go b/tests/e2e/common.go index 9e8bd1f803..5f0906c775 100644 --- a/tests/e2e/common.go +++ b/tests/e2e/common.go @@ -406,3 +406,19 @@ func (suite *CCVTestSuite) CreateCustomClient(endpoint *ibctesting.Endpoint, unb endpoint.ClientID, err = ibctesting.ParseClientIDFromEvents(res.GetEvents()) require.NoError(endpoint.Chain.T, err) } + +func (suite *CCVTestSuite) GetConsumerEndpointClientAndConsState() (exported.ClientState, exported.ConsensusState) { + + clientID, found := suite.consumerApp.GetConsumerKeeper().GetProviderClientID(suite.consumerCtx()) + suite.Require().True(found) + + clientState, found := suite.consumerApp.GetIBCKeeper().ClientKeeper.GetClientState( + suite.consumerCtx(), clientID) + suite.Require().True(found) + + consState, found := suite.consumerApp.GetIBCKeeper().ClientKeeper.GetClientConsensusState( + suite.consumerCtx(), clientID, clientState.GetLatestHeight()) + suite.Require().True(found) + + return clientState, consState +} diff --git a/tests/e2e/setup.go b/tests/e2e/setup.go index 069566253f..83c07ba6c9 100644 --- a/tests/e2e/setup.go +++ b/tests/e2e/setup.go @@ -1,8 +1,6 @@ package e2e import ( - "time" - ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" "bytes" @@ -28,16 +26,14 @@ import ( // Any method implemented for this struct will be ran when suite.Run() is called. type CCVTestSuite struct { suite.Suite - coordinator *ibctesting.Coordinator - providerChain *ibctesting.TestChain - consumerChain *ibctesting.TestChain - providerApp e2e.ProviderApp - consumerApp e2e.ConsumerApp - providerClient *ibctmtypes.ClientState - providerConsState *ibctmtypes.ConsensusState - path *ibctesting.Path - transferPath *ibctesting.Path - setupCallback SetupCallback + coordinator *ibctesting.Coordinator + providerChain *ibctesting.TestChain + consumerChain *ibctesting.TestChain + providerApp e2e.ProviderApp + consumerApp e2e.ConsumerApp + path *ibctesting.Path + transferPath *ibctesting.Path + setupCallback SetupCallback } // NewCCVTestSuite returns a new instance of CCVTestSuite, ready to be tested against using suite.Run(). @@ -94,40 +90,40 @@ func (suite *CCVTestSuite) SetupTest() { suite.providerChain.NextBlock() // initialize the consumer chain with the genesis state stored on the provider - consumerGenesis, found := providerKeeper.GetConsumerGenesis( + consumerGenesisState, found := providerKeeper.GetConsumerGenesis( suite.providerCtx(), suite.consumerChain.ChainID, ) suite.Require().True(found, "consumer genesis not found") - consumerKeeper.InitGenesis(suite.consumerCtx(), &consumerGenesis) - suite.providerClient = consumerGenesis.ProviderClientState - suite.providerConsState = consumerGenesis.ProviderConsensusState + consumerKeeper.InitGenesis(suite.consumerCtx(), &consumerGenesisState) + + // Confirm client and cons state for consumer were set correctly in InitGenesis + consumerEndpointClientState, consumerEndpointConsState := suite.GetConsumerEndpointClientAndConsState() + suite.Require().Equal(consumerGenesisState.ProviderClientState, consumerEndpointClientState) + suite.Require().Equal(consumerGenesisState.ProviderConsensusState, consumerEndpointConsState) // create path for the CCV channel suite.path = ibctesting.NewPath(suite.consumerChain, suite.providerChain) - // update CCV path with correct info - // - set provider endpoint's clientID - consumerClient, found := providerKeeper.GetConsumerClientId( + // Set provider endpoint's clientID + providerEndpointClientID, found := providerKeeper.GetConsumerClientId( suite.providerCtx(), suite.consumerChain.ChainID, ) + suite.Require().True(found, "provider endpoint clientID not found") + suite.path.EndpointB.ClientID = providerEndpointClientID + + // Set consumer endpoint's clientID + consumerEndpointClientID, found := consumerKeeper.GetProviderClientID(suite.consumerChain.GetContext()) + suite.Require().True(found, "consumer endpoint clientID not found") + suite.path.EndpointA.ClientID = consumerEndpointClientID + + // Note: suite.path.EndpointA.ClientConfig and suite.path.EndpointB.ClientConfig are not populated, + // since these IBC testing package fields are unused in our tests. + + // Confirm client config is now correct + suite.ValidateEndpointsClientConfig() - suite.Require().True(found, "consumer client not found") - suite.path.EndpointB.ClientID = consumerClient - // - set consumer endpoint's clientID - providerClient, found := consumerKeeper.GetProviderClientID(suite.consumerChain.GetContext()) - suite.Require().True(found, "provider client not found") - suite.path.EndpointA.ClientID = providerClient - // - client config - - trustingPeriodFraction := suite.providerApp.GetProviderKeeper().GetTrustingPeriodFraction(suite.providerCtx()) - providerUnbondingPeriod := suite.providerApp.GetStakingKeeper().UnbondingTime(suite.providerCtx()) - suite.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = providerUnbondingPeriod - suite.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = providerUnbondingPeriod / time.Duration(trustingPeriodFraction) - consumerUnbondingPeriod := consumerKeeper.GetUnbondingPeriod(suite.consumerCtx()) - suite.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = consumerUnbondingPeriod - suite.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = consumerUnbondingPeriod / time.Duration(trustingPeriodFraction) // - channel config suite.path.EndpointA.ChannelConfig.PortID = ccv.ConsumerPortID suite.path.EndpointB.ChannelConfig.PortID = ccv.ProviderPortID @@ -206,3 +202,26 @@ func (suite *CCVTestSuite) SetupTransferChannel() { err = suite.transferPath.EndpointA.UpdateClient() suite.Require().NoError(err) } + +func (s CCVTestSuite) ValidateEndpointsClientConfig() { + consumerKeeper := s.consumerApp.GetConsumerKeeper() + providerStakingKeeper := s.providerApp.GetStakingKeeper() + + consumerUnbondingPeriod := consumerKeeper.GetUnbondingPeriod(s.consumerCtx()) + cs, ok := s.providerApp.GetIBCKeeper().ClientKeeper.GetClientState(s.providerCtx(), s.path.EndpointB.ClientID) + s.Require().True(ok) + s.Require().Equal( + consumerUnbondingPeriod, + cs.(*ibctmtypes.ClientState).UnbondingPeriod, + "unexpected unbonding period in consumer client state", + ) + + providerUnbondingPeriod := providerStakingKeeper.UnbondingTime(s.providerCtx()) + cs, ok = s.consumerApp.GetIBCKeeper().ClientKeeper.GetClientState(s.consumerCtx(), s.path.EndpointA.ClientID) + s.Require().True(ok) + s.Require().Equal( + providerUnbondingPeriod, + cs.(*ibctmtypes.ClientState).UnbondingPeriod, + "unexpected unbonding period in provider client state", + ) +} diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index 9844ab55ac..b235476260 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -210,8 +210,8 @@ func (k Keeper) MakeConsumerGenesis(ctx sdk.Context) (gen consumertypes.GenesisS height := clienttypes.GetSelfHeight(ctx) clientState := k.GetTemplateClient(ctx) - clientState.ChainId = ctx.ChainID() - clientState.LatestHeight = height //(+-1???) + clientState.ChainId = ctx.ChainID() // This will be the counter party chain ID for the consumer + clientState.LatestHeight = height //(+-1???) clientState.TrustingPeriod = providerUnbondingPeriod / time.Duration(k.GetTrustingPeriodFraction(ctx)) clientState.UnbondingPeriod = providerUnbondingPeriod @@ -224,6 +224,7 @@ func (k Keeper) MakeConsumerGenesis(ctx sdk.Context) (gen consumertypes.GenesisS gen.Params.Enabled = true gen.NewChain = true + // This will become the ccv client state for the consumer gen.ProviderClientState = clientState gen.ProviderConsensusState = consState.(*ibctmtypes.ConsensusState)