Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update commission_test.go #1821

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions app/ante/commission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ package ante_test
import (
"testing"

sdkclienttx "github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"

"github.com/NibiruChain/nibiru/app"
"github.com/NibiruChain/nibiru/app/ante"
"github.com/NibiruChain/nibiru/x/common/testutil"
)

func (s *AnteTestSuite) TestAnteDecoratorStakingCommission() {
// nextAnteHandler: A no-op next handler to make this a unit test.
// Define a no-op next handler to make this a unit test.
var nextAnteHandler sdk.AnteHandler = func(
ctx sdk.Context, tx sdk.Tx, simulate bool,
) (newCtx sdk.Context, err error) {
return ctx, nil
}

// Mock description for testing.
mockDescription := stakingtypes.Description{
Moniker: "mock-moniker",
Identity: "mock-identity",
Expand All @@ -30,49 +29,47 @@ func (s *AnteTestSuite) TestAnteDecoratorStakingCommission() {
Details: "mock-details",
}

// Define validator address.
valAddr := sdk.ValAddress(testutil.AccAddress()).String()
commissionRatePointer := new(sdk.Dec)
*commissionRatePointer = sdk.NewDecWithPrec(10, 2)

// Define commission rate.
commissionRate := sdk.NewDecWithPrec(10, 2)

// Define happy messages.
happyMsgs := []sdk.Msg{
&stakingtypes.MsgCreateValidator{
Description: mockDescription,
Commission: stakingtypes.CommissionRates{
Rate: sdk.NewDecWithPrec(6, 2), // 6%
MaxRate: sdk.NewDec(420),
MaxChangeRate: sdk.NewDec(420),
},
Description: mockDescription,
Commission: stakingtypes.CommissionRates{Rate: sdk.NewDecWithPrec(6, 2)},
MinSelfDelegation: sdk.NewInt(1),
DelegatorAddress: testutil.AccAddress().String(),
ValidatorAddress: valAddr,
Pubkey: &codectypes.Any{},
Pubkey: nil,
Value: sdk.NewInt64Coin("unibi", 1),
},
&stakingtypes.MsgEditValidator{
Description: mockDescription,
ValidatorAddress: valAddr,
CommissionRate: commissionRatePointer, // 10%
MinSelfDelegation: nil,
Description: mockDescription,
ValidatorAddress: valAddr,
CommissionRate: &commissionRate,
},
}

// Define function to create sad messages.
createSadMsgs := func() []sdk.Msg {
sadMsgCreateVal := new(stakingtypes.MsgCreateValidator)
*sadMsgCreateVal = *(happyMsgs[0]).(*stakingtypes.MsgCreateValidator)
sadMsgCreateVal := *(happyMsgs[0]).(*stakingtypes.MsgCreateValidator)
sadMsgCreateVal.Commission.Rate = sdk.NewDecWithPrec(26, 2)

sadMsgEditVal := new(stakingtypes.MsgEditValidator)
*sadMsgEditVal = *(happyMsgs[1]).(*stakingtypes.MsgEditValidator)
newCommissionRate := new(sdk.Dec)
*newCommissionRate = sdk.NewDecWithPrec(26, 2)
sadMsgEditVal.CommissionRate = newCommissionRate
sadMsgEditVal := *(happyMsgs[1]).(*stakingtypes.MsgEditValidator)
newCommissionRate := sdk.NewDecWithPrec(26, 2)
sadMsgEditVal.CommissionRate = &newCommissionRate

return []sdk.Msg{
sadMsgCreateVal,
sadMsgEditVal,
&sadMsgCreateVal,
&sadMsgEditVal,
}
}
sadMsgs := createSadMsgs()

// Test cases.
for _, tc := range []struct {
name string
txMsgs []sdk.Msg
Expand Down Expand Up @@ -115,7 +112,7 @@ func (s *AnteTestSuite) TestAnteDecoratorStakingCommission() {
)

encCfg := app.MakeEncodingConfig()
txBuilder, err := sdkclienttx.Factory{}.
txBuilder, err := tx.Factory{}.
WithFees(txGasCoins.String()).
WithChainID(s.ctx.ChainID()).
WithTxConfig(encCfg.TxConfig).
Expand Down
Loading