feat(x/crisis): add autocli options for tx (#17965)
This commit is contained in:
parent
96e68fa754
commit
12b45f3db6
@ -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
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -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
|
||||
}
|
||||
@ -1,103 +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"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"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").
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
|
||||
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())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||
"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/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
@ -79,11 +78,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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user