github.com/Finschia/finschia-sdk@v0.49.1/x/distribution/proposal_handler_test.go (about) 1 package distribution_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 tmproto "github.com/tendermint/tendermint/proto/tendermint/types" 8 9 "github.com/Finschia/finschia-sdk/crypto/keys/ed25519" 10 "github.com/Finschia/finschia-sdk/simapp" 11 sdk "github.com/Finschia/finschia-sdk/types" 12 "github.com/Finschia/finschia-sdk/x/distribution" 13 "github.com/Finschia/finschia-sdk/x/distribution/types" 14 ) 15 16 var ( 17 delPk1 = ed25519.GenPrivKey().PubKey() 18 delAddr1 = sdk.AccAddress(delPk1.Address()) 19 20 amount = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1))) 21 ) 22 23 func testProposal(recipient sdk.AccAddress, amount sdk.Coins) *types.CommunityPoolSpendProposal { 24 return types.NewCommunityPoolSpendProposal("Test", "description", recipient, amount) 25 } 26 27 func TestProposalHandlerPassed(t *testing.T) { 28 app := simapp.Setup(false) 29 ctx := app.BaseApp.NewContext(false, tmproto.Header{}) 30 31 recipient := delAddr1 32 33 // add coins to the module account 34 macc := app.DistrKeeper.GetDistributionAccount(ctx) 35 require.NoError(t, simapp.FundModuleAccount(app, ctx, macc.GetName(), amount)) 36 37 app.AccountKeeper.SetModuleAccount(ctx, macc) 38 39 account := app.AccountKeeper.NewAccountWithAddress(ctx, recipient) 40 app.AccountKeeper.SetAccount(ctx, account) 41 require.True(t, app.BankKeeper.GetAllBalances(ctx, account.GetAddress()).IsZero()) 42 43 feePool := app.DistrKeeper.GetFeePool(ctx) 44 feePool.CommunityPool = sdk.NewDecCoinsFromCoins(amount...) 45 app.DistrKeeper.SetFeePool(ctx, feePool) 46 47 tp := testProposal(recipient, amount) 48 hdlr := distribution.NewCommunityPoolSpendProposalHandler(app.DistrKeeper) 49 require.NoError(t, hdlr(ctx, tp)) 50 51 balances := app.BankKeeper.GetAllBalances(ctx, recipient) 52 require.Equal(t, balances, amount) 53 } 54 55 func TestProposalHandlerFailed(t *testing.T) { 56 app := simapp.Setup(false) 57 ctx := app.BaseApp.NewContext(false, tmproto.Header{}) 58 59 recipient := delAddr1 60 61 account := app.AccountKeeper.NewAccountWithAddress(ctx, recipient) 62 app.AccountKeeper.SetAccount(ctx, account) 63 require.True(t, app.BankKeeper.GetAllBalances(ctx, account.GetAddress()).IsZero()) 64 65 tp := testProposal(recipient, amount) 66 hdlr := distribution.NewCommunityPoolSpendProposalHandler(app.DistrKeeper) 67 require.Error(t, hdlr(ctx, tp)) 68 69 balances := app.BankKeeper.GetAllBalances(ctx, recipient) 70 require.True(t, balances.IsZero()) 71 }