feat(upgrade): autocli query support (#16903)

This commit is contained in:
Julien Robert 2023-07-11 15:02:19 +02:00 committed by GitHub
parent 8003261569
commit 320eea11c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 74 additions and 500 deletions

View File

@ -1,26 +0,0 @@
//go:build e2e
// +build e2e
package upgrade
import (
"testing"
"github.com/stretchr/testify/suite"
"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"
)
func TestE2ETestSuite(t *testing.T) {
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
cfg.NumValidators = 1
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false)
app.UpgradeKeeper.SetVersionSetter(app.BaseApp)
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap())
suite.Run(t, NewE2ETestSuite(cfg, app.UpgradeKeeper, ctx))
}

View File

@ -1,115 +0,0 @@
package upgrade
import (
"fmt"
"github.com/stretchr/testify/suite"
"cosmossdk.io/x/upgrade/client/cli"
"cosmossdk.io/x/upgrade/keeper"
"cosmossdk.io/x/upgrade/types"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func NewE2ETestSuite(cfg network.Config, keeper *keeper.Keeper, ctx sdk.Context) *E2ETestSuite {
return &E2ETestSuite{
cfg: cfg,
upgradeKeeper: keeper,
ctx: ctx,
}
}
type E2ETestSuite struct {
suite.Suite
upgradeKeeper *keeper.Keeper
cfg network.Config
network *network.Network
ctx sdk.Context
}
func (s *E2ETestSuite) SetupSuite() {
s.T().Log("setting up e2e test suite")
var err error
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err)
}
func (s *E2ETestSuite) TearDownSuite() {
s.T().Log("tearing down e2e test suite")
s.network.Cleanup()
}
func (s *E2ETestSuite) TestModuleVersionsCLI() {
testCases := []struct {
msg string
req types.QueryModuleVersionsRequest
single bool
expPass bool
}{
{
msg: "test full query",
req: types.QueryModuleVersionsRequest{ModuleName: ""},
single: false,
expPass: true,
},
{
msg: "test single module",
req: types.QueryModuleVersionsRequest{ModuleName: "bank"},
single: true,
expPass: true,
},
{
msg: "test non-existent module",
req: types.QueryModuleVersionsRequest{ModuleName: "abcdefg"},
single: true,
expPass: false,
},
}
val := s.network.Validators[0]
clientCtx := val.ClientCtx
// avoid printing as yaml from CLI command
clientCtx.OutputFormat = "JSON"
vm, err := s.upgradeKeeper.GetModuleVersionMap(s.ctx)
s.Require().NoError(err)
s.Require().NotEmpty(vm)
mv, err := s.upgradeKeeper.GetModuleVersions(s.ctx)
s.Require().NoError(err)
for _, tc := range testCases {
s.Run(fmt.Sprintf("Case %s", tc.msg), func() {
expect := mv
if tc.expPass {
if tc.single {
expect = []*types.ModuleVersion{{Name: tc.req.ModuleName, Version: vm[tc.req.ModuleName]}}
}
// setup expected response
pm := types.QueryModuleVersionsResponse{
ModuleVersions: expect,
}
jsonVM, _ := clientCtx.Codec.MarshalJSON(&pm)
expectedRes := string(jsonVM)
// append new line to match behavior of PrintProto
expectedRes += "\n"
// get actual module versions list response from cli
cmd := cli.GetModuleVersionsCmd()
outVM, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{tc.req.ModuleName})
s.Require().NoError(err)
s.Require().Equal(expectedRes, outVM.String())
} else {
cmd := cli.GetModuleVersionsCmd()
_, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{tc.req.ModuleName})
s.Require().Error(err)
}
})
}
}

View File

