From 16f99570412fd0d3c0d4ef113bda828ad747db72 Mon Sep 17 00:00:00 2001 From: dudong2 Date: Mon, 8 Jul 2024 13:33:33 +0900 Subject: [PATCH] test: Add authority check for proposal execution --- x/erc20/client/cli/tx.go | 2 +- x/erc20/keeper/msg_server_test.go | 98 ++++++++++++++++++++++++++----- 2 files changed, 84 insertions(+), 16 deletions(-) diff --git a/x/erc20/client/cli/tx.go b/x/erc20/client/cli/tx.go index 0eb785ad..3282109d 100644 --- a/x/erc20/client/cli/tx.go +++ b/x/erc20/client/cli/tx.go @@ -303,7 +303,7 @@ func NewToggleTokenConversionProposalCmd(ac addresscodec.Codec) *cobra.Command { Args: cobra.ExactArgs(1), Short: "Submit a toggle token conversion proposal", Long: "Submit a proposal to toggle the conversion of a token pair along with an initial deposit.", - Example: fmt.Sprintf("$ %s tx gov submit-proposal toggle-token-conversion --from=", version.AppName), + Example: fmt.Sprintf("$ %s tx gov submit-proposal toggle-token-conversion ", version.AppName), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { diff --git a/x/erc20/keeper/msg_server_test.go b/x/erc20/keeper/msg_server_test.go index c23982c5..c496480a 100644 --- a/x/erc20/keeper/msg_server_test.go +++ b/x/erc20/keeper/msg_server_test.go @@ -1543,9 +1543,35 @@ func (suite *KeeperTestSuite) TestMsgExecutionByProposal() { msg sdk.Msg malleate func() checkFunc func(uint64) + expectErr bool }{ { - "ok - proposal MsgRegisterCoin", + "fail - MsgRegisterCoin - authority check", + &types.MsgRegisterCoin{ + Authority: "canto1yrmjye0zyfvr0lthc6fwq7qlwg9e8muftxa630", + Title: "MsgRegisterCoin", + Description: "MsgRegisterCoin test", + Metadata: banktypes.Metadata{ + Description: "ATOM IBC voucher (channel 14)", + Base: ibcBase, + // NOTE: Denom units MUST be increasing + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: ibcBase, + Exponent: 0, + }, + }, + Name: "ATOM channel-14", + Symbol: "ibcATOM-14", + Display: ibcBase, + }, + }, + func() {}, + func(_ uint64) {}, + true, + }, + { + "ok - MsgRegisterCoin", &types.MsgRegisterCoin{ Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), Title: "MsgRegisterCoin", @@ -1580,9 +1606,22 @@ func (suite *KeeperTestSuite) TestMsgExecutionByProposal() { suite.Require().Equal(suite.app.Erc20Keeper.GetDenomMap(suite.ctx, pair.Denom), id) suite.Require().Equal(suite.app.Erc20Keeper.GetERC20Map(suite.ctx, common.HexToAddress(pair.Erc20Address)), id) }, + false, + }, + { + "fail - MsgRegisterERC20 - authority check", + &types.MsgRegisterERC20{ + Authority: "canto1yrmjye0zyfvr0lthc6fwq7qlwg9e8muftxa630", + Title: "MsgRegisterERC20", + Description: "MsgRegisterERC20 test", + Erc20Address: erc20Address, + }, + func() {}, + func(_ uint64) {}, + true, }, { - "ok - proposal MsgRegisterERC20", + "ok - MsgRegisterERC20", &types.MsgRegisterERC20{ Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), Title: "MsgRegisterERC20", @@ -1601,9 +1640,22 @@ func (suite *KeeperTestSuite) TestMsgExecutionByProposal() { suite.Require().Equal(suite.app.Erc20Keeper.GetDenomMap(suite.ctx, pair.Denom), id) suite.Require().Equal(suite.app.Erc20Keeper.GetERC20Map(suite.ctx, common.HexToAddress(pair.Erc20Address)), id) }, + false, }, { - "ok - proposal MsgToggleTokenConversion", + "fail - MsgToggleTokenConversion - authority check", + &types.MsgToggleTokenConversion{ + Authority: "canto1yrmjye0zyfvr0lthc6fwq7qlwg9e8muftxa630", + Title: "MsgToggleTokenConversion", + Description: "MsgToggleTokenConversion test", + Token: erc20Address, + }, + func() {}, + func(_ uint64) {}, + true, + }, + { + "ok - MsgToggleTokenConversion", &types.MsgToggleTokenConversion{ Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), Title: "MsgToggleTokenConversion", @@ -1621,9 +1673,20 @@ func (suite *KeeperTestSuite) TestMsgExecutionByProposal() { suite.Require().True(ok) suite.Require().Equal(pair.Enabled, false) }, + false, + }, + { + "fail - MsgUpdateParams - authority check", + &types.MsgUpdateParams{ + Authority: "canto1yrmjye0zyfvr0lthc6fwq7qlwg9e8muftxa630", + Params: types.NewParams(false, false), + }, + func() {}, + func(proposalId uint64) {}, + true, }, { - "ok - proposal MsgUpdateParams", + "ok - MsgUpdateParams", &types.MsgUpdateParams{ Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), Params: types.NewParams(false, false), @@ -1637,6 +1700,7 @@ func (suite *KeeperTestSuite) TestMsgExecutionByProposal() { suite.Require().Equal(govtypesv1.ProposalStatus_PROPOSAL_STATUS_PASSED, proposal.Status) suite.Require().Equal(suite.app.Erc20Keeper.GetParams(suite.ctx), changeParams) }, + false, }, } @@ -1646,20 +1710,24 @@ func (suite *KeeperTestSuite) TestMsgExecutionByProposal() { // submit proposal proposal, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, []sdk.Msg{tc.msg}, "", "test", "description", proposer, false) - suite.Require().NoError(err) - suite.Commit() + if tc.expectErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Commit() - ok, err := suite.app.GovKeeper.AddDeposit(suite.ctx, proposal.Id, proposer, govParams.MinDeposit) - suite.Require().NoError(err) - suite.Require().True(ok) - suite.Commit() + ok, err := suite.app.GovKeeper.AddDeposit(suite.ctx, proposal.Id, proposer, govParams.MinDeposit) + suite.Require().NoError(err) + suite.Require().True(ok) + suite.Commit() - err = suite.app.GovKeeper.AddVote(suite.ctx, proposal.Id, proposer, govtypesv1.NewNonSplitVoteOption(govtypesv1.OptionYes), "") - suite.Require().NoError(err) - suite.CommitAfter(*govParams.VotingPeriod) + err = suite.app.GovKeeper.AddVote(suite.ctx, proposal.Id, proposer, govtypesv1.NewNonSplitVoteOption(govtypesv1.OptionYes), "") + suite.Require().NoError(err) + suite.CommitAfter(*govParams.VotingPeriod) - // check proposal result - tc.checkFunc(proposal.Id) + // check proposal result + tc.checkFunc(proposal.Id) + } }) } }