2022-09-29 17:01:06 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2022-12-09 21:24:35 +00:00
|
|
|
communitytypes "github.com/kava-labs/kava/x/community/types"
|
2022-09-29 17:01:06 +00:00
|
|
|
"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() {
|
|
|
|
ctx := suite.Ctx
|
2022-12-09 21:24:35 +00:00
|
|
|
macc := suite.App.GetAccountKeeper().GetModuleAccount(ctx, communitytypes.ModuleAccountName)
|
2022-09-29 17:01:06 +00:00
|
|
|
fundAmount := sdk.NewCoins(sdk.NewInt64Coin("ukava", 100000000))
|
|
|
|
depositAmount := sdk.NewCoin("ukava", sdk.NewInt(10000000))
|
|
|
|
suite.Require().NoError(suite.App.FundModuleAccount(ctx, macc.GetName(), fundAmount))
|
2022-12-09 21:24:35 +00:00
|
|
|
|
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())
|
|
|
|
suite.Require().Equal(fundAmount.Sub(sdk.NewCoins(depositAmount)), balance)
|
2022-12-09 21:24:35 +00:00
|
|
|
|
|
|
|
communityPoolBalance := suite.App.GetCommunityKeeper().GetModuleAccountBalance(ctx)
|
2022-09-29 17:01:06 +00:00
|
|
|
suite.Require().Equal(fundAmount.Sub(sdk.NewCoins(depositAmount)), communityPoolBalance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *proposalTestSuite) TestCommunityWithdrawProposal() {
|
|
|
|
ctx := suite.Ctx
|
2022-12-09 21:24:35 +00:00
|
|
|
macc := suite.App.GetAccountKeeper().GetModuleAccount(ctx, communitytypes.ModuleAccountName)
|
2022-09-29 17:01:06 +00:00
|
|
|
fundAmount := sdk.NewCoins(sdk.NewInt64Coin("ukava", 100000000))
|
|
|
|
depositAmount := sdk.NewCoin("ukava", sdk.NewInt(10000000))
|
|
|
|
suite.Require().NoError(suite.App.FundModuleAccount(ctx, macc.GetName(), fundAmount))
|
2022-12-09 21:24:35 +00:00
|
|
|
|
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())
|
|
|
|
suite.Require().Equal(fundAmount.Sub(sdk.NewCoins(depositAmount)), balance)
|
|
|
|
|
|
|
|
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)
|
2022-12-09 21:24:35 +00:00
|
|
|
|
|
|
|
communityPoolBalance := suite.App.GetCommunityKeeper().GetModuleAccountBalance(ctx)
|
2022-09-29 17:01:06 +00:00
|
|
|
suite.Require().Equal(fundAmount, communityPoolBalance)
|
|
|
|
}
|