@ -13,7 +13,7 @@ require (
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c
github.com/cometbft/cometbft v0.38.0-rc2
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230709172657-53a07864b68f
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff
github.com/cosmos/gogoproto v1.4.10
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3

View File

@ -177,8 +177,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230709172657-53a07864b68f h1:3791c4kToJ9u46bfd7J4lXeg9HSrMwRJHJ5YJD1foZY=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230709172657-53a07864b68f/go.mod h1:dmZ0kV7SplzqHiYR9aV/iIpIGVoUF8r0NfiigmXxKeM=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff h1:jqNK08KgB3ExmUWsG8VNo+3QSODQnFefEiLNTKbcx2A=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff/go.mod h1:dmZ0kV7SplzqHiYR9aV/iIpIGVoUF8r0NfiigmXxKeM=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=

View File

@ -12,7 +12,7 @@ require (
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c
github.com/cometbft/cometbft v0.38.0-rc2
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230709172657-53a07864b68f
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff
github.com/cosmos/gogoproto v1.4.10
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3

View File

@ -175,8 +175,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230709172657-53a07864b68f h1:3791c4kToJ9u46bfd7J4lXeg9HSrMwRJHJ5YJD1foZY=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230709172657-53a07864b68f/go.mod h1:dmZ0kV7SplzqHiYR9aV/iIpIGVoUF8r0NfiigmXxKeM=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff h1:jqNK08KgB3ExmUWsG8VNo+3QSODQnFefEiLNTKbcx2A=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff/go.mod h1:dmZ0kV7SplzqHiYR9aV/iIpIGVoUF8r0NfiigmXxKeM=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=

View File

@ -12,7 +12,7 @@ require (
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c
github.com/cometbft/cometbft v0.38.0-rc2
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230709172657-53a07864b68f
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff
github.com/cosmos/gogoproto v1.4.10
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3

View File

@ -176,8 +176,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230709172657-53a07864b68f h1:3791c4kToJ9u46bfd7J4lXeg9HSrMwRJHJ5YJD1foZY=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230709172657-53a07864b68f/go.mod h1:dmZ0kV7SplzqHiYR9aV/iIpIGVoUF8r0NfiigmXxKeM=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff h1:jqNK08KgB3ExmUWsG8VNo+3QSODQnFefEiLNTKbcx2A=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff/go.mod h1:dmZ0kV7SplzqHiYR9aV/iIpIGVoUF8r0NfiigmXxKeM=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=

View File

@ -30,6 +30,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#14880](https://github.com/cosmos/cosmos-sdk/pull/14880) Switch from using gov v1beta1 to gov v1 in upgrade CLIs.
* [#14764](https://github.com/cosmos/cosmos-sdk/pull/14764) The `x/upgrade` module is extracted to have a separate go.mod file which allows it be a standalone module.
### Improvements
* [#16903](https://github.com/cosmos/cosmos-sdk/pull/16903) Use AutoCLI for upgrade querying commands.
### API Breaking Changes
* [#16845](https://github.com/cosmos/cosmos-sdk/pull/16845) Remove gov v1beta1 handler. Use gov v1 proposals directly, or replicate the handler in your app.

View File

@ -8,7 +8,6 @@ import (
"time"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/header"
@ -31,8 +30,6 @@ import (
)
type TestSuite struct {
suite.Suite
module appmodule.HasBeginBlocker
keeper *keeper.Keeper
ctx sdk.Context
@ -115,7 +112,7 @@ func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite {
s.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModuleBasic{})
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
s.baseApp = baseapp.NewBaseApp(
"upgrade",

53
x/upgrade/autocli.go Normal file
View File

@ -0,0 +1,53 @@
package upgrade
import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
upgradev1beta1 "cosmossdk.io/api/cosmos/upgrade/v1beta1"
)
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: &autocliv1.ServiceCommandDescriptor{
Service: upgradev1beta1.Query_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "CurrentPlan",
Use: "plan",
Short: "Query the upgrade plan (if one exists)",
Long: "Gets the currently scheduled upgrade plan, if one exists",
},
{
RpcMethod: "AppliedPlan",
Use: "applied [upgrade-name]",
Short: "Query the block header for height at which a completed upgrade was applied",
Long: "If upgrade-name was previously executed on the chain, this returns the header for the block at which it was applied. This helps a client determine which binary was valid over a given range of blocks, as well as more context to understand past migrations.",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "name"},
},
},
{
RpcMethod: "ModuleVersions",
Use: "module-versions [optional module_name]",
Alias: []string{"module_versions"},
Short: "Query the list of module versions",
Long: "Gets a list of module names and their respective consensus versions. Following the command with a specific module name will return only that module's information.",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "module_name", Optional: true},
},
},
{
RpcMethod: "Authority",
Use: "authority",
Short: "Get the upgrade authority address",
},
{
RpcMethod: "UpgradedConsensusState",
Skip: true, // Skipping this command as the query is deprecated.
},
},
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: upgradev1beta1.Query_ServiceDesc.ServiceName,
},
}
}

View File

