Skip to content

Commit

Permalink
test: Add authority check for proposal execution
Browse files Browse the repository at this point in the history
  • Loading branch information
dudong2 committed Jul 8, 2024
1 parent 5c91ae9 commit 16f9957
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 16 deletions.
2 changes: 1 addition & 1 deletion x/erc20/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <denom_or_contract> --from=<key_or_address>", version.AppName),
Example: fmt.Sprintf("$ %s tx gov submit-proposal toggle-token-conversion <denom_or_contract>", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand Down
98 changes: 83 additions & 15 deletions x/erc20/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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),
Expand All @@ -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,
},
}

Expand All @@ -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)
}
})
}
}

0 comments on commit 16f9957

Please sign in to comment.