github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/distribution/keeper/proposal_handler_test.go (about) 1 package keeper 2 3 import ( 4 "testing" 5 6 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 7 tmtypes "github.com/fibonacci-chain/fbc/libs/tendermint/types" 8 "github.com/fibonacci-chain/fbc/x/distribution/types" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestHandleChangeDistributionTypeProposal(t *testing.T) { 13 communityTax := sdk.NewDecWithPrec(2, 2) 14 tmtypes.UnittestOnlySetMilestoneVenus2Height(0) 15 ctx, _, _, dk, sk, _, _ := CreateTestInputAdvanced(t, false, 1000, communityTax) 16 // create validator 17 DoCreateValidator(t, ctx, sk, valOpAddr1, valConsPk1) 18 // next block 19 ctx.SetBlockHeight(ctx.BlockHeight() + 1) 20 require.Equal(t, types.DistributionTypeOffChain, dk.GetDistributionType(ctx)) 21 22 //distribution type proposal ok 23 proposal := types.NewChangeDistributionTypeProposal("change distri type", "", types.DistributionTypeOnChain) 24 tmtypes.UnittestOnlySetMilestoneVenus2Height(-1) 25 err := HandleChangeDistributionTypeProposal(ctx, dk, proposal) 26 require.Nil(t, err) 27 require.Equal(t, types.DistributionTypeOnChain, dk.GetDistributionType(ctx)) 28 29 //same 30 err = HandleChangeDistributionTypeProposal(ctx, dk, proposal) 31 require.Nil(t, err) 32 require.Equal(t, types.DistributionTypeOnChain, dk.GetDistributionType(ctx)) 33 } 34 35 func TestHandleWithdrawRewardEnabledProposal(t *testing.T) { 36 communityTax := sdk.NewDecWithPrec(2, 2) 37 tmtypes.UnittestOnlySetMilestoneVenus2Height(0) 38 ctx, _, _, dk, sk, _, _ := CreateTestInputAdvanced(t, false, 1000, communityTax) 39 // create validator 40 DoCreateValidator(t, ctx, sk, valOpAddr1, valConsPk1) 41 // next block 42 ctx.SetBlockHeight(ctx.BlockHeight() + 1) 43 require.Equal(t, true, dk.GetWithdrawRewardEnabled(ctx)) 44 45 //set withdraw reward proposal false 46 proposal := types.NewWithdrawRewardEnabledProposal("title", "description", false) 47 tmtypes.UnittestOnlySetMilestoneVenus2Height(-1) 48 err := HandleWithdrawRewardEnabledProposal(ctx, dk, proposal) 49 require.Nil(t, err) 50 require.Equal(t, false, dk.GetWithdrawRewardEnabled(ctx)) 51 52 //set withdraw reward proposal true 53 proposal.Enabled = true 54 err = HandleWithdrawRewardEnabledProposal(ctx, dk, proposal) 55 require.Nil(t, err) 56 require.Equal(t, true, dk.GetWithdrawRewardEnabled(ctx)) 57 58 //set withdraw reward proposal true, same 59 err = HandleWithdrawRewardEnabledProposal(ctx, dk, proposal) 60 require.Nil(t, err) 61 require.Equal(t, true, dk.GetWithdrawRewardEnabled(ctx)) 62 }