From a8c6c798231a9c164e1922aac55079a761a50ac4 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Thu, 7 Mar 2024 08:17:11 +0100 Subject: [PATCH 1/5] draft multi consumer transfer setup and test --- tests/integration/distribution.go | 92 ++++++++++++++++++++++++++++++ tests/integration/setup.go | 59 +++++++++++++++---- testutil/integration/debug_test.go | 4 ++ 3 files changed, 143 insertions(+), 12 deletions(-) diff --git a/tests/integration/distribution.go b/tests/integration/distribution.go index f06c6f9482..49b0c3d506 100644 --- a/tests/integration/distribution.go +++ b/tests/integration/distribution.go @@ -979,3 +979,95 @@ func (s *CCVTestSuite) TestAllocateTokensToValidator() { }) } } + +func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() { + s.SetupAllCCVChannels() + s.SetupAllTransferChannels() + + providerBankKeeper := s.providerApp.GetTestBankKeeper() + providerAccountKeeper := s.providerApp.GetTestAccountKeeper() + + // check all consumer transfer channels are setup + for chainID := range s.consumerBundles { + bundle := s.consumerBundles[chainID] + s.Require().Equal( + bundle.TransferPath.EndpointA.ChannelID, + bundle.App.GetConsumerKeeper().GetDistributionTransmissionChannel(bundle.GetCtx()), + ) + } + + _, ok := s.consumerApp.GetConsumerKeeper().GetProviderChannel(s.consumerCtx()) + s.Require().False(ok) + + bondAmt := sdk.NewInt(10000000) + delAddr := s.providerChain.SenderAccount.GetAddress() + delegate(s, delAddr, bondAmt) + s.providerChain.NextBlock() + + // relay VSC packets from provider to consumer + relayAllCommittedPackets(s, s.providerChain, s.path, ccv.ProviderPortID, s.path.EndpointB.ChannelID, 1) + + _, ok = s.consumerApp.GetConsumerKeeper().GetProviderChannel(s.consumerCtx()) + s.Require().True(ok) + + // check that the reward provider pool is empty + rewardPool := providerAccountKeeper.GetModuleAccount(s.providerCtx(), providertypes.ConsumerRewardsPool).GetAddress() + rewardCoins := providerBankKeeper.GetAllBalances(s.providerCtx(), rewardPool) + s.Require().Empty(rewardCoins) + + rewardPerConsumer := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))) + totalConsumerRewards := sdk.Coins{} + + // for each chain, fill the reward pool + // and transfer the rewards to the provider + for chainID := range s.consumerBundles { + bundle := s.consumerBundles[chainID] + + bankKeeper := bundle.App.GetTestBankKeeper() + consumerKeeper := bundle.App.GetConsumerKeeper() + + err := bankKeeper.SendCoinsFromAccountToModule( + bundle.GetCtx(), + bundle.Chain.SenderAccount.GetAddress(), + consumertypes.ConsumerToSendToProviderName, + rewardPerConsumer, + ) + s.Require().NoError(err) + + // register consumer reward denom + params := consumerKeeper.GetConsumerParams(bundle.GetCtx()) + params.RewardDenoms = []string{sdk.DefaultBondDenom} + consumerKeeper.SetParams(bundle.GetCtx(), params) + + // reward for the provider chain will be sent after each 2 blocks + consumerParams := bundle.App.GetSubspace(consumertypes.ModuleName) + consumerParams.Set(bundle.GetCtx(), ccv.KeyBlocksPerDistributionTransmission, int64(2)) + bundle.Chain.NextBlock() + bundle.Chain.NextBlock() + + // relay IBC transfer packet from consumer to provider + relayAllCommittedPackets( + s, + bundle.Chain, + bundle.TransferPath, + transfertypes.PortID, + bundle.TransferPath.EndpointA.ChannelID, + 1, + ) + totalConsumerRewards = totalConsumerRewards.Add(rewardPerConsumer...) + } + + // Check that the provider receives the rewards + rewardPool = providerAccountKeeper.GetModuleAccount(s.providerCtx(), providertypes.ConsumerRewardsPool).GetAddress() + rewardCoins = providerBankKeeper.GetAllBalances(s.providerCtx(), rewardPool) + s.Require().Equal(totalConsumerRewards, rewardCoins) + + for chainID := range s.consumerBundles { + // check that the consumer rewards allocation are empty since relayAllCommittedPackets call BeginBlock + rewardsAlloc := s.providerApp.GetProviderKeeper().GetConsumerRewardsAllocation( + s.providerCtx(), + chainID, + ) + s.Require().Empty(rewardsAlloc.Rewards) + } +} diff --git a/tests/integration/setup.go b/tests/integration/setup.go index e401324c82..1041e82e8e 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -222,7 +222,6 @@ func initConsumerChain( ) s.Require().True(found, "provider endpoint clientID not found") bundle.Path.EndpointB.ClientID = providerEndpointClientID - // Set consumer endpoint's clientID consumerKeeper := bundle.GetKeeper() consumerEndpointClientID, found := consumerKeeper.GetProviderClientID(bundle.GetCtx()) @@ -302,34 +301,70 @@ func (suite *CCVTestSuite) ExecuteCCVChannelHandshake(path *ibctesting.Path) { // TODO: Make SetupTransferChannel functional for multiple consumers by pattern matching SetupCCVChannel. // See: https://github.com/cosmos/interchain-security/issues/506 +// SetupTransferChannel setup the transfer channel of the first consumer chain among multiple func (suite *CCVTestSuite) SetupTransferChannel() { - // transfer path will use the same connection as ccv path + suite.setupTransferChannel( + suite.transferPath, + suite.path, + suite.consumerApp.GetConsumerKeeper().GetDistributionTransmissionChannel( + suite.consumerChain.GetContext(), + ), + ) +} - suite.transferPath.EndpointA.ClientID = suite.path.EndpointA.ClientID - suite.transferPath.EndpointA.ConnectionID = suite.path.EndpointA.ConnectionID - suite.transferPath.EndpointB.ClientID = suite.path.EndpointB.ClientID - suite.transferPath.EndpointB.ConnectionID = suite.path.EndpointB.ConnectionID +func (suite *CCVTestSuite) setupTransferChannel( + transferPath *ibctesting.Path, + ccvPath *ibctesting.Path, + channelID string, +) { + // transfer path will use the same connection as ccv path + transferPath.EndpointA.ClientID = ccvPath.EndpointA.ClientID + transferPath.EndpointA.ConnectionID = ccvPath.EndpointA.ConnectionID + transferPath.EndpointB.ClientID = ccvPath.EndpointB.ClientID + transferPath.EndpointB.ConnectionID = ccvPath.EndpointB.ConnectionID // CCV channel handshake will automatically initiate transfer channel handshake on ACK // so transfer channel will be on stage INIT when CompleteSetupCCVChannel returns. - suite.transferPath.EndpointA.ChannelID = suite.consumerApp.GetConsumerKeeper().GetDistributionTransmissionChannel( - suite.consumerChain.GetContext()) + transferPath.EndpointA.ChannelID = channelID // Complete TRY, ACK, CONFIRM for transfer path - err := suite.transferPath.EndpointB.ChanOpenTry() + err := transferPath.EndpointB.ChanOpenTry() suite.Require().NoError(err) - err = suite.transferPath.EndpointA.ChanOpenAck() + err = transferPath.EndpointA.ChanOpenAck() suite.Require().NoError(err) - err = suite.transferPath.EndpointB.ChanOpenConfirm() + err = transferPath.EndpointB.ChanOpenConfirm() suite.Require().NoError(err) // ensure counterparty is up to date - err = suite.transferPath.EndpointA.UpdateClient() + err = transferPath.EndpointA.UpdateClient() suite.Require().NoError(err) } +// SetupAllTransferChannel setup all consumer chains transfer channel +func (suite *CCVTestSuite) SetupAllTransferChannels() { + // setup the first consumer transfer channel + suite.SetupTransferChannel() + + // setup all the remaining consumers transfer channels + for chainID := range suite.consumerBundles { + // skip fist consumer + if chainID == suite.consumerChain.ChainID { + continue + } + + // get the bundle for the chain ID + bundle := suite.consumerBundles[chainID] + // setup the transfer channel + suite.setupTransferChannel( + bundle.TransferPath, + bundle.Path, + bundle.App.GetConsumerKeeper().GetDistributionTransmissionChannel(bundle.GetCtx()), + ) + } +} + func (s CCVTestSuite) validateEndpointsClientConfig(consumerBundle icstestingutils.ConsumerBundle) { //nolint:govet // this is a test so we can copy locks consumerKeeper := consumerBundle.GetKeeper() providerStakingKeeper := s.providerApp.GetTestStakingKeeper() diff --git a/testutil/integration/debug_test.go b/testutil/integration/debug_test.go index c370e8e701..2481e865ab 100644 --- a/testutil/integration/debug_test.go +++ b/testutil/integration/debug_test.go @@ -299,3 +299,7 @@ func TestTransferConsumerRewardsToDistributionModule(t *testing.T) { func TestAllocateTokensToValidator(t *testing.T) { runCCVTestByName(t, "TestAllocateTokensToValidator") } + +func TestMultiConsumerRewardsDistribution(t *testing.T) { + runCCVTestByName(t, "TestMultiConsumerRewardsDistribution") +} From 1cd2281f0a79f00063ab3e70c1e3ecf56a752d39 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Thu, 7 Mar 2024 08:43:39 +0100 Subject: [PATCH 2/5] format multi consumer distribution test --- tests/integration/distribution.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/integration/distribution.go b/tests/integration/distribution.go index 49b0c3d506..176aa6593e 100644 --- a/tests/integration/distribution.go +++ b/tests/integration/distribution.go @@ -980,6 +980,8 @@ func (s *CCVTestSuite) TestAllocateTokensToValidator() { } } +// TestMultiConsumerRewardsDistribution tests the reward distribution in the conext +// of multiple consumers sending rewards to the provider func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() { s.SetupAllCCVChannels() s.SetupAllTransferChannels() @@ -1015,7 +1017,7 @@ func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() { rewardCoins := providerBankKeeper.GetAllBalances(s.providerCtx(), rewardPool) s.Require().Empty(rewardCoins) - rewardPerConsumer := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))) + rewardsPerConsumer := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) totalConsumerRewards := sdk.Coins{} // for each chain, fill the reward pool @@ -1030,13 +1032,13 @@ func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() { bundle.GetCtx(), bundle.Chain.SenderAccount.GetAddress(), consumertypes.ConsumerToSendToProviderName, - rewardPerConsumer, + sdk.NewCoins(rewardsPerConsumer), ) s.Require().NoError(err) // register consumer reward denom params := consumerKeeper.GetConsumerParams(bundle.GetCtx()) - params.RewardDenoms = []string{sdk.DefaultBondDenom} + params.RewardDenoms = []string{rewardsPerConsumer.Denom} consumerKeeper.SetParams(bundle.GetCtx(), params) // reward for the provider chain will be sent after each 2 blocks @@ -1054,7 +1056,15 @@ func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() { bundle.TransferPath.EndpointA.ChannelID, 1, ) - totalConsumerRewards = totalConsumerRewards.Add(rewardPerConsumer...) + + // construct the denom of the reward tokens for the provider + prefixedDenom := ibctransfertypes.GetPrefixedDenom( + transfertypes.PortID, + bundle.TransferPath.EndpointB.ChannelID, + rewardsPerConsumer.Denom, + ) + provIBCDenom := ibctransfertypes.ParseDenomTrace(prefixedDenom).IBCDenom() + totalConsumerRewards = totalConsumerRewards.Add(sdk.NewCoin(provIBCDenom, rewardsPerConsumer.Amount)) } // Check that the provider receives the rewards From 762fbe4bf709b3cc955478077c31d85b43fa6b33 Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Thu, 7 Mar 2024 15:54:29 +0100 Subject: [PATCH 3/5] update test for democ consumer chains --- tests/integration/distribution.go | 102 ++++++++++++-------------- tests/integration/setup.go | 8 +- testutil/ibc_testing/generic_setup.go | 19 +++++ 3 files changed, 72 insertions(+), 57 deletions(-) diff --git a/tests/integration/distribution.go b/tests/integration/distribution.go index 176aa6593e..0a47faf3a0 100644 --- a/tests/integration/distribution.go +++ b/tests/integration/distribution.go @@ -989,62 +989,61 @@ func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() { providerBankKeeper := s.providerApp.GetTestBankKeeper() providerAccountKeeper := s.providerApp.GetTestAccountKeeper() - // check all consumer transfer channels are setup - for chainID := range s.consumerBundles { - bundle := s.consumerBundles[chainID] - s.Require().Equal( - bundle.TransferPath.EndpointA.ChannelID, - bundle.App.GetConsumerKeeper().GetDistributionTransmissionChannel(bundle.GetCtx()), - ) - } - - _, ok := s.consumerApp.GetConsumerKeeper().GetProviderChannel(s.consumerCtx()) - s.Require().False(ok) - - bondAmt := sdk.NewInt(10000000) - delAddr := s.providerChain.SenderAccount.GetAddress() - delegate(s, delAddr, bondAmt) - s.providerChain.NextBlock() - - // relay VSC packets from provider to consumer - relayAllCommittedPackets(s, s.providerChain, s.path, ccv.ProviderPortID, s.path.EndpointB.ChannelID, 1) - - _, ok = s.consumerApp.GetConsumerKeeper().GetProviderChannel(s.consumerCtx()) - s.Require().True(ok) - // check that the reward provider pool is empty rewardPool := providerAccountKeeper.GetModuleAccount(s.providerCtx(), providertypes.ConsumerRewardsPool).GetAddress() rewardCoins := providerBankKeeper.GetAllBalances(s.providerCtx(), rewardPool) s.Require().Empty(rewardCoins) - rewardsPerConsumer := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) totalConsumerRewards := sdk.Coins{} - // for each chain, fill the reward pool - // and transfer the rewards to the provider + // Iterate over the consumers and perform the reward distribution + // to the provider. for chainID := range s.consumerBundles { bundle := s.consumerBundles[chainID] - - bankKeeper := bundle.App.GetTestBankKeeper() consumerKeeper := bundle.App.GetConsumerKeeper() + bankKeeper := bundle.App.GetTestBankKeeper() + accountKeeper := bundle.App.GetTestAccountKeeper() - err := bankKeeper.SendCoinsFromAccountToModule( - bundle.GetCtx(), - bundle.Chain.SenderAccount.GetAddress(), - consumertypes.ConsumerToSendToProviderName, - sdk.NewCoins(rewardsPerConsumer), - ) - s.Require().NoError(err) - - // register consumer reward denom + // set the consumer reward denom and block per distribution params params := consumerKeeper.GetConsumerParams(bundle.GetCtx()) - params.RewardDenoms = []string{rewardsPerConsumer.Denom} + params.RewardDenoms = []string{sdk.DefaultBondDenom} + // set the reward distribution for the next block + params.BlocksPerDistributionTransmission = int64(1) consumerKeeper.SetParams(bundle.GetCtx(), params) - // reward for the provider chain will be sent after each 2 blocks - consumerParams := bundle.App.GetSubspace(consumertypes.ModuleName) - consumerParams.Set(bundle.GetCtx(), ccv.KeyBlocksPerDistributionTransmission, int64(2)) - bundle.Chain.NextBlock() + // transfer the consumer reward pool to the provider + var rewardsPerConsumer sdk.Coin + + // check the consumer pool balance + // Note that for a democracy consumer chain the reward pool may already be filled + if pool := bankKeeper.GetAllBalances( + bundle.GetCtx(), + accountKeeper.GetModuleAccount(bundle.GetCtx(), consumertypes.ConsumerToSendToProviderName).GetAddress(), + ); pool.Empty() { + // if pool is empty, fill it with some tokens + rewardsPerConsumer = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) + err := bankKeeper.SendCoinsFromAccountToModule( + bundle.GetCtx(), + bundle.Chain.SenderAccount.GetAddress(), + consumertypes.ConsumerToSendToProviderName, + sdk.NewCoins(rewardsPerConsumer), + ) + s.Require().NoError(err) + } else { + // the pool is filled so we force + // the internal reward distribution + // and save the pool balance before + // it get transferred to the provider + consumerKeeper.DistributeRewardsInternally(bundle.GetCtx()) + pool = bankKeeper.GetAllBalances( + bundle.GetCtx(), + accountKeeper.GetModuleAccount(bundle.GetCtx(), consumertypes.ConsumerToSendToProviderName).GetAddress(), + ) + s.Require().Len(pool, 1, "consumer reward pool cannot have mutiple token denoms") + rewardsPerConsumer = pool[0] + } + + // perform the reward transfer bundle.Chain.NextBlock() // relay IBC transfer packet from consumer to provider @@ -1064,20 +1063,13 @@ func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() { rewardsPerConsumer.Denom, ) provIBCDenom := ibctransfertypes.ParseDenomTrace(prefixedDenom).IBCDenom() - totalConsumerRewards = totalConsumerRewards.Add(sdk.NewCoin(provIBCDenom, rewardsPerConsumer.Amount)) + + // sum the total rewards transferred to the provider + totalConsumerRewards = totalConsumerRewards. + Add(sdk.NewCoin(provIBCDenom, rewardsPerConsumer.Amount)) } - // Check that the provider receives the rewards - rewardPool = providerAccountKeeper.GetModuleAccount(s.providerCtx(), providertypes.ConsumerRewardsPool).GetAddress() + // Check that the provider receives the rewards of each consumer rewardCoins = providerBankKeeper.GetAllBalances(s.providerCtx(), rewardPool) - s.Require().Equal(totalConsumerRewards, rewardCoins) - - for chainID := range s.consumerBundles { - // check that the consumer rewards allocation are empty since relayAllCommittedPackets call BeginBlock - rewardsAlloc := s.providerApp.GetProviderKeeper().GetConsumerRewardsAllocation( - s.providerCtx(), - chainID, - ) - s.Require().Empty(rewardsAlloc.Rewards) - } + s.Require().Equal(totalConsumerRewards, rewardCoins, totalConsumerRewards.String(), rewardCoins.String()) } diff --git a/tests/integration/setup.go b/tests/integration/setup.go index 1041e82e8e..9f5ed59f64 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -136,12 +136,16 @@ func (suite *CCVTestSuite) SetupTest() { preProposalKeyAssignment(suite, icstestingutils.FirstConsumerChainID) // start consumer chains - numConsumers := 5 suite.consumerBundles = make(map[string]*icstestingutils.ConsumerBundle) - for i := 0; i < numConsumers; i++ { + for i := 0; i < icstestingutils.NumConsumers; i++ { bundle := suite.setupConsumerCallback(&suite.Suite, suite.coordinator, i) suite.consumerBundles[bundle.Chain.ChainID] = bundle suite.registerPacketSniffer(bundle.Chain) + + // check that TopN was correctly set + topN, found := providerKeeper.GetTopN(suite.providerCtx(), bundle.Chain.ChainID) + suite.Require().True(found) + suite.Require().Equal(bundle.TopN, topN) } // initialize each consumer chain with it's corresponding genesis state diff --git a/testutil/ibc_testing/generic_setup.go b/testutil/ibc_testing/generic_setup.go index 6d17337853..4232997547 100644 --- a/testutil/ibc_testing/generic_setup.go +++ b/testutil/ibc_testing/generic_setup.go @@ -30,10 +30,16 @@ type ( // and/or democracy consumer app.go implementation. You should not need to modify or replicate this file // to run integration tests against your app.go implementations! +const ( + // Default number of setup consumer chains + NumConsumers = 5 +) + var ( FirstConsumerChainID string provChainID string democConsumerChainID string + consumerTopNParams [NumConsumers]uint32 ) func init() { @@ -42,6 +48,9 @@ func init() { FirstConsumerChainID = ibctesting.GetChainID(2) provChainID = ibctesting.GetChainID(1) democConsumerChainID = ibctesting.GetChainID(5000) + // TopN parameter values per consumer chain initiated + // sorted in ascending order i.e. testchain2, testchain3, ..., testchain6 + consumerTopNParams = [NumConsumers]uint32{100, 100, 100, 100, 100} } // ConsumerBundle serves as a way to store useful in-mem consumer app chain state @@ -51,6 +60,7 @@ type ConsumerBundle struct { App testutil.ConsumerApp Path *ibctesting.Path TransferPath *ibctesting.Path + TopN uint32 } // GetCtx returns the context for the ConsumerBundle @@ -116,6 +126,9 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp]( index int, appIniter ValSetAppIniter, ) *ConsumerBundle { + // check index isn't bigger that the number of consumers + s.Require().LessOrEqual(index, NumConsumers) + // consumer chain ID chainID := ibctesting.GetChainID(index + 2) @@ -126,6 +139,7 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp]( prop := testkeeper.GetTestConsumerAdditionProp() prop.ChainId = chainID + prop.Top_N = consumerTopNParams[index] // isn't used in CreateConsumerClient // NOTE: the initial height passed to CreateConsumerClient // must be the height on the consumer when InitGenesis is called prop.InitialHeight = clienttypes.Height{RevisionNumber: 0, RevisionHeight: 3} @@ -135,6 +149,10 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp]( ) s.Require().NoError(err) + // set the consumer TopN here since the test suite setup only used the consumer addition prop + // to create the consumer genesis, see BeginBlockInit in /x/ccv/provider/keeper/proposal.go. + providerKeeper.SetTopN(providerChain.GetContext(), chainID, prop.Top_N) + // commit the state on the provider chain coordinator.CommitBlock(providerChain) @@ -174,5 +192,6 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp]( return &ConsumerBundle{ Chain: testChain, App: consumerToReturn, + TopN: prop.Top_N, } } From cb090f4951731455f651f41b530a747d879397ca Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Thu, 7 Mar 2024 17:26:47 +0100 Subject: [PATCH 4/5] nits --- tests/integration/distribution.go | 17 ++++++++--------- tests/integration/setup.go | 2 +- testutil/ibc_testing/generic_setup.go | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/integration/distribution.go b/tests/integration/distribution.go index 0a47faf3a0..0e188ce876 100644 --- a/tests/integration/distribution.go +++ b/tests/integration/distribution.go @@ -980,7 +980,7 @@ func (s *CCVTestSuite) TestAllocateTokensToValidator() { } } -// TestMultiConsumerRewardsDistribution tests the reward distribution in the conext +// TestMultiConsumerRewardsDistribution tests the reward distribution in the context // of multiple consumers sending rewards to the provider func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() { s.SetupAllCCVChannels() @@ -997,17 +997,17 @@ func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() { totalConsumerRewards := sdk.Coins{} // Iterate over the consumers and perform the reward distribution - // to the provider. + // to the provider for chainID := range s.consumerBundles { bundle := s.consumerBundles[chainID] consumerKeeper := bundle.App.GetConsumerKeeper() bankKeeper := bundle.App.GetTestBankKeeper() accountKeeper := bundle.App.GetTestAccountKeeper() - // set the consumer reward denom and block per distribution params + // set the consumer reward denom and the block per distribution params params := consumerKeeper.GetConsumerParams(bundle.GetCtx()) params.RewardDenoms = []string{sdk.DefaultBondDenom} - // set the reward distribution for the next block + // set the reward distribution to be performed during the next block params.BlocksPerDistributionTransmission = int64(1) consumerKeeper.SetParams(bundle.GetCtx(), params) @@ -1015,7 +1015,7 @@ func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() { var rewardsPerConsumer sdk.Coin // check the consumer pool balance - // Note that for a democracy consumer chain the reward pool may already be filled + // Note that for a democracy consumer chain the pool may already be filled if pool := bankKeeper.GetAllBalances( bundle.GetCtx(), accountKeeper.GetModuleAccount(bundle.GetCtx(), consumertypes.ConsumerToSendToProviderName).GetAddress(), @@ -1030,10 +1030,9 @@ func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() { ) s.Require().NoError(err) } else { - // the pool is filled so we force - // the internal reward distribution - // and save the pool balance before - // it get transferred to the provider + // execute the internal rewards distribution + // to save the pool's balance before + // it gets transferred to the provider in EndBlock consumerKeeper.DistributeRewardsInternally(bundle.GetCtx()) pool = bankKeeper.GetAllBalances( bundle.GetCtx(), diff --git a/tests/integration/setup.go b/tests/integration/setup.go index 9f5ed59f64..91c4c4d21f 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -142,7 +142,7 @@ func (suite *CCVTestSuite) SetupTest() { suite.consumerBundles[bundle.Chain.ChainID] = bundle suite.registerPacketSniffer(bundle.Chain) - // check that TopN was correctly set + // check that TopN is correctly set for the consumer topN, found := providerKeeper.GetTopN(suite.providerCtx(), bundle.Chain.ChainID) suite.Require().True(found) suite.Require().Equal(bundle.TopN, topN) diff --git a/testutil/ibc_testing/generic_setup.go b/testutil/ibc_testing/generic_setup.go index 4232997547..da00d76b85 100644 --- a/testutil/ibc_testing/generic_setup.go +++ b/testutil/ibc_testing/generic_setup.go @@ -31,7 +31,7 @@ type ( // to run integration tests against your app.go implementations! const ( - // Default number of setup consumer chains + // Default number of consumer chains NumConsumers = 5 ) From fbe56884e4bb72c90bb311def6d5645ea107a66d Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Fri, 8 Mar 2024 09:04:30 +0100 Subject: [PATCH 5/5] nit --- tests/integration/distribution.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/distribution.go b/tests/integration/distribution.go index 0e188ce876..cc4a2a21a9 100644 --- a/tests/integration/distribution.go +++ b/tests/integration/distribution.go @@ -980,8 +980,7 @@ func (s *CCVTestSuite) TestAllocateTokensToValidator() { } } -// TestMultiConsumerRewardsDistribution tests the reward distribution in the context -// of multiple consumers sending rewards to the provider +// TestMultiConsumerRewardsDistribution tests the rewards distribution of multiple consumers chains func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() { s.SetupAllCCVChannels() s.SetupAllTransferChannels()