github.com/Finschia/finschia-sdk@v0.48.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 balances := app.BankKeeper.GetAllBalances(ctx, macc.GetAddress()) 36 require.NoError(t, simapp.FundModuleAccount(app, ctx, macc.GetName(), amount)) 37 38 app.AccountKeeper.SetModuleAccount(ctx, macc) 39 40 account := app.AccountKeeper.NewAccountWithAddress(ctx, recipient) 41 app.AccountKeeper.SetAccount(ctx, account) 42 require.True(t, app.BankKeeper.GetAllBalances(ctx, account.GetAddress()).IsZero()) 43 44 feePool := app.DistrKeeper.GetFeePool(ctx) 45 feePool.CommunityPool = sdk.NewDecCoinsFromCoins(amount...) 46 app.DistrKeeper.SetFeePool(ctx, feePool) 47 48 tp := testProposal(recipient, amount) 49 hdlr := distribution.NewCommunityPoolSpendProposalHandler(app.DistrKeeper) 50 require.NoError(t, hdlr(ctx, tp)) 51 52 balances = app.BankKeeper.GetAllBalances(ctx, recipient) 53 require.Equal(t, balances, amount) 54 } 55 56 func TestProposalHandlerFailed(t *testing.T) { 57 app := simapp.Setup(false) 58 ctx := app.BaseApp.NewContext(false, tmproto.Header{}) 59 60 recipient := delAddr1 61 62 account := app.AccountKeeper.NewAccountWithAddress(ctx, recipient) 63 app.AccountKeeper.SetAccount(ctx, account) 64 require.True(t, app.BankKeeper.GetAllBalances(ctx, account.GetAddress()).IsZero()) 65 66 tp := testProposal(recipient, amount) 67 hdlr := distribution.NewCommunityPoolSpendProposalHandler(app.DistrKeeper) 68 require.Error(t, hdlr(ctx, tp)) 69 70 balances := app.BankKeeper.GetAllBalances(ctx, recipient) 71 require.True(t, balances.IsZero()) 72 }