Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Community pool spend proposal #4329

Merged
merged 17 commits into from
May 21, 2019
Prev Previous commit
Next Next commit
Add testcases
  • Loading branch information
cwgoes committed May 20, 2019
commit b7052b7db3e1faa47295bc025d2b7b57474704f3
59 changes: 59 additions & 0 deletions x/distribution/proposal_handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package distribution

import (
"testing"

"github.com/tendermint/tendermint/crypto/ed25519"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/stretchr/testify/require"
)

var (
delPk1 = ed25519.GenPrivKey().PubKey()
delAddr1 = sdk.AccAddress(delPk1.Address())
)

func testProposal(recipient sdk.AccAddress, amount sdk.Coins) types.CommunityPoolSpendProposal {
return types.NewCommunityPoolSpendProposal(
"Test",
"description",
recipient,
amount,
)
}

func TestProposalHandlerPassed(t *testing.T) {
ctx, accountKeeper, keeper, _, _ := CreateTestInputDefault(t, false, 10)
recipient := delAddr1
amount := sdk.NewCoin("stake", sdk.NewInt(1))

account := accountKeeper.NewAccountWithAddress(ctx, recipient)
require.True(t, account.GetCoins().IsZero())
accountKeeper.SetAccount(ctx, account)

feePool := keeper.GetFeePool(ctx)
feePool.CommunityPool = sdk.DecCoins{sdk.NewDecCoinFromCoin(amount)}
keeper.SetFeePool(ctx, feePool)

tp := testProposal(recipient, sdk.NewCoins(amount))
hdlr := NewCommunityPoolSpendProposalHandler(keeper)
require.NoError(t, hdlr(ctx, tp))
require.Equal(t, accountKeeper.GetAccount(ctx, recipient).GetCoins(), sdk.NewCoins(amount))
}

func TestProposalHandlerFailed(t *testing.T) {
ctx, accountKeeper, keeper, _, _ := CreateTestInputDefault(t, false, 10)
recipient := delAddr1
amount := sdk.NewCoin("stake", sdk.NewInt(1))

account := accountKeeper.NewAccountWithAddress(ctx, recipient)
require.True(t, account.GetCoins().IsZero())
accountKeeper.SetAccount(ctx, account)

tp := testProposal(recipient, sdk.NewCoins(amount))
hdlr := NewCommunityPoolSpendProposalHandler(keeper)
require.Error(t, hdlr(ctx, tp))
require.True(t, accountKeeper.GetAccount(ctx, recipient).GetCoins().IsZero())
}