diff --git a/testutil/integration/checks.go b/testutil/integration/checks.go index b487b346..d9498814 100644 --- a/testutil/integration/checks.go +++ b/testutil/integration/checks.go @@ -2,6 +2,7 @@ package integration import ( "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "time" "cosmossdk.io/store" @@ -452,7 +453,7 @@ func (suite *KeeperTestSuite) VerifyFundersModuleIntegrity() { Expect(found).To(BeTrue()) // check if funding is active - if funding.Amount > 0 { + if !funding.Amounts.IsZero() { key := string(funderstypes.FundingKeyByFunder(funding.FunderAddress, funding.PoolId)) allActiveFundings[key] = true } @@ -485,28 +486,28 @@ func (suite *KeeperTestSuite) VerifyFundersModuleIntegrity() { } func (suite *KeeperTestSuite) VerifyFundersModuleAssetsIntegrity() { - expectedBalance := uint64(0) + expectedBalance := sdk.NewCoins() for _, funding := range suite.App().FundersKeeper.GetAllFundings(suite.Ctx()) { - expectedBalance += funding.Amount + expectedBalance = expectedBalance.Add(funding.Amounts...) } - expectedFundingStateTotalAmount := uint64(0) + expectedFundingStateTotalAmount := sdk.NewCoins() for _, fundingState := range suite.App().FundersKeeper.GetAllFundingStates(suite.Ctx()) { activeFundings := suite.App().FundersKeeper.GetActiveFundings(suite.Ctx(), fundingState) - totalAmount := uint64(0) + totalAmount := sdk.NewCoins() for _, activeFunding := range activeFundings { - totalAmount += activeFunding.Amount + totalAmount = totalAmount.Add(activeFunding.Amounts...) } totalActiveFunding := suite.App().FundersKeeper.GetTotalActiveFunding(suite.ctx, fundingState.PoolId) Expect(totalAmount).To(Equal(totalActiveFunding)) - expectedFundingStateTotalAmount += totalAmount + expectedFundingStateTotalAmount = expectedFundingStateTotalAmount.Add(totalAmount...) } // total amount of fundings should be equal to the amount of the funders module account moduleAcc := suite.App().AccountKeeper.GetModuleAccount(suite.Ctx(), funderstypes.ModuleName).GetAddress() - actualBalance := suite.App().BankKeeper.GetBalance(suite.Ctx(), moduleAcc, globalTypes.Denom).Amount.Uint64() - Expect(actualBalance).To(Equal(expectedBalance)) - Expect(actualBalance).To(Equal(expectedFundingStateTotalAmount)) + actualBalance := suite.App().BankKeeper.GetAllBalances(suite.Ctx(), moduleAcc) + Expect(actualBalance.String()).To(Equal(expectedBalance.String())) + Expect(actualBalance.String()).To(Equal(expectedFundingStateTotalAmount.String())) } // ======================== diff --git a/testutil/integration/helpers.go b/testutil/integration/helpers.go index 418bc540..3f59e890 100644 --- a/testutil/integration/helpers.go +++ b/testutil/integration/helpers.go @@ -16,6 +16,15 @@ func (suite *KeeperTestSuite) GetBalanceFromAddress(address string) uint64 { return uint64(balance.Amount.Int64()) } +func (suite *KeeperTestSuite) GetBalancesFromAddress(address string) sdk.Coins { + accAddress, err := sdk.AccAddressFromBech32(address) + if err != nil { + return sdk.NewCoins() + } + + return suite.App().BankKeeper.GetAllBalances(suite.Ctx(), accAddress) +} + func (suite *KeeperTestSuite) GetBalanceFromPool(poolId uint64) uint64 { pool, found := suite.App().PoolKeeper.GetPool(suite.Ctx(), poolId) if !found { diff --git a/x/funders/keeper/logic_funders_test.go b/x/funders/keeper/logic_funders_test.go index 0c63aeac..308394cb 100644 --- a/x/funders/keeper/logic_funders_test.go +++ b/x/funders/keeper/logic_funders_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "cosmossdk.io/math" i "github.com/KYVENetwork/chain/testutil/integration" funderstypes "github.com/KYVENetwork/chain/x/funders/types" globaltypes "github.com/KYVENetwork/chain/x/global/types" @@ -71,14 +72,14 @@ var _ = Describe("logic_funders.go", Ordered, func() { s.RunTxPoolSuccess(&funderstypes.MsgFundPool{ Creator: i.ALICE, PoolId: 0, - Amounts: sdk.NewCoins(sdk.NewInt64Coin(i.A_DENOM, 100*i.T_KYVE)), - AmountsPerBundle: sdk.NewCoins(sdk.NewInt64Coin(i.A_DENOM, 1*i.T_KYVE)), + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) s.RunTxPoolSuccess(&funderstypes.MsgFundPool{ Creator: i.BOB, PoolId: 0, - Amounts: sdk.NewCoins(sdk.NewInt64Coin(i.A_DENOM, 50*i.T_KYVE)), - AmountsPerBundle: sdk.NewCoins(sdk.NewInt64Coin(i.A_DENOM, 10*i.T_KYVE)), + Amounts: i.ACoins(50 * i.T_KYVE), + AmountsPerBundle: i.ACoins(10 * i.T_KYVE), }) fundersBalance := s.App().BankKeeper.GetBalance(s.Ctx(), fundersModuleAcc, globaltypes.Denom).Amount.Uint64() @@ -123,14 +124,14 @@ var _ = Describe("logic_funders.go", Ordered, func() { s.RunTxPoolSuccess(&funderstypes.MsgFundPool{ Creator: i.ALICE, PoolId: 0, - Amounts: sdk.NewCoins(sdk.NewInt64Coin(i.B_DENOM, 1000*i.T_KYVE)), - AmountsPerBundle: sdk.NewCoins(sdk.NewInt64Coin(i.B_DENOM, 20*i.T_KYVE)), + Amounts: i.ACoins(1000 * i.T_KYVE), + AmountsPerBundle: i.ACoins(20 * i.T_KYVE), }) s.RunTxPoolSuccess(&funderstypes.MsgFundPool{ Creator: i.BOB, PoolId: 0, - Amounts: sdk.NewCoins(sdk.NewInt64Coin(i.C_DENOM, 100*i.T_KYVE)), - AmountsPerBundle: sdk.NewCoins(sdk.NewInt64Coin(i.C_DENOM, 2*i.T_KYVE)), + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(2 * i.T_KYVE), }) // ACT @@ -176,24 +177,24 @@ var _ = Describe("logic_funders.go", Ordered, func() { fundingAlice, foundAlice := s.App().FundersKeeper.GetFunding(s.Ctx(), i.ALICE, 0) Expect(foundAlice).To(BeTrue()) - Expect(fundingAlice.Amount).To(Equal(95 * i.KYVE)) - Expect(fundingAlice.TotalFunded).To(Equal(5 * i.KYVE)) + Expect(fundingAlice.Amounts.String()).To(Equal(i.ACoins(95 * i.T_KYVE).String())) + Expect(fundingAlice.TotalFunded.String()).To(Equal(i.ACoins(5 * i.T_KYVE).String())) fundingBob, foundBob := s.App().FundersKeeper.GetFunding(s.Ctx(), i.BOB, 0) Expect(foundBob).To(BeTrue()) - Expect(fundingBob.Amount).To(Equal(0 * i.KYVE)) - Expect(fundingBob.TotalFunded).To(Equal(50 * i.KYVE)) + Expect(fundingBob.Amounts.IsZero()).To(BeTrue()) + Expect(fundingBob.TotalFunded.String()).To(Equal(i.ACoins(50 * i.T_KYVE).String())) - fundersBalance := s.App().BankKeeper.GetBalance(s.Ctx(), fundersModuleAcc, globaltypes.Denom).Amount.Uint64() - poolBalance := s.App().BankKeeper.GetBalance(s.Ctx(), poolModuleAcc, globaltypes.Denom).Amount.Uint64() - Expect(fundersBalance).To(Equal(95 * i.KYVE)) - Expect(poolBalance).To(Equal(55 * i.KYVE)) + fundersBalance := s.App().BankKeeper.GetAllBalances(s.Ctx(), fundersModuleAcc) + poolBalance := s.App().BankKeeper.GetAllBalances(s.Ctx(), poolModuleAcc) + Expect(fundersBalance.String()).To(Equal(i.ACoins(95 * i.T_KYVE).String())) + Expect(poolBalance.String()).To(Equal(i.ACoins(55 * i.T_KYVE).String())) }) It("Charge funders until all funders run out of funds", func() { // ARRANGE funding, _ := s.App().FundersKeeper.GetFunding(s.Ctx(), i.ALICE, 0) - funding.AmountPerBundle = 10 * i.KYVE + funding.AmountsPerBundle = i.ACoins(10 * i.T_KYVE) s.App().FundersKeeper.SetFunding(s.Ctx(), &funding) // ACT / ASSERT @@ -203,7 +204,7 @@ var _ = Describe("logic_funders.go", Ordered, func() { payout, err := s.App().FundersKeeper.ChargeFundersOfPool(s.Ctx(), 0) Expect(err).NotTo(HaveOccurred()) - Expect(payout).To(Equal(20 * i.KYVE)) + Expect(payout.String()).To(Equal(i.ACoins(10 * i.T_KYVE).String())) } fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) Expect(fundingState.ActiveFunderAddresses).To(HaveLen(1)) @@ -211,13 +212,13 @@ var _ = Describe("logic_funders.go", Ordered, func() { fundingAlice, foundAlice := s.App().FundersKeeper.GetFunding(s.Ctx(), i.ALICE, 0) Expect(foundAlice).To(BeTrue()) - Expect(fundingAlice.Amount).To(Equal(50 * i.KYVE)) - Expect(fundingAlice.TotalFunded).To(Equal(50 * i.KYVE)) + Expect(fundingAlice.Amounts.String()).To(Equal(i.ACoins(50 * i.T_KYVE).String())) + Expect(fundingAlice.TotalFunded.String()).To(Equal(i.ACoins(50 * i.T_KYVE).String())) fundingBob, foundBob := s.App().FundersKeeper.GetFunding(s.Ctx(), i.BOB, 0) Expect(foundBob).To(BeTrue()) - Expect(fundingBob.Amount).To(Equal(0 * i.KYVE)) - Expect(fundingBob.TotalFunded).To(Equal(50 * i.KYVE)) + Expect(fundingBob.Amounts.IsZero()).To(BeTrue()) + Expect(fundingBob.TotalFunded.String()).To(Equal(i.ACoins(50 * i.T_KYVE).String())) for range [5]struct{}{} { fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -225,44 +226,44 @@ var _ = Describe("logic_funders.go", Ordered, func() { payout, err := s.App().FundersKeeper.ChargeFundersOfPool(s.Ctx(), 0) Expect(err).NotTo(HaveOccurred()) - Expect(payout).To(Equal(10 * i.KYVE)) + Expect(payout.String()).To(Equal(i.ACoins(10 * i.T_KYVE))) } fundingState, _ = s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) Expect(fundingState.ActiveFunderAddresses).To(HaveLen(0)) fundingAlice, foundAlice = s.App().FundersKeeper.GetFunding(s.Ctx(), i.ALICE, 0) Expect(foundAlice).To(BeTrue()) - Expect(fundingAlice.Amount).To(Equal(0 * i.KYVE)) - Expect(fundingAlice.TotalFunded).To(Equal(100 * i.KYVE)) + Expect(fundingAlice.Amounts.IsZero()).To(Equal(BeTrue())) + Expect(fundingAlice.TotalFunded.String()).To(Equal(i.ACoins(100 * i.T_KYVE).String())) fundingBob, foundBob = s.App().FundersKeeper.GetFunding(s.Ctx(), i.BOB, 0) Expect(foundBob).To(BeTrue()) - Expect(fundingBob.Amount).To(Equal(0 * i.KYVE)) - Expect(fundingBob.TotalFunded).To(Equal(50 * i.KYVE)) + Expect(fundingBob.Amounts.IsZero()).To(Equal(BeTrue())) + Expect(fundingBob.TotalFunded.String()).To(Equal(i.ACoins(50 * i.T_KYVE).String())) payout, err := s.App().FundersKeeper.ChargeFundersOfPool(s.Ctx(), 0) Expect(err).NotTo(HaveOccurred()) - Expect(payout).To(Equal(0 * i.KYVE)) + Expect(payout.IsZero()).To(Equal(BeTrue())) fundingState, _ = s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) Expect(fundingState.ActiveFunderAddresses).To(HaveLen(0)) - fundersBalance := s.App().BankKeeper.GetBalance(s.Ctx(), fundersModuleAcc, globaltypes.Denom).Amount.Uint64() - poolBalance := s.App().BankKeeper.GetBalance(s.Ctx(), poolModuleAcc, globaltypes.Denom).Amount.Uint64() - Expect(fundersBalance).To(Equal(0 * i.KYVE)) - Expect(poolBalance).To(Equal(150 * i.KYVE)) + fundersBalance := s.App().BankKeeper.GetAllBalances(s.Ctx(), fundersModuleAcc) + poolBalance := s.App().BankKeeper.GetAllBalances(s.Ctx(), poolModuleAcc) + Expect(fundersBalance.IsZero()).To(Equal(BeTrue())) + Expect(poolBalance.String()).To(Equal(i.ACoins(150 * i.T_KYVE).String())) }) It("Charge funder with less funds than amount_per_bundle", func() { // ARRANGE funding, _ := s.App().FundersKeeper.GetFunding(s.Ctx(), i.ALICE, 0) - funding.AmountPerBundle = 105 * i.KYVE + funding.AmountsPerBundle = i.ACoins(105 * i.T_KYVE) s.App().FundersKeeper.SetFunding(s.Ctx(), &funding) // ACT payout, err := s.App().FundersKeeper.ChargeFundersOfPool(s.Ctx(), 0) Expect(err).NotTo(HaveOccurred()) - Expect(payout).To(Equal(110 * i.KYVE)) + Expect(payout.String()).To(Equal(i.ACoins(110 * i.T_KYVE).String())) // ASSERT fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -271,18 +272,18 @@ var _ = Describe("logic_funders.go", Ordered, func() { fundingAlice, foundAlice := s.App().FundersKeeper.GetFunding(s.Ctx(), i.ALICE, 0) Expect(foundAlice).To(BeTrue()) - Expect(fundingAlice.Amount).To(Equal(0 * i.KYVE)) - Expect(fundingAlice.TotalFunded).To(Equal(100 * i.KYVE)) + Expect(fundingAlice.Amounts.IsZero()).To(Equal(BeTrue())) + Expect(fundingAlice.TotalFunded.String()).To(Equal(i.ACoins(100 * i.T_KYVE).String())) fundingBob, foundBob := s.App().FundersKeeper.GetFunding(s.Ctx(), i.BOB, 0) Expect(foundBob).To(BeTrue()) - Expect(fundingBob.Amount).To(Equal(40 * i.KYVE)) - Expect(fundingBob.TotalFunded).To(Equal(10 * i.KYVE)) + Expect(fundingBob.Amounts.String()).To(Equal(i.ACoins(40 * i.T_KYVE).String())) + Expect(fundingBob.TotalFunded.String()).To(Equal(i.ACoins(10 * i.T_KYVE).String())) - fundersBalance := s.App().BankKeeper.GetBalance(s.Ctx(), fundersModuleAcc, globaltypes.Denom).Amount.Uint64() - poolBalance := s.App().BankKeeper.GetBalance(s.Ctx(), poolModuleAcc, globaltypes.Denom).Amount.Uint64() - Expect(fundersBalance).To(Equal(40 * i.KYVE)) - Expect(poolBalance).To(Equal(110 * i.KYVE)) + fundersBalance := s.App().BankKeeper.GetAllBalances(s.Ctx(), fundersModuleAcc) + poolBalance := s.App().BankKeeper.GetAllBalances(s.Ctx(), poolModuleAcc) + Expect(fundersBalance.String()).To(Equal(i.ACoins(40 * i.T_KYVE).String())) + Expect(poolBalance.String()).To(Equal(i.ACoins(110 * i.T_KYVE).String())) }) It("Charge without fundings", func() { @@ -290,63 +291,79 @@ var _ = Describe("logic_funders.go", Ordered, func() { s.RunTxFundersSuccess(&funderstypes.MsgDefundPool{ Creator: i.ALICE, PoolId: 0, - Amount: 100 * i.KYVE, + Amounts: i.ACoins(100 * i.T_KYVE), }) s.RunTxFundersSuccess(&funderstypes.MsgDefundPool{ Creator: i.BOB, PoolId: 0, - Amount: 50 * i.KYVE, + Amounts: i.ACoins(50 * i.T_KYVE), }) // ACT payout, err := s.App().FundersKeeper.ChargeFundersOfPool(s.Ctx(), 0) // ASSERT + Expect(err).NotTo(HaveOccurred()) + Expect(payout.IsZero()).To(Equal(BeTrue())) + fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) Expect(fundingState.ActiveFunderAddresses).To(HaveLen(0)) fundingAlice, foundAlice := s.App().FundersKeeper.GetFunding(s.Ctx(), i.ALICE, 0) Expect(foundAlice).To(BeTrue()) - Expect(fundingAlice.Amount).To(Equal(0 * i.KYVE)) - Expect(fundingAlice.TotalFunded).To(Equal(0 * i.KYVE)) + Expect(fundingAlice.Amounts.IsZero()).To(BeTrue()) + Expect(fundingAlice.TotalFunded.IsZero()).To(BeTrue()) fundingBob, foundBob := s.App().FundersKeeper.GetFunding(s.Ctx(), i.BOB, 0) Expect(foundBob).To(BeTrue()) - Expect(fundingBob.Amount).To(Equal(0 * i.KYVE)) - Expect(fundingBob.TotalFunded).To(Equal(0 * i.KYVE)) + Expect(fundingBob.Amounts.IsZero()).To(BeTrue()) + Expect(fundingBob.TotalFunded.IsZero()).To(BeTrue()) - Expect(err).NotTo(HaveOccurred()) - Expect(payout).To(Equal(0 * i.KYVE)) - fundersBalance := s.App().BankKeeper.GetBalance(s.Ctx(), fundersModuleAcc, globaltypes.Denom).Amount.Uint64() - poolBalance := s.App().BankKeeper.GetBalance(s.Ctx(), poolModuleAcc, globaltypes.Denom).Amount.Uint64() - Expect(fundersBalance).To(Equal(0 * i.KYVE)) - Expect(poolBalance).To(Equal(0 * i.KYVE)) + fundersBalance := s.App().BankKeeper.GetAllBalances(s.Ctx(), fundersModuleAcc) + poolBalance := s.App().BankKeeper.GetAllBalances(s.Ctx(), poolModuleAcc) + Expect(fundersBalance.IsZero()).To(BeTrue()) + Expect(poolBalance.IsZero()).To(BeTrue()) }) It("Check if the lowest funding is returned correctly", func() { + whitelist := []*funderstypes.WhitelistCoinEntry{ + { + CoinDenom: i.A_DENOM, + CoinWeight: math.LegacyNewDec(1), + }, + { + CoinDenom: i.B_DENOM, + CoinWeight: math.LegacyNewDec(2), + }, + { + CoinDenom: i.C_DENOM, + CoinWeight: math.LegacyNewDec(3), + }, + } + fundings := []funderstypes.Funding{ { - FunderAddress: i.DUMMY[0], - PoolId: 0, - Amount: 1000 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + FunderAddress: i.DUMMY[0], + PoolId: 0, + Amounts: sdk.NewCoins(i.ACoin(1000*i.T_KYVE), i.BCoin(500*i.T_KYVE), i.CCoin(100)), + AmountsPerBundle: sdk.NewCoins(i.ACoin(1*i.T_KYVE), i.BCoin(1*i.T_KYVE), i.CCoin(1)), }, { - FunderAddress: i.DUMMY[1], - PoolId: 0, - Amount: 900 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + FunderAddress: i.DUMMY[1], + PoolId: 0, + Amounts: sdk.NewCoins(i.ACoin(1100*i.T_KYVE), i.BCoin(600*i.T_KYVE), i.CCoin(5)), + AmountsPerBundle: sdk.NewCoins(i.ACoin(1*i.T_KYVE), i.BCoin(1*i.T_KYVE), i.CCoin(1)), }, { - FunderAddress: i.DUMMY[2], - PoolId: 0, - Amount: 1100 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + FunderAddress: i.DUMMY[2], + PoolId: 0, + Amounts: sdk.NewCoins(i.ACoin(500*i.T_KYVE), i.CCoin(700)), + AmountsPerBundle: sdk.NewCoins(i.ACoin(1*i.T_KYVE), i.CCoin(1)), }, } - getLowestFunding, err := s.App().FundersKeeper.GetLowestFunding(fundings) + getLowestFunding, err := s.App().FundersKeeper.GetLowestFunding(fundings, whitelist) Expect(err).NotTo(HaveOccurred()) - Expect(getLowestFunding.Amount).To(Equal(900 * i.KYVE)) + Expect(getLowestFunding.FunderAddress).To(Equal(i.DUMMY[1])) }) }) diff --git a/x/funders/keeper/msg_server_fund_pool_test.go b/x/funders/keeper/msg_server_fund_pool_test.go index a6a251b8..86d8f2bc 100644 --- a/x/funders/keeper/msg_server_fund_pool_test.go +++ b/x/funders/keeper/msg_server_fund_pool_test.go @@ -1,9 +1,11 @@ package keeper_test import ( + "cosmossdk.io/math" i "github.com/KYVENetwork/chain/testutil/integration" funderstypes "github.com/KYVENetwork/chain/x/funders/types" pooltypes "github.com/KYVENetwork/chain/x/pool/types" + sdk "github.com/cosmos/cosmos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -12,14 +14,14 @@ import ( TEST CASES - msg_server_fund_pool.go -* Fund a pool with 100 $KYVE -* Fund additional 50 $KYVE to an existing funding with 100 $KYVE -* Try to fund more $KYVE than available in balance -* Fund with a new funder less $KYVE than the existing one -* Fund with a new funder more $KYVE than the existing one +* Fund a pool with 100 coins +* Fund additional 50 coins to an existing funding with 100 coins +* Try to fund more coins than available in balance +* Fund with a new funder less coins than the existing one +* Fund with a new funder more coins than the existing one * Try to fund with a non-existent funder -* Try to fund less $KYVE than the lowest funder with full funding slots -* Fund more $KYVE than the lowest funder with full funding slots +* Try to fund less coins than the lowest funder with full funding slots +* Fund more coins than the lowest funder with full funding slots * Refund a funding as the lowest funder * Try to fund a non-existent pool * Try to fund below the minimum amount @@ -31,7 +33,27 @@ TEST CASES - msg_server_fund_pool.go var _ = Describe("msg_server_fund_pool.go", Ordered, func() { s := i.NewCleanChain() - initialBalance := s.GetBalanceFromAddress(i.ALICE) + initialBalance := s.GetBalancesFromAddress(i.ALICE) + whitelist := []*funderstypes.WhitelistCoinEntry{ + { + CoinDenom: i.A_DENOM, + MinFundingAmount: 10 * i.KYVE, + MinFundingAmountPerBundle: 1 * i.KYVE, + CoinWeight: math.LegacyNewDec(1), + }, + { + CoinDenom: i.B_DENOM, + MinFundingAmount: 10 * i.KYVE, + MinFundingAmountPerBundle: 1 * i.KYVE, + CoinWeight: math.LegacyNewDec(2), + }, + { + CoinDenom: i.C_DENOM, + MinFundingAmount: 10 * i.KYVE, + MinFundingAmountPerBundle: 1 * i.KYVE, + CoinWeight: math.LegacyNewDec(3), + }, + } BeforeEach(func() { // init new clean chain @@ -57,6 +79,9 @@ var _ = Describe("msg_server_fund_pool.go", Ordered, func() { } s.RunTxPoolSuccess(msg) + // set whitelist + s.App().FundersKeeper.SetParams(s.Ctx(), funderstypes.NewParams(whitelist, 20)) + // create funder s.RunTxFundersSuccess(&funderstypes.MsgCreateFunder{ Creator: i.ALICE, @@ -72,26 +97,26 @@ var _ = Describe("msg_server_fund_pool.go", Ordered, func() { s.PerformValidityChecks() }) - It("Fund a pool with 100 $KYVE", func() { + It("Fund a pool with 100 coins", func() { // ACT s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: 100 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.ALICE, + PoolId: 0, + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) // ASSERT - balanceAfter := s.GetBalanceFromAddress(i.ALICE) + balanceAfter := s.GetBalancesFromAddress(i.ALICE) - Expect(initialBalance - balanceAfter).To(Equal(100 * i.KYVE)) + Expect(initialBalance.Sub(balanceAfter...).String()).To(Equal(i.ACoins(100 * i.T_KYVE).String())) funding, _ := s.App().FundersKeeper.GetFunding(s.Ctx(), i.ALICE, 0) Expect(funding.FunderAddress).To(Equal(i.ALICE)) Expect(funding.PoolId).To(Equal(uint64(0))) - Expect(funding.Amount).To(Equal(100 * i.KYVE)) - Expect(funding.AmountPerBundle).To(Equal(1 * i.KYVE)) - Expect(funding.TotalFunded).To(Equal(0 * i.KYVE)) + Expect(funding.Amounts).To(Equal(i.ACoins(100 * i.T_KYVE).String())) + Expect(funding.AmountsPerBundle).To(Equal(i.ACoins(1 * i.T_KYVE).String())) + Expect(funding.TotalFunded.IsZero()).To(BeTrue()) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) Expect(fundingState.PoolId).To(Equal(uint64(0))) @@ -99,33 +124,34 @@ var _ = Describe("msg_server_fund_pool.go", Ordered, func() { Expect(fundingState.ActiveFunderAddresses[0]).To(Equal(i.ALICE)) }) - It("Fund additional 50 $KYVE to an existing funding with 100 $KYVE", func() { + It("Fund additional 50 coins to an existing funding with 100 coins", func() { // ARRANGE s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: 100 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.ALICE, + PoolId: 0, + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) // ACT s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: 50 * i.KYVE, + Creator: i.ALICE, + PoolId: 0, + Amounts: i.ACoins(50 * i.T_KYVE), + AmountsPerBundle: sdk.NewCoins(), }) // ASSERT - balanceAfter := s.GetBalanceFromAddress(i.ALICE) + balanceAfter := s.GetBalancesFromAddress(i.ALICE) - Expect(initialBalance - balanceAfter).To(Equal(150 * i.KYVE)) + Expect(initialBalance.Sub(balanceAfter...).String()).To(Equal(i.ACoins(150 * i.T_KYVE).String())) funding, _ := s.App().FundersKeeper.GetFunding(s.Ctx(), i.ALICE, 0) Expect(funding.FunderAddress).To(Equal(i.ALICE)) Expect(funding.PoolId).To(Equal(uint64(0))) - Expect(funding.Amount).To(Equal(150 * i.KYVE)) - Expect(funding.AmountPerBundle).To(Equal(1 * i.KYVE)) - Expect(funding.TotalFunded).To(Equal(0 * i.KYVE)) + Expect(funding.Amounts).To(Equal(i.ACoins(150 * i.T_KYVE).String())) + Expect(funding.AmountsPerBundle).To(Equal(i.ACoins(1 * i.T_KYVE).String())) + Expect(funding.TotalFunded.IsZero()).To(BeTrue()) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) Expect(fundingState.PoolId).To(Equal(uint64(0))) @@ -133,25 +159,25 @@ var _ = Describe("msg_server_fund_pool.go", Ordered, func() { Expect(fundingState.ActiveFunderAddresses[0]).To(Equal(i.ALICE)) activeFundings := s.App().FundersKeeper.GetActiveFundings(s.Ctx(), fundingState) - lowestFunding, err := s.App().FundersKeeper.GetLowestFunding(activeFundings) + lowestFunding, err := s.App().FundersKeeper.GetLowestFunding(activeFundings, whitelist) Expect(err).To(BeNil()) Expect(lowestFunding.FunderAddress).To(Equal(i.ALICE)) }) - It("Try to fund more $KYVE than available in balance", func() { + It("Try to fund more coins than available in balance", func() { // ACT - currentBalance := s.GetBalanceFromAddress(i.ALICE) + currentBalance := s.GetBalancesFromAddress(i.ALICE) s.RunTxFundersError(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: currentBalance + 1, - AmountPerBundle: 1 * i.KYVE, + Creator: i.ALICE, + PoolId: 0, + Amounts: currentBalance.Add(i.ACoin(1)), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) // ASSERT - balanceAfter := s.GetBalanceFromAddress(i.ALICE) - Expect(initialBalance - balanceAfter).To(BeZero()) + balanceAfter := s.GetBalancesFromAddress(i.ALICE) + Expect(initialBalance.Sub(balanceAfter...).IsZero()).To(BeTrue()) _, found := s.App().FundersKeeper.GetFunding(s.Ctx(), i.ALICE, 0) Expect(found).To(BeFalse()) @@ -161,74 +187,74 @@ var _ = Describe("msg_server_fund_pool.go", Ordered, func() { Expect(len(fundingState.ActiveFunderAddresses)).To(Equal(0)) }) - It("Fund with a new funder less $KYVE than the existing one", func() { + It("Fund with a new funder less coins than the existing one", func() { // ARRANGE s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: 100 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.ALICE, + PoolId: 0, + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) // ACT s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.BOB, - PoolId: 0, - Amount: 50 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.BOB, + PoolId: 0, + Amounts: i.ACoins(50 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) // ASSERT - balanceAfter := s.GetBalanceFromAddress(i.BOB) - Expect(initialBalance - balanceAfter).To(Equal(50 * i.KYVE)) + balanceAfter := s.GetBalancesFromAddress(i.BOB) + Expect(initialBalance.Sub(balanceAfter...).String()).To(Equal(i.ACoins(50 * i.T_KYVE).String())) funding, _ := s.App().FundersKeeper.GetFunding(s.Ctx(), i.BOB, 0) - Expect(funding.Amount).To(Equal(50 * i.KYVE)) - Expect(funding.AmountPerBundle).To(Equal(1 * i.KYVE)) - Expect(funding.TotalFunded).To(Equal(0 * i.KYVE)) + Expect(funding.Amounts.String()).To(Equal(i.ACoins(50 * i.T_KYVE).String())) + Expect(funding.AmountsPerBundle.String()).To(Equal(i.ACoins(1 * i.T_KYVE).String())) + Expect(funding.TotalFunded.IsZero()).To(Equal(BeTrue())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) Expect(fundingState.PoolId).To(Equal(uint64(0))) Expect(len(fundingState.ActiveFunderAddresses)).To(Equal(2)) activeFundings := s.App().FundersKeeper.GetActiveFundings(s.Ctx(), fundingState) - lowestFunding, err := s.App().FundersKeeper.GetLowestFunding(activeFundings) + lowestFunding, err := s.App().FundersKeeper.GetLowestFunding(activeFundings, whitelist) Expect(err).To(BeNil()) Expect(lowestFunding.FunderAddress).To(Equal(i.BOB)) }) - It("Fund with a new funder more $KYVE than the existing one", func() { + It("Fund with a new funder more coins than the existing one", func() { // ARRANGE s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: 100 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.ALICE, + PoolId: 0, + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) // ACT s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.BOB, - PoolId: 0, - Amount: 200 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.BOB, + PoolId: 0, + Amounts: i.ACoins(200 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) // ASSERT - balanceAfter := s.GetBalanceFromAddress(i.BOB) - Expect(initialBalance - balanceAfter).To(Equal(200 * i.KYVE)) + balanceAfter := s.GetBalancesFromAddress(i.BOB) + Expect(initialBalance.Sub(balanceAfter...).String()).To(Equal(i.ACoins(200 * i.T_KYVE).String())) funding, _ := s.App().FundersKeeper.GetFunding(s.Ctx(), i.BOB, 0) - Expect(funding.Amount).To(Equal(200 * i.KYVE)) - Expect(funding.AmountPerBundle).To(Equal(1 * i.KYVE)) - Expect(funding.TotalFunded).To(Equal(0 * i.KYVE)) + Expect(funding.Amounts.String()).To(Equal(i.ACoins(200 * i.T_KYVE).String())) + Expect(funding.AmountsPerBundle.String()).To(Equal(i.ACoins(1 * i.T_KYVE).String())) + Expect(funding.TotalFunded.IsZero()).To(BeTrue()) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) Expect(fundingState.PoolId).To(Equal(uint64(0))) Expect(len(fundingState.ActiveFunderAddresses)).To(Equal(2)) activeFundings := s.App().FundersKeeper.GetActiveFundings(s.Ctx(), fundingState) - lowestFunding, err := s.App().FundersKeeper.GetLowestFunding(activeFundings) + lowestFunding, err := s.App().FundersKeeper.GetLowestFunding(activeFundings, whitelist) Expect(err).To(BeNil()) Expect(lowestFunding.FunderAddress).To(Equal(i.ALICE)) }) @@ -236,20 +262,20 @@ var _ = Describe("msg_server_fund_pool.go", Ordered, func() { It("Try to fund with a non-existent funder", func() { // ASSERT s.RunTxFundersError(&funderstypes.MsgFundPool{ - Creator: i.CHARLIE, - PoolId: 0, - Amount: 100 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.CHARLIE, + PoolId: 0, + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) }) - It("Try to fund less $KYVE than the lowest funder with full funding slots", func() { + It("Try to fund less coins than the lowest funder with full funding slots", func() { // ARRANGE s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: 100 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.ALICE, + PoolId: 0, + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) for a := 0; a < funderstypes.MaxFunders-1; a++ { @@ -259,25 +285,25 @@ var _ = Describe("msg_server_fund_pool.go", Ordered, func() { }) // fill remaining funding slots s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.DUMMY[a], - PoolId: 0, - Amount: 1000 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.DUMMY[a], + PoolId: 0, + Amounts: i.ACoins(1000 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) } fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) Expect(len(fundingState.ActiveFunderAddresses)).To(Equal(funderstypes.MaxFunders)) - balanceAfter := s.GetBalanceFromAddress(i.ALICE) - Expect(initialBalance - balanceAfter).To(Equal(100 * i.KYVE)) + balanceAfter := s.GetBalancesFromAddress(i.ALICE) + Expect(initialBalance.Sub(balanceAfter...)).To(Equal(i.ACoins(100 * i.T_KYVE))) // ACT s.RunTxFundersError(&funderstypes.MsgFundPool{ - Creator: i.BOB, - PoolId: 0, - Amount: 50 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.BOB, + PoolId: 0, + Amounts: i.ACoins(50 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) // ASSERT @@ -286,19 +312,19 @@ var _ = Describe("msg_server_fund_pool.go", Ordered, func() { activeFundings := s.App().FundersKeeper.GetActiveFundings(s.Ctx(), fundingState) Expect(activeFundings).To(HaveLen(50)) - lowestFunding, err := s.App().FundersKeeper.GetLowestFunding(activeFundings) + lowestFunding, err := s.App().FundersKeeper.GetLowestFunding(activeFundings, whitelist) Expect(err).To(BeNil()) Expect(lowestFunding.FunderAddress).To(Equal(i.ALICE)) }) - It("Fund more $KYVE than the lowest funder with full funding slots", func() { + It("Fund more coins than the lowest funder with full funding slots", func() { // ARRANGE - initialBalanceBob := s.GetBalanceFromAddress(i.BOB) + initialBalanceBob := s.GetBalancesFromAddress(i.BOB) s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: 100 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.ALICE, + PoolId: 0, + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) for a := 0; a < funderstypes.MaxFunders-1; a++ { @@ -308,48 +334,48 @@ var _ = Describe("msg_server_fund_pool.go", Ordered, func() { }) // fill remaining funding slots s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.DUMMY[a], - PoolId: 0, - Amount: 1000 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.DUMMY[a], + PoolId: 0, + Amounts: i.ACoins(1000 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) } - balanceAfter := s.GetBalanceFromAddress(i.ALICE) - Expect(initialBalance - balanceAfter).To(Equal(100 * i.KYVE)) + balanceAfter := s.GetBalancesFromAddress(i.ALICE) + Expect(initialBalance.Sub(balanceAfter...).String()).To(Equal(i.ACoins(100 * i.T_KYVE).String())) // ACT s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.BOB, - PoolId: 0, - Amount: 200 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.BOB, + PoolId: 0, + Amounts: i.ACoins(200 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) - x := s.GetBalanceFromAddress(i.BOB) - Expect(initialBalanceBob - x).To(Equal(200 * i.KYVE)) + x := s.GetBalancesFromAddress(i.BOB) + Expect(initialBalanceBob.Sub(x...).String()).To(Equal(i.ACoins(200 * i.T_KYVE).String())) // ASSERT fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) Expect(len(fundingState.ActiveFunderAddresses)).To(Equal(funderstypes.MaxFunders)) activeFundings := s.App().FundersKeeper.GetActiveFundings(s.Ctx(), fundingState) Expect(activeFundings).To(HaveLen(50)) - lowestFunding, err := s.App().FundersKeeper.GetLowestFunding(activeFundings) + lowestFunding, err := s.App().FundersKeeper.GetLowestFunding(activeFundings, whitelist) Expect(err).To(BeNil()) Expect(lowestFunding.FunderAddress).To(Equal(i.BOB)) - balanceEnd := s.GetBalanceFromAddress(i.ALICE) - Expect(initialBalance - balanceEnd).To(BeZero()) + balanceEnd := s.GetBalancesFromAddress(i.ALICE) + Expect(initialBalance.Sub(balanceEnd...).IsZero()).To(BeTrue()) - balanceAfterBob := s.GetBalanceFromAddress(i.BOB) - Expect(initialBalanceBob - balanceAfterBob).To(Equal(200 * i.KYVE)) + balanceAfterBob := s.GetBalancesFromAddress(i.BOB) + Expect(initialBalanceBob.Sub(balanceAfterBob...).String()).To(Equal(i.ACoins(200 * i.T_KYVE))) }) It("Refund a funding as the lowest funder", func() { // ARRANGE s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: 100 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.ALICE, + PoolId: 0, + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) for a := 0; a < funderstypes.MaxFunders-1; a++ { @@ -359,74 +385,73 @@ var _ = Describe("msg_server_fund_pool.go", Ordered, func() { }) // fill remaining funding slots s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.DUMMY[a], - PoolId: 0, - Amount: 1000 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.DUMMY[a], + PoolId: 0, + Amounts: i.ACoins(1000 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) } fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) activeFundings := s.App().FundersKeeper.GetActiveFundings(s.Ctx(), fundingState) Expect(activeFundings).To(HaveLen(50)) - lowestFunding, err := s.App().FundersKeeper.GetLowestFunding(activeFundings) + lowestFunding, err := s.App().FundersKeeper.GetLowestFunding(activeFundings, whitelist) Expect(err).To(BeNil()) Expect(lowestFunding.FunderAddress).To(Equal(i.ALICE)) // ACT s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: 50 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.ALICE, + PoolId: 0, + Amounts: i.ACoins(50 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) // ASSERT fundingState, _ = s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) Expect(len(fundingState.ActiveFunderAddresses)).To(Equal(funderstypes.MaxFunders)) - balanceEnd := s.GetBalanceFromAddress(i.ALICE) - Expect(initialBalance - balanceEnd).To(Equal(150 * i.KYVE)) + balanceEnd := s.GetBalancesFromAddress(i.ALICE) + Expect(initialBalance.Sub(balanceEnd...).String()).To(Equal(i.ACoins(150 * i.T_KYVE).String())) }) It("Try to fund a non-existent pool", func() { // ASSERT s.RunTxFundersError(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 1, - Amount: 100 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + Creator: i.ALICE, + PoolId: 1, + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) }) It("Try to fund below the minimum amount", func() { // ASSERT s.RunTxFundersError(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: 1, - AmountPerBundle: 1 * i.KYVE, + Creator: i.ALICE, + PoolId: 0, + Amounts: i.ACoins(1 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1 * i.T_KYVE), }) }) It("Try to fund below the minimum amount per bundle", func() { // ASSERT s.RunTxFundersError(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: 100 * i.KYVE, - AmountPerBundle: 1, + Creator: i.ALICE, + PoolId: 0, + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(1), }) }) It("Try to fund without fulfilling min_funding_multiple", func() { // ASSERT - _, err := s.RunTx(&funderstypes.MsgFundPool{ - Creator: i.ALICE, - PoolId: 0, - Amount: 2 * i.KYVE, - AmountPerBundle: 1 * i.KYVE, + s.RunTxFundersError(&funderstypes.MsgFundPool{ + Creator: i.ALICE, + PoolId: 0, + Amounts: i.ACoins(100 * i.T_KYVE), + AmountsPerBundle: i.ACoins(50 * i.T_KYVE), }) - Expect(err.Error()).To(Equal("per_bundle_amount (1000000000kyve) times min_funding_multiple (1000000000) is smaller than funded_amount (2000000000kyve): invalid request")) }) })