2019-05-21 03:02:10 -07:00
|
|
|
package distribution
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
|
|
|
|
2019-07-22 08:26:42 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-05-21 03:02:10 -07:00
|
|
|
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)))
|
2019-05-21 03:02:10 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func testProposal(recipient sdk.AccAddress, amount sdk.Coins) types.CommunityPoolSpendProposal {
|
|
|
|
return types.NewCommunityPoolSpendProposal(
|
|
|
|
"Test",
|
|
|
|
"description",
|
|
|
|
recipient,
|
|
|
|
amount,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProposalHandlerPassed(t *testing.T) {
|
2019-06-28 13:11:27 -07:00
|
|
|
ctx, accountKeeper, keeper, _, supplyKeeper := CreateTestInputDefault(t, false, 10)
|
2019-05-21 03:02:10 -07:00
|
|
|
recipient := delAddr1
|
2019-06-28 13:11:27 -07:00
|
|
|
|
|
|
|
// add coins to the module account
|
|
|
|
macc := keeper.GetDistributionAccount(ctx)
|
|
|
|
err := macc.SetCoins(macc.GetCoins().Add(amount))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
supplyKeeper.SetModuleAccount(ctx, macc)
|
2019-05-21 03:02:10 -07:00
|
|
|
|
|
|
|
account := accountKeeper.NewAccountWithAddress(ctx, recipient)
|
|
|
|
require.True(t, account.GetCoins().IsZero())
|
|
|
|
accountKeeper.SetAccount(ctx, account)
|
|
|
|
|
|
|
|
feePool := keeper.GetFeePool(ctx)
|
2019-06-28 13:11:27 -07:00
|
|
|
feePool.CommunityPool = sdk.NewDecCoins(amount)
|
2019-05-21 03:02:10 -07:00
|
|
|
keeper.SetFeePool(ctx, feePool)
|
|
|
|
|
2019-06-28 13:11:27 -07:00
|
|
|
tp := testProposal(recipient, amount)
|
2019-05-21 03:02:10 -07:00
|
|
|
hdlr := NewCommunityPoolSpendProposalHandler(keeper)
|
|
|
|
require.NoError(t, hdlr(ctx, tp))
|
2019-06-28 13:11:27 -07:00
|
|
|
require.Equal(t, accountKeeper.GetAccount(ctx, recipient).GetCoins(), amount)
|
2019-05-21 03:02:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestProposalHandlerFailed(t *testing.T) {
|
|
|
|
ctx, accountKeeper, keeper, _, _ := CreateTestInputDefault(t, false, 10)
|
|
|
|
recipient := delAddr1
|
|
|
|
|
|
|
|
account := accountKeeper.NewAccountWithAddress(ctx, recipient)
|
|
|
|
require.True(t, account.GetCoins().IsZero())
|
|
|
|
accountKeeper.SetAccount(ctx, account)
|
|
|
|
|
2019-06-28 13:11:27 -07:00
|
|
|
tp := testProposal(recipient, amount)
|
2019-05-21 03:02:10 -07:00
|
|
|
hdlr := NewCommunityPoolSpendProposalHandler(keeper)
|
|
|
|
require.Error(t, hdlr(ctx, tp))
|
|
|
|
require.True(t, accountKeeper.GetAccount(ctx, recipient).GetCoins().IsZero())
|
|
|
|
}
|