2022-09-29 17:01:06 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-04-05 23:21:59 +00:00
|
|
|
sdkmath "cosmossdk.io/math"
|
2022-09-29 17:01:06 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/kava-labs/kava/x/earn/keeper"
|
|
|
|
"github.com/kava-labs/kava/x/earn/testutil"
|
|
|
|
"github.com/kava-labs/kava/x/earn/types"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type proposalTestSuite struct {
|
|
|
|
testutil.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *proposalTestSuite) SetupTest() {
|
|
|
|
suite.Suite.SetupTest()
|
|
|
|
suite.Keeper.SetParams(suite.Ctx, types.DefaultParams())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProposalTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(proposalTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *proposalTestSuite) TestCommunityDepositProposal() {
|
2023-01-26 17:01:28 +00:00
|
|
|
distKeeper := suite.App.GetDistrKeeper()
|
2022-09-29 17:01:06 +00:00
|
|
|
ctx := suite.Ctx
|
2023-01-26 17:01:28 +00:00
|
|
|
macc := distKeeper.GetDistributionAccount(ctx)
|
2022-09-29 17:01:06 +00:00
|
|
|
fundAmount := sdk.NewCoins(sdk.NewInt64Coin("ukava", 100000000))
|
2023-04-05 23:21:59 +00:00
|
|
|
depositAmount := sdk.NewCoin("ukava", sdkmath.NewInt(10000000))
|
2022-09-29 17:01:06 +00:00
|
|
|
suite.Require().NoError(suite.App.FundModuleAccount(ctx, macc.GetName(), fundAmount))
|
2023-01-26 17:01:28 +00:00
|
|
|
feePool := distKeeper.GetFeePool(ctx)
|
|
|
|
feePool.CommunityPool = sdk.NewDecCoinsFromCoins(fundAmount...)
|
|
|
|
distKeeper.SetFeePool(ctx, feePool)
|
2022-09-29 17:01:06 +00:00
|
|
|
suite.CreateVault("ukava", types.StrategyTypes{types.STRATEGY_TYPE_SAVINGS}, false, nil)
|
|
|
|
prop := types.NewCommunityPoolDepositProposal("test title",
|
|
|
|
"desc", depositAmount)
|
|
|
|
err := keeper.HandleCommunityPoolDepositProposal(ctx, suite.Keeper, prop)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
|
|
|
|
balance := suite.BankKeeper.GetAllBalances(ctx, macc.GetAddress())
|
2023-04-04 00:08:45 +00:00
|
|
|
suite.Require().Equal(fundAmount.Sub(depositAmount), balance)
|
2023-01-26 17:01:28 +00:00
|
|
|
feePool = distKeeper.GetFeePool(ctx)
|
|
|
|
communityPoolBalance, change := feePool.CommunityPool.TruncateDecimal()
|
2023-04-04 00:08:45 +00:00
|
|
|
suite.Require().Equal(fundAmount.Sub(depositAmount), communityPoolBalance)
|
2023-01-26 17:01:28 +00:00
|
|
|
suite.Require().True(change.Empty())
|
2022-09-29 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *proposalTestSuite) TestCommunityWithdrawProposal() {
|
2023-01-26 17:01:28 +00:00
|
|
|
distKeeper := suite.App.GetDistrKeeper()
|
2022-09-29 17:01:06 +00:00
|
|
|
ctx := suite.Ctx
|
2023-01-26 17:01:28 +00:00
|
|
|
macc := distKeeper.GetDistributionAccount(ctx)
|
2022-09-29 17:01:06 +00:00
|
|
|
fundAmount := sdk.NewCoins(sdk.NewInt64Coin("ukava", 100000000))
|
2023-04-05 23:21:59 +00:00
|
|
|
depositAmount := sdk.NewCoin("ukava", sdkmath.NewInt(10000000))
|
2022-09-29 17:01:06 +00:00
|
|
|
suite.Require().NoError(suite.App.FundModuleAccount(ctx, macc.GetName(), fundAmount))
|
2023-01-26 17:01:28 +00:00
|
|
|
feePool := distKeeper.GetFeePool(ctx)
|
|
|
|
feePool.CommunityPool = sdk.NewDecCoinsFromCoins(fundAmount...)
|
|
|
|
distKeeper.SetFeePool(ctx, feePool)
|
|
|
|
// TODO update to STRATEGY_TYPE_SAVINGS once implemented
|
2022-09-29 17:01:06 +00:00
|
|
|
suite.CreateVault("ukava", types.StrategyTypes{types.STRATEGY_TYPE_SAVINGS}, false, nil)
|
|
|
|
deposit := types.NewCommunityPoolDepositProposal("test title",
|
|
|
|
"desc", depositAmount)
|
|
|
|
err := keeper.HandleCommunityPoolDepositProposal(ctx, suite.Keeper, deposit)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
|
|
|
|
balance := suite.BankKeeper.GetAllBalances(ctx, macc.GetAddress())
|
2023-04-04 00:08:45 +00:00
|
|
|
suite.Require().Equal(fundAmount.Sub(depositAmount), balance)
|
2022-09-29 17:01:06 +00:00
|
|
|
|
|
|
|
withdraw := types.NewCommunityPoolWithdrawProposal("test title",
|
|
|
|
"desc", depositAmount)
|
|
|
|
err = keeper.HandleCommunityPoolWithdrawProposal(ctx, suite.Keeper, withdraw)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
balance = suite.BankKeeper.GetAllBalances(ctx, macc.GetAddress())
|
|
|
|
suite.Require().Equal(fundAmount, balance)
|
2023-01-26 17:01:28 +00:00
|
|
|
feePool = distKeeper.GetFeePool(ctx)
|
|
|
|
communityPoolBalance, change := feePool.CommunityPool.TruncateDecimal()
|
2022-09-29 17:01:06 +00:00
|
|
|
suite.Require().Equal(fundAmount, communityPoolBalance)
|
2023-01-26 17:01:28 +00:00
|
|
|
suite.Require().True(change.Empty())
|
2022-09-29 17:01:06 +00:00
|
|
|
}
|