2022-12-09 21:24:35 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-04-05 23:21:59 +00:00
|
|
|
sdkmath "cosmossdk.io/math"
|
2022-12-09 21:24:35 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/community/testutil"
|
|
|
|
"github.com/kava-labs/kava/x/community/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Test suite used for all keeper tests
|
|
|
|
type KeeperTestSuite struct {
|
|
|
|
testutil.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
// The default state used by each test
|
|
|
|
func (suite *KeeperTestSuite) SetupTest() {
|
|
|
|
suite.Suite.SetupTest()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(KeeperTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestCommunityPool() {
|
|
|
|
suite.SetupTest()
|
|
|
|
maccAddr := suite.App.GetAccountKeeper().GetModuleAddress(types.ModuleAccountName)
|
|
|
|
|
|
|
|
funds := sdk.NewCoins(
|
2023-04-05 23:21:59 +00:00
|
|
|
sdk.NewCoin("ukava", sdkmath.NewInt(10000)),
|
|
|
|
sdk.NewCoin("usdx", sdkmath.NewInt(100)),
|
2022-12-09 21:24:35 +00:00
|
|
|
)
|
|
|
|
sender := suite.CreateFundedAccount(funds)
|
|
|
|
|
|
|
|
suite.Run("FundCommunityPool", func() {
|
|
|
|
err := suite.Keeper.FundCommunityPool(suite.Ctx, sender, funds)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
|
|
|
|
// check that community pool received balance
|
|
|
|
suite.App.CheckBalance(suite.T(), suite.Ctx, maccAddr, funds)
|
2022-12-19 21:50:11 +00:00
|
|
|
suite.Equal(funds, suite.Keeper.GetModuleAccountBalance(suite.Ctx))
|
2022-12-09 21:24:35 +00:00
|
|
|
// check that sender had balance deducted
|
|
|
|
suite.App.CheckBalance(suite.T(), suite.Ctx, sender, sdk.NewCoins())
|
|
|
|
})
|
|
|
|
|
|
|
|
// send it back
|
|
|
|
suite.Run("DistributeFromCommunityPool - valid", func() {
|
|
|
|
err := suite.Keeper.DistributeFromCommunityPool(suite.Ctx, sender, funds)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
|
|
|
|
// community pool has funds deducted
|
|
|
|
suite.App.CheckBalance(suite.T(), suite.Ctx, maccAddr, sdk.NewCoins())
|
2022-12-19 21:50:11 +00:00
|
|
|
suite.Equal(sdk.NewCoins(), suite.Keeper.GetModuleAccountBalance(suite.Ctx))
|
2022-12-09 21:24:35 +00:00
|
|
|
// receiver receives the funds
|
|
|
|
suite.App.CheckBalance(suite.T(), suite.Ctx, sender, funds)
|
|
|
|
})
|
|
|
|
|
|
|
|
// can't send more than we have!
|
|
|
|
suite.Run("DistributeFromCommunityPool - insufficient funds", func() {
|
2022-12-19 21:50:11 +00:00
|
|
|
suite.Equal(sdk.NewCoins(), suite.Keeper.GetModuleAccountBalance(suite.Ctx))
|
2022-12-09 21:24:35 +00:00
|
|
|
err := suite.Keeper.DistributeFromCommunityPool(suite.Ctx, sender, funds)
|
|
|
|
suite.Require().ErrorContains(err, "insufficient funds")
|
|
|
|
})
|
|
|
|
}
|