From a2f2c927967d1c93619cf1058b147e62c8bd173f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 6 Oct 2023 08:46:27 +0000 Subject: [PATCH] feat(x/crisis): add autocli options for tx (backport #17965) (#17982) Co-authored-by: Julien Robert Co-authored-by: marbar3778 --- x/crisis/autocli.go | 15 ++++-- x/crisis/client/cli/tx.go | 60 --------------------- x/crisis/client/cli/tx_test.go | 99 ---------------------------------- x/crisis/module.go | 6 --- 4 files changed, 11 insertions(+), 169 deletions(-) delete mode 100644 x/crisis/client/cli/tx.go delete mode 100644 x/crisis/client/cli/tx_test.go diff --git a/x/crisis/autocli.go b/x/crisis/autocli.go index 2a979f63cfc8..92edd95d0cd8 100644 --- a/x/crisis/autocli.go +++ b/x/crisis/autocli.go @@ -12,10 +12,17 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Service: crisisv1beta1.Msg_ServiceDesc.ServiceName, RpcCommandOptions: []*autocliv1.RpcCommandOptions{ { - RpcMethod: "VerifyInvariant", - Use: "invariant-broken [module-name] [invariant-route]", - Short: "Submit proof that an invariant broken to halt the chain", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "invariant_module_name"}, {ProtoField: "invariant_route"}}, + RpcMethod: "VerifyInvariant", + Use: "invariant-broken [module-name] [invariant-route] --from mykey", + Short: "Submit proof that an invariant broken", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "invariant_module_name"}, + {ProtoField: "invariant_route"}, + }, + }, + { + RpcMethod: "UpdateParams", + Skip: true, // Skipped because UpdateParams is authority gated }, }, }, diff --git a/x/crisis/client/cli/tx.go b/x/crisis/client/cli/tx.go deleted file mode 100644 index 50b7e16a34b8..000000000000 --- a/x/crisis/client/cli/tx.go +++ /dev/null @@ -1,60 +0,0 @@ -package cli - -import ( - "errors" - - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/x/crisis/types" -) - -// NewTxCmd returns a root CLI command handler for all x/crisis transaction commands. -func NewTxCmd() *cobra.Command { - txCmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Crisis transactions subcommands", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - txCmd.AddCommand(NewMsgVerifyInvariantTxCmd()) - - return txCmd -} - -// NewMsgVerifyInvariantTxCmd returns a CLI command handler for creating a -// MsgVerifyInvariant transaction. -func NewMsgVerifyInvariantTxCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "invariant-broken [module-name] [invariant-route]", - Short: "Submit proof that an invariant broken to halt the chain", - Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - moduleName, route := args[0], args[1] - if moduleName == "" { - return errors.New("invalid module name") - } - if route == "" { - return errors.New("invalid invariant route") - } - - senderAddr := clientCtx.GetFromAddress() - - msg := types.NewMsgVerifyInvariant(senderAddr, moduleName, route) - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} diff --git a/x/crisis/client/cli/tx_test.go b/x/crisis/client/cli/tx_test.go deleted file mode 100644 index c6b8717294dc..000000000000 --- a/x/crisis/client/cli/tx_test.go +++ /dev/null @@ -1,99 +0,0 @@ -package cli_test - -import ( - "context" - "fmt" - "io" - "testing" - - rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" - "github.com/stretchr/testify/require" - - sdkmath "cosmossdk.io/math" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" - "github.com/cosmos/cosmos-sdk/testutil" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - sdk "github.com/cosmos/cosmos-sdk/types" - testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/cosmos/cosmos-sdk/x/crisis" - "github.com/cosmos/cosmos-sdk/x/crisis/client/cli" -) - -func TestNewMsgVerifyInvariantTxCmd(t *testing.T) { - encCfg := testutilmod.MakeTestEncodingConfig(crisis.AppModuleBasic{}) - kr := keyring.NewInMemory(encCfg.Codec) - baseCtx := client.Context{}. - WithKeyring(kr). - WithTxConfig(encCfg.TxConfig). - WithCodec(encCfg.Codec). - WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}). - WithAccountRetriever(client.MockAccountRetriever{}). - WithOutput(io.Discard). - WithChainID("test-chain") - - accounts := testutil.CreateKeyringAccounts(t, kr, 1) - testCases := []struct { - name string - args []string - expectErrMsg string - }{ - { - "missing module", - []string{ - "", "total-supply", - fmt.Sprintf("--%s=%s", flags.FlagFrom, accounts[0].Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(10))).String()), - }, - "invalid module name", - }, - { - "missing invariant route", - []string{ - "bank", "", - fmt.Sprintf("--%s=%s", flags.FlagFrom, accounts[0].Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(10))).String()), - }, - "invalid invariant route", - }, - { - "valid transaction", - []string{ - "bank", "total-supply", - fmt.Sprintf("--%s=%s", flags.FlagFrom, accounts[0].Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(10))).String()), - }, - "", - }, - } - - for _, tc := range testCases { - tc := tc - t.Run(tc.name, func(t *testing.T) { - ctx := svrcmd.CreateExecuteContext(context.Background()) - cmd := cli.NewMsgVerifyInvariantTxCmd() - cmd.SetContext(ctx) - cmd.SetArgs(tc.args) - require.NoError(t, client.SetCmdClientContextHandler(baseCtx, cmd)) - - out, err := clitestutil.ExecTestCLICmd(baseCtx, cmd, tc.args) - if tc.expectErrMsg != "" { - require.Error(t, err) - require.Contains(t, out.String(), tc.expectErrMsg) - } else { - require.NoError(t, err) - msg := &sdk.TxResponse{} - require.NoError(t, baseCtx.Codec.UnmarshalJSON(out.Bytes(), msg), out.String()) - } - }) - } -} diff --git a/x/crisis/module.go b/x/crisis/module.go index 87bb60efa273..6dc6880a8043 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -25,7 +25,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/crisis/client/cli" "github.com/cosmos/cosmos-sdk/x/crisis/exported" "github.com/cosmos/cosmos-sdk/x/crisis/keeper" "github.com/cosmos/cosmos-sdk/x/crisis/types" @@ -81,11 +80,6 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the crisis module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {} -// GetTxCmd returns the root tx command for the crisis module. -func (b AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.NewTxCmd() -} - // RegisterInterfaces registers interfaces and implementations of the crisis // module. func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {