From 3c3776bbfa249adb67f670b88613d7ca3139df6d Mon Sep 17 00:00:00 2001 From: Troy Kessler Date: Tue, 7 May 2024 12:18:55 +0200 Subject: [PATCH] test: fixed tests --- ...sg_server_claim_commission_rewards_test.go | 36 +++++++++++++++---- .../types/message_claim_commission_rewards.go | 4 +++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/x/stakers/keeper/msg_server_claim_commission_rewards_test.go b/x/stakers/keeper/msg_server_claim_commission_rewards_test.go index 0ed372af..3149e796 100644 --- a/x/stakers/keeper/msg_server_claim_commission_rewards_test.go +++ b/x/stakers/keeper/msg_server_claim_commission_rewards_test.go @@ -6,6 +6,7 @@ import ( i "github.com/KYVENetwork/chain/testutil/integration" bundletypes "github.com/KYVENetwork/chain/x/bundles/types" funderstypes "github.com/KYVENetwork/chain/x/funders/types" + globaltypes "github.com/KYVENetwork/chain/x/global/types" pooltypes "github.com/KYVENetwork/chain/x/pool/types" stakertypes "github.com/KYVENetwork/chain/x/stakers/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -47,6 +48,34 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { bundleParams.StorageCosts = append(bundleParams.StorageCosts, bundletypes.StorageCost{StorageProviderId: 1, Cost: math.LegacyMustNewDecFromStr("0.5")}) s.App().BundlesKeeper.SetParams(s.Ctx(), bundleParams) + // set whitelist + s.App().FundersKeeper.SetParams(s.Ctx(), funderstypes.NewParams([]*funderstypes.WhitelistCoinEntry{ + { + CoinDenom: globaltypes.Denom, + MinFundingAmount: 10 * i.KYVE, + MinFundingAmountPerBundle: uint64(amountPerBundle), + CoinWeight: math.LegacyNewDec(1), + }, + { + CoinDenom: i.A_DENOM, + MinFundingAmount: 10 * i.KYVE, + MinFundingAmountPerBundle: uint64(amountPerBundle), + CoinWeight: math.LegacyNewDec(1), + }, + { + CoinDenom: i.B_DENOM, + MinFundingAmount: 10 * i.KYVE, + MinFundingAmountPerBundle: uint64(amountPerBundle), + CoinWeight: math.LegacyNewDec(2), + }, + { + CoinDenom: i.C_DENOM, + MinFundingAmount: 10 * i.KYVE, + MinFundingAmountPerBundle: uint64(amountPerBundle), + CoinWeight: math.LegacyNewDec(3), + }, + }, 20)) + // create clean pool for every test case gov := s.App().GovKeeper.GetGovernanceAccount(s.Ctx()).GetAddress().String() msg := &pooltypes.MsgCreatePool{ @@ -102,11 +131,6 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { Moniker: "Alice", }) - params := funderstypes.DefaultParams() - - params.CoinWhitelist[0].MinFundingAmountPerBundle = uint64(amountPerBundle) - s.App().FundersKeeper.SetParams(s.Ctx(), params) - // create a valid bundle so that uploader earns commission rewards s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ Creator: i.ALICE, @@ -431,7 +455,7 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { uploader, _ = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) Expect(uploader.CommissionRewards.String()).To(Equal(commissionRewardsBefore.Sub(i.KYVECoin(100), i.ACoin(200), i.BCoin(300)).String())) - Expect(s.GetCoinsFromAddress(i.STAKER_0).String()).To(Equal(initialBalanceStaker0.Add(i.KYVECoin(100), i.ACoin(200), i.BCoin(300)).String())) + Expect(s.GetCoinsFromAddress(i.STAKER_0).String()).To(Equal(initialBalanceStaker0.Add(sdk.NewCoins(i.KYVECoin(100), i.ACoin(200), i.BCoin(300))...).String())) }) It("Claim one coin of multiple coins", func() { diff --git a/x/stakers/types/message_claim_commission_rewards.go b/x/stakers/types/message_claim_commission_rewards.go index ef924328..fa2b1803 100644 --- a/x/stakers/types/message_claim_commission_rewards.go +++ b/x/stakers/types/message_claim_commission_rewards.go @@ -39,5 +39,9 @@ func (msg *MsgClaimCommissionRewards) ValidateBasic() error { return errors.Wrapf(errorsTypes.ErrInvalidAddress, "invalid validator address: %s", err) } + if err := msg.Amount.Validate(); !msg.Amount.Empty() && err != nil { + return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid amount: %s", err) + } + return nil }