Skip to content

Commit

Permalink
Merge PR: modify-new- proposal (#2986)
Browse files Browse the repository at this point in the history
* update

* update

---------

Co-authored-by: KamiD <[email protected]>
  • Loading branch information
zjg555543 and KamiD authored Mar 1, 2023
1 parent bb1f68e commit 6f892cd
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/x/mint/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Where proposal.json contains:
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().WithCodec(cdc)

proposal, err := utils2.ParseParseModifyNextBlockUpdateProposalJSON(cdc, args[0])
proposal, err := utils2.ParseModifyNextBlockUpdateProposalJSON(cdc, args[0])
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/x/mint/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ModifyNextBlockUpdateProposalJSON struct {
}

// ParseModifyNextBlockUpdateProposalJSON parses json from proposal file to ModifyNextBlockUpdateProposalJSON struct
func ParseParseModifyNextBlockUpdateProposalJSON(cdc *codec.Codec, proposalFilePath string) (
func ParseModifyNextBlockUpdateProposalJSON(cdc *codec.Codec, proposalFilePath string) (
proposal ModifyNextBlockUpdateProposalJSON, err error) {
contents, err := ioutil.ReadFile(proposalFilePath)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions libs/cosmos-sdk/x/mint/internal/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
ErrProposerMustBeValidator = sdkerrors.Register(ModuleName, 5, "the proposal of proposer must be validator")
ErrNotReachedVenus5Height = sdkerrors.Register(ModuleName, 6, "venus5 block height has not been reached")
ErrNextBlockUpdateTooLate = sdkerrors.Register(ModuleName, 7, "the next block to update is too late")
ErrCodeInvalidHeight = sdkerrors.Register(ModuleName, 8, "height must be greater than current block")
)

// ErrTreasuresInternal returns an error when the length of address list in the proposal is larger than the max limitation
Expand Down
4 changes: 4 additions & 0 deletions libs/cosmos-sdk/x/mint/internal/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func (mp ModifyNextBlockUpdateProposal) ValidateBasic() sdk.Error {
return govtypes.ErrInvalidProposalType(mp.ProposalType())
}

if global.GetGlobalHeight() > 0 && mp.BlockNum <= uint64(global.GetGlobalHeight()) {
return ErrCodeInvalidHeight
}

return nil
}

Expand Down
50 changes: 42 additions & 8 deletions libs/cosmos-sdk/x/mint/internal/types/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,76 @@ func (suite *ProposalSuite) TestNewChangeDistributionTypeProposal() {
}{
{
"no proposal title",
func() {},
func() {
global.SetGlobalHeight(0)
tmtypes.UnittestOnlySetMilestoneVenus5Height(0)
},
"",
"description",
0,
exgovtypes.ErrInvalidProposalContent("title is required"),
},
{
"gt max proposal title length",
func() {},
func() {
global.SetGlobalHeight(0)
tmtypes.UnittestOnlySetMilestoneVenus5Height(0)
},
RandStr(types.MaxTitleLength + 1),
"description",
0,
exgovtypes.ErrInvalidProposalContent("title length is bigger than max title length"),
},
{
"gt max proposal title length",
func() {},
func() {
global.SetGlobalHeight(0)
tmtypes.UnittestOnlySetMilestoneVenus5Height(0)
},
RandStr(types.MaxTitleLength),
"",
0,
exgovtypes.ErrInvalidProposalContent("description is required"),
},
{
"gt max proposal description length",
func() {},
func() {
global.SetGlobalHeight(0)
tmtypes.UnittestOnlySetMilestoneVenus5Height(0)
},
RandStr(types.MaxTitleLength),
RandStr(types.MaxDescriptionLength + 1),
0,
exgovtypes.ErrInvalidProposalContent("description length is bigger than max description length"),
},
{
"invalid height",
func() {
global.SetGlobalHeight(100)
tmtypes.UnittestOnlySetMilestoneVenus5Height(-1)
},
RandStr(types.MaxTitleLength),
RandStr(types.MaxDescriptionLength),
100,
ErrCodeInvalidHeight,
},
{
"valid height",
func() {
global.SetGlobalHeight(100)
tmtypes.UnittestOnlySetMilestoneVenus5Height(-1)
},
RandStr(types.MaxTitleLength),
RandStr(types.MaxDescriptionLength),
101,
nil,
},
{
"ok",
func() {},
func() {
global.SetGlobalHeight(0)
tmtypes.UnittestOnlySetMilestoneVenus5Height(0)
},
RandStr(types.MaxTitleLength),
RandStr(types.MaxDescriptionLength),
0,
Expand All @@ -84,9 +121,6 @@ func (suite *ProposalSuite) TestNewChangeDistributionTypeProposal() {
}

for _, tc := range testCases {
global.SetGlobalHeight(0)
tmtypes.UnittestOnlySetMilestoneVenus2Height(0)

suite.Run(tc.title, func() {
tc.setMilestoneHeight()
title := tc.proposalTitle
Expand Down
8 changes: 4 additions & 4 deletions libs/cosmos-sdk/x/mint/proposal_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,12 @@ func (suite *MintTestSuite) TestModifyNextBlockUpdateProposal() {
proposal.BlockNum = tc.blockNum
govProposal.Content = proposal

oldMinter := suite.app.MintKeeper.GetMinterCustom(suite.ctx)
err := suite.govHandler(suite.ctx, &govProposal)
suite.Require().Equal(err, tc.expectError)
if err != nil {
minter := suite.app.MintKeeper.GetMinterCustom(suite.ctx)
suite.Require().Equal(tc.expectBlockNum, minter.NextBlockToUpdate)
}
newMinter := suite.app.MintKeeper.GetMinterCustom(suite.ctx)
suite.Require().Equal(tc.expectBlockNum, newMinter.NextBlockToUpdate)
suite.app.MintKeeper.SetMinterCustom(suite.ctx, oldMinter)
})
}
}

0 comments on commit 6f892cd

Please sign in to comment.