@ -1,157 +0,0 @@
package cli
import (
"fmt"
"github.com/spf13/cobra"
"cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/types/errors"
)
// GetQueryCmd returns the parent command for all x/upgrade CLI query commands.
func GetQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the upgrade module",
}
cmd.AddCommand(
GetCurrentPlanCmd(),
GetAppliedPlanCmd(),
GetModuleVersionsCmd(),
)
return cmd
}
// GetCurrentPlanCmd returns the query upgrade plan command.
func GetCurrentPlanCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "plan",
Short: "get upgrade plan (if one exists)",
Long: "Gets the currently scheduled upgrade plan, if one exists",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
req := types.QueryCurrentPlanRequest{}
res, err := queryClient.CurrentPlan(cmd.Context(), &req)
if err != nil {
return err
}
if res.Plan == nil {
return fmt.Errorf("no upgrade scheduled")
}
return clientCtx.PrintProto(res.GetPlan())
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GetAppliedPlanCmd returns information about the block at which a completed
// upgrade was applied.
func GetAppliedPlanCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "applied [upgrade-name]",
Short: "block header for height at which a completed upgrade was applied",
Long: "If upgrade-name was previously executed on the chain, this returns the header for the block at which it was applied.\n" +
"This helps a client determine which binary was valid over a given range of blocks, as well as more context to understand past migrations.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
ctx := cmd.Context()
req := types.QueryAppliedPlanRequest{Name: args[0]}
res, err := queryClient.AppliedPlan(ctx, &req)
if err != nil {
return err
}
if res.Height == 0 {
return fmt.Errorf("no upgrade found")
}
// we got the height, now let's return the headers
node, err := clientCtx.GetNode()
if err != nil {
return err
}
headers, err := node.BlockchainInfo(ctx, res.Height, res.Height)
if err != nil {
return err
}
if len(headers.BlockMetas) == 0 {
return fmt.Errorf("no headers returned for height %d", res.Height)
}
// always output json as Header is unreable in toml ([]byte is a long list of numbers)
bz, err := clientCtx.LegacyAmino.MarshalJSONIndent(headers.BlockMetas[0], "", " ")
if err != nil {
return err
}
return clientCtx.PrintString(fmt.Sprintf("%s\n", bz))
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GetModuleVersionsCmd returns the module version list from state
func GetModuleVersionsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "module_versions [optional module_name]",
Short: "get the list of module versions",
Long: "Gets a list of module names and their respective consensus versions.\n" +
"Following the command with a specific module name will return only\n" +
"that module's information.",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
var req types.QueryModuleVersionsRequest
if len(args) == 1 {
req = types.QueryModuleVersionsRequest{ModuleName: args[0]}
} else {
req = types.QueryModuleVersionsRequest{}
}
res, err := queryClient.ModuleVersions(cmd.Context(), &req)
if err != nil {
return err
}
if res.ModuleVersions == nil {
return errors.ErrNotFound
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

View File

@ -1,177 +0,0 @@
package cli_test
import (
"context"
"fmt"
"io"
"testing"
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
"github.com/stretchr/testify/require"
"cosmossdk.io/x/upgrade"
upgradecli "cosmossdk.io/x/upgrade/client/cli"
"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"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil"
)
func TestGetCurrentPlanCmd(t *testing.T) {
encCfg := testutilmod.MakeTestEncodingConfig(upgrade.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")
testCases := []struct {
name string
args []string
expCmdOutput string
}{
{
name: "json output",
args: []string{fmt.Sprintf("--%s=json", flags.FlagOutput)},
expCmdOutput: `[--output=json]`,
},
{
name: "text output",
args: []string{fmt.Sprintf("--%s=text", flags.FlagOutput)},
expCmdOutput: `[--output=text]`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
ctx := svrcmd.CreateExecuteContext(context.Background())
cmd := upgradecli.GetCurrentPlanCmd()
cmd.SetOut(io.Discard)
require.NotNil(t, cmd)
cmd.SetContext(ctx)
cmd.SetArgs(tc.args)
require.NoError(t, client.SetCmdClientContextHandler(baseCtx, cmd))
require.Contains(t, fmt.Sprint(cmd), "plan [] [] get upgrade plan (if one exists)")
require.Contains(t, fmt.Sprint(cmd), tc.expCmdOutput)
})
}
}
func TestGetAppliedPlanCmd(t *testing.T) {
encCfg := testutilmod.MakeTestEncodingConfig(upgrade.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")
testCases := []struct {
name string
args []string
expCmdOutput string
}{
{
name: "json output",
args: []string{"test-upgrade", fmt.Sprintf("--%s=json", flags.FlagOutput)},
expCmdOutput: `[test-upgrade --output=json]`,
},
{
name: "text output",
args: []string{"test-upgrade", fmt.Sprintf("--%s=text", flags.FlagOutput)},
expCmdOutput: `[test-upgrade --output=text]`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
ctx := svrcmd.CreateExecuteContext(context.Background())
cmd := upgradecli.GetAppliedPlanCmd()
cmd.SetOut(io.Discard)
require.NotNil(t, cmd)
cmd.SetContext(ctx)
cmd.SetArgs(tc.args)
require.NoError(t, client.SetCmdClientContextHandler(baseCtx, cmd))
require.Contains(t, fmt.Sprint(cmd), "applied [upgrade-name] [] [] block header for height at which a completed upgrade was applied")
require.Contains(t, fmt.Sprint(cmd), tc.expCmdOutput)
})
}
}
func TestGetModuleVersionsCmd(t *testing.T) {
encCfg := testutilmod.MakeTestEncodingConfig(upgrade.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")
testCases := []struct {
msg string
args []string
expCmdOutput string
}{
{
msg: "test full query with json output",
args: []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=json", flags.FlagOutput)},
expCmdOutput: `--height=1 --output=json`,
},
{
msg: "test full query with text output",
args: []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", flags.FlagOutput)},
expCmdOutput: `--height=1 --output=text`,
},
{
msg: "test single module",
args: []string{"bank", fmt.Sprintf("--%s=1", flags.FlagHeight)},
expCmdOutput: `bank --height=1`,
},
{
msg: "test non-existent module",
args: []string{"abcdefg", fmt.Sprintf("--%s=1", flags.FlagHeight)},
expCmdOutput: `abcdefg --height=1`,
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.msg, func(t *testing.T) {
ctx := svrcmd.CreateExecuteContext(context.Background())
cmd := upgradecli.GetModuleVersionsCmd()
cmd.SetOut(io.Discard)
require.NotNil(t, cmd)
cmd.SetContext(ctx)
cmd.SetArgs(tc.args)
require.NoError(t, client.SetCmdClientContextHandler(baseCtx, cmd))
require.Contains(t, fmt.Sprint(cmd), "module_versions [optional module_name] [] [] get the list of module versions")
require.Contains(t, fmt.Sprint(cmd), tc.expCmdOutput)
})
}
}

View File

@ -7,12 +7,12 @@ require (
cosmossdk.io/core v0.9.0
cosmossdk.io/depinject v1.0.0-alpha.3
cosmossdk.io/errors v1.0.0-beta.7.0.20230524212735-6cabb6aa5741
cosmossdk.io/log v1.1.0
cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c
github.com/cometbft/cometbft v0.38.0-rc2
github.com/cosmos/cosmos-db v1.0.0
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230630100245-46dd31a05ab3
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff
github.com/cosmos/gogoproto v1.4.10
github.com/golang/protobuf v1.5.3
github.com/grpc-ecosystem/grpc-gateway v1.16.0

View File

@ -198,8 +198,8 @@ cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z
cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU=
cosmossdk.io/errors v1.0.0-beta.7.0.20230524212735-6cabb6aa5741 h1:BCRz06fvddw7cKGiEGDiSox3qMsjQ97f92K+PDZDHdc=
cosmossdk.io/errors v1.0.0-beta.7.0.20230524212735-6cabb6aa5741/go.mod h1:TB05o6YXkZkzsc+6bZFAV5kZRBtoCU9tUkbeMIqEg0w=
cosmossdk.io/log v1.1.0 h1:v0ogPHYeTzPcBTcPR1A3j1hkei4pZama8kz8LKlCMv0=
cosmossdk.io/log v1.1.0/go.mod h1:6zjroETlcDs+mm62gd8Ig7mZ+N+fVOZS91V17H+M4N4=
cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca h1:msenprh2BLLRwNT7zN56TbBHOGk/7ARQckXHxXyvjoQ=
cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca/go.mod h1:PkIAKXZvaxrTRc++z53XMRvFk8AcGGWYHcMIPzVYX9c=
cosmossdk.io/math v1.0.1 h1:Qx3ifyOPaMLNH/89WeZFH268yCvU4xEcnPLu3sJqPPg=
cosmossdk.io/math v1.0.1/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k=
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c h1:A+FMPW9GtfcPBDQNtFeDFN27h1SAP6OVjnGgPLlYXmI=
@ -341,8 +341,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230630100245-46dd31a05ab3 h1:dW/6ZHI9RauOiZEBtAOdqczsdTpknMCSrRPsUSrySJQ=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230630100245-46dd31a05ab3/go.mod h1:byblbRGAX/24iecgMItNVp6/F2NuxBgW1xm+sorUCfQ=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff h1:jqNK08KgB3ExmUWsG8VNo+3QSODQnFefEiLNTKbcx2A=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff/go.mod h1:dmZ0kV7SplzqHiYR9aV/iIpIGVoUF8r0NfiigmXxKeM=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=

View File

@ -41,7 +41,7 @@ func (suite *UpgradeTestSuite) SetupTest() {
skipUpgradeHeights := make(map[int64]bool)
suite.upgradeKeeper = keeper.NewKeeper(skipUpgradeHeights, storeService, suite.encCfg.Codec, "", nil, authtypes.NewModuleAddress(govtypes.ModuleName).String())
suite.upgradeKeeper = keeper.NewKeeper(skipUpgradeHeights, storeService, suite.encCfg.Codec, suite.T().TempDir(), nil, authtypes.NewModuleAddress(govtypes.ModuleName).String())
suite.upgradeKeeper.SetModuleVersionMap(suite.ctx, module.VersionMap{
"bank": 0,
})

View File

@ -64,11 +64,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g
}
}
// GetQueryCmd returns the CLI query commands for this module
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}
// GetTxCmd returns the CLI transaction commands for this module
func (ab AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd(ab.ac)