cosmos-sdk/x/distribution/proposal_handler_test.go

68 lines
2.0 KiB
Go
Raw Normal View History

package distribution
import (
"testing"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/stretchr/testify/require"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)
var (
delPk1 = ed25519.GenPrivKey().PubKey()
delAddr1 = sdk.AccAddress(delPk1.Address())
2019-06-28 13:11:27 -07:00
amount = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1)))
)
func testProposal(recipient sdk.AccAddress, amount sdk.Coins) types.CommunityPoolSpendProposal {
2020-01-30 13:31:16 -08:00
return types.NewCommunityPoolSpendProposal("Test", "description", recipient, amount)
}
func TestProposalHandlerPassed(t *testing.T) {
2020-01-30 13:31:16 -08:00
ctx, ak, bk, keeper, _, supplyKeeper := CreateTestInputDefault(t, false, 10)
recipient := delAddr1
2019-06-28 13:11:27 -07:00
// add coins to the module account
macc := keeper.GetDistributionAccount(ctx)
2020-01-30 13:31:16 -08:00
balances := bk.GetAllBalances(ctx, macc.GetAddress())
err := bk.SetBalances(ctx, macc.GetAddress(), balances.Add(amount...))
2019-06-28 13:11:27 -07:00
require.NoError(t, err)
supplyKeeper.SetModuleAccount(ctx, macc)
2020-01-30 13:31:16 -08:00
account := ak.NewAccountWithAddress(ctx, recipient)
ak.SetAccount(ctx, account)
require.True(t, bk.GetAllBalances(ctx, account.GetAddress()).IsZero())
feePool := keeper.GetFeePool(ctx)
feePool.CommunityPool = sdk.NewDecCoinsFromCoins(amount...)
keeper.SetFeePool(ctx, feePool)
2019-06-28 13:11:27 -07:00
tp := testProposal(recipient, amount)
hdlr := NewCommunityPoolSpendProposalHandler(keeper)
require.NoError(t, hdlr(ctx, tp))
2020-01-30 13:31:16 -08:00
balances = bk.GetAllBalances(ctx, recipient)
require.Equal(t, balances, amount)
}
func TestProposalHandlerFailed(t *testing.T) {
2020-01-30 13:31:16 -08:00
ctx, ak, bk, keeper, _, _ := CreateTestInputDefault(t, false, 10)
recipient := delAddr1
2020-01-30 13:31:16 -08:00
account := ak.NewAccountWithAddress(ctx, recipient)
ak.SetAccount(ctx, account)
require.True(t, bk.GetAllBalances(ctx, account.GetAddress()).IsZero())
2019-06-28 13:11:27 -07:00
tp := testProposal(recipient, amount)
hdlr := NewCommunityPoolSpendProposalHandler(keeper)
require.Error(t, hdlr(ctx, tp))
2020-01-30 13:31:16 -08:00
balances := bk.GetAllBalances(ctx, recipient)
require.True(t, balances.IsZero())
}