diff --git a/CHANGELOG.md b/CHANGELOG.md index 4144d7025859..b53a2b15a30c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (all modules) [#15901](https://github.com/cosmos/cosmos-sdk/issues/15901) All core Cosmos SDK modules query have migrated to [AutoCLI](https://docs.cosmos.network/main/building-modules/autocli), ensuring parity between gRPC and CLI queries. * (types) [#16890](https://github.com/cosmos/cosmos-sdk/pull/16890) Remove `GetTxCmd() *cobra.Command` and `GetQueryCmd() *cobra.Command` from `module.AppModuleBasic` interface. * (cli) [#16856](https://github.com/cosmos/cosmos-sdk/pull/16856) Improve `simd prune` UX by using the app default home directory and set pruning method as first variable argument (defaults to default). * (all) [#16537](https://github.com/cosmos/cosmos-sdk/pull/16537) Properly propagated fmt.Errorf errors + using errors.New where appropriate. @@ -102,7 +103,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * (all) [#16497](https://github.com/cosmos/cosmos-sdk/pull/16497) Removed all exported vestiges of `sdk.MustSortJSON` and `sdk.SortJSON`. -* (x/distribution) [#16218](https://github.com/cosmos/cosmos-sdk/pull/16218) Add Autocli config to distribution module. * (cli) [#16206](https://github.com/cosmos/cosmos-sdk/pull/16206) Make ABCI handshake profileable. ### Bug Fixes diff --git a/tests/e2e/params/app_config.go b/tests/e2e/params/app_config.go deleted file mode 100644 index 71fad4815af9..000000000000 --- a/tests/e2e/params/app_config.go +++ /dev/null @@ -1,22 +0,0 @@ -package testutil - -import ( - "github.com/cosmos/cosmos-sdk/testutil/configurator" - _ "github.com/cosmos/cosmos-sdk/x/auth" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/bank" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/params" // import as blank for app wiring - _ "github.com/cosmos/cosmos-sdk/x/staking" // import as blank for app wiring -) - -var AppConfig = configurator.NewAppConfig( - configurator.AuthModule(), - configurator.BankModule(), - configurator.StakingModule(), - configurator.TxModule(), - configurator.ConsensusModule(), - configurator.ParamsModule(), - configurator.GenutilModule(), -) diff --git a/tests/e2e/params/cli_test.go b/tests/e2e/params/cli_test.go deleted file mode 100644 index 80081e2bcaf8..000000000000 --- a/tests/e2e/params/cli_test.go +++ /dev/null @@ -1,19 +0,0 @@ -//go:build e2e -// +build e2e - -package testutil - -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 - suite.Run(t, NewE2ETestSuite(cfg)) -} diff --git a/tests/e2e/params/grpc.go b/tests/e2e/params/grpc.go deleted file mode 100644 index 99c1b603a609..000000000000 --- a/tests/e2e/params/grpc.go +++ /dev/null @@ -1,85 +0,0 @@ -package testutil - -import ( - "fmt" - - "github.com/cosmos/gogoproto/proto" - - "github.com/cosmos/cosmos-sdk/testutil" - "github.com/cosmos/cosmos-sdk/x/params/types/proposal" -) - -func (s *E2ETestSuite) TestQueryParamsGRPC() { - val := s.network.Validators[0] - baseURL := val.APIAddress - - testCases := []struct { - name string - url string - headers map[string]string - expErr bool - respType proto.Message - expected proto.Message - }{ - { - "with no subspace, key", - fmt.Sprintf("%s/cosmos/params/v1beta1/params?subspace=%s&key=%s", baseURL, "", ""), - map[string]string{}, - true, - &proposal.QueryParamsResponse{}, - nil, - }, - { - "with wrong subspace", - fmt.Sprintf("%s/cosmos/params/v1beta1/params?subspace=%s&key=%s", baseURL, "wrongSubspace", "foo"), - map[string]string{}, - true, - &proposal.QueryParamsResponse{}, - nil, - }, - { - "with wrong key", - fmt.Sprintf("%s/cosmos/params/v1beta1/params?subspace=%s&key=%s", baseURL, mySubspace, "wrongKey"), - map[string]string{}, - false, - &proposal.QueryParamsResponse{}, - &proposal.QueryParamsResponse{ - Param: proposal.ParamChange{ - Subspace: mySubspace, - Key: "wrongKey", - }, - }, - }, - { - "params", - fmt.Sprintf("%s/cosmos/params/v1beta1/params?subspace=%s&key=%s", baseURL, mySubspace, "bar"), - map[string]string{}, - false, - &proposal.QueryParamsResponse{}, - &proposal.QueryParamsResponse{ - Param: proposal.ParamChange{ - Subspace: mySubspace, - Key: "bar", - Value: `"1234"`, - }, - }, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) - s.Require().NoError(err) - - err = val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType) - - if tc.expErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - s.Require().Equal(tc.expected.String(), tc.respType.String()) - } - }) - } -} diff --git a/tests/e2e/params/suite.go b/tests/e2e/params/suite.go deleted file mode 100644 index 89c8618440f6..000000000000 --- a/tests/e2e/params/suite.go +++ /dev/null @@ -1,148 +0,0 @@ -package testutil - -import ( - "fmt" - "strings" - - abci "github.com/cometbft/cometbft/abci/types" - dbm "github.com/cosmos/cosmos-db" - "github.com/stretchr/testify/suite" - - "cosmossdk.io/depinject" - pruningtypes "cosmossdk.io/store/pruning/types" - - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/runtime" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - "github.com/cosmos/cosmos-sdk/testutil/network" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/params/client/cli" - "github.com/cosmos/cosmos-sdk/x/params/keeper" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -// mySubspace is a x/params subspace created for the purpose of this -// test suite. -const mySubspace = "foo" - -// myParams defines some params in the `mySubspace` subspace. -type myParams struct{} - -func (p *myParams) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair([]byte("bar"), 1234, func(value interface{}) error { return nil }), - } -} - -type E2ETestSuite struct { - suite.Suite - - cfg network.Config - network *network.Network -} - -func NewE2ETestSuite(cfg network.Config) *E2ETestSuite { - return &E2ETestSuite{cfg: cfg} -} - -func (s *E2ETestSuite) SetupSuite() { - s.T().Log("setting up e2e test suite") - - // Create a new AppConstructor for this test suite, where we manually - // add a subspace and `myParams` to the x/params store. - s.cfg.AppConstructor = func(val network.ValidatorI) servertypes.Application { - var ( - appBuilder *runtime.AppBuilder - paramsKeeper keeper.Keeper - ) - if err := depinject.Inject( - depinject.Configs( - AppConfig, - depinject.Supply(val.GetCtx().Logger), - ), - &appBuilder, ¶msKeeper); err != nil { - panic(err) - } - - // Add this test's `myParams` to the x/params store. - paramSet := myParams{} - subspace := paramsKeeper.Subspace(mySubspace).WithKeyTable(paramtypes.NewKeyTable().RegisterParamSet(¶mSet)) - - app := appBuilder.Build( - dbm.NewMemDB(), - nil, - baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), - baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices), - baseapp.SetChainID(s.cfg.ChainID), - ) - - s.Require().NoError(app.Load(false)) - - // Make sure not to forget to persist `myParams` into the actual store, - // this is done in InitChain. - app.SetInitChainer(func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { - subspace.SetParamSet(ctx, ¶mSet) - - return app.InitChainer(ctx, req) - }) - - s.Require().NoError(app.LoadLatestVersion()) - - return app - } - - var err error - s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) - s.Require().NoError(err) - - s.Require().NoError(s.network.WaitForNextBlock()) -} - -func (s *E2ETestSuite) TearDownSuite() { - s.T().Log("tearing down e2e test suite") - s.network.Cleanup() -} - -func (s *E2ETestSuite) TestNewQuerySubspaceParamsCmd() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectedOutput string - }{ - { - "json output", - []string{ - "foo", "bar", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - `{"subspace":"foo","key":"bar","value":"\"1234\""}`, - }, - { - "text output", - []string{ - "foo", "bar", - fmt.Sprintf("--%s=text", flags.FlagOutput), - }, - `key: bar -subspace: foo -value: '"1234"'`, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.NewQuerySubspaceParamsCmd() - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - s.Require().NoError(err) - s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String())) - }) - } -} diff --git a/x/params/autocli.go b/x/params/autocli.go new file mode 100644 index 000000000000..b01e73e45504 --- /dev/null +++ b/x/params/autocli.go @@ -0,0 +1,31 @@ +package params + +import ( + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + paramsv1beta1 "cosmossdk.io/api/cosmos/params/v1beta1" +) + +// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: paramsv1beta1.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Params", + Use: "subspace [subspace] [key]", + Short: "Query for raw parameters by subspace and key", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "subspace"}, + {ProtoField: "key"}, + }, + }, + { + RpcMethod: "Subspaces", + Use: "subspaces", + Short: "Query for all registered subspaces and all keys for a subspace", + }, + }, + }, + } +} diff --git a/x/params/client/cli/query.go b/x/params/client/cli/query.go deleted file mode 100644 index ce7b45d0602d..000000000000 --- a/x/params/client/cli/query.go +++ /dev/null @@ -1,54 +0,0 @@ -package cli - -import ( - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/cosmos/cosmos-sdk/x/params/types/proposal" -) - -// NewQueryCmd returns a root CLI command handler for all x/params query commands. -func NewQueryCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Querying commands for the params module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand(NewQuerySubspaceParamsCmd()) - - return cmd -} - -// NewQuerySubspaceParamsCmd returns a CLI command handler for querying subspace -// parameters managed by the x/params module. -func NewQuerySubspaceParamsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "subspace [subspace] [key]", - Short: "Query for raw parameters by subspace and key", - Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := proposal.NewQueryClient(clientCtx) - - params := proposal.QueryParamsRequest{Subspace: args[0], Key: args[1]} - res, err := queryClient.Params(cmd.Context(), ¶ms) - if err != nil { - return err - } - - return clientCtx.PrintProto(&res.Param) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/params/module.go b/x/params/module.go index 778f846c4949..ada51ae1e7dd 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -4,7 +4,6 @@ import ( "context" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" modulev1 "cosmossdk.io/api/cosmos/params/module/v1" "cosmossdk.io/core/appmodule" @@ -17,7 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/cosmos/cosmos-sdk/x/params/client/cli" "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/params/types/proposal" @@ -52,11 +50,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g } } -// GetQueryCmd returns no root query command for the params module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.NewQueryCmd() -} - func (am AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { proposal.RegisterInterfaces(registry) }