cosmos-sdk/x/distribution/proposal_handler_test.go
Marko 8de96d16f9
tendermint: update to rc3 (#6892)
* modify light imports

* change abci.header to tmproto.header

* use rc

* rc

* fix import

* Merge PR #6893: fix key imports

* fix rc2

* tendermint: update 3 (#6899)

* tendermint: update 4 (#6919)

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

* tendermint: update 5 (#6923)

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* bump to latest master

* tendermint: update (#6972)

Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com>
Co-authored-by: Cory Levinson <cjlevinson@gmail.com>

* Update x/ibc/07-tendermint/types/test_utils.go

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* address comment

* go mod

* bring back things

* fix test

* update tm proto files

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com>
Co-authored-by: Cory Levinson <cjlevinson@gmail.com>
Co-authored-by: Federico Kunze <federico.kunze94@gmail.com>
2020-08-14 13:58:53 -04:00

74 lines
2.4 KiB
Go

package distribution_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)
var (
delPk1 = ed25519.GenPrivKey().PubKey()
delAddr1 = sdk.AccAddress(delPk1.Address())
amount = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1)))
)
func testProposal(recipient sdk.AccAddress, amount sdk.Coins) *types.CommunityPoolSpendProposal {
return types.NewCommunityPoolSpendProposal("Test", "description", recipient, amount)
}
func TestProposalHandlerPassed(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
recipient := delAddr1
// add coins to the module account
macc := app.DistrKeeper.GetDistributionAccount(ctx)
balances := app.BankKeeper.GetAllBalances(ctx, macc.GetAddress())
err := app.BankKeeper.SetBalances(ctx, macc.GetAddress(), balances.Add(amount...))
require.NoError(t, err)
app.AccountKeeper.SetModuleAccount(ctx, macc)
account := app.AccountKeeper.NewAccountWithAddress(ctx, recipient)
app.AccountKeeper.SetAccount(ctx, account)
require.True(t, app.BankKeeper.GetAllBalances(ctx, account.GetAddress()).IsZero())
feePool := app.DistrKeeper.GetFeePool(ctx)
feePool.CommunityPool = sdk.NewDecCoinsFromCoins(amount...)
app.DistrKeeper.SetFeePool(ctx, feePool)
tp := testProposal(recipient, amount)
hdlr := distribution.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)
require.NoError(t, hdlr(ctx, tp))
balances = app.BankKeeper.GetAllBalances(ctx, recipient)
require.Equal(t, balances, amount)
}
func TestProposalHandlerFailed(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
recipient := delAddr1
account := app.AccountKeeper.NewAccountWithAddress(ctx, recipient)
app.AccountKeeper.SetAccount(ctx, account)
require.True(t, app.BankKeeper.GetAllBalances(ctx, account.GetAddress()).IsZero())
tp := testProposal(recipient, amount)
hdlr := distribution.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)
require.Error(t, hdlr(ctx, tp))
balances := app.BankKeeper.GetAllBalances(ctx, recipient)
require.True(t, balances.IsZero())
}