github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/distribution/proposal_handler_test.go (about)

     1  package distribution
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/fibonacci-chain/fbc/libs/tendermint/crypto/ed25519"
     7  
     8  	"github.com/stretchr/testify/require"
     9  
    10  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    11  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/distribution/types"
    12  )
    13  
    14  var (
    15  	delPk1   = ed25519.GenPrivKey().PubKey()
    16  	delAddr1 = sdk.AccAddress(delPk1.Address())
    17  
    18  	amount = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1)))
    19  )
    20  
    21  func testProposal(recipient sdk.AccAddress, amount sdk.Coins) types.CommunityPoolSpendProposal {
    22  	return types.NewCommunityPoolSpendProposal(
    23  		"Test",
    24  		"description",
    25  		recipient,
    26  		amount,
    27  	)
    28  }
    29  
    30  func TestProposalHandlerPassed(t *testing.T) {
    31  	ctx, accountKeeper, keeper, _, supplyKeeper := CreateTestInputDefault(t, false, 10)
    32  	recipient := delAddr1
    33  
    34  	// add coins to the module account
    35  	macc := keeper.GetDistributionAccount(ctx)
    36  	err := macc.SetCoins(macc.GetCoins().Add(amount...))
    37  	require.NoError(t, err)
    38  
    39  	supplyKeeper.SetModuleAccount(ctx, macc)
    40  
    41  	account := accountKeeper.NewAccountWithAddress(ctx, recipient)
    42  	require.True(t, account.GetCoins().IsZero())
    43  	accountKeeper.SetAccount(ctx, account)
    44  
    45  	feePool := keeper.GetFeePool(ctx)
    46  	feePool.CommunityPool = sdk.NewDecCoinsFromCoins(amount...)
    47  	keeper.SetFeePool(ctx, feePool)
    48  
    49  	tp := testProposal(recipient, amount)
    50  	hdlr := NewCommunityPoolSpendProposalHandler(keeper)
    51  	require.NoError(t, hdlr(ctx, tp))
    52  	require.Equal(t, accountKeeper.GetAccount(ctx, recipient).GetCoins(), amount)
    53  }
    54  
    55  func TestProposalHandlerFailed(t *testing.T) {
    56  	ctx, accountKeeper, keeper, _, _ := CreateTestInputDefault(t, false, 10)
    57  	recipient := delAddr1
    58  
    59  	account := accountKeeper.NewAccountWithAddress(ctx, recipient)
    60  	require.True(t, account.GetCoins().IsZero())
    61  	accountKeeper.SetAccount(ctx, account)
    62  
    63  	tp := testProposal(recipient, amount)
    64  	hdlr := NewCommunityPoolSpendProposalHandler(keeper)
    65  	require.Error(t, hdlr(ctx, tp))
    66  	require.True(t, accountKeeper.GetAccount(ctx, recipient).GetCoins().IsZero())
    67  }