From ea1c4572da9d271cb2c051feda2def88cf1c63d7 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 23 Feb 2024 14:50:51 +0100 Subject: [PATCH] updates --- x/staking/CHANGELOG.md | 2 +- x/staking/keeper/msg_server.go | 2 +- x/staking/keeper/msg_server_test.go | 36 +++++++++++++++++++++++------ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/x/staking/CHANGELOG.md b/x/staking/CHANGELOG.md index 5067befc4137..6712884d8d94 100644 --- a/x/staking/CHANGELOG.md +++ b/x/staking/CHANGELOG.md @@ -27,7 +27,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features -* []() Governance change of `MinCommissionRate` in `MsgUpdateParams`, now updates the minimum commission rate for all validators. +* [#19537](https://github.com/cosmos/cosmos-sdk/pull/19537) Changing `MinCommissionRate` in `MsgUpdateParams` now updates the minimum commission rate for all validators. ### Improvements diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index c69ac161b642..903b38d082ed 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -623,7 +623,7 @@ func (k msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) // set the commission rate to min rate if val.Commission.CommissionRates.Rate.LT(minRate) { val.Commission.CommissionRates.Rate = minRate - // set the max rate to minRate if it is less than minRate + // set the max rate to minRate if it is less than min rate if val.Commission.CommissionRates.MaxRate.LT(minRate) { val.Commission.CommissionRates.MaxRate = minRate } diff --git a/x/staking/keeper/msg_server_test.go b/x/staking/keeper/msg_server_test.go index 7a6c57f55e8c..c0d9785557e5 100644 --- a/x/staking/keeper/msg_server_test.go +++ b/x/staking/keeper/msg_server_test.go @@ -1027,8 +1027,17 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() { ctx, keeper, msgServer := s.ctx, s.stakingKeeper, s.msgServer require := s.Require() - // create validators to test commission rate - // TODO + // create validator to test commission rate + pk := ed25519.GenPrivKey().PubKey() + require.NotNil(pk) + comm := types.NewCommissionRates(math.LegacyNewDec(0), math.LegacyNewDec(0), math.LegacyNewDec(0)) + s.bankKeeper.EXPECT().DelegateCoinsFromAccountToModule(gomock.Any(), Addr, types.NotBondedPoolName, gomock.Any()).AnyTimes() + msg, err := types.NewMsgCreateValidator(ValAddr.String(), pk, sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(10)), types.Description{Moniker: "NewVal"}, comm, math.OneInt()) + require.NoError(err) + _, err = msgServer.CreateValidator(ctx, msg) + require.NoError(err) + paramsWithUpdatedMinCommissionRate := types.DefaultParams() + paramsWithUpdatedMinCommissionRate.MinCommissionRate = math.LegacyNewDecWithPrec(5, 2) testCases := []struct { name string @@ -1043,13 +1052,26 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() { Params: types.DefaultParams(), }, postCheck: func() { + // verify that the commission isn't changed vals, err := keeper.GetAllValidators(ctx) require.NoError(err) - require.Len(vals, 6) - for _, val := range vals { - require.True(val.Commission.Rate.GTE(types.DefaultParams().MinCommissionRate)) - require.True(val.Commission.MaxRate.GTE(types.DefaultParams().MinCommissionRate)) - } + require.Len(vals, 1) + require.True(vals[0].Commission.Rate.Equal(comm.Rate)) + require.True(vals[0].Commission.MaxRate.GTE(comm.MaxRate)) + }, + }, + { + name: "valid params with updated min commission rate", + input: &types.MsgUpdateParams{ + Authority: keeper.GetAuthority(), + Params: paramsWithUpdatedMinCommissionRate, + }, + postCheck: func() { + vals, err := keeper.GetAllValidators(ctx) + require.NoError(err) + require.Len(vals, 1) + require.True(vals[0].Commission.Rate.GTE(paramsWithUpdatedMinCommissionRate.MinCommissionRate)) + require.True(vals[0].Commission.MaxRate.GTE(paramsWithUpdatedMinCommissionRate.MinCommissionRate)) }, }, {