fix(distribution): correct default for deprecated distribution params (#14462)

This commit is contained in:
Julien Robert
2023-01-02 17:54:49 +00:00
committed by GitHub
parent 572af96fa6
commit bca18ba2ea
24 changed files with 185 additions and 330 deletions
+3 -3
View File
@@ -80,13 +80,13 @@ func (s *E2ETestSuite) TestGetCmdQueryParams() {
{
"json output",
[]string{fmt.Sprintf("--%s=json", flags.FlagOutput)},
`{"community_tax":"0.020000000000000000","base_proposer_reward":"0.010000000000000000","bonus_proposer_reward":"0.040000000000000000","withdraw_addr_enabled":true}`,
`{"community_tax":"0.020000000000000000","base_proposer_reward":"0.000000000000000000","bonus_proposer_reward":"0.000000000000000000","withdraw_addr_enabled":true}`,
},
{
"text output",
[]string{fmt.Sprintf("--%s=text", flags.FlagOutput)},
`base_proposer_reward: "0.010000000000000000"
bonus_proposer_reward: "0.040000000000000000"
`base_proposer_reward: "0.000000000000000000"
bonus_proposer_reward: "0.000000000000000000"
community_tax: "0.020000000000000000"
withdraw_addr_enabled: true`,
},
+2 -2
View File
@@ -172,8 +172,8 @@
"distribution": {
"params": {
"community_tax": "0.020000000000000000",
"base_proposer_reward": "0.010000000000000000",
"bonus_proposer_reward": "0.040000000000000000",
"base_proposer_reward": "0.000000000000000000",
"bonus_proposer_reward": "0.000000000000000000",
"withdraw_addr_enabled": true
},
"fee_pool": {
@@ -15,7 +15,6 @@ var (
valConsPk2 = PKS[2]
valConsAddr0 = sdk.ConsAddress(valConsPk0.Address())
valConsAddr1 = sdk.ConsAddress(valConsPk1.Address())
distrAcc = authtypes.NewEmptyModuleAccount(types.ModuleName)
)
@@ -95,8 +95,8 @@ func (suite *KeeperTestSuite) TestGRPCParams() {
func() {
params = types.Params{
CommunityTax: sdk.NewDecWithPrec(3, 1),
BaseProposerReward: sdk.NewDecWithPrec(2, 1),
BonusProposerReward: sdk.NewDecWithPrec(1, 1),
BaseProposerReward: sdk.ZeroDec(),
BonusProposerReward: sdk.ZeroDec(),
WithdrawAddrEnabled: true,
}
@@ -117,7 +117,7 @@ func (suite *KeeperTestSuite) TestGRPCParams() {
if testCase.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(paramsRes)
suite.Require().Equal(paramsRes.Params, expParams)
suite.Require().Equal(expParams, paramsRes.Params)
} else {
suite.Require().Error(err)
}
@@ -12,9 +12,7 @@ import (
func (s *KeeperTestSuite) TestMsgUpdateParams() {
// default params
communityTax := sdk.NewDecWithPrec(2, 2) // 2%
baseProposerReward := sdk.NewDecWithPrec(1, 2) // 1%
bonusProposerReward := sdk.NewDecWithPrec(4, 2) // 4%
communityTax := sdk.NewDecWithPrec(2, 2) // 2%
withdrawAddrEnabled := true
testCases := []struct {
@@ -29,9 +27,9 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() {
Authority: "invalid",
Params: types.Params{
CommunityTax: sdk.NewDecWithPrec(2, 0),
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawAddrEnabled,
BaseProposerReward: sdk.ZeroDec(),
BonusProposerReward: sdk.ZeroDec(),
},
},
expErr: true,
@@ -43,9 +41,9 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() {
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: sdk.NewDecWithPrec(2, 0),
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawAddrEnabled,
BaseProposerReward: sdk.ZeroDec(),
BonusProposerReward: sdk.ZeroDec(),
},
},
expErr: true,
@@ -57,69 +55,41 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() {
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: sdk.NewDecWithPrec(-2, 1),
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawAddrEnabled,
BaseProposerReward: sdk.ZeroDec(),
BonusProposerReward: sdk.ZeroDec(),
},
},
expErr: true,
expErrMsg: "community tax should be non-negative and less than one",
},
{
name: "base proposer reward > 1",
name: "base proposer reward set",
input: &types.MsgUpdateParams{
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: communityTax,
BaseProposerReward: sdk.NewDecWithPrec(2, 0),
BonusProposerReward: bonusProposerReward,
BaseProposerReward: sdk.NewDecWithPrec(1, 2),
BonusProposerReward: sdk.ZeroDec(),
WithdrawAddrEnabled: withdrawAddrEnabled,
},
},
expErr: true,
expErrMsg: "sum of base, bonus proposer rewards, and community tax cannot be greater than one",
expErrMsg: "cannot update base or bonus proposer reward because these are deprecated fields: invalid request",
},
{
name: "negative base proposer reward",
name: "bonus proposer reward set",
input: &types.MsgUpdateParams{
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: communityTax,
BaseProposerReward: sdk.NewDecWithPrec(-2, 0),
BonusProposerReward: bonusProposerReward,
BaseProposerReward: sdk.ZeroDec(),
BonusProposerReward: sdk.NewDecWithPrec(1, 2),
WithdrawAddrEnabled: withdrawAddrEnabled,
},
},
expErr: true,
expErrMsg: "base proposer reward should be positive",
},
{
name: "bonus proposer reward > 1",
input: &types.MsgUpdateParams{
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: communityTax,
BaseProposerReward: baseProposerReward,
BonusProposerReward: sdk.NewDecWithPrec(2, 0),
WithdrawAddrEnabled: withdrawAddrEnabled,
},
},
expErr: true,
expErrMsg: "sum of base, bonus proposer rewards, and community tax cannot be greater than one",
},
{
name: "negative bonus proposer reward",
input: &types.MsgUpdateParams{
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: communityTax,
BaseProposerReward: baseProposerReward,
BonusProposerReward: sdk.NewDecWithPrec(-2, 0),
WithdrawAddrEnabled: withdrawAddrEnabled,
},
},
expErr: true,
expErrMsg: "bonus proposer reward should be positive",
expErrMsg: "cannot update base or bonus proposer reward because these are deprecated fields: invalid request",
},
{
name: "all good",
@@ -127,8 +97,8 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() {
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: communityTax,
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
BaseProposerReward: sdk.ZeroDec(),
BonusProposerReward: sdk.ZeroDec(),
WithdrawAddrEnabled: withdrawAddrEnabled,
},
},
@@ -1,117 +0,0 @@
package keeper_test
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)
func (s *KeeperTestSuite) TestParams() {
// default params
communityTax := sdk.NewDecWithPrec(2, 2) // 2%
baseProposerReward := sdk.NewDecWithPrec(1, 2) // 1%
bonusProposerReward := sdk.NewDecWithPrec(4, 2) // 4%
withdrawAddrEnabled := true
testCases := []struct {
name string
input types.Params
expErr bool
expErrMsg string
}{
{
name: "community tax > 1",
input: types.Params{
CommunityTax: sdk.NewDecWithPrec(2, 0),
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawAddrEnabled,
},
expErr: true,
expErrMsg: "community tax should be non-negative and less than one",
},
{
name: "negative community tax",
input: types.Params{
CommunityTax: sdk.NewDecWithPrec(-2, 1),
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawAddrEnabled,
},
expErr: true,
expErrMsg: "community tax should be non-negative and less than one",
},
{
name: "base proposer reward > 1",
input: types.Params{
CommunityTax: communityTax,
BaseProposerReward: sdk.NewDecWithPrec(2, 0),
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawAddrEnabled,
},
expErr: true,
expErrMsg: "sum of base, bonus proposer rewards, and community tax cannot be greater than one",
},
{
name: "negative base proposer reward",
input: types.Params{
CommunityTax: communityTax,
BaseProposerReward: sdk.NewDecWithPrec(-2, 0),
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawAddrEnabled,
},
expErr: true,
expErrMsg: "base proposer reward should be positive",
},
{
name: "bonus proposer reward > 1",
input: types.Params{
CommunityTax: communityTax,
BaseProposerReward: baseProposerReward,
BonusProposerReward: sdk.NewDecWithPrec(2, 0),
WithdrawAddrEnabled: withdrawAddrEnabled,
},
expErr: true,
expErrMsg: "sum of base, bonus proposer rewards, and community tax cannot be greater than one",
},
{
name: "negative bonus proposer reward",
input: types.Params{
CommunityTax: communityTax,
BaseProposerReward: baseProposerReward,
BonusProposerReward: sdk.NewDecWithPrec(-2, 0),
WithdrawAddrEnabled: withdrawAddrEnabled,
},
expErr: true,
expErrMsg: "bonus proposer reward should be positive",
},
{
name: "all good",
input: types.Params{
CommunityTax: communityTax,
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawAddrEnabled,
},
expErr: false,
},
}
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
expected := s.distrKeeper.GetParams(s.ctx)
err := s.distrKeeper.SetParams(s.ctx, tc.input)
if tc.expErr {
s.Require().Error(err)
s.Require().Contains(err.Error(), tc.expErrMsg)
} else {
expected = tc.input
s.Require().NoError(err)
}
params := s.distrKeeper.GetParams(s.ctx)
s.Require().Equal(expected, params)
})
}
}