Skip to content

Commit

Permalink
test: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler committed May 7, 2024
1 parent 0317a06 commit 3c3776b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
36 changes: 30 additions & 6 deletions x/stakers/keeper/msg_server_claim_commission_rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions x/stakers/types/message_claim_commission_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 3c3776b

Please sign in to comment.