132 lines
3.9 KiB
Go
132 lines
3.9 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"cosmossdk.io/math"
|
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
|
)
|
|
|
|
func (s *KeeperTestSuite) TestMsgUpdateParams() {
|
|
ctx, keeper, msgServer := s.ctx, s.stakingKeeper, s.msgServer
|
|
require := s.Require()
|
|
|
|
testCases := []struct {
|
|
name string
|
|
input *stakingtypes.MsgUpdateParams
|
|
expErr bool
|
|
expErrMsg string
|
|
}{
|
|
{
|
|
name: "valid params",
|
|
input: &stakingtypes.MsgUpdateParams{
|
|
Authority: keeper.GetAuthority(),
|
|
Params: stakingtypes.DefaultParams(),
|
|
},
|
|
expErr: false,
|
|
},
|
|
{
|
|
name: "invalid authority",
|
|
input: &stakingtypes.MsgUpdateParams{
|
|
Authority: "invalid",
|
|
Params: stakingtypes.DefaultParams(),
|
|
},
|
|
expErr: true,
|
|
expErrMsg: "invalid authority",
|
|
},
|
|
{
|
|
name: "negative commission rate",
|
|
input: &stakingtypes.MsgUpdateParams{
|
|
Authority: keeper.GetAuthority(),
|
|
Params: stakingtypes.Params{
|
|
MinCommissionRate: math.LegacyNewDec(-10),
|
|
UnbondingTime: stakingtypes.DefaultUnbondingTime,
|
|
MaxValidators: stakingtypes.DefaultMaxValidators,
|
|
MaxEntries: stakingtypes.DefaultMaxEntries,
|
|
HistoricalEntries: stakingtypes.DefaultHistoricalEntries,
|
|
BondDenom: stakingtypes.BondStatusBonded,
|
|
},
|
|
},
|
|
expErr: true,
|
|
expErrMsg: "minimum commission rate cannot be negative",
|
|
},
|
|
{
|
|
name: "commission rate cannot be bigger than 100",
|
|
input: &stakingtypes.MsgUpdateParams{
|
|
Authority: keeper.GetAuthority(),
|
|
Params: stakingtypes.Params{
|
|
MinCommissionRate: math.LegacyNewDec(2),
|
|
UnbondingTime: stakingtypes.DefaultUnbondingTime,
|
|
MaxValidators: stakingtypes.DefaultMaxValidators,
|
|
MaxEntries: stakingtypes.DefaultMaxEntries,
|
|
HistoricalEntries: stakingtypes.DefaultHistoricalEntries,
|
|
BondDenom: stakingtypes.BondStatusBonded,
|
|
},
|
|
},
|
|
expErr: true,
|
|
expErrMsg: "minimum commission rate cannot be greater than 100%",
|
|
},
|
|
{
|
|
name: "invalid bond denom",
|
|
input: &stakingtypes.MsgUpdateParams{
|
|
Authority: keeper.GetAuthority(),
|
|
Params: stakingtypes.Params{
|
|
MinCommissionRate: stakingtypes.DefaultMinCommissionRate,
|
|
UnbondingTime: stakingtypes.DefaultUnbondingTime,
|
|
MaxValidators: stakingtypes.DefaultMaxValidators,
|
|
MaxEntries: stakingtypes.DefaultMaxEntries,
|
|
HistoricalEntries: stakingtypes.DefaultHistoricalEntries,
|
|
BondDenom: "",
|
|
},
|
|
},
|
|
expErr: true,
|
|
expErrMsg: "bond denom cannot be blank",
|
|
},
|
|
{
|
|
name: "max validators most be positive",
|
|
input: &stakingtypes.MsgUpdateParams{
|
|
Authority: keeper.GetAuthority(),
|
|
Params: stakingtypes.Params{
|
|
MinCommissionRate: stakingtypes.DefaultMinCommissionRate,
|
|
UnbondingTime: stakingtypes.DefaultUnbondingTime,
|
|
MaxValidators: 0,
|
|
MaxEntries: stakingtypes.DefaultMaxEntries,
|
|
HistoricalEntries: stakingtypes.DefaultHistoricalEntries,
|
|
BondDenom: stakingtypes.BondStatusBonded,
|
|
},
|
|
},
|
|
expErr: true,
|
|
expErrMsg: "max validators must be positive",
|
|
},
|
|
{
|
|
name: "max entries most be positive",
|
|
input: &stakingtypes.MsgUpdateParams{
|
|
Authority: keeper.GetAuthority(),
|
|
Params: stakingtypes.Params{
|
|
MinCommissionRate: stakingtypes.DefaultMinCommissionRate,
|
|
UnbondingTime: stakingtypes.DefaultUnbondingTime,
|
|
MaxValidators: stakingtypes.DefaultMaxValidators,
|
|
MaxEntries: 0,
|
|
HistoricalEntries: stakingtypes.DefaultHistoricalEntries,
|
|
BondDenom: stakingtypes.BondStatusBonded,
|
|
},
|
|
},
|
|
expErr: true,
|
|
expErrMsg: "max entries must be positive",
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
s.T().Run(tc.name, func(t *testing.T) {
|
|
_, err := msgServer.UpdateParams(ctx, tc.input)
|
|
if tc.expErr {
|
|
require.Error(err)
|
|
require.Contains(err.Error(), tc.expErrMsg)
|
|
} else {
|
|
require.NoError(err)
|
|
}
|
|
})
|
|
}
|
|
}
|