From 78ba8cdb72eaa41ecdf28cd5c7861ba1f0bc0cd2 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 3 Jun 2021 13:50:32 +0200 Subject: [PATCH 1/6] add amino for authz --- x/authz/client/testutil/tx.go | 60 +++++++++++++++++++++++++++++++++++ x/authz/msgs.go | 52 ++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/x/authz/client/testutil/tx.go b/x/authz/client/testutil/tx.go index 91f1275f4a15..28d8a9c309f2 100644 --- a/x/authz/client/testutil/tx.go +++ b/x/authz/client/testutil/tx.go @@ -79,6 +79,7 @@ func (s *IntegrationTestSuite) TearDownSuite() { var typeMsgSend = bank.SendAuthorization{}.MsgTypeURL() var typeMsgVote = sdk.MsgTypeURL(&govtypes.MsgVote{}) +var typeMsgSubmitProposal = sdk.MsgTypeURL(&govtypes.MsgSubmitProposal{}) func (s *IntegrationTestSuite) TestCLITxGrantAuthorization() { val := s.network.Validators[0] @@ -258,6 +259,22 @@ func (s *IntegrationTestSuite) TestCLITxGrantAuthorization() { 0, false, }, + { + "Valid tx with amino", + []string{ + grantee.String(), + "generic", + fmt.Sprintf("--%s=%s", cli.FlagMsgType, typeMsgVote), + fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%d", cli.FlagExpiration, twoHours), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON), + }, + 0, + false, + }, } for _, tc := range testCases { @@ -324,6 +341,22 @@ func (s *IntegrationTestSuite) TestCmdRevokeAuthorizations() { ) s.Require().NoError(err) + // generic-authorization used for amino testing + _, err = ExecGrant( + val, + []string{ + grantee.String(), + "generic", + fmt.Sprintf("--%s=%s", cli.FlagMsgType, typeMsgSubmitProposal), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%d", cli.FlagExpiration, twoHours), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + }, + ) + s.Require().NoError(err) + testCases := []struct { name string args []string @@ -381,6 +414,20 @@ func (s *IntegrationTestSuite) TestCmdRevokeAuthorizations() { &sdk.TxResponse{}, 0, false, }, + { + "Valid tx with amino", + []string{ + grantee.String(), + typeMsgSubmitProposal, + fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON), + }, + &sdk.TxResponse{}, 0, + false, + }, } for _, tc := range testCases { tc := tc @@ -509,6 +556,19 @@ func (s *IntegrationTestSuite) TestNewExecGenericAuthorized() { 0, false, }, + { + "valid tx with amino", + []string{ + execMsg.Name(), + fmt.Sprintf("--%s=%s", flags.FlagFrom, grantee.String()), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON), + }, + &sdk.TxResponse{}, 0, + false, + }, } for _, tc := range testCases { diff --git a/x/authz/msgs.go b/x/authz/msgs.go index dd6bc8b19deb..3bf2a9563f32 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -5,9 +5,11 @@ import ( "github.com/gogo/protobuf/proto" + "github.com/cosmos/cosmos-sdk/codec/legacy" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx" ) var ( @@ -15,6 +17,11 @@ var ( _ sdk.Msg = &MsgRevoke{} _ sdk.Msg = &MsgExec{} + // For amino support. + _ legacytx.LegacyMsg = &MsgGrant{} + _ legacytx.LegacyMsg = &MsgRevoke{} + _ legacytx.LegacyMsg = &MsgExec{} + _ cdctypes.UnpackInterfacesMessage = &MsgGrant{} _ cdctypes.UnpackInterfacesMessage = &MsgExec{} ) @@ -60,6 +67,21 @@ func (msg MsgGrant) ValidateBasic() error { return msg.Grant.ValidateBasic() } +// Type implements the LegacyMsg.Type method. +func (msg MsgGrant) Type() string { + return sdk.MsgTypeURL(&msg) +} + +// Route implements the LegacyMsg.Type method. +func (msg MsgGrant) Route() string { + return sdk.MsgTypeURL(&msg) +} + +// Route implements the LegacyMsg.Type method. +func (msg MsgGrant) GetSignBytes() []byte { + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) +} + // GetAuthorization returns the cache value from the MsgGrant.Authorization if present. func (msg *MsgGrant) GetAuthorization() Authorization { return msg.Grant.GetAuthorization() @@ -138,6 +160,21 @@ func (msg MsgRevoke) ValidateBasic() error { return nil } +// Type implements the LegacyMsg.Type method. +func (msg MsgRevoke) Type() string { + return sdk.MsgTypeURL(&msg) +} + +// Route implements the LegacyMsg.Type method. +func (msg MsgRevoke) Route() string { + return sdk.MsgTypeURL(&msg) +} + +// Route implements the LegacyMsg.Type method. +func (msg MsgRevoke) GetSignBytes() []byte { + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) +} + // NewMsgExec creates a new MsgExecAuthorized //nolint:interfacer func NewMsgExec(grantee sdk.AccAddress, msgs []sdk.Msg) MsgExec { @@ -193,3 +230,18 @@ func (msg MsgExec) ValidateBasic() error { return nil } + +// Type implements the LegacyMsg.Type method. +func (msg MsgExec) Type() string { + return sdk.MsgTypeURL(&msg) +} + +// Route implements the LegacyMsg.Type method. +func (msg MsgExec) Route() string { + return sdk.MsgTypeURL(&msg) +} + +// Route implements the LegacyMsg.Type method. +func (msg MsgExec) GetSignBytes() []byte { + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) +} From 7f77a92fe1bbfac8257b73bb41a7281f632f2412 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 3 Jun 2021 14:08:30 +0200 Subject: [PATCH 2/6] Add amion for feegrant --- x/feegrant/client/testutil/suite.go | 60 +++++++++++++++++++++++------ x/feegrant/msgs.go | 38 +++++++++++++++++- 2 files changed, 85 insertions(+), 13 deletions(-) diff --git a/x/feegrant/client/testutil/suite.go b/x/feegrant/client/testutil/suite.go index 013a44286334..90dc13307f6a 100644 --- a/x/feegrant/client/testutil/suite.go +++ b/x/feegrant/client/testutil/suite.go @@ -59,6 +59,22 @@ func (s *IntegrationTestSuite) SetupSuite() { granter := val.Address grantee := s.network.Validators[1].Address + s.createGrant(granter, grantee) + + grant, err := feegrant.NewGrant(granter, grantee, &feegrant.BasicAllowance{ + SpendLimit: sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))), + }) + s.Require().NoError(err) + + s.addedGrant = grant + s.addedGranter = granter + s.addedGrantee = grantee +} + +// createGrant creates a new basic allowance fee grant from granter to grantee. +func (s *IntegrationTestSuite) createGrant(granter, grantee sdk.Address) { + val := s.network.Validators[0] + clientCtx := val.ClientCtx commonFlags := []string{ fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), @@ -81,20 +97,10 @@ func (s *IntegrationTestSuite) SetupSuite() { cmd := cli.NewCmdFeeGrant() - _, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) + _, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) s.Require().NoError(err) _, err = s.network.WaitForHeight(1) s.Require().NoError(err) - - s.addedGranter = granter - s.addedGrantee = grantee - - grant, err := feegrant.NewGrant(granter, grantee, &feegrant.BasicAllowance{ - SpendLimit: sdk.NewCoins(fee), - }) - s.Require().NoError(err) - - s.addedGrant = grant } func (s *IntegrationTestSuite) TearDownSuite() { @@ -302,6 +308,20 @@ func (s *IntegrationTestSuite) TestNewCmdFeeGrant() { ), false, 0, &sdk.TxResponse{}, }, + { + "valid basic fee grant with amino", + append( + []string{ + granter.String(), + "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h", + fmt.Sprintf("--%s=%s", cli.FlagSpendLimit, "100stake"), + fmt.Sprintf("--%s=%s", flags.FlagFrom, granter), + fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON), + }, + commonFlags..., + ), + false, 0, &sdk.TxResponse{}, + }, { "valid basic fee grant without spend limit", append( @@ -507,6 +527,11 @@ func (s *IntegrationTestSuite) TestNewCmdRevokeFeegrant() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), } + // Create new fee grant specifically to test amino. + aminoGrantee, err := sdk.AccAddressFromBech32("cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00") + s.Require().NoError(err) + s.createGrant(granter, aminoGrantee) + testCases := []struct { name string args []string @@ -562,6 +587,19 @@ func (s *IntegrationTestSuite) TestNewCmdRevokeFeegrant() { ), false, 0, &sdk.TxResponse{}, }, + { + "Valid revoke with amino", + append( + []string{ + granter.String(), + aminoGrantee.String(), + fmt.Sprintf("--%s=%s", flags.FlagFrom, granter), + fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON), + }, + commonFlags..., + ), + false, 0, &sdk.TxResponse{}, + }, } for _, tc := range testCases { diff --git a/x/feegrant/msgs.go b/x/feegrant/msgs.go index 3731668a91a5..272b4fa41c28 100644 --- a/x/feegrant/msgs.go +++ b/x/feegrant/msgs.go @@ -3,14 +3,18 @@ package feegrant import ( "github.com/gogo/protobuf/proto" + "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx" ) var ( - _, _ sdk.Msg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} - _ types.UnpackInterfacesMessage = &MsgGrantAllowance{} + _, _ sdk.Msg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} + _, _ legacytx.LegacyMsg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} // For amino support. + + _ types.UnpackInterfacesMessage = &MsgGrantAllowance{} ) // NewMsgGrantAllowance creates a new MsgGrantAllowance. @@ -61,6 +65,21 @@ func (msg MsgGrantAllowance) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{granter} } +// Type implements the LegacyMsg.Type method. +func (msg MsgGrantAllowance) Type() string { + return sdk.MsgTypeURL(&msg) +} + +// Route implements the LegacyMsg.Type method. +func (msg MsgGrantAllowance) Route() string { + return sdk.MsgTypeURL(&msg) +} + +// Route implements the LegacyMsg.Type method. +func (msg MsgGrantAllowance) GetSignBytes() []byte { + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) +} + // GetFeeAllowanceI returns unpacked FeeAllowance func (msg MsgGrantAllowance) GetFeeAllowanceI() (FeeAllowanceI, error) { allowance, ok := msg.Allowance.GetCachedValue().(FeeAllowanceI) @@ -108,3 +127,18 @@ func (msg MsgRevokeAllowance) GetSigners() []sdk.AccAddress { } return []sdk.AccAddress{granter} } + +// Type implements the LegacyMsg.Type method. +func (msg MsgRevokeAllowance) Type() string { + return sdk.MsgTypeURL(&msg) +} + +// Route implements the LegacyMsg.Type method. +func (msg MsgRevokeAllowance) Route() string { + return sdk.MsgTypeURL(&msg) +} + +// Route implements the LegacyMsg.Type method. +func (msg MsgRevokeAllowance) GetSignBytes() []byte { + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) +} From 429bcff026fc412303172e3469c2332958d2947a Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 3 Jun 2021 14:36:25 +0200 Subject: [PATCH 3/6] add cl --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe9eee18f626..19cccad5a2ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ if input key is empty, or input data contains empty key. * [\#9133](https://github.com/cosmos/cosmos-sdk/pull/9133) Added hooks for governance actions. * (x/staking) [\#9214](https://github.com/cosmos/cosmos-sdk/pull/9214) Added `new_shares` attribute inside `EventTypeDelegate` event. * [\#9382](https://github.com/cosmos/cosmos-sdk/pull/9382) feat: add Dec.Float64() function. +* [\#9457](https://github.com/cosmos/cosmos-sdk/pull/9457) Add amino support for x/authz and x/feegrant Msgs. ### Client Breaking Changes From 6126087286524cdd40eff925729931d1e74ae8d0 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 3 Jun 2021 18:00:37 +0200 Subject: [PATCH 4/6] Remove protoCdc from simulations --- x/authz/module/module.go | 3 +-- x/authz/simulation/operations.go | 21 ++++++++++----------- x/authz/simulation/operations_test.go | 15 ++++++--------- x/feegrant/module/module.go | 3 +-- x/feegrant/simulation/operations.go | 13 ++++++------- x/feegrant/simulation/operations_test.go | 12 ++++-------- 6 files changed, 28 insertions(+), 39 deletions(-) diff --git a/x/authz/module/module.go b/x/authz/module/module.go index e3235a723f15..211b814aa6d7 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -187,9 +187,8 @@ func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { // WeightedOperations returns the all the gov module operations with their respective weights. func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { - protoCdc := codec.NewProtoCodec(am.registry) return simulation.WeightedOperations( simState.AppParams, simState.Cdc, - am.accountKeeper, am.bankKeeper, am.keeper, am.cdc, protoCdc, + am.accountKeeper, am.bankKeeper, am.keeper, am.cdc, ) } diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index f25bf56ad949..b2a5f20d4d90 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -45,7 +45,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( - appParams simtypes.AppParams, cdc codec.JSONCodec, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, appCdc cdctypes.AnyUnpacker, protoCdc *codec.ProtoCodec) simulation.WeightedOperations { + appParams simtypes.AppParams, cdc codec.JSONCodec, ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, appCdc cdctypes.AnyUnpacker) simulation.WeightedOperations { var ( weightMsgGrant int @@ -74,22 +74,21 @@ func WeightedOperations( return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgGrant, - SimulateMsgGrant(ak, bk, k, protoCdc), + SimulateMsgGrant(ak, bk, k), ), simulation.NewWeightedOperation( weightRevoke, - SimulateMsgRevoke(ak, bk, k, protoCdc), + SimulateMsgRevoke(ak, bk, k), ), simulation.NewWeightedOperation( weightExec, - SimulateMsgExec(ak, bk, k, appCdc, protoCdc), + SimulateMsgExec(ak, bk, k, appCdc), ), } } // SimulateMsgGrant generates a MsgGrant with random values. -func SimulateMsgGrant(ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keeper, - protoCdc *codec.ProtoCodec) simtypes.Operation { +func SimulateMsgGrant(ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -136,7 +135,7 @@ func SimulateMsgGrant(ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keep if err != nil { return simtypes.NoOpMsg(authz.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, "", protoCdc), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -149,7 +148,7 @@ func generateRandomAuthorization(r *rand.Rand, spendLimit sdk.Coins) authz.Autho } // SimulateMsgRevoke generates a MsgRevoke with random values. -func SimulateMsgRevoke(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation { +func SimulateMsgRevoke(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -203,12 +202,12 @@ func SimulateMsgRevoke(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Kee return simtypes.NoOpMsg(authz.ModuleName, TypeMsgRevoke, "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", protoCdc), nil, nil + return simtypes.NewOperationMsg(&msg, true, "", nil), nil, nil } } // SimulateMsgExec generates a MsgExec with random values. -func SimulateMsgExec(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, cdc cdctypes.AnyUnpacker, protoCdc *codec.ProtoCodec) simtypes.Operation { +func SimulateMsgExec(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keeper, cdc cdctypes.AnyUnpacker) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -293,6 +292,6 @@ func SimulateMsgExec(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keepe if err != nil { return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, "unmarshal error"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "success", protoCdc), nil, nil + return simtypes.NewOperationMsg(&msg, true, "success", nil), nil, nil } } diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 8d87fd37c147..9e36abc9512d 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -10,7 +10,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -22,9 +21,8 @@ import ( type SimTestSuite struct { suite.Suite - ctx sdk.Context - app *simapp.SimApp - protoCdc *codec.ProtoCodec + ctx sdk.Context + app *simapp.SimApp } func (suite *SimTestSuite) SetupTest() { @@ -32,7 +30,6 @@ func (suite *SimTestSuite) SetupTest() { app := simapp.Setup(checkTx) suite.app = app suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) - suite.protoCdc = codec.NewProtoCodec(suite.app.InterfaceRegistry()) } func (suite *SimTestSuite) TestWeightedOperations() { @@ -40,7 +37,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { appParams := make(simtypes.AppParams) weightesOps := simulation.WeightedOperations(appParams, cdc, suite.app.AccountKeeper, - suite.app.BankKeeper, suite.app.AuthzKeeper, cdc, suite.protoCdc, + suite.app.BankKeeper, suite.app.AuthzKeeper, cdc, ) // setup 3 accounts @@ -104,7 +101,7 @@ func (suite *SimTestSuite) TestSimulateGrant() { grantee := accounts[1] // execute operation - op := simulation.SimulateMsgGrant(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.AuthzKeeper, suite.protoCdc) + op := simulation.SimulateMsgGrant(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.AuthzKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, ctx, accounts, "") suite.Require().NoError(err) @@ -141,7 +138,7 @@ func (suite *SimTestSuite) TestSimulateRevoke() { suite.Require().NoError(err) // execute operation - op := simulation.SimulateMsgRevoke(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.AuthzKeeper, suite.protoCdc) + op := simulation.SimulateMsgRevoke(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.AuthzKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) @@ -176,7 +173,7 @@ func (suite *SimTestSuite) TestSimulateExec() { suite.Require().NoError(err) // execute operation - op := simulation.SimulateMsgExec(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.AuthzKeeper, suite.app.AppCodec(), suite.protoCdc) + op := simulation.SimulateMsgExec(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.AuthzKeeper, suite.app.AppCodec()) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 4690aea250ef..c9a7555506ad 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -207,8 +207,7 @@ func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { // WeightedOperations returns all the feegrant module operations with their respective weights. func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { - protoCdc := codec.NewProtoCodec(am.registry) return simulation.WeightedOperations( - simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, am.keeper, protoCdc, + simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, am.keeper, ) } diff --git a/x/feegrant/simulation/operations.go b/x/feegrant/simulation/operations.go index 6a8606271076..095830215d5d 100644 --- a/x/feegrant/simulation/operations.go +++ b/x/feegrant/simulation/operations.go @@ -28,7 +28,6 @@ var ( func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONCodec, ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper, - protoCdc *codec.ProtoCodec, ) simulation.WeightedOperations { var ( @@ -51,17 +50,17 @@ func WeightedOperations( return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgGrantAllowance, - SimulateMsgGrantAllowance(ak, bk, k, protoCdc), + SimulateMsgGrantAllowance(ak, bk, k), ), simulation.NewWeightedOperation( weightMsgRevokeAllowance, - SimulateMsgRevokeAllowance(ak, bk, k, protoCdc), + SimulateMsgRevokeAllowance(ak, bk, k), ), } } // SimulateMsgGrantAllowance generates MsgGrantAllowance with random values. -func SimulateMsgGrantAllowance(ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation { +func SimulateMsgGrantAllowance(ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -118,12 +117,12 @@ func SimulateMsgGrantAllowance(ak feegrant.AccountKeeper, bk feegrant.BankKeeper if err != nil { return simtypes.NoOpMsg(feegrant.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, "", protoCdc), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } // SimulateMsgRevokeAllowance generates a MsgRevokeAllowance with random values. -func SimulateMsgRevokeAllowance(ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper, protoCdc *codec.ProtoCodec) simtypes.Operation { +func SimulateMsgRevokeAllowance(ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -182,6 +181,6 @@ func SimulateMsgRevokeAllowance(ak feegrant.AccountKeeper, bk feegrant.BankKeepe } _, _, err = app.Deliver(txGen.TxEncoder(), tx) - return simtypes.NewOperationMsg(&msg, true, "", protoCdc), nil, err + return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err } } diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index 86b21d802333..8101480a0d05 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -10,7 +10,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" @@ -22,9 +21,8 @@ import ( type SimTestSuite struct { suite.Suite - ctx sdk.Context - app *simapp.SimApp - protoCdc *codec.ProtoCodec + ctx sdk.Context + app *simapp.SimApp } func (suite *SimTestSuite) SetupTest() { @@ -34,7 +32,6 @@ func (suite *SimTestSuite) SetupTest() { suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{ Time: time.Now(), }) - suite.protoCdc = codec.NewProtoCodec(suite.app.InterfaceRegistry()) } @@ -65,7 +62,6 @@ func (suite *SimTestSuite) TestWeightedOperations() { weightesOps := simulation.WeightedOperations( appParams, cdc, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, - suite.protoCdc, ) s := rand.NewSource(1) @@ -112,7 +108,7 @@ func (suite *SimTestSuite) TestSimulateMsgGrantAllowance() { app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash}}) // execute operation - op := simulation.SimulateMsgGrantAllowance(app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, suite.protoCdc) + op := simulation.SimulateMsgGrantAllowance(app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper) operationMsg, futureOperations, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(err) @@ -154,7 +150,7 @@ func (suite *SimTestSuite) TestSimulateMsgRevokeAllowance() { require.NoError(err) // execute operation - op := simulation.SimulateMsgRevokeAllowance(app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, suite.protoCdc) + op := simulation.SimulateMsgRevokeAllowance(app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper) operationMsg, futureOperations, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(err) From 4c18379a693b11730d1b650e57aa8db2081e4d99 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Fri, 4 Jun 2021 09:04:11 +0200 Subject: [PATCH 5/6] Update x/authz/client/testutil/tx.go Co-authored-by: likhita-809 <78951027+likhita-809@users.noreply.github.com> --- x/authz/client/testutil/tx.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/authz/client/testutil/tx.go b/x/authz/client/testutil/tx.go index 28d8a9c309f2..66c077ad688f 100644 --- a/x/authz/client/testutil/tx.go +++ b/x/authz/client/testutil/tx.go @@ -353,6 +353,7 @@ func (s *IntegrationTestSuite) TestCmdRevokeAuthorizations() { fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), fmt.Sprintf("--%s=%d", cli.FlagExpiration, twoHours), fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON), }, ) s.Require().NoError(err) From 148135e33c229cfc685c94e59f59e45532fd75be Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Fri, 4 Jun 2021 09:05:06 +0200 Subject: [PATCH 6/6] Address reviews --- x/authz/msgs.go | 12 ++++++------ x/authz/simulation/operations_test.go | 4 ++-- x/feegrant/msgs.go | 8 ++++---- x/feegrant/simulation/operations_test.go | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/x/authz/msgs.go b/x/authz/msgs.go index 3bf2a9563f32..e8ecde0553b4 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -72,12 +72,12 @@ func (msg MsgGrant) Type() string { return sdk.MsgTypeURL(&msg) } -// Route implements the LegacyMsg.Type method. +// Route implements the LegacyMsg.Route method. func (msg MsgGrant) Route() string { return sdk.MsgTypeURL(&msg) } -// Route implements the LegacyMsg.Type method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgGrant) GetSignBytes() []byte { return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) } @@ -165,12 +165,12 @@ func (msg MsgRevoke) Type() string { return sdk.MsgTypeURL(&msg) } -// Route implements the LegacyMsg.Type method. +// Route implements the LegacyMsg.Route method. func (msg MsgRevoke) Route() string { return sdk.MsgTypeURL(&msg) } -// Route implements the LegacyMsg.Type method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgRevoke) GetSignBytes() []byte { return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) } @@ -236,12 +236,12 @@ func (msg MsgExec) Type() string { return sdk.MsgTypeURL(&msg) } -// Route implements the LegacyMsg.Type method. +// Route implements the LegacyMsg.Route method. func (msg MsgExec) Route() string { return sdk.MsgTypeURL(&msg) } -// Route implements the LegacyMsg.Type method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgExec) GetSignBytes() []byte { return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) } diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 9e36abc9512d..bdb7f98f82db 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -36,7 +36,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { cdc := suite.app.AppCodec() appParams := make(simtypes.AppParams) - weightesOps := simulation.WeightedOperations(appParams, cdc, suite.app.AccountKeeper, + weightedOps := simulation.WeightedOperations(appParams, cdc, suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.AuthzKeeper, cdc, ) @@ -55,7 +55,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { {simulation.WeightExec, authz.ModuleName, simulation.TypeMsgExec}, } - for i, w := range weightesOps { + for i, w := range weightedOps { operationMsg, _, _ := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests diff --git a/x/feegrant/msgs.go b/x/feegrant/msgs.go index 272b4fa41c28..63c29eb4eaeb 100644 --- a/x/feegrant/msgs.go +++ b/x/feegrant/msgs.go @@ -70,12 +70,12 @@ func (msg MsgGrantAllowance) Type() string { return sdk.MsgTypeURL(&msg) } -// Route implements the LegacyMsg.Type method. +// Route implements the LegacyMsg.Route method. func (msg MsgGrantAllowance) Route() string { return sdk.MsgTypeURL(&msg) } -// Route implements the LegacyMsg.Type method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgGrantAllowance) GetSignBytes() []byte { return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) } @@ -133,12 +133,12 @@ func (msg MsgRevokeAllowance) Type() string { return sdk.MsgTypeURL(&msg) } -// Route implements the LegacyMsg.Type method. +// Route implements the LegacyMsg.Route method. func (msg MsgRevokeAllowance) Route() string { return sdk.MsgTypeURL(&msg) } -// Route implements the LegacyMsg.Type method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgRevokeAllowance) GetSignBytes() []byte { return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&msg)) } diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index 8101480a0d05..4d7671f77287 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -59,7 +59,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { cdc := app.AppCodec() appParams := make(simtypes.AppParams) - weightesOps := simulation.WeightedOperations( + weightedOps := simulation.WeightedOperations( appParams, cdc, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, ) @@ -85,7 +85,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { }, } - for i, w := range weightesOps { + for i, w := range weightedOps { operationMsg, _, _ := w.Op()(r, app.BaseApp, ctx, accs, ctx.ChainID()) // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests