diff --git a/tests/integration/provider_gov_hooks.go b/tests/integration/provider_gov_hooks.go deleted file mode 100644 index 0890436781..0000000000 --- a/tests/integration/provider_gov_hooks.go +++ /dev/null @@ -1,178 +0,0 @@ -package integration - -import ( - "time" - - "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - - testkeeper "github.com/cosmos/interchain-security/v5/testutil/keeper" -) - -// TestAfterPropSubmissionAndVotingPeriodEnded tests AfterProposalSubmission and AfterProposalVotingPeriodEnded hooks -// require adding a proposal in the gov module and registering a consumer chain with the provider module -func (s *CCVTestSuite) TestAfterPropSubmissionAndVotingPeriodEnded() { - ctx := s.providerChain.GetContext() - providerKeeper := s.providerApp.GetProviderKeeper() - govKeeper := s.providerApp.GetTestGovKeeper() - proposer := s.providerChain.SenderAccount - - msgUpdateConsumer := testkeeper.GetTestMsgUpdateConsumer() - - proposal, err := v1.NewProposal([]sdk.Msg{&msgUpdateConsumer}, 1, time.Now(), time.Now().Add(1*time.Hour), "metadata", "title", "summary", proposer.GetAddress(), false) - s.Require().NoError(err) - - err = govKeeper.SetProposal(ctx, proposal) - s.Require().NoError(err) - - // the proposal can only be submitted if the owner of the chain is the gov module - providerKeeper.SetConsumerOwnerAddress(ctx, msgUpdateConsumer.ConsumerId, "some bogus address") - - err = providerKeeper.Hooks().AfterProposalSubmission(ctx, proposal.Id) - s.Require().Error(err) - - // the proposal can only be submitted if the owner of the chain is the gov module - govModuleAddress := "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn" - providerKeeper.SetConsumerOwnerAddress(ctx, msgUpdateConsumer.ConsumerId, govModuleAddress) - - err = providerKeeper.Hooks().AfterProposalSubmission(ctx, proposal.Id) - s.Require().NoError(err) - - // verify that the proposal id is created - consumerIdOnProvider, ok := providerKeeper.GetProposalIdToConsumerId(ctx, proposal.Id) - s.Require().True(ok) - s.Require().NotEmpty(consumerIdOnProvider) - s.Require().Equal(msgUpdateConsumer.ConsumerId, consumerIdOnProvider) - - providerKeeper.Hooks().AfterProposalVotingPeriodEnded(ctx, proposal.Id) - // verify that the proposal id is deleted - s.Require().Empty(providerKeeper.GetProposalIdToConsumerId(ctx, proposal.Id)) - - // assert that a proposal with more than one `MsgUpdateConsumer` messages fails - proposal, err = v1.NewProposal([]sdk.Msg{&msgUpdateConsumer, &msgUpdateConsumer}, 1, time.Now(), time.Now().Add(1*time.Hour), "metadata", "title", "summary", proposer.GetAddress(), false) - s.Require().NoError(err) - - err = govKeeper.SetProposal(ctx, proposal) - s.Require().NoError(err) - - err = providerKeeper.Hooks().AfterProposalSubmission(ctx, proposal.Id) - s.Require().Error(err) - -} - -func (s *CCVTestSuite) TestGetConsumerAdditionFromProp() { - ctx := s.providerChain.GetContext() - proposer := s.providerChain.SenderAccount - - // create a dummy bank send message - dummyMsg := &banktypes.MsgSend{ - FromAddress: sdk.AccAddress(proposer.GetAddress()).String(), - ToAddress: sdk.AccAddress(proposer.GetAddress()).String(), - Amount: sdk.NewCoins(sdk.NewCoin("stake", math.OneInt())), - } - - // create a legacy proposal - textProp, err := v1.NewLegacyContent( - v1beta1.NewTextProposal("a title", "a legacy text prop"), - authtypes.NewModuleAddress("gov").String(), - ) - s.Require().NoError(err) - - // create a valid consumer addition message - msgConsumerAddition := testkeeper.GetTestMsgConsumerAddition() - - // create a legacy consumer addition proposal content - // (not supported anymore) - addConsumerPropLegacy, err := v1.NewLegacyContent( - testkeeper.GetTestConsumerAdditionProp(), - authtypes.NewModuleAddress("gov").String(), - ) - s.Require().NoError(err) - - testCases := []struct { - name string - propMsg sdk.Msg - expectConsumerPropFound bool - expPanic bool - }{ - { - name: "prop not found", - propMsg: nil, - expectConsumerPropFound: false, - expPanic: false, - }, - { - name: "msgs in prop contain no consumer addition props", - propMsg: dummyMsg, - expectConsumerPropFound: false, - expPanic: false, - }, - { - name: "msgs contain a legacy prop but not of ConsumerAdditionProposal type", - propMsg: textProp, - expectConsumerPropFound: false, - }, - { - name: "msgs contain an invalid legacy prop", - propMsg: &v1.MsgExecLegacyContent{}, - expectConsumerPropFound: false, - expPanic: false, - }, - { - name: "msg contains a prop of legacy ConsumerAdditionProposal type - hook should NOT create a new proposed chain", - propMsg: addConsumerPropLegacy, - expectConsumerPropFound: false, - expPanic: false, - }, - { - name: "msg contains a prop of MsgConsumerAddition type - hook should create a new proposed chain", - propMsg: &msgConsumerAddition, - expectConsumerPropFound: true, - expPanic: false, - }, - } - - for _, tc := range testCases { - s.Run(tc.name, func() { - providerKeeper := s.providerApp.GetProviderKeeper() - govKeeper := s.providerApp.GetTestGovKeeper() - - var proposal v1.Proposal - var err error - - if tc.propMsg == nil { - // cover edgecase where proposal has no messages - proposal, err = v1.NewProposal([]sdk.Msg{}, 1, time.Now(), time.Now().Add(1*time.Hour), "metadata", "title", "summary", proposer.GetAddress(), false) - s.Require().NoError(err) - } else { - // cover variolus cases where proposal has messages but only some are consumer addition proposals - proposal, err = v1.NewProposal([]sdk.Msg{tc.propMsg}, 1, time.Now(), time.Now().Add(1*time.Hour), "metadata", "title", "summary", proposer.GetAddress(), false) - s.Require().NoError(err) - } - - err = govKeeper.SetProposal(ctx, proposal) - s.Require().NoError(err) - - if tc.expPanic { - s.Require().Panics(func() { - // this panics with a nil pointer dereference because the proposal is invalid and cannot be unmarshalled - providerKeeper.Hooks().GetConsumerAdditionFromProp(ctx, proposal.Id) - }) - return - } - - savedProp, found := providerKeeper.Hooks().GetConsumerAdditionFromProp(ctx, proposal.Id) - if tc.expectConsumerPropFound { - s.Require().True(found) - s.Require().NotEmpty(savedProp, savedProp) - } else { - s.Require().False(found) - s.Require().Empty(savedProp) - } - }) - } -} diff --git a/tests/integration/setup.go b/tests/integration/setup.go index 04f1882113..48d00d14ed 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -149,9 +149,8 @@ func (suite *CCVTestSuite) SetupTest() { // 1. the consumer chain is added to the coordinator // 2. MakeGenesis is called on the provider chain // 3. ibc/testing sets the tendermint header for the consumer chain app - - providerKeeper.SetConsumerPhase(suite.providerCtx(), icstestingutils.FirstConsumerId, providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED) - preProposalKeyAssignment(suite, icstestingutils.FirstConsumerId) + providerKeeper.SetConsumerPhase(suite.providerCtx(), icstestingutils.FirstConsumerID, providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED) + preProposalKeyAssignment(suite, icstestingutils.FirstConsumerID) // start consumer chains suite.consumerBundles = make(map[string]*icstestingutils.ConsumerBundle) diff --git a/testutil/ibc_testing/generic_setup.go b/testutil/ibc_testing/generic_setup.go index 8b0cdfa9f0..74bf620080 100644 --- a/testutil/ibc_testing/generic_setup.go +++ b/testutil/ibc_testing/generic_setup.go @@ -38,7 +38,8 @@ const ( ) var ( - FirstConsumerId string + firstConsumerChainID string + FirstConsumerID string provChainID string democConsumerChainID string consumerTopNParams [NumConsumers]uint32 @@ -47,7 +48,8 @@ var ( func init() { // Disable revision format ibctesting.ChainIDSuffix = "" - FirstConsumerId = "2" + firstConsumerChainID = ibctesting.GetChainID(2) + FirstConsumerID = "" provChainID = ibctesting.GetChainID(1) democConsumerChainID = ibctesting.GetChainID(5000) // TopN parameter values per consumer chain initiated @@ -153,7 +155,10 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp]( powerShapingParameters := testkeeper.GetTestPowerShapingParameters() powerShapingParameters.Top_N = consumerTopNParams[index] // isn't used in CreateConsumerClient - consumerId := fmt.Sprintf("%d", index+2) + consumerId := providerKeeper.FetchAndIncrementConsumerId(providerChain.GetContext()) + if chainID == firstConsumerChainID { + FirstConsumerID = consumerId + } providerKeeper.SetConsumerChainId(providerChain.GetContext(), consumerId, chainID) providerKeeper.SetConsumerMetadata(providerChain.GetContext(), consumerId, consumerMetadata) providerKeeper.SetConsumerInitializationParameters(providerChain.GetContext(), consumerId, initializationParameters) @@ -180,14 +185,13 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp]( providerChain.GetContext(), consumerId, ) + s.Require().True(found, "consumer genesis not found in AddConsumer") - foo, found := providerKeeper.GetConsumerClientId( + _, found = providerKeeper.GetConsumerClientId( providerChain.GetContext(), consumerId, ) - _ = foo - - s.Require().True(found, "consumer genesis not found in AddConsumer") + s.Require().True(found, "clientID not found in AddConsumer") // use InitialValSet as the valset on the consumer var valz []*tmtypes.Validator diff --git a/testutil/keeper/unit_test_helpers.go b/testutil/keeper/unit_test_helpers.go index a7ef6d7563..e4b52dbb01 100644 --- a/testutil/keeper/unit_test_helpers.go +++ b/testutil/keeper/unit_test_helpers.go @@ -282,23 +282,18 @@ func GetTestConsumerMetadata() providertypes.ConsumerMetadata { } func GetTestInitializationParameters() providertypes.ConsumerInitializationParameters { - initialHeight := clienttypes.NewHeight(4, 5) - spawnTime := time.Now().UTC() - ccvTimeoutPeriod := types.DefaultCCVTimeoutPeriod - transferTimeoutPeriod := types.DefaultTransferTimeoutPeriod - unbondingPeriod := types.DefaultConsumerUnbondingPeriod return providertypes.ConsumerInitializationParameters{ - InitialHeight: initialHeight, + InitialHeight: clienttypes.NewHeight(4, 5), GenesisHash: []byte("gen_hash"), BinaryHash: []byte("bin_hash"), - SpawnTime: spawnTime, + SpawnTime: time.Now().UTC(), ConsumerRedistributionFraction: types.DefaultConsumerRedistributeFrac, BlocksPerDistributionTransmission: types.DefaultBlocksPerDistributionTransmission, DistributionTransmissionChannel: "", HistoricalEntries: types.DefaultHistoricalEntries, - CcvTimeoutPeriod: ccvTimeoutPeriod, - TransferTimeoutPeriod: transferTimeoutPeriod, - UnbondingPeriod: unbondingPeriod, + CcvTimeoutPeriod: types.DefaultCCVTimeoutPeriod, + TransferTimeoutPeriod: types.DefaultTransferTimeoutPeriod, + UnbondingPeriod: types.DefaultConsumerUnbondingPeriod, } } @@ -309,37 +304,11 @@ func GetTestPowerShapingParameters() providertypes.PowerShapingParameters { ValidatorSetCap: 0, Allowlist: nil, Denylist: nil, + MinStake: 0, + AllowInactiveVals: false, } } -func GetTestConsumerAdditionProp() *providertypes.ConsumerAdditionProposal { - prop := providertypes.NewConsumerAdditionProposal( - "chainID", - "description", - "chainID", - clienttypes.NewHeight(4, 5), - []byte("gen_hash"), - []byte("bin_hash"), - time.Now(), - types.DefaultConsumerRedistributeFrac, - types.DefaultBlocksPerDistributionTransmission, - "", - types.DefaultHistoricalEntries, - types.DefaultCCVTimeoutPeriod, - types.DefaultTransferTimeoutPeriod, - types.DefaultConsumerUnbondingPeriod, - 0, - 0, - 0, - nil, - nil, - 0, - false, - ).(*providertypes.ConsumerAdditionProposal) - - return prop -} - func GetTestMsgUpdateConsumer() providertypes.MsgUpdateConsumer { return providertypes.MsgUpdateConsumer{ Signer: "signer",