From 81b70496c56a30318d5df01f39b97f5747dad88b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 10 Jul 2023 11:42:20 +0200 Subject: [PATCH 1/7] feat(auth): autocli query support (#16650) --- CHANGELOG.md | 1 + tests/e2e/auth/suite.go | 203 +-------------- .../integration/auth/client/cli/suite_test.go | 38 --- x/auth/autocli.go | 55 ++++- x/auth/client/cli/query.go | 233 ------------------ x/auth/client/testutil/helpers.go | 8 - x/auth/keeper/grpc_query_test.go | 2 +- x/auth/module.go | 3 +- 8 files changed, 57 insertions(+), 486 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9d8897c4f24..d3780e540802 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (x/auth) [#16650](https://github.com/cosmos/cosmos-sdk/pull/16650) The testutil `QueryAccountExec` has been removed from auth as it was using the CLI. * (types/math) [#16040](https://github.com/cosmos/cosmos-sdk/pull/16798) Remove aliases in `types/math.go` (part 2). * (x/distribution) [#16440](https://github.com/cosmos/cosmos-sdk/pull/16440) use collections for `DelegatorWithdrawAddresState`: * remove `Keeper`: `SetDelegatorWithdrawAddr`, `DeleteDelegatorWithdrawAddr`, `IterateDelegatorWithdrawAddrs`. diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index 7d8b28bd8f08..81df6f4b1e87 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -31,7 +31,6 @@ import ( authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authclitestutil "github.com/cosmos/cosmos-sdk/x/auth/client/testutil" authtestutil "github.com/cosmos/cosmos-sdk/x/auth/testutil" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" bank "github.com/cosmos/cosmos-sdk/x/bank/client/cli" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" @@ -289,50 +288,6 @@ func (s *E2ETestSuite) TestCLISignBatch() { s.Require().Equal(sigs[0].Sequence, seq1) } -func (s *E2ETestSuite) TestCliGetAccountAddressByID() { - require := s.Require() - val1 := s.network.Validators[0] - testCases := []struct { - name string - args []string - expectErr bool - }{ - { - "not enough args", - []string{fmt.Sprintf("--%s=json", flags.FlagOutput)}, - true, - }, - { - "invalid account id", - []string{fmt.Sprint(-1), fmt.Sprintf("--%s=json", flags.FlagOutput)}, - true, - }, - { - "valid account id", - []string{fmt.Sprint(0), fmt.Sprintf("--%s=json", flags.FlagOutput)}, - false, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - cmd := authcli.GetAccountAddressByIDCmd() - clientCtx := val1.ClientCtx - - queryResJSON, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - var res authtypes.QueryAccountAddressByIDResponse - require.NoError(val1.ClientCtx.Codec.UnmarshalJSON(queryResJSON.Bytes(), &res)) - require.NotNil(res.GetAccountAddress()) - } - }) - } -} - func (s *E2ETestSuite) TestCLIQueryTxCmdByHash() { val := s.network.Validators[0] @@ -1228,10 +1183,8 @@ func (s *E2ETestSuite) TestMultisignBatch() { defer filename.Close() val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1) - queryResJSON, err := authclitestutil.QueryAccountExec(val.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos")) + account, err := val.ClientCtx.AccountRetriever.GetAccount(val.ClientCtx, addr) s.Require().NoError(err) - var account sdk.AccountI - s.Require().NoError(val.ClientCtx.Codec.UnmarshalInterfaceJSON(queryResJSON.Bytes(), &account)) // sign-batch file addr1, err := account1.GetAddress() @@ -1270,121 +1223,6 @@ func (s *E2ETestSuite) TestMultisignBatch() { } } -func (s *E2ETestSuite) TestGetAccountCmd() { - val := s.network.Validators[0] - _, _, addr1 := testdata.KeyTestPubAddr() - - testCases := []struct { - name string - address sdk.AccAddress - expectErr bool - }{ - { - "invalid address", - addr1, - true, - }, - { - "valid address", - val.Address, - false, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - clientCtx := val.ClientCtx - - out, err := authclitestutil.QueryAccountExec(clientCtx, tc.address, addresscodec.NewBech32Codec("cosmos")) - if tc.expectErr { - s.Require().Error(err) - s.Require().NotEqual("internal", err.Error()) - } else { - var acc sdk.AccountI - s.Require().NoError(val.ClientCtx.Codec.UnmarshalInterfaceJSON(out.Bytes(), &acc)) - s.Require().Equal(val.Address, acc.GetAddress()) - } - }) - } -} - -func (s *E2ETestSuite) TestGetAccountsCmd() { - val := s.network.Validators[0] - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, authcli.GetAccountsCmd(), []string{ - fmt.Sprintf("--%s=json", flags.FlagOutput), - }) - s.Require().NoError(err) - - var res authtypes.QueryAccountsResponse - s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res)) - s.Require().NotEmpty(res.Accounts) -} - -func (s *E2ETestSuite) TestQueryModuleAccountByNameCmd() { - val := s.network.Validators[0] - - testCases := []struct { - name string - moduleName string - expectErr bool - }{ - { - "invalid module name", - "gover", - true, - }, - { - "valid module name", - "mint", - false, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, authcli.QueryModuleAccountByNameCmd(), []string{ - tc.moduleName, - fmt.Sprintf("--%s=json", flags.FlagOutput), - }) - if tc.expectErr { - s.Require().Error(err) - s.Require().NotEqual("internal", err.Error()) - } else { - var res authtypes.QueryModuleAccountByNameResponse - s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res)) - - var account sdk.AccountI - err := val.ClientCtx.InterfaceRegistry.UnpackAny(res.Account, &account) - s.Require().NoError(err) - - moduleAccount, ok := account.(sdk.ModuleAccountI) - s.Require().True(ok) - s.Require().Equal(tc.moduleName, moduleAccount.GetName()) - } - }) - } -} - -func (s *E2ETestSuite) TestQueryModuleAccountsCmd() { - val := s.network.Validators[0] - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, authcli.QueryModuleAccountsCmd(), []string{ - fmt.Sprintf("--%s=json", flags.FlagOutput), - }) - s.Require().NoError(err) - - var res authtypes.QueryModuleAccountsResponse - s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res)) - s.Require().NotEmpty(res.Accounts) -} - func TestGetBroadcastCommandOfflineFlag(t *testing.T) { cmd := authcli.GetBroadcastCommand() _ = testutil.ApplyMockIODiscardOutErr(cmd) @@ -1427,45 +1265,6 @@ func TestGetBroadcastCommandWithoutOfflineFlag(t *testing.T) { require.Contains(t, out.String(), "connect: connection refused") } -func (s *E2ETestSuite) TestQueryParamsCmd() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectErr bool - }{ - { - "happy case", - []string{fmt.Sprintf("--%s=json", flags.FlagOutput)}, - false, - }, - { - "with specific height", - []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=json", flags.FlagOutput)}, - false, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - cmd := authcli.QueryParamsCmd() - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - s.Require().NotEqual("internal", err.Error()) - } else { - var authParams authtypes.Params - s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &authParams)) - s.Require().NotNil(authParams.MaxMemoCharacters) - } - }) - } -} - // TestTxWithoutPublicKey makes sure sending a proto tx message without the // public key doesn't cause any error in the RPC layer (broadcast). // See https://github.com/cosmos/cosmos-sdk/issues/7585 for more details. diff --git a/tests/integration/auth/client/cli/suite_test.go b/tests/integration/auth/client/cli/suite_test.go index cbb69752c7d6..ce81f4b2fd44 100644 --- a/tests/integration/auth/client/cli/suite_test.go +++ b/tests/integration/auth/client/cli/suite_test.go @@ -30,7 +30,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth" authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtestutil "github.com/cosmos/cosmos-sdk/x/auth/client/testutil" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" @@ -818,43 +817,6 @@ func (s *CLITestSuite) TestGetBroadcastCommandWithoutOfflineFlag() { s.Require().Contains(out.String(), "connect: connection refused") } -func (s *CLITestSuite) TestQueryParamsCmd() { - testCases := []struct { - name string - args []string - expectErr bool - }{ - { - "happy case", - []string{fmt.Sprintf("--%s=json", flags.FlagOutput)}, - false, - }, - { - "with specific height", - []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=json", flags.FlagOutput)}, - false, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - cmd := authcli.QueryParamsCmd() - clientCtx := s.clientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - s.Require().NotEqual("internal", err.Error()) - } else { - var authParams authtypes.Params - s.Require().NoError(s.clientCtx.Codec.UnmarshalJSON(out.Bytes(), &authParams)) - s.Require().NotNil(authParams.MaxMemoCharacters) - } - }) - } -} - // TestTxWithoutPublicKey makes sure sending a proto tx message without the // public key doesn't cause any error in the RPC layer (broadcast). // See https://github.com/cosmos/cosmos-sdk/issues/7585 for more details. diff --git a/x/auth/autocli.go b/x/auth/autocli.go index 3eaa323cc70a..c7b52e42e0c0 100644 --- a/x/auth/autocli.go +++ b/x/auth/autocli.go @@ -1,8 +1,14 @@ package auth import ( + "fmt" + authv1beta1 "cosmossdk.io/api/cosmos/auth/v1beta1" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + _ "cosmossdk.io/api/cosmos/crypto/secp256k1" // register to that it shows up in protoregistry.GlobalTypes + _ "cosmossdk.io/api/cosmos/crypto/secp256r1" // register to that it shows up in protoregistry.GlobalTypes + + "github.com/cosmos/cosmos-sdk/version" ) // AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. @@ -11,18 +17,63 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Query: &autocliv1.ServiceCommandDescriptor{ Service: authv1beta1.Query_ServiceDesc.ServiceName, RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Accounts", + Use: "accounts", + Short: "Query all the accounts", + }, { RpcMethod: "Account", Use: "account [address]", - Short: "query account by address", + Short: "Query account by address", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}}, + }, + { + RpcMethod: "AccountInfo", + Use: "account-info [address]", + Short: "Query account info which is common to all account types.", PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}}, }, { RpcMethod: "AccountAddressByID", Use: "address-by-acc-num [acc-num]", - Short: "query account address by account number", + Short: "Query account address by account number", PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "id"}}, }, + { + RpcMethod: "ModuleAccounts", + Use: "module-accounts", + Short: "Query all module accounts", + }, + { + RpcMethod: "ModuleAccountByName", + Use: "module-account [module-name]", + Short: "Query module account info by module name", + Example: fmt.Sprintf("%s q auth module-account gov", version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "name"}}, + }, + { + RpcMethod: "AddressBytesToString", + Use: "address-bytes-to-string [address-bytes]", + Short: "Transform an address bytes to string", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address_bytes"}}, + }, + { + RpcMethod: "AddressStringToBytes", + Use: "address-string-to-bytes [address-string]", + Short: "Transform an address string to bytes", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address_string"}}, + }, + { + RpcMethod: "Bech32Prefix", + Use: "bech32-prefix", + Short: "Query the chain bech32 prefix (if applicable)", + }, + { + RpcMethod: "Params", + Use: "params", + Short: "Query the current auth parameters", + }, }, }, // Tx is purposely left empty, as the only tx is MsgUpdateParams which is gov gated. diff --git a/x/auth/client/cli/query.go b/x/auth/client/cli/query.go index 52de6b8c2d74..8d3ee8e793db 100644 --- a/x/auth/client/cli/query.go +++ b/x/auth/client/cli/query.go @@ -1,16 +1,11 @@ package cli import ( - "context" "fmt" - "strconv" "strings" "github.com/spf13/cobra" - "cosmossdk.io/core/address" - errorsmod "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" @@ -18,11 +13,9 @@ import ( querytypes "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/version" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" - "github.com/cosmos/cosmos-sdk/x/auth/types" ) const ( - FlagEvents = "events" // TODO: Remove when #14758 is merged FlagQuery = "query" FlagType = "type" FlagOrderBy = "order_by" @@ -35,232 +28,6 @@ const ( EventFormat = "{eventType}.{eventAttribute}={value}" ) -// GetQueryCmd returns the transaction commands for this module -func GetQueryCmd(ac address.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Querying commands for the auth module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand( - GetAccountCmd(ac), - GetAccountAddressByIDCmd(), - GetAccountsCmd(), - QueryParamsCmd(), - QueryModuleAccountsCmd(), - QueryModuleAccountByNameCmd(), - ) - - return cmd -} - -// QueryParamsCmd returns the command handler for evidence parameter querying. -func QueryParamsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "params", - Short: "Query the current auth parameters", - Args: cobra.NoArgs, - Long: strings.TrimSpace(`Query the current auth parameters: - -$ query auth params -`), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(&res.Params) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// GetAccountCmd returns a query account that will display the state of the -// account at a given address. -func GetAccountCmd(ac address.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "account [address]", - Short: "Query for account by address", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - _, err = ac.StringToBytes(args[0]) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - res, err := queryClient.Account(cmd.Context(), &types.QueryAccountRequest{Address: args[0]}) - if err != nil { - node, err2 := clientCtx.GetNode() - if err2 != nil { - return err2 - } - status, err2 := node.Status(context.Background()) - if err2 != nil { - return err2 - } - catchingUp := status.SyncInfo.CatchingUp - if !catchingUp { - return errorsmod.Wrapf(err, "your node may be syncing, please check node status using `/status`") - } - return err - } - - return clientCtx.PrintProto(res.Account) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// GetAccountAddressByIDCmd returns a query account that will display the account address of a given account id. -func GetAccountAddressByIDCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "address-by-acc-num [acc-num]", - Aliases: []string{"address-by-id"}, - Short: "Query for an address by account number", - Args: cobra.ExactArgs(1), - Example: fmt.Sprintf("%s q auth address-by-acc-num 1", version.AppName), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - accNum, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - res, err := queryClient.AccountAddressByID(cmd.Context(), &types.QueryAccountAddressByIDRequest{ - AccountId: accNum, - }) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// GetAccountsCmd returns a query command that will display a list of accounts -func GetAccountsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "accounts", - Short: "Query all the accounts", - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - res, err := queryClient.Accounts(cmd.Context(), &types.QueryAccountsRequest{Pagination: pageReq}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "all-accounts") - - return cmd -} - -// QueryAllModuleAccountsCmd returns a list of all the existing module accounts with their account information and permissions -func QueryModuleAccountsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "module-accounts", - Short: "Query all module accounts", - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.ModuleAccounts(context.Background(), &types.QueryModuleAccountsRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// QueryModuleAccountByNameCmd returns a command to -func QueryModuleAccountByNameCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "module-account [module-name]", - Short: "Query module account info by module name", - Args: cobra.ExactArgs(1), - Example: fmt.Sprintf("%s q auth module-account auth", version.AppName), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - moduleName := args[0] - if len(moduleName) == 0 { - return fmt.Errorf("module name should not be empty") - } - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.ModuleAccountByName(context.Background(), &types.QueryModuleAccountByNameRequest{Name: moduleName}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - // QueryTxsByEventsCmd returns a command to search through transactions by events. func QueryTxsByEventsCmd() *cobra.Command { cmd := &cobra.Command{ diff --git a/x/auth/client/testutil/helpers.go b/x/auth/client/testutil/helpers.go index 9f18e4b12f38..8ca44048cbd1 100644 --- a/x/auth/client/testutil/helpers.go +++ b/x/auth/client/testutil/helpers.go @@ -4,8 +4,6 @@ import ( "fmt" "strings" - "cosmossdk.io/core/address" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -91,12 +89,6 @@ func TxAuxToFeeExec(clientCtx client.Context, filename string, extraArgs ...stri return clitestutil.ExecTestCLICmd(clientCtx, cli.GetAuxToFeeCommand(), append(args, extraArgs...)) } -func QueryAccountExec(clientCtx client.Context, address fmt.Stringer, ac address.Codec, extraArgs ...string) (testutil.BufferWriter, error) { - args := []string{address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)} - - return clitestutil.ExecTestCLICmd(clientCtx, cli.GetAccountCmd(ac), append(args, extraArgs...)) -} - func TxMultiSignBatchExec(clientCtx client.Context, filename, from, sigFile1, sigFile2 string, extraArgs ...string) (testutil.BufferWriter, error) { args := []string{ fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), diff --git a/x/auth/keeper/grpc_query_test.go b/x/auth/keeper/grpc_query_test.go index f2d0a766648c..b0479a8c0991 100644 --- a/x/auth/keeper/grpc_query_test.go +++ b/x/auth/keeper/grpc_query_test.go @@ -222,7 +222,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryAccountAddressByID() { } } -func (suite *KeeperTestSuite) TestGRPCQueryParameters() { +func (suite *KeeperTestSuite) TestGRPCQueryParams() { var ( req *types.QueryParamsRequest expParams types.Params diff --git a/x/auth/module.go b/x/auth/module.go index 8cd8ccc35b2f..eb49321e2f34 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -21,7 +21,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -86,7 +85,7 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command { // GetQueryCmd returns the root query command for the auth module. func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd(ab.ac) + return nil } // RegisterInterfaces registers interfaces and implementations of the auth module. From febeced2e12928b5e478aff240b6ac13adcaa333 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 10 Jul 2023 14:20:45 +0200 Subject: [PATCH 2/7] feat(bank): autocli query support (#16899) --- CHANGELOG.md | 9 +- tests/e2e/auth/suite.go | 43 +- tests/e2e/bank/suite.go | 271 ----------- tests/e2e/gov/tx.go | 10 +- .../integration/auth/client/cli/suite_test.go | 4 +- testutil/cli/cmd.go | 8 - x/bank/autocli.go | 91 ++++ x/bank/client/cli/query.go | 350 -------------- x/bank/client/cli/query_test.go | 428 ------------------ x/bank/client/cli/suite_test.go | 39 -- x/bank/client/cli/tx_test.go | 31 ++ x/bank/keeper/grpc_query_test.go | 114 +++-- x/bank/module.go | 2 +- 13 files changed, 241 insertions(+), 1159 deletions(-) create mode 100644 x/bank/autocli.go delete mode 100644 x/bank/client/cli/query.go delete mode 100644 x/bank/client/cli/query_test.go delete mode 100644 x/bank/client/cli/suite_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index d3780e540802..c5a7c38582fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,7 +53,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes -* (x/auth) [#16650](https://github.com/cosmos/cosmos-sdk/pull/16650) The testutil `QueryAccountExec` has been removed from auth as it was using the CLI. +* (testutil) [#16899](https://github.com/cosmos/cosmos-sdk/pull/16899) The *cli testutil* `QueryBalancesExec` has been removed. Use the gRPC or REST query instead. +* (x/auth) [#16650](https://github.com/cosmos/cosmos-sdk/pull/16650) The *cli testutil* `QueryAccountExec` has been removed. Use the gRPC or REST query instead. * (types/math) [#16040](https://github.com/cosmos/cosmos-sdk/pull/16798) Remove aliases in `types/math.go` (part 2). * (x/distribution) [#16440](https://github.com/cosmos/cosmos-sdk/pull/16440) use collections for `DelegatorWithdrawAddresState`: * remove `Keeper`: `SetDelegatorWithdrawAddr`, `DeleteDelegatorWithdrawAddr`, `IterateDelegatorWithdrawAddrs`. @@ -71,6 +72,12 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/staking) [#16795](https://github.com/cosmos/cosmos-sdk/pull/16795) `DelegationToDelegationResponse`, `DelegationsToDelegationResponses`, `RedelegationsToRedelegationResponses` are no longer exported. * [#16441](https://github.com/cosmos/cosmos-sdk/pull/16441) Params state is migrated to collections. `GetParams` has been removed +## CLI Breaking Changes + +* (x/bank) [#16899](https://github.com/cosmos/cosmos-sdk/pull/16899) With the migration to AutoCLI some bank commands have been split in two: + * Use `denoms-metadata` for querying all denom metadata and `denom-metadata` for querying a specific denom metadata. + * Use `total-supply` (or `total`) for querying the total supply and `total-supply-of` for querying the supply of a specific denom. + ## [v0.50.0-alpha.1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0-alpha.1) - 2023-06-30 ### Features diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index 81df6f4b1e87..8209a6fd4a49 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -612,11 +612,11 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() { s.Require().NoError(err) s.Require().Equal(0, len(sigs)) - resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address, addresscodec.NewBech32Codec("cosmos")) + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, val1.Address)) s.Require().NoError(err) var balRes banktypes.QueryAllBalancesResponse - err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) + err = val1.ClientCtx.Codec.UnmarshalJSON(resp, &balRes) s.Require().NoError(err) startTokens := balRes.Balances.AmountOf(s.cfg.BondDenom) @@ -679,10 +679,9 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() { s.Require().NoError(s.network.WaitForNextBlock()) // Ensure foo has right amount of funds - resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address, addresscodec.NewBech32Codec("cosmos")) + resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, val1.Address)) s.Require().NoError(err) - - err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) + err = val1.ClientCtx.Codec.UnmarshalJSON(resp, &balRes) s.Require().NoError(err) s.Require().Equal(startTokens, balRes.Balances.AmountOf(s.cfg.BondDenom)) @@ -701,20 +700,20 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() { // Ensure destiny account state err = s.network.RetryForBlocks(func() error { - resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos")) + resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, addr)) + s.Require().NoError(err) return err }, 3) s.Require().NoError(err) - err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) + err = val1.ClientCtx.Codec.UnmarshalJSON(resp, &balRes) s.Require().NoError(err) s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom)) // Ensure origin account state - resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address, addresscodec.NewBech32Codec("cosmos")) + resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, val1.Address)) s.Require().NoError(err) - - err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) + err = val1.ClientCtx.Codec.UnmarshalJSON(resp, &balRes) s.Require().NoError(err) } @@ -833,11 +832,11 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() { addr, err := multisigRecord.GetAddress() s.Require().NoError(err) - resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos")) + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, addr)) s.Require().NoError(err) var balRes banktypes.QueryAllBalancesResponse - err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) + err = val1.ClientCtx.Codec.UnmarshalJSON(resp, &balRes) s.Require().NoError(err) intialCoins := balRes.Balances @@ -851,10 +850,9 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() { s.Require().NoError(err) s.Require().NoError(s.network.WaitForNextBlock()) - resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos")) + resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, addr)) s.Require().NoError(err) - - err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) + err = val1.ClientCtx.Codec.UnmarshalJSON(resp, &balRes) s.Require().NoError(err) diff, _ := balRes.Balances.SafeSub(intialCoins...) s.Require().Equal(sendTokens.Amount, diff.AmountOf(s.cfg.BondDenom)) @@ -993,11 +991,12 @@ func (s *E2ETestSuite) TestCLIMultisign() { var balRes banktypes.QueryAllBalancesResponse err = s.network.RetryForBlocks(func() error { - resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos")) + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, addr)) + s.Require().NoError(err) if err != nil { return err } - return val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) + return val1.ClientCtx.Codec.UnmarshalJSON(resp, &balRes) }, 3) s.Require().NoError(err) s.Require().True(sendTokens.Amount.Equal(balRes.Balances.AmountOf(s.cfg.BondDenom))) @@ -1393,10 +1392,10 @@ func (s *E2ETestSuite) TestSignWithMultiSignersAminoJSON() { require.Equal(uint32(0), txRes.Code, txRes.RawLog) // Make sure the addr1's balance got funded. - queryResJSON, err := clitestutil.QueryBalancesExec(val0.ClientCtx, addr1, addresscodec.NewBech32Codec("cosmos")) - require.NoError(err) + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val0.APIAddress, addr1)) + s.Require().NoError(err) var queryRes banktypes.QueryAllBalancesResponse - err = val0.ClientCtx.Codec.UnmarshalJSON(queryResJSON.Bytes(), &queryRes) + err = val0.ClientCtx.Codec.UnmarshalJSON(resp, &queryRes) require.NoError(err) require.Equal(sdk.NewCoins(val0Coin, val1Coin), queryRes.Balances) } @@ -1729,11 +1728,11 @@ func (s *E2ETestSuite) createBankMsg(val *network.Validator, toAddr sdk.AccAddre } func (s *E2ETestSuite) getBalances(clientCtx client.Context, addr sdk.AccAddress, denom string) math.Int { - resp, err := clitestutil.QueryBalancesExec(clientCtx, addr, addresscodec.NewBech32Codec("cosmos")) + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/by_denom?denom=%s", s.cfg.APIAddress, addr.String(), denom)) s.Require().NoError(err) var balRes banktypes.QueryAllBalancesResponse - err = clientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) + err = clientCtx.Codec.UnmarshalJSON(resp, &balRes) s.Require().NoError(err) startTokens := balRes.Balances.AmountOf(denom) return startTokens diff --git a/tests/e2e/bank/suite.go b/tests/e2e/bank/suite.go index 449d46a310e0..48b34f12b483 100644 --- a/tests/e2e/bank/suite.go +++ b/tests/e2e/bank/suite.go @@ -18,7 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/x/bank/client/cli" "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -96,276 +95,6 @@ func (s *E2ETestSuite) TearDownSuite() { s.network.Cleanup() } -func (s *E2ETestSuite) TestGetBalancesCmd() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectErr bool - respType proto.Message - expected proto.Message - }{ - {"no address provided", []string{}, true, nil, nil}, - { - "total account balance", - []string{ - val.Address.String(), - fmt.Sprintf("--%s=json", flags.FlagOutput), - fmt.Sprintf("--%s=1", flags.FlagHeight), - }, - false, - &types.QueryAllBalancesResponse{}, - &types.QueryAllBalancesResponse{ - Balances: sdk.NewCoins( - sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), s.cfg.AccountTokens), - sdk.NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Sub(s.cfg.BondedTokens)), - ), - Pagination: &query.PageResponse{}, - }, - }, - { - "total account balance of a specific denom", - []string{ - val.Address.String(), - fmt.Sprintf("--%s=json", flags.FlagOutput), - fmt.Sprintf("--%s=%s", cli.FlagDenom, s.cfg.BondDenom), - fmt.Sprintf("--%s=1", flags.FlagHeight), - }, - false, - &sdk.Coin{}, - NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Sub(s.cfg.BondedTokens)), - }, - { - "total account balance of a bogus denom", - []string{ - val.Address.String(), - fmt.Sprintf("--%s=foobar", cli.FlagDenom), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - false, - &sdk.Coin{}, - NewCoin("foobar", math.ZeroInt()), - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetBalancesCmd(addresscodec.NewBech32Codec("cosmos")) - out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, tc.args) - - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType)) - s.Require().Equal(tc.expected.String(), tc.respType.String()) - } - }) - } -} - -func (s *E2ETestSuite) TestGetCmdQueryTotalSupply() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectErr bool - respType proto.Message - expected proto.Message - }{ - { - name: "total supply", - args: []string{ - fmt.Sprintf("--%s=1", flags.FlagHeight), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - respType: &types.QueryTotalSupplyResponse{}, - expected: &types.QueryTotalSupplyResponse{ - Supply: sdk.NewCoins( - sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), s.cfg.AccountTokens), - sdk.NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Add(math.NewInt(10))), - ), - Pagination: &query.PageResponse{Total: 0}, - }, - }, - { - name: "total supply of a specific denomination", - args: []string{ - fmt.Sprintf("--%s=1", flags.FlagHeight), - fmt.Sprintf("--%s=%s", cli.FlagDenom, s.cfg.BondDenom), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - respType: &sdk.Coin{}, - expected: &sdk.Coin{ - Denom: s.cfg.BondDenom, - Amount: s.cfg.StakingTokens.Add(math.NewInt(10)), - }, - }, - { - name: "total supply of a bogus denom", - args: []string{ - fmt.Sprintf("--%s=1", flags.FlagHeight), - fmt.Sprintf("--%s=foobar", cli.FlagDenom), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - respType: &sdk.Coin{}, - expected: &sdk.Coin{ - Denom: "foobar", - Amount: math.ZeroInt(), - }, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryTotalSupply() - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType)) - s.Require().Equal(tc.expected, tc.respType) - } - }) - } -} - -func (s *E2ETestSuite) TestGetCmdQueryDenomsMetadata() { - val := s.network.Validators[0] - - testCases := []struct { - name string - args []string - expectErr bool - respType proto.Message - expected proto.Message - }{ - { - name: "all denoms client metadata", - args: []string{ - fmt.Sprintf("--%s=1", flags.FlagHeight), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - respType: &types.QueryDenomsMetadataResponse{}, - expected: &types.QueryDenomsMetadataResponse{ - Metadatas: []types.Metadata{ - { - Name: "Cosmos Hub Atom", - Symbol: "ATOM", - Description: "The native staking token of the Cosmos Hub.", - DenomUnits: []*types.DenomUnit{ - { - Denom: "uatom", - Exponent: 0, - Aliases: []string{"microatom"}, - }, - { - Denom: "atom", - Exponent: 6, - Aliases: []string{"ATOM"}, - }, - }, - Base: "uatom", - Display: "atom", - }, - { - Name: "Ethereum", - Symbol: "ETH", - Description: "Ethereum mainnet token", - DenomUnits: []*types.DenomUnit{ - { - Denom: "wei", - Exponent: 0, - Aliases: []string{}, - }, - { - Denom: "eth", - Exponent: 6, - Aliases: []string{"ETH"}, - }, - }, - Base: "wei", - Display: "eth", - }, - }, - Pagination: &query.PageResponse{Total: 2}, - }, - }, - { - name: "client metadata of a specific denomination", - args: []string{ - fmt.Sprintf("--%s=1", flags.FlagHeight), - fmt.Sprintf("--%s=%s", cli.FlagDenom, "uatom"), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - respType: &types.QueryDenomMetadataResponse{}, - expected: &types.QueryDenomMetadataResponse{ - Metadata: types.Metadata{ - Name: "Cosmos Hub Atom", - Symbol: "ATOM", - Description: "The native staking token of the Cosmos Hub.", - DenomUnits: []*types.DenomUnit{ - { - Denom: "uatom", - Exponent: 0, - Aliases: []string{"microatom"}, - }, - { - Denom: "atom", - Exponent: 6, - Aliases: []string{"ATOM"}, - }, - }, - Base: "uatom", - Display: "atom", - }, - }, - }, - { - name: "client metadata of a bogus denom", - args: []string{ - fmt.Sprintf("--%s=1", flags.FlagHeight), - fmt.Sprintf("--%s=foobar", cli.FlagDenom), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - expectErr: true, - respType: &types.QueryDenomMetadataResponse{}, - expected: &types.QueryDenomMetadataResponse{ - Metadata: types.Metadata{ - DenomUnits: []*types.DenomUnit{}, - }, - }, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdDenomsMetadata() - clientCtx := val.ClientCtx - - out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType)) - s.Require().Equal(tc.expected, tc.respType) - } - }) - } -} - func (s *E2ETestSuite) TestNewSendTxCmdGenOnly() { val := s.network.Validators[0] diff --git a/tests/e2e/gov/tx.go b/tests/e2e/gov/tx.go index 8d8d51f824f9..8c37f1342fd8 100644 --- a/tests/e2e/gov/tx.go +++ b/tests/e2e/gov/tx.go @@ -10,7 +10,6 @@ import ( "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/flags" - addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" @@ -353,9 +352,9 @@ func (s *E2ETestSuite) TestNewCmdCancelProposal() { var balRes banktypes.QueryAllBalancesResponse var newBalance banktypes.QueryAllBalancesResponse if !tc.expectErr && tc.expectedCode == 0 { - resp, err := clitestutil.QueryBalancesExec(clientCtx, val.Address, addresscodec.NewBech32Codec("cosmos")) + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val.APIAddress, val.Address.String())) s.Require().NoError(err) - err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) + err = val.ClientCtx.Codec.UnmarshalJSON(resp, &balRes) s.Require().NoError(err) } @@ -364,14 +363,13 @@ func (s *E2ETestSuite) TestNewCmdCancelProposal() { s.Require().Error(err) } else { s.Require().NoError(err) - s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String()) s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, tc.expectedCode)) if !tc.expectErr && tc.expectedCode == 0 { - resp, err := clitestutil.QueryBalancesExec(clientCtx, val.Address, addresscodec.NewBech32Codec("cosmos")) + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val.APIAddress, val.Address.String())) s.Require().NoError(err) - err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &newBalance) + err = val.ClientCtx.Codec.UnmarshalJSON(resp, &newBalance) s.Require().NoError(err) remainingAmount := v1.DefaultMinDepositTokens.Mul( v1.DefaultProposalCancelRatio.Mul(math.LegacyMustNewDecFromStr("100")).TruncateInt(), diff --git a/tests/integration/auth/client/cli/suite_test.go b/tests/integration/auth/client/cli/suite_test.go index ce81f4b2fd44..f618c64b8d6d 100644 --- a/tests/integration/auth/client/cli/suite_test.go +++ b/tests/integration/auth/client/cli/suite_test.go @@ -1242,11 +1242,11 @@ func (s *CLITestSuite) TestAuxToFeeWithTips() { } func (s *CLITestSuite) getBalances(clientCtx client.Context, addr sdk.AccAddress, denom string) math.Int { - resp, err := clitestutil.QueryBalancesExec(clientCtx, addr, s.ac) + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/by_denom?denom=%s", s.baseCtx.NodeURI, addr.String(), denom)) s.Require().NoError(err) var balRes banktypes.QueryAllBalancesResponse - err = clientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes) + err = clientCtx.Codec.UnmarshalJSON(resp, &balRes) s.Require().NoError(err) startTokens := balRes.Balances.AmountOf(denom) return startTokens diff --git a/testutil/cli/cmd.go b/testutil/cli/cmd.go index e9860c4d5272..57b5b11ee6e5 100644 --- a/testutil/cli/cmd.go +++ b/testutil/cli/cmd.go @@ -9,7 +9,6 @@ import ( "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/x/bank/client/cli" ) @@ -37,10 +36,3 @@ func MsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, ac add return ExecTestCLICmd(clientCtx, cli.NewSendTxCmd(ac), args) } - -func QueryBalancesExec(clientCtx client.Context, address fmt.Stringer, ac address.Codec, extraArgs ...string) (testutil.BufferWriter, error) { - args := []string{address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)} - args = append(args, extraArgs...) - - return ExecTestCLICmd(clientCtx, cli.GetBalancesCmd(ac), args) -} diff --git a/x/bank/autocli.go b/x/bank/autocli.go new file mode 100644 index 000000000000..6d839f94ca08 --- /dev/null +++ b/x/bank/autocli.go @@ -0,0 +1,91 @@ +package bank + +import ( + "strings" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" +) + +// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: bankv1beta1.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Balance", + Use: "balance [address] [denom]", + Short: "Query an account balance by address and denom", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}, {ProtoField: "denom"}}, + }, + { + RpcMethod: "AllBalances", + Use: "balances [address]", + Short: "Query for account balances by address", + Long: "Query the total balance of an account or of a specific denomination.", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}}, + }, + { + RpcMethod: "SpendableBalances", + Use: "spendable-balances [address]", + Short: "Query for account spendable balances by address", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}}, + }, + { + RpcMethod: "SpendableBalanceByDenom", + Use: "spendable-balances [address] [denom]", + Short: "Query the spendable balance of a single denom for a single account.", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}, {ProtoField: "denom"}}, + }, + { + RpcMethod: "TotalSupply", + Use: "total-supply", + Alias: []string{"total"}, + Short: "Query the total supply of coins of the chain", + Long: "Query total supply of coins that are held by accounts in the chain. To query for the total supply of a specific coin denomination use --denom flag.", + }, + { + RpcMethod: "SupplyOf", + Use: "total-supply-of [denom]", + Short: "Query the supply of a single coin denom", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "denom"}}, + }, + { + RpcMethod: "Params", + Use: "params", + Short: "Query the current bank parameters", + }, + { + RpcMethod: "DenomMetadata", + Use: "denom-metadata [denom]", + Short: "Query the client metadata of a given coin denomination", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "denom"}}, + }, + { + RpcMethod: "DenomsMetadata", + Use: "denoms-metadata", + Short: "Query the client metadata for all registered coin denominations", + }, + { + RpcMethod: "DenomOwners", + Use: "denom-owners [denom]", + Short: "Query for all account addresses that own a particular token denomination.", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "denom"}}, + }, + { + RpcMethod: "SendEnabled", + Use: "send-enabled [denom1 ...]", + Short: "Query for send enabled entries", + Long: strings.TrimSpace(`Query for send enabled entries that have been specifically set. + + To look up one or more specific denoms, supply them as arguments to this command. + To look up all denoms, do not provide any arguments. + `, + ), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "denoms"}}, + }, + }, + }, + } +} diff --git a/x/bank/client/cli/query.go b/x/bank/client/cli/query.go deleted file mode 100644 index 61950d88de45..000000000000 --- a/x/bank/client/cli/query.go +++ /dev/null @@ -1,350 +0,0 @@ -package cli - -import ( - "fmt" - "strings" - - "github.com/spf13/cobra" - - "cosmossdk.io/core/address" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/bank/types" -) - -const ( - FlagDenom = "denom" - FlagResolveDenom = "resolve-denom" -) - -// GetQueryCmd returns the parent command for all x/bank CLi query commands. The -// provided clientCtx should have, at a minimum, a verifier, CometBFT RPC client, -// and marshaler set. -func GetQueryCmd(ac address.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Querying commands for the bank module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand( - GetBalancesCmd(ac), - GetSpendableBalancesCmd(ac), - GetCmdQueryTotalSupply(), - GetCmdDenomsMetadata(), - GetCmdQuerySendEnabled(), - ) - - return cmd -} - -func GetBalancesCmd(ac address.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "balances [address]", - Short: "Query for account balances by address", - Long: strings.TrimSpace( - fmt.Sprintf(`Query the total balance of an account or of a specific denomination. - -Example: - $ %s query %s balances [address] - $ %s query %s balances [address] --denom=[denom] - $ %s query %s balances [address] --resolve-denom -`, - version.AppName, types.ModuleName, version.AppName, types.ModuleName, version.AppName, types.ModuleName, - ), - ), - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - denom, err := cmd.Flags().GetString(FlagDenom) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - addr, err := ac.StringToBytes(args[0]) - if err != nil { - return err - } - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - ctx := cmd.Context() - - if denom == "" { - resolveDenom, err := cmd.Flags().GetBool(FlagResolveDenom) - if err != nil { - return err - } - - params := types.NewQueryAllBalancesRequest(addr, pageReq, resolveDenom) - - res, err := queryClient.AllBalances(ctx, params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - } - - params := types.NewQueryBalanceRequest(addr, denom) - - res, err := queryClient.Balance(ctx, params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res.Balance) - }, - } - - cmd.Flags().String(FlagDenom, "", "The specific balance denomination to query for") - cmd.Flags().Bool(FlagResolveDenom, false, "Resolve denom to human-readable denom from metadata") - flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "all balances") - - return cmd -} - -func GetSpendableBalancesCmd(ac address.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "spendable-balances [address]", - Short: "Query for account spendable balances by address", - Example: fmt.Sprintf("$ %s query %s spendable-balances [address]", version.AppName, types.ModuleName), - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - denom, err := cmd.Flags().GetString(FlagDenom) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - addr, err := ac.StringToBytes(args[0]) - if err != nil { - return err - } - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - ctx := cmd.Context() - - if denom == "" { - params := types.NewQuerySpendableBalancesRequest(addr, pageReq) - - res, err := queryClient.SpendableBalances(ctx, params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - } - - params := types.NewQuerySpendableBalanceByDenomRequest(addr, denom) - - res, err := queryClient.SpendableBalanceByDenom(ctx, params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - cmd.Flags().String(FlagDenom, "", "The specific balance denomination to query for") - flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "spendable balances") - - return cmd -} - -// GetCmdDenomsMetadata defines the cobra command to query client denomination metadata. -func GetCmdDenomsMetadata() *cobra.Command { - cmd := &cobra.Command{ - Use: "denom-metadata", - Short: "Query the client metadata for coin denominations", - Long: strings.TrimSpace( - fmt.Sprintf(`Query the client metadata for all the registered coin denominations - -Example: - To query for the client metadata of all coin denominations use: - $ %s query %s denom-metadata - -To query for the client metadata of a specific coin denomination use: - $ %s query %s denom-metadata --denom=[denom] -`, - version.AppName, types.ModuleName, version.AppName, types.ModuleName, - ), - ), - RunE: func(cmd *cobra.Command, _ []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - denom, err := cmd.Flags().GetString(FlagDenom) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - if denom == "" { - res, err := queryClient.DenomsMetadata(cmd.Context(), &types.QueryDenomsMetadataRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - } - - res, err := queryClient.DenomMetadata(cmd.Context(), &types.QueryDenomMetadataRequest{Denom: denom}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - cmd.Flags().String(FlagDenom, "", "The specific denomination to query client metadata for") - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -func GetCmdQueryTotalSupply() *cobra.Command { - cmd := &cobra.Command{ - Use: "total", - Short: "Query the total supply of coins of the chain", - Args: cobra.NoArgs, - Long: strings.TrimSpace( - fmt.Sprintf(`Query total supply of coins that are held by accounts in the chain. - -Example: - $ %s query %s total - -To query for the total supply of a specific coin denomination use: - $ %s query %s total --denom=[denom] -`, - version.AppName, types.ModuleName, version.AppName, types.ModuleName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - denom, err := cmd.Flags().GetString(FlagDenom) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - ctx := cmd.Context() - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - if denom == "" { - res, err := queryClient.TotalSupply(ctx, &types.QueryTotalSupplyRequest{Pagination: pageReq}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - } - - res, err := queryClient.SupplyOf(ctx, &types.QuerySupplyOfRequest{Denom: denom}) - if err != nil { - return err - } - - return clientCtx.PrintProto(&res.Amount) - }, - } - - cmd.Flags().String(FlagDenom, "", "The specific balance denomination to query for") - flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "all supply totals") - - return cmd -} - -func GetCmdQuerySendEnabled() *cobra.Command { - cmd := &cobra.Command{ - Use: "send-enabled [denom1 ...]", - Short: "Query for send enabled entries", - Long: strings.TrimSpace(`Query for send enabled entries that have been specifically set. - -To look up one or more specific denoms, supply them as arguments to this command. -To look up all denoms, do not provide any arguments. -`, - ), - Example: strings.TrimSpace( - fmt.Sprintf(`Getting one specific entry: - $ %[1]s query %[2]s send-enabled foocoin - -Getting two specific entries: - $ %[1]s query %[2]s send-enabled foocoin barcoin - -Getting all entries: - $ %[1]s query %[2]s send-enabled -`, - version.AppName, types.ModuleName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - reqPag, err := client.ReadPageRequest(client.MustFlagSetWithPageKeyDecoded(cmd.Flags())) - if err != nil { - return err - } - - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - req := &types.QuerySendEnabledRequest{ - Denoms: args, - Pagination: reqPag, - } - - res, err := queryClient.SendEnabled(cmd.Context(), req) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "send enabled entries") - - return cmd -} diff --git a/x/bank/client/cli/query_test.go b/x/bank/client/cli/query_test.go deleted file mode 100644 index 800530b53d18..000000000000 --- a/x/bank/client/cli/query_test.go +++ /dev/null @@ -1,428 +0,0 @@ -package cli_test - -import ( - "context" - "fmt" - "io" - - abci "github.com/cometbft/cometbft/abci/types" - "github.com/cosmos/gogoproto/proto" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec/address" - 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" - "github.com/cosmos/cosmos-sdk/x/bank/client/cli" - "github.com/cosmos/cosmos-sdk/x/bank/types" -) - -func (s *CLITestSuite) TestGetBalancesCmd() { - accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) - cmd := cli.GetBalancesCmd(address.NewBech32Codec("cosmos")) - cmd.SetOutput(io.Discard) - - testCases := []struct { - name string - ctxGen func() client.Context - args []string - expectResult proto.Message - expectErr bool - }{ - { - "valid query", - func() client.Context { - bz, _ := s.encCfg.Codec.Marshal(&types.QueryAllBalancesResponse{}) - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Value: bz, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - accounts[0].Address.String(), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - &types.QueryAllBalancesResponse{}, - false, - }, - { - "valid query with denom", - func() client.Context { - bz, _ := s.encCfg.Codec.Marshal(&types.QueryBalanceResponse{ - Balance: &sdk.Coin{}, - }) - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Value: bz, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - accounts[0].Address.String(), - fmt.Sprintf("--%s=photon", cli.FlagDenom), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - &sdk.Coin{}, - false, - }, - { - "invalid Address", - func() client.Context { - return s.baseCtx - }, - []string{ - "foo", - }, - nil, - true, - }, - { - "invalid denom", - func() client.Context { - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Code: 1, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - accounts[0].Address.String(), - fmt.Sprintf("--%s=foo", cli.FlagDenom), - }, - nil, - true, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - - cmd.SetContext(ctx) - cmd.SetArgs(tc.args) - - s.Require().NoError(client.SetCmdClientContextHandler(tc.ctxGen(), cmd)) - - out, err := clitestutil.ExecTestCLICmd(tc.ctxGen(), cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(s.encCfg.Codec.UnmarshalJSON(out.Bytes(), tc.expectResult)) - s.Require().NoError(err) - } - }) - } -} - -func (s *CLITestSuite) TestGetSpendableBalancesCmd() { - accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) - - cmd := cli.GetSpendableBalancesCmd(address.NewBech32Codec("cosmos")) - cmd.SetOutput(io.Discard) - - testCases := []struct { - name string - ctxGen func() client.Context - args []string - expectResult proto.Message - expectErr bool - }{ - { - "valid query", - func() client.Context { - bz, _ := s.encCfg.Codec.Marshal(&types.QuerySpendableBalancesResponse{}) - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Value: bz, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - accounts[0].Address.String(), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - &types.QuerySpendableBalancesResponse{}, - false, - }, - { - "valid query with denom flag", - func() client.Context { - bz, _ := s.encCfg.Codec.Marshal(&types.QuerySpendableBalanceByDenomRequest{}) - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Value: bz, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - accounts[0].Address.String(), - fmt.Sprintf("--%s=json", flags.FlagOutput), - fmt.Sprintf("--%s=photon", cli.FlagDenom), - }, - &types.QuerySpendableBalanceByDenomResponse{}, - false, - }, - { - "invalid Address", - func() client.Context { - return s.baseCtx - }, - []string{ - "foo", - }, - nil, - true, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - cmd.SetContext(ctx) - cmd.SetArgs(tc.args) - s.Require().NoError(client.SetCmdClientContextHandler(tc.ctxGen(), cmd)) - - out, err := clitestutil.ExecTestCLICmd(tc.ctxGen(), cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(s.encCfg.Codec.UnmarshalJSON(out.Bytes(), tc.expectResult)) - s.Require().NoError(err) - } - }) - } -} - -func (s *CLITestSuite) TestGetCmdDenomsMetadata() { - cmd := cli.GetCmdDenomsMetadata() - cmd.SetOutput(io.Discard) - - testCases := []struct { - name string - ctxGen func() client.Context - args []string - expectResult proto.Message - expectErr bool - }{ - { - "valid query", - func() client.Context { - bz, _ := s.encCfg.Codec.Marshal(&types.QueryDenomsMetadataResponse{}) - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Value: bz, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - &types.QueryDenomsMetadataResponse{}, - false, - }, - { - "valid query with denom", - func() client.Context { - bz, _ := s.encCfg.Codec.Marshal(&types.QueryDenomMetadataResponse{}) - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Value: bz, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - fmt.Sprintf("--%s=photon", cli.FlagDenom), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - &types.QueryDenomMetadataResponse{}, - false, - }, - { - "invalid query with denom", - func() client.Context { - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Code: 1, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - fmt.Sprintf("--%s=foo", cli.FlagDenom), - }, - nil, - true, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - - cmd.SetContext(ctx) - cmd.SetArgs(tc.args) - - s.Require().NoError(client.SetCmdClientContextHandler(tc.ctxGen(), cmd)) - - out, err := clitestutil.ExecTestCLICmd(tc.ctxGen(), cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(s.encCfg.Codec.UnmarshalJSON(out.Bytes(), tc.expectResult)) - s.Require().NoError(err) - } - }) - } -} - -func (s *CLITestSuite) TestGetCmdQueryTotalSupply() { - cmd := cli.GetCmdQueryTotalSupply() - cmd.SetOutput(io.Discard) - - testCases := []struct { - name string - ctxGen func() client.Context - args []string - expectResult proto.Message - expectErr bool - }{ - { - "valid query", - func() client.Context { - bz, _ := s.encCfg.Codec.Marshal(&types.QueryTotalSupplyResponse{}) - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Value: bz, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - &types.QueryTotalSupplyResponse{}, - false, - }, - { - "valid query with denom", - func() client.Context { - bz, _ := s.encCfg.Codec.Marshal(&types.QuerySupplyOfResponse{ - Amount: sdk.Coin{}, - }) - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Value: bz, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - fmt.Sprintf("--%s=photon", cli.FlagDenom), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - &sdk.Coin{}, - false, - }, - { - "invalid query with denom", - func() client.Context { - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Code: 1, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - fmt.Sprintf("--%s=foo", cli.FlagDenom), - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - nil, - true, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - cmd.SetContext(ctx) - cmd.SetArgs(tc.args) - s.Require().NoError(client.SetCmdClientContextHandler(tc.ctxGen(), cmd)) - - out, err := clitestutil.ExecTestCLICmd(tc.ctxGen(), cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(s.encCfg.Codec.UnmarshalJSON(out.Bytes(), tc.expectResult)) - s.Require().NoError(err) - } - }) - } -} - -func (s *CLITestSuite) TestGetCmdQuerySendEnabled() { - cmd := cli.GetCmdQuerySendEnabled() - cmd.SetOutput(io.Discard) - - testCases := []struct { - name string - ctxGen func() client.Context - args []string - expectResult proto.Message - expectErr bool - }{ - { - "valid query", - func() client.Context { - bz, _ := s.encCfg.Codec.Marshal(&types.QuerySendEnabledResponse{ - SendEnabled: []*types.SendEnabled{}, - }) - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Value: bz, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - &types.QuerySendEnabledResponse{}, - false, - }, - { - "valid query with denoms", - func() client.Context { - bz, _ := s.encCfg.Codec.Marshal(&types.QuerySendEnabledResponse{ - SendEnabled: []*types.SendEnabled{}, - }) - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Value: bz, - }) - return s.baseCtx.WithClient(c) - }, - []string{ - "photon", - "stake", - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - &types.QuerySendEnabledResponse{}, - false, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - ctx := svrcmd.CreateExecuteContext(context.Background()) - - cmd.SetContext(ctx) - cmd.SetArgs(tc.args) - - s.Require().NoError(client.SetCmdClientContextHandler(tc.ctxGen(), cmd)) - - out, err := clitestutil.ExecTestCLICmd(tc.ctxGen(), cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(s.encCfg.Codec.UnmarshalJSON(out.Bytes(), tc.expectResult)) - s.Require().NoError(err) - } - }) - } -} diff --git a/x/bank/client/cli/suite_test.go b/x/bank/client/cli/suite_test.go deleted file mode 100644 index 9ba83b31b662..000000000000 --- a/x/bank/client/cli/suite_test.go +++ /dev/null @@ -1,39 +0,0 @@ -package cli_test - -import ( - "io" - "testing" - - rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" - "github.com/stretchr/testify/suite" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/cosmos/cosmos-sdk/x/bank" -) - -type CLITestSuite struct { - suite.Suite - - kr keyring.Keyring - encCfg testutilmod.TestEncodingConfig - baseCtx client.Context -} - -func TestCLITestSuite(t *testing.T) { - suite.Run(t, new(CLITestSuite)) -} - -func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(bank.AppModuleBasic{}) - s.kr = keyring.NewInMemory(s.encCfg.Codec) - s.baseCtx = client.Context{}. - WithKeyring(s.kr). - WithTxConfig(s.encCfg.TxConfig). - WithCodec(s.encCfg.Codec). - WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}). - WithAccountRetriever(client.MockAccountRetriever{}). - WithOutput(io.Discard) -} diff --git a/x/bank/client/cli/tx_test.go b/x/bank/client/cli/tx_test.go index 1391ba835298..a9a5280f0bff 100644 --- a/x/bank/client/cli/tx_test.go +++ b/x/bank/client/cli/tx_test.go @@ -4,19 +4,50 @@ import ( "context" "fmt" "io" + "testing" + + rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" + "github.com/stretchr/testify/suite" sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "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/bank" "github.com/cosmos/cosmos-sdk/x/bank/client/cli" ) +type CLITestSuite struct { + suite.Suite + + kr keyring.Keyring + encCfg testutilmod.TestEncodingConfig + baseCtx client.Context +} + +func TestCLITestSuite(t *testing.T) { + suite.Run(t, new(CLITestSuite)) +} + +func (s *CLITestSuite) SetupSuite() { + s.encCfg = testutilmod.MakeTestEncodingConfig(bank.AppModuleBasic{}) + s.kr = keyring.NewInMemory(s.encCfg.Codec) + s.baseCtx = client.Context{}. + WithKeyring(s.kr). + WithTxConfig(s.encCfg.TxConfig). + WithCodec(s.encCfg.Codec). + WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}). + WithAccountRetriever(client.MockAccountRetriever{}). + WithOutput(io.Discard) +} + func (s *CLITestSuite) TestSendTxCmd() { accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1) cmd := cli.NewSendTxCmd(address.NewBech32Codec("cosmos")) diff --git a/x/bank/keeper/grpc_query_test.go b/x/bank/keeper/grpc_query_test.go index 2a7585e5f509..0a72fab3deb2 100644 --- a/x/bank/keeper/grpc_query_test.go +++ b/x/bank/keeper/grpc_query_test.go @@ -18,31 +18,81 @@ func (suite *KeeperTestSuite) TestQueryBalance() { ctx, queryClient := suite.ctx, suite.queryClient _, _, addr := testdata.KeyTestPubAddr() - _, err := queryClient.Balance(gocontext.Background(), &types.QueryBalanceRequest{}) - suite.Require().Error(err) - - _, err = queryClient.Balance(gocontext.Background(), &types.QueryBalanceRequest{Address: addr.String()}) - suite.Require().Error(err) - - req := types.NewQueryBalanceRequest(addr, "0000") - _, err = queryClient.Balance(gocontext.Background(), req) - suite.Require().Error(err) + origCoins := sdk.NewCoins(newBarCoin(30)) + suite.mockFundAccount(addr) + suite.Require().NoError(testutil.FundAccount(ctx, suite.bankKeeper, addr, origCoins)) - req = types.NewQueryBalanceRequest(addr, fooDenom) - res, err := queryClient.Balance(gocontext.Background(), req) - suite.Require().NoError(err) - suite.Require().NotNil(res) - suite.True(res.Balance.IsZero()) + testCases := []struct { + name string + req *types.QueryBalanceRequest + expectErrMsg string + postFn func(res *types.QueryBalanceResponse) + }{ + { + "empty request", + &types.QueryBalanceRequest{}, + "invalid denom", + nil, + }, + { + "invalid denom", + types.NewQueryBalanceRequest(addr, "0000"), + "invalid denom", + nil, + }, + { + "empty address", + types.NewQueryBalanceRequest(sdk.AccAddress{}, barDenom), + "empty address string is not allowed", + nil, + }, + { + "invalid address", + &types.QueryBalanceRequest{Address: "foo", Denom: barDenom}, + "invalid address", + nil, + }, + { + "query missing denom", + &types.QueryBalanceRequest{Address: addr.String()}, + "invalid denom", + nil, + }, + { + "valid query empty result", + types.NewQueryBalanceRequest(addr, fooDenom), + "", + func(res *types.QueryBalanceResponse) { + suite.True(res.Balance.IsZero()) + }, + }, + { + "valid query", + types.NewQueryBalanceRequest(addr, barDenom), + "", + func(res *types.QueryBalanceResponse) { + suite.True(res.Balance.IsEqual(newBarCoin(30))) + }, + }, + } - origCoins := sdk.NewCoins(newFooCoin(50), newBarCoin(30)) + for _, tc := range testCases { + tc := tc - suite.mockFundAccount(addr) - suite.Require().NoError(testutil.FundAccount(ctx, suite.bankKeeper, addr, origCoins)) + suite.Run(tc.name, func() { + res, err := queryClient.Balance(gocontext.Background(), tc.req) + if tc.expectErrMsg == "" { + suite.Require().NoError(err) + suite.Require().NotNil(res) + } else { + suite.Require().ErrorContains(err, tc.expectErrMsg) + } - res, err = queryClient.Balance(gocontext.Background(), req) - suite.Require().NoError(err) - suite.Require().NotNil(res) - suite.True(res.Balance.IsEqual(newFooCoin(50))) + if tc.postFn != nil { + tc.postFn(res) + } + }) + } } func (suite *KeeperTestSuite) TestQueryAllBalances() { @@ -230,13 +280,12 @@ func (suite *KeeperTestSuite) TestQueryTotalSupply() { ctx, queryClient := suite.ctx, suite.queryClient res, err := queryClient.TotalSupply(gocontext.Background(), &types.QueryTotalSupplyRequest{}) suite.Require().NoError(err) + suite.Require().NotNil(res) genesisSupply := res.Supply testCoins := sdk.NewCoins(sdk.NewInt64Coin("test", 400000000)) suite.mockMintCoins(mintAcc) - suite. - Require(). - NoError(suite.bankKeeper.MintCoins(ctx, types.MintModuleName, testCoins)) + suite.Require().NoError(suite.bankKeeper.MintCoins(ctx, types.MintModuleName, testCoins)) res, err = queryClient.TotalSupply(gocontext.Background(), &types.QueryTotalSupplyRequest{}) suite.Require().NoError(err) @@ -255,9 +304,7 @@ func (suite *KeeperTestSuite) TestQueryTotalSupplyOf() { expectedTotalSupply := sdk.NewCoins(test1Supply, test2Supply) suite.mockMintCoins(mintAcc) - suite. - Require(). - NoError(suite.bankKeeper.MintCoins(ctx, types.MintModuleName, expectedTotalSupply)) + suite.Require().NoError(suite.bankKeeper.MintCoins(ctx, types.MintModuleName, expectedTotalSupply)) _, err := queryClient.SupplyOf(gocontext.Background(), &types.QuerySupplyOfRequest{}) suite.Require().Error(err) @@ -265,8 +312,13 @@ func (suite *KeeperTestSuite) TestQueryTotalSupplyOf() { res, err := queryClient.SupplyOf(gocontext.Background(), &types.QuerySupplyOfRequest{Denom: test1Supply.Denom}) suite.Require().NoError(err) suite.Require().NotNil(res) - suite.Require().Equal(test1Supply, res.Amount) + + // total supply bogus denom + res, err = queryClient.SupplyOf(gocontext.Background(), &types.QuerySupplyOfRequest{Denom: "bogus"}) + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(sdk.NewInt64Coin("bogus", 0), res.Amount) } func (suite *KeeperTestSuite) TestQueryParams() { @@ -276,7 +328,7 @@ func (suite *KeeperTestSuite) TestQueryParams() { suite.Require().Equal(suite.bankKeeper.GetParams(suite.ctx), res.GetParams()) } -func (suite *KeeperTestSuite) TestQueryDenomsMetadataRequest() { +func (suite *KeeperTestSuite) TestQueryDenomsMetadata() { var ( req *types.QueryDenomsMetadataRequest expMetadata = []types.Metadata(nil) @@ -378,7 +430,7 @@ func (suite *KeeperTestSuite) TestQueryDenomsMetadataRequest() { } } -func (suite *KeeperTestSuite) TestQueryDenomMetadataRequest() { +func (suite *KeeperTestSuite) TestQueryDenomMetadata() { var ( req *types.QueryDenomMetadataRequest expMetadata = types.Metadata{} @@ -455,7 +507,7 @@ func (suite *KeeperTestSuite) TestQueryDenomMetadataRequest() { } } -func (suite *KeeperTestSuite) TestGRPCDenomOwners() { +func (suite *KeeperTestSuite) TestQueryDenomOwners() { ctx := suite.ctx keeper := suite.bankKeeper diff --git a/x/bank/module.go b/x/bank/module.go index 67661837b4b3..ef52a77fd1fa 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -86,7 +86,7 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command { // GetQueryCmd returns no root query command for the bank module. func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd(ab.ac) + return nil } // RegisterInterfaces registers interfaces and implementations of the bank module. From 217bb1001e8d8e65018c6f772749dcede0cb72a3 Mon Sep 17 00:00:00 2001 From: Elias Naur <103319121+elias-orijtech@users.noreply.github.com> Date: Mon, 10 Jul 2023 14:38:32 +0200 Subject: [PATCH 3/7] perf: benchmark end-to-end transaction submit (#16717) --- tests/e2e/tx/benchmarks_test.go | 191 ++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 tests/e2e/tx/benchmarks_test.go diff --git a/tests/e2e/tx/benchmarks_test.go b/tests/e2e/tx/benchmarks_test.go new file mode 100644 index 000000000000..e323ddb91e26 --- /dev/null +++ b/tests/e2e/tx/benchmarks_test.go @@ -0,0 +1,191 @@ +package tx_test + +import ( + "context" + "fmt" + "testing" + + "gotest.tools/v3/assert" + + sdkmath "cosmossdk.io/math" + "cosmossdk.io/simapp" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + clienttx "github.com/cosmos/cosmos-sdk/client/tx" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/cosmos/cosmos-sdk/testutil/network" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + authclient "github.com/cosmos/cosmos-sdk/x/auth/client" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" +) + +type E2EBenchmarkSuite struct { + cfg network.Config + network *network.Network + + txHeight int64 + queryClient tx.ServiceClient + txRes sdk.TxResponse +} + +// BenchmarkTx is lifted from E2ETestSuite from this package, with irrelevant state checks removed. +// +// Benchmark results: +// +// On a M1 macOS, on commit ab77fe20d3c00ef4cb73dfd0c803c4593a3c8233: +// +// BenchmarkTx-8 4108 268935 ns/op +// +// By comparison, the benchmark modified for v0.47.0: +// +// BenchmarkTx-8 3772 301750 ns/op +func BenchmarkTx(b *testing.B) { + s := NewE2EBenchmarkSuite(b) + b.Cleanup(s.Close) + + val := s.network.Validators[0] + txBuilder := mkTxBuilder(b, s) + // Convert the txBuilder to a tx.Tx. + protoTx, err := txBuilderToProtoTx(txBuilder) + assert.NilError(b, err) + // Encode the txBuilder to txBytes. + txBytes, err := val.ClientCtx.TxConfig.TxEncoder()(txBuilder.GetTx()) + assert.NilError(b, err) + + testCases := []struct { + name string + req *tx.SimulateRequest + }{ + {"valid request with proto tx (deprecated)", &tx.SimulateRequest{Tx: protoTx}}, + {"valid request with tx_bytes", &tx.SimulateRequest{TxBytes: txBytes}}, + } + + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + for _, tc := range testCases { + // Broadcast the tx via gRPC via the validator's clientCtx (which goes + // through Tendermint). + res, err := s.queryClient.Simulate(context.Background(), tc.req) + assert.NilError(b, err) + // Check the result and gas used are correct. + // + // The 12 events are: + // - Sending Fee to the pool: coin_spent, coin_received, transfer and message.sender= + // - tx.* events: tx.fee, tx.acc_seq, tx.signature + // - Sending Amount to recipient: coin_spent, coin_received, transfer and message.sender= + // - Msg events: message.module=bank and message.action=/cosmos.bank.v1beta1.MsgSend (in one message) + assert.Equal(b, 12, len(res.GetResult().GetEvents())) + assert.Assert(b, res.GetGasInfo().GetGasUsed() > 0) // Gas used sometimes change, just check it's not empty. + } + } +} + +func NewE2EBenchmarkSuite(tb testing.TB) *E2EBenchmarkSuite { + tb.Helper() + + s := new(E2EBenchmarkSuite) + + cfg := network.DefaultConfig(simapp.NewTestNetworkFixture) + cfg.NumValidators = 1 + s.cfg = cfg + + var err error + s.network, err = network.New(tb, tb.TempDir(), s.cfg) + assert.NilError(tb, err) + + val := s.network.Validators[0] + assert.NilError(tb, s.network.WaitForNextBlock()) + + s.queryClient = tx.NewServiceClient(val.ClientCtx) + + // Create a new MsgSend tx from val to itself. + out, err := cli.MsgSendExec( + val.ClientCtx, + val.Address, + val.Address, + sdk.NewCoins( + sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10)), + ), + addresscodec.NewBech32Codec("cosmos"), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), + fmt.Sprintf("--gas=%d", flags.DefaultGasLimit), + fmt.Sprintf("--%s=foobar", flags.FlagNote), + ) + assert.NilError(tb, err) + assert.NilError(tb, val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &s.txRes)) + assert.Equal(tb, uint32(0), s.txRes.Code, s.txRes) + + out, err = cli.MsgSendExec( + val.ClientCtx, + val.Address, + val.Address, + sdk.NewCoins( + sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(1)), + ), + addresscodec.NewBech32Codec("cosmos"), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s", flags.FlagOffline), + fmt.Sprintf("--%s=0", flags.FlagAccountNumber), + fmt.Sprintf("--%s=2", flags.FlagSequence), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), + fmt.Sprintf("--gas=%d", flags.DefaultGasLimit), + fmt.Sprintf("--%s=foobar", flags.FlagNote), + ) + assert.NilError(tb, err) + var tr sdk.TxResponse + assert.NilError(tb, val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &tr)) + assert.Equal(tb, uint32(0), tr.Code) + + resp, err := cli.GetTxResponse(s.network, val.ClientCtx, tr.TxHash) + assert.NilError(tb, err) + s.txHeight = resp.Height + return s +} + +func (s *E2EBenchmarkSuite) Close() { + s.network.Cleanup() +} + +func mkTxBuilder(tb testing.TB, s *E2EBenchmarkSuite) client.TxBuilder { + tb.Helper() + + val := s.network.Validators[0] + assert.NilError(tb, s.network.WaitForNextBlock()) + + // prepare txBuilder with msg + txBuilder := val.ClientCtx.TxConfig.NewTxBuilder() + feeAmount := sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)} + gasLimit := testdata.NewTestGasLimit() + assert.NilError(tb, + txBuilder.SetMsgs(&banktypes.MsgSend{ + FromAddress: val.Address.String(), + ToAddress: val.Address.String(), + Amount: sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)}, + }), + ) + txBuilder.SetFeeAmount(feeAmount) + txBuilder.SetGasLimit(gasLimit) + txBuilder.SetMemo("foobar") + + // setup txFactory + txFactory := clienttx.Factory{}. + WithChainID(val.ClientCtx.ChainID). + WithKeybase(val.ClientCtx.Keyring). + WithTxConfig(val.ClientCtx.TxConfig). + WithSignMode(signing.SignMode_SIGN_MODE_DIRECT) + + // Sign Tx. + err := authclient.SignTx(txFactory, val.ClientCtx, val.Moniker, txBuilder, false, true) + assert.NilError(tb, err) + + return txBuilder +} From f3e4697195ff2c62a8843460f99cae19d3adab6f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 10 Jul 2023 15:36:22 +0200 Subject: [PATCH 4/7] feat!: simplify `AppModuleBasic` interface for CLI (#16890) --- CHANGELOG.md | 1 + UPGRADING.md | 26 ++-- .../building-modules/01-module-manager.md | 6 +- .../building-modules/09-module-interfaces.md | 17 +-- docs/docs/core/03-node.md | 2 +- docs/docs/core/07-cli.md | 40 +++++-- scripts/mockgen.sh | 2 +- testutil/mock/types_mock_appmodule.go | 29 ----- testutil/mock/types_module_module.go | 113 ------------------ tools/confix/README.md | 2 +- tools/rosetta/README.md | 2 +- types/module/module.go | 20 ++-- types/module/module_test.go | 10 +- x/auth/module.go | 11 -- x/auth/vesting/module.go | 5 - x/bank/module.go | 5 - x/consensus/module.go | 11 -- x/crisis/module.go | 3 - x/distribution/module.go | 5 - x/evidence/go.mod | 5 +- x/evidence/go.sum | 10 +- x/evidence/module.go | 5 - x/feegrant/go.mod | 4 +- x/feegrant/go.sum | 8 +- x/feegrant/module/module.go | 5 - x/genutil/module.go | 7 -- x/mint/module.go | 9 -- x/nft/go.mod | 5 +- x/nft/go.sum | 10 +- x/nft/module/module.go | 6 - x/params/module.go | 3 - x/staking/module.go | 5 - 32 files changed, 102 insertions(+), 290 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5a7c38582fc..5e9609791e2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (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. * (x/authz) [#16869](https://github.com/cosmos/cosmos-sdk/pull/16869) Error message has been improvised in `Exec` command when grant not found. diff --git a/UPGRADING.md b/UPGRADING.md index 8c049ea967f5..a109cbd127d3 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -222,23 +222,25 @@ The return type of the interface method `TxConfig.SignModeHandler()` has been ch #### `**all**` -[RFC 001](https://docs.cosmos.network/main/rfc/rfc-001-tx-validation) has defined a simplification of the message validation process for modules. +* [RFC 001](https://docs.cosmos.network/main/rfc/rfc-001-tx-validation) has defined a simplification of the message validation process for modules. The `sdk.Msg` interface has been updated to not require the implementation of the `ValidateBasic` method. It is now recommended to validate message directly in the message server. When the validation is performed in the message server, the `ValidateBasic` method on a message is no longer required and can be removed. -Messages no longer need to implement the `LegacyMsg` interface and implementations of `GetSignBytes` can be deleted. Because of this change, global legacy Amino codec definitions and their registration in `init()` can safely be removed as well. +* Messages no longer need to implement the `LegacyMsg` interface and implementations of `GetSignBytes` can be deleted. Because of this change, global legacy Amino codec definitions and their registration in `init()` can safely be removed as well. -The following modules' `Keeper` methods now take in a `context.Context` instead of `sdk.Context`. Any module that has an interfaces for them (like "expected keepers") will need to update and re-generate mocks if needed: +* The `AppModuleBasic` interface has been simplifed. Defining `GetTxCmd() *cobra.Command` and `GetQueryCmd() *cobra.Command` is no longer required. The module manager registers detects when module commands are defined. If AutoCLI is enabled, `EnhanceRootCommand()` will add the auto-generated commands to the root command, unless a custom module command is defined and register that one instead. -* `x/authz` -* `x/bank` -* `x/mint` -* `x/crisis` -* `x/distribution` -* `x/evidence` -* `x/gov` -* `x/slashing` -* `x/upgrade` +* The following modules' `Keeper` methods now take in a `context.Context` instead of `sdk.Context`. Any module that has an interfaces for them (like "expected keepers") will need to update and re-generate mocks if needed: + + * `x/authz` + * `x/bank` + * `x/mint` + * `x/crisis` + * `x/distribution` + * `x/evidence` + * `x/gov` + * `x/slashing` + * `x/upgrade` #### `x/auth` diff --git a/docs/docs/building-modules/01-module-manager.md b/docs/docs/building-modules/01-module-manager.md index 86d1f345e36e..15d0e85053cc 100644 --- a/docs/docs/building-modules/01-module-manager.md +++ b/docs/docs/building-modules/01-module-manager.md @@ -59,8 +59,6 @@ Let us go through the methods: * `RegisterLegacyAminoCodec(*codec.LegacyAmino)`: Registers the `amino` codec for the module, which is used to marshal and unmarshal structs to/from `[]byte` in order to persist them in the module's `KVStore`. * `RegisterInterfaces(codectypes.InterfaceRegistry)`: Registers a module's interface types and their concrete implementations as `proto.Message`. * `RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux)`: Registers gRPC routes for the module. -* `GetTxCmd()`: Returns the root [`Tx` command](./09-module-interfaces.md#tx) for the module. The subcommands of this root command are used by end-users to generate new transactions containing [`message`s](./02-messages-and-queries.md#queries) defined in the module. -* `GetQueryCmd()`: Return the root [`query` command](./09-module-interfaces.md#query) for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module. All the `AppModuleBasic` of an application are managed by the [`BasicManager`](#basicmanager). @@ -242,8 +240,8 @@ It implements the following methods: * `DefaultGenesis(cdc codec.JSONCodec)`: Provides default genesis information for modules in the application by calling the [`DefaultGenesis(cdc codec.JSONCodec)`](./08-genesis.md#defaultgenesis) function of each module. It only calls the modules that implements the `HasGenesisBasics` interfaces. * `ValidateGenesis(cdc codec.JSONCodec, txEncCfg client.TxEncodingConfig, genesis map[string]json.RawMessage)`: Validates the genesis information modules by calling the [`ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage)`](./08-genesis.md#validategenesis) function of modules implementing the `HasGenesisBasics` interface. * `RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *runtime.ServeMux)`: Registers gRPC routes for modules. -* `AddTxCommands(rootTxCmd *cobra.Command)`: Adds modules' transaction commands to the application's [`rootTxCommand`](../core/07-cli.md#transaction-commands). This function is usually called function from the `main.go` function of the [application's command-line interface](../core/07-cli.md). -* `AddQueryCommands(rootQueryCmd *cobra.Command)`: Adds modules' query commands to the application's [`rootQueryCommand`](../core/07-cli.md#query-commands). This function is usually called function from the `main.go` function of the [application's command-line interface](../core/07-cli.md). +* `AddTxCommands(rootTxCmd *cobra.Command)`: Adds modules' transaction commands (defined as `GetTxCmd() *cobra.Command`) to the application's [`rootTxCommand`](../core/07-cli.md#transaction-commands). This function is usually called function from the `main.go` function of the [application's command-line interface](../core/07-cli.md). +* `AddQueryCommands(rootQueryCmd *cobra.Command)`: Adds modules' query commands (defined as `GetQueryCmd() *cobra.Command`) to the application's [`rootQueryCommand`](../core/07-cli.md#query-commands). This function is usually called function from the `main.go` function of the [application's command-line interface](../core/07-cli.md). ### `Manager` diff --git a/docs/docs/building-modules/09-module-interfaces.md b/docs/docs/building-modules/09-module-interfaces.md index f50cc8c2f371..dc4ba0951104 100644 --- a/docs/docs/building-modules/09-module-interfaces.md +++ b/docs/docs/building-modules/09-module-interfaces.md @@ -48,13 +48,13 @@ In general, the getter function does the following: * **Adds transaction flags:** All transaction commands must add a set of transaction [flags](#flags). The transaction flags are used to collect additional information from the user (e.g. the amount of fees the user is willing to pay). The transaction flags are added to the constructed command using `AddTxFlagsToCmd(cmd)`. * **Returns the command:** Finally, the transaction command is returned. -Each module must implement `NewTxCmd()`, which aggregates all of the transaction commands of the module. Here is an example from the `x/bank` module: +Each module can implement `NewTxCmd()`, which aggregates all of the transaction commands of the module. Here is an example from the `x/bank` module: ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/bank/client/cli/tx.go#L20-L35 ``` -Each module must also implement the `GetTxCmd()` method for `AppModuleBasic` that simply returns `NewTxCmd()`. This allows the root command to easily aggregate all of the transaction commands for each module. Here is an example: +Each module then can also implement a `GetTxCmd()` method that simply returns `NewTxCmd()`. This allows the root command to easily aggregate all of the transaction commands for each module. Here is an example: ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/bank/module.go#L84-L86 @@ -62,8 +62,11 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/bank/module.go#L84-L ### Query Commands - - ## gRPC @@ -160,4 +163,4 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/proto/cosmos/auth/v1be gRPC gateway is started in-process along with the application and CometBFT. It can be enabled or disabled by setting gRPC Configuration `enable` in [`app.toml`](../run-node/02-interact-node.md#configuring-the-node-using-apptoml). -The Cosmos SDK provides a command for generating [Swagger](https://swagger.io/) documentation (`protoc-gen-swagger`). Setting `swagger` in [`app.toml`](../run-node/02-interact-node.md#configuring-the-node-using-apptoml) defines if swagger documentation should be automatically registered. --> +The Cosmos SDK provides a command for generating [Swagger](https://swagger.io/) documentation (`protoc-gen-swagger`). Setting `swagger` in [`app.toml`](../run-node/02-interact-node.md#configuring-the-node-using-apptoml) defines if swagger documentation should be automatically registered. diff --git a/docs/docs/core/03-node.md b/docs/docs/core/03-node.md index c2abe2c2f519..c24b9e4ec8d4 100644 --- a/docs/docs/core/03-node.md +++ b/docs/docs/core/03-node.md @@ -74,7 +74,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/server/types/app.go#L6 In practice, the [constructor of the application](../basics/00-app-anatomy.md#constructor-function) is passed as the `appCreator`. ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root.go#L278-L291 +https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root_v2.go#L294-L308 ``` Then, the instance of `app` is used to instantiate a new CometBFT node: diff --git a/docs/docs/core/07-cli.md b/docs/docs/core/07-cli.md index bf9f260c0dab..42d4f66ed358 100644 --- a/docs/docs/core/07-cli.md +++ b/docs/docs/core/07-cli.md @@ -37,7 +37,7 @@ The `main.go` file needs to have a `main()` function that creates a root command * **setting configurations** by reading in configuration files (e.g. the Cosmos SDK config file). * **adding any flags** to it, such as `--chain-id`. -* **instantiating the `codec`** by calling the application's `MakeCodec()` function (called `MakeTestEncodingConfig` in `simapp`). The [`codec`](../core/05-encoding.md) is used to encode and decode data structures for the application - stores can only persist `[]byte`s so the developer must define a serialization format for their data structures or use the default, Protobuf. +* **instantiating the `codec`** by injecting the application codecs. The [`codec`](../core/05-encoding.md) is used to encode and decode data structures for the application - stores can only persist `[]byte`s so the developer must define a serialization format for their data structures or use the default, Protobuf. * **adding subcommand** for all the possible user interactions, including [transaction commands](#transaction-commands) and [query commands](#query-commands). The `main()` function finally creates an executor and [execute](https://pkg.go.dev/github.com/spf13/cobra#Command.Execute) the root command. See an example of `main()` function from the `simapp` application: @@ -66,21 +66,27 @@ Learn more [here](https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/serv Next is an example `rootCmd` function from the `simapp` application. It instantiates the root command, adds a [*persistent* flag](#flags) and `PreRun` function to be run before every execution, and adds all of the necessary subcommands. ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root.go#L47-L120 +https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root_v2.go#L47-L130 ``` +:::tip +Use the `EnhanceRootCommand()` from the AutoCLI options to automatically add auto-generated commands from the modules to the root command. +Additionnally it adds all manually defined modules commands (`tx` and `query`) as well. +Read more about [AutoCLI](https://docs.cosmos.network/main/building-modules/autocli#getting-started) in its dedicated section. +::: + `rootCmd` has a function called `initAppConfig()` which is useful for setting the application's custom configs. By default app uses CometBFT app config template from Cosmos SDK, which can be over-written via `initAppConfig()`. Here's an example code to override default `app.toml` template. ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root.go#L136-L188 +https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root_v2.go#L144-L199 ``` The `initAppConfig()` also allows overriding the default Cosmos SDK's [server config](https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/server/config/config.go#L235). One example is the `min-gas-prices` config, which defines the minimum gas prices a validator is willing to accept for processing a transaction. By default, the Cosmos SDK sets this parameter to `""` (empty string), which forces all validators to tweak their own `app.toml` and set a non-empty value, or else the node will halt on startup. This might not be the best UX for validators, so the chain developer can set a default `app.toml` value for validators inside this `initAppConfig()` function. ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root.go#L154-L170 +https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root_v2.go#L164-L180 ``` The root-level `status` and `keys` subcommands are common across most applications and do not interact with application state. The bulk of an application's functionality - what users can actually *do* with it - is enabled by its `tx` and `query` commands. @@ -90,43 +96,53 @@ The root-level `status` and `keys` subcommands are common across most applicatio [Transactions](./01-transactions.md) are objects wrapping [`Msg`s](../building-modules/02-messages-and-queries.md#messages) that trigger state changes. To enable the creation of transactions using the CLI interface, a function `txCommand` is generally added to the `rootCmd`: ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root.go#L181-L189 +https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root_v2.go#L222-L229 ``` This `txCommand` function adds all the transaction available to end-users for the application. This typically includes: * **Sign command** from the [`auth`](../modules/auth/README.md) module that signs messages in a transaction. To enable multisig, add the `auth` module's `MultiSign` command. Since every transaction requires some sort of signature in order to be valid, the signing command is necessary for every application. * **Broadcast command** from the Cosmos SDK client tools, to broadcast transactions. -* **All [module transaction commands](../building-modules/09-module-interfaces.md#transaction-commands)** the application is dependent on, retrieved by using the [basic module manager's](../building-modules/01-module-manager.md#basic-manager) `AddTxCommands()` function. +* **All [module transaction commands](../building-modules/09-module-interfaces.md#transaction-commands)** the application is dependent on, retrieved by using the [basic module manager's](../building-modules/01-module-manager.md#basic-manager) `AddTxCommands()` function, or enhanced by [AutoCLI](https://docs.cosmos.network/main/building-modules/autocli#getting-started). Here is an example of a `txCommand` aggregating these subcommands from the `simapp` application: ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root.go#L253-L275 +https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root_v2.go#L270-L292 ``` +:::tip +When using AutoCLI to generate module transaction commands, `EnhanceRootCommand()` automatically adds the module `tx` command to the root command. +Read more about [AutoCLI](https://docs.cosmos.network/main/building-modules/autocli#getting-started) in its dedicated section. +::: + ### Query Commands [**Queries**](../building-modules/02-messages-and-queries.md#queries) are objects that allow users to retrieve information about the application's state. To enable the creation of queries using the CLI interface, a function `queryCommand` is generally added to the `rootCmd`: ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root.go#L232-L251 +https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root_v2.go#L222-L229 ``` This `queryCommand` function adds all the queries available to end-users for the application. This typically includes: -* **QueryTx** and/or other transaction query commands] from the `auth` module which allow the user to search for a transaction by inputting its hash, a list of tags, or a block height. These queries allow users to see if transactions have been included in a block. +* **QueryTx** and/or other transaction query commands from the `auth` module which allow the user to search for a transaction by inputting its hash, a list of tags, or a block height. These queries allow users to see if transactions have been included in a block. * **Account command** from the `auth` module, which displays the state (e.g. account balance) of an account given an address. * **Validator command** from the Cosmos SDK rpc client tools, which displays the validator set of a given height. * **Block command** from the Cosmos SDK RPC client tools, which displays the block data for a given height. -* **All [module query commands](../building-modules/09-module-interfaces.md#query-commands)** the application is dependent on, retrieved by using the [basic module manager's](../building-modules/01-module-manager.md#basic-manager) `AddQueryCommands()` function. +* **All [module query commands](../building-modules/09-module-interfaces.md#query-commands)** the application is dependent on, retrieved by using the [basic module manager's](../building-modules/01-module-manager.md#basic-manager) `AddQueryCommands()` function, or enhanced by [AutoCLI](https://docs.cosmos.network/main/building-modules/autocli#getting-started). Here is an example of a `queryCommand` aggregating subcommands from the `simapp` application: ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root.go#L232-L251 +https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root_v2.go#L249-L268 ``` +:::tip +When using AutoCLI to generate module query commands, `EnhanceRootCommand()` automatically adds the module `query` command to the root command. +Read more about [AutoCLI](https://docs.cosmos.network/main/building-modules/autocli#getting-started) in its dedicated section. +::: + ## Flags Flags are used to modify commands; developers can include them in a `flags.go` file with their CLI. Users can explicitly include them in commands or pre-configure them by inside their [`app.toml`](../run-node/02-interact-node.md#configuring-the-node-using-apptoml). Commonly pre-configured flags include the `--node` to connect to and `--chain-id` of the blockchain the user wishes to interact with. @@ -163,7 +179,7 @@ It is vital that the root command of an application uses `PersistentPreRun()` co Here is an example of an `PersistentPreRun()` function from `simapp`: ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root.go#L70-L110 +https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/simd/cmd/root_v2.go#L81-L120 ``` The `SetCmdClientContextHandler` call reads persistent flags via `ReadPersistentCommandFlags` which creates a `client.Context` and sets that on the root command's `Context`. diff --git a/scripts/mockgen.sh b/scripts/mockgen.sh index a57691b951f7..cda998093a19 100755 --- a/scripts/mockgen.sh +++ b/scripts/mockgen.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash mockgen_cmd="mockgen" -$mockgen_cmd -source=baseapp/abci_utils.go -package mock -destination baseapp/testutil/mock/validator_store.go +$mockgen_cmd -source=baseapp/abci_utils.go -package mock -destination baseapp/testutil/mock/mocks.go $mockgen_cmd -source=client/account_retriever.go -package mock -destination testutil/mock/account_retriever.go $mockgen_cmd -package mock -destination store/mock/cosmos_cosmos_db_DB.go github.com/cosmos/cosmos-db DB $mockgen_cmd -source=types/module/module.go -package mock -destination testutil/mock/types_module_module.go diff --git a/testutil/mock/types_mock_appmodule.go b/testutil/mock/types_mock_appmodule.go index dd31281640ad..b5cab1121f0e 100644 --- a/testutil/mock/types_mock_appmodule.go +++ b/testutil/mock/types_mock_appmodule.go @@ -18,7 +18,6 @@ import ( module "github.com/cosmos/cosmos-sdk/types/module" gomock "github.com/golang/mock/gomock" runtime "github.com/grpc-ecosystem/grpc-gateway/runtime" - cobra "github.com/spf13/cobra" ) // MockAppModuleWithAllExtensions is a mock of AppModuleWithAllExtensions interface. @@ -101,34 +100,6 @@ func (mr *MockAppModuleWithAllExtensionsMockRecorder) ExportGenesis(arg0, arg1 i return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).ExportGenesis), arg0, arg1) } -// GetQueryCmd mocks base method. -func (m *MockAppModuleWithAllExtensions) GetQueryCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetQueryCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetQueryCmd indicates an expected call of GetQueryCmd. -func (mr *MockAppModuleWithAllExtensionsMockRecorder) GetQueryCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).GetQueryCmd)) -} - -// GetTxCmd mocks base method. -func (m *MockAppModuleWithAllExtensions) GetTxCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTxCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetTxCmd indicates an expected call of GetTxCmd. -func (mr *MockAppModuleWithAllExtensionsMockRecorder) GetTxCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).GetTxCmd)) -} - // InitGenesis mocks base method. func (m *MockAppModuleWithAllExtensions) InitGenesis(arg0 types1.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types.ValidatorUpdate { m.ctrl.T.Helper() diff --git a/testutil/mock/types_module_module.go b/testutil/mock/types_module_module.go index 550628701c8e..223db3bcb86c 100644 --- a/testutil/mock/types_module_module.go +++ b/testutil/mock/types_module_module.go @@ -17,7 +17,6 @@ import ( module "github.com/cosmos/cosmos-sdk/types/module" gomock "github.com/golang/mock/gomock" runtime "github.com/grpc-ecosystem/grpc-gateway/runtime" - cobra "github.com/spf13/cobra" ) // MockAppModuleBasic is a mock of AppModuleBasic interface. @@ -43,34 +42,6 @@ func (m *MockAppModuleBasic) EXPECT() *MockAppModuleBasicMockRecorder { return m.recorder } -// GetQueryCmd mocks base method. -func (m *MockAppModuleBasic) GetQueryCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetQueryCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetQueryCmd indicates an expected call of GetQueryCmd. -func (mr *MockAppModuleBasicMockRecorder) GetQueryCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockAppModuleBasic)(nil).GetQueryCmd)) -} - -// GetTxCmd mocks base method. -func (m *MockAppModuleBasic) GetTxCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTxCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetTxCmd indicates an expected call of GetTxCmd. -func (mr *MockAppModuleBasicMockRecorder) GetTxCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModuleBasic)(nil).GetTxCmd)) -} - // Name mocks base method. func (m *MockAppModuleBasic) Name() string { m.ctrl.T.Helper() @@ -260,34 +231,6 @@ func (mr *MockAppModuleGenesisMockRecorder) ExportGenesis(arg0, arg1 interface{} return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockAppModuleGenesis)(nil).ExportGenesis), arg0, arg1) } -// GetQueryCmd mocks base method. -func (m *MockAppModuleGenesis) GetQueryCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetQueryCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetQueryCmd indicates an expected call of GetQueryCmd. -func (mr *MockAppModuleGenesisMockRecorder) GetQueryCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockAppModuleGenesis)(nil).GetQueryCmd)) -} - -// GetTxCmd mocks base method. -func (m *MockAppModuleGenesis) GetTxCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTxCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetTxCmd indicates an expected call of GetTxCmd. -func (mr *MockAppModuleGenesisMockRecorder) GetTxCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModuleGenesis)(nil).GetTxCmd)) -} - // InitGenesis mocks base method. func (m *MockAppModuleGenesis) InitGenesis(arg0 types1.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types.ValidatorUpdate { m.ctrl.T.Helper() @@ -468,34 +411,6 @@ func (m *MockAppModule) EXPECT() *MockAppModuleMockRecorder { return m.recorder } -// GetQueryCmd mocks base method. -func (m *MockAppModule) GetQueryCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetQueryCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetQueryCmd indicates an expected call of GetQueryCmd. -func (mr *MockAppModuleMockRecorder) GetQueryCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockAppModule)(nil).GetQueryCmd)) -} - -// GetTxCmd mocks base method. -func (m *MockAppModule) GetTxCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTxCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetTxCmd indicates an expected call of GetTxCmd. -func (mr *MockAppModuleMockRecorder) GetTxCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModule)(nil).GetTxCmd)) -} - // Name mocks base method. func (m *MockAppModule) Name() string { m.ctrl.T.Helper() @@ -691,34 +606,6 @@ func (mr *MockHasABCIEndblockMockRecorder) EndBlock(arg0 interface{}) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockHasABCIEndblock)(nil).EndBlock), arg0) } -// GetQueryCmd mocks base method. -func (m *MockHasABCIEndblock) GetQueryCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetQueryCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetQueryCmd indicates an expected call of GetQueryCmd. -func (mr *MockHasABCIEndblockMockRecorder) GetQueryCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockHasABCIEndblock)(nil).GetQueryCmd)) -} - -// GetTxCmd mocks base method. -func (m *MockHasABCIEndblock) GetTxCmd() *cobra.Command { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTxCmd") - ret0, _ := ret[0].(*cobra.Command) - return ret0 -} - -// GetTxCmd indicates an expected call of GetTxCmd. -func (mr *MockHasABCIEndblockMockRecorder) GetTxCmd() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockHasABCIEndblock)(nil).GetTxCmd)) -} - // Name mocks base method. func (m *MockHasABCIEndblock) Name() string { m.ctrl.T.Helper() diff --git a/tools/confix/README.md b/tools/confix/README.md index 19c637ba90b6..a990ed98d267 100644 --- a/tools/confix/README.md +++ b/tools/confix/README.md @@ -12,7 +12,7 @@ It is based on the [CometBFT RFC 019](https://github.com/cometbft/cometbft/blob/ ### Add Config Command -To add the confix tool, it's required to add the `ConfigCommand` to your application's root command file (e.g. `simd/cmd/root.go`). +To add the confix tool, it's required to add the `ConfigCommand` to your application's root command file (e.g. `/cmd/root.go`). Import the `confixCmd` package: diff --git a/tools/rosetta/README.md b/tools/rosetta/README.md index 3d8467aea892..68ad08becc7b 100644 --- a/tools/rosetta/README.md +++ b/tools/rosetta/README.md @@ -10,7 +10,7 @@ The `rosetta` package implements Coinbase's [Rosetta API](https://www.rosetta-ap The Rosetta API server is a stand-alone server that connects to a node of a chain developed with Cosmos SDK. -To enable Rosetta API support, it's required to add the `RosettaCommand` to your application's root command file (e.g. `simd/cmd/root.go`). +To enable Rosetta API support, it's required to add the `RosettaCommand` to your application's root command file (e.g. `/cmd/root.go`). Import the `rosettaCmd` package: diff --git a/types/module/module.go b/types/module/module.go index 6fe25a934be0..51e57e524100 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -57,11 +57,7 @@ type AppModuleBasic interface { HasName RegisterLegacyAminoCodec(*codec.LegacyAmino) RegisterInterfaces(types.InterfaceRegistry) - - // client functionality RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux) - GetTxCmd() *cobra.Command - GetQueryCmd() *cobra.Command } // HasName allows the module to provide its own name for legacy purposes. @@ -163,8 +159,12 @@ func (bm BasicManager) RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr * // AddTxCommands adds all tx commands to the rootTxCmd. func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command) { for _, b := range bm { - if cmd := b.GetTxCmd(); cmd != nil { - rootTxCmd.AddCommand(cmd) + if mod, ok := b.(interface { + GetTxCmd() *cobra.Command + }); ok { + if cmd := mod.GetTxCmd(); cmd != nil { + rootTxCmd.AddCommand(cmd) + } } } } @@ -172,8 +172,12 @@ func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command) { // AddQueryCommands adds all query commands to the rootQueryCmd. func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) { for _, b := range bm { - if cmd := b.GetQueryCmd(); cmd != nil { - rootQueryCmd.AddCommand(cmd) + if mod, ok := b.(interface { + GetQueryCmd() *cobra.Command + }); ok { + if cmd := mod.GetQueryCmd(); cmd != nil { + rootQueryCmd.AddCommand(cmd) + } } } } diff --git a/types/module/module_test.go b/types/module/module_test.go index 264e9c8b3598..3cde79f6a6fe 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -27,6 +27,12 @@ import ( var errFoo = errors.New("dummy") +func (MockCoreAppModule) GetQueryCmd() *cobra.Command { + return &cobra.Command{ + Use: "foo", + } +} + func TestBasicManager(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) @@ -52,8 +58,6 @@ func TestBasicManager(t *testing.T) { mockAppModuleBasic1.EXPECT().ValidateGenesis(gomock.Eq(cdc), gomock.Eq(nil), gomock.Eq(expDefaultGenesis["mockAppModuleBasic1"])).AnyTimes().Return(nil) mockAppModuleBasic1.EXPECT().RegisterLegacyAminoCodec(gomock.Eq(legacyAmino)).Times(1) mockAppModuleBasic1.EXPECT().RegisterInterfaces(gomock.Eq(interfaceRegistry)).Times(1) - mockAppModuleBasic1.EXPECT().GetTxCmd().Times(1).Return(nil) - mockAppModuleBasic1.EXPECT().GetQueryCmd().Times(1).Return(nil) // mock core API module mockCoreAppModule2 := mock.NewMockCoreAppModule(mockCtrl) @@ -82,8 +86,8 @@ func TestBasicManager(t *testing.T) { mockCmd := &cobra.Command{Use: "root"} mm.AddTxCommands(mockCmd) - mm.AddQueryCommands(mockCmd) + require.Equal(t, 1, len(mockCmd.Commands())) // validate genesis returns nil require.Nil(t, module.NewBasicManager().ValidateGenesis(cdc, nil, expDefaultGenesis)) diff --git a/x/auth/module.go b/x/auth/module.go index eb49321e2f34..171d8a3b5b4d 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -7,7 +7,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" modulev1 "cosmossdk.io/api/cosmos/auth/module/v1" "cosmossdk.io/core/address" @@ -78,16 +77,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g } } -// GetTxCmd returns the root tx command for the auth module. -func (AppModuleBasic) GetTxCmd() *cobra.Command { - return nil -} - -// GetQueryCmd returns the root query command for the auth module. -func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} - // RegisterInterfaces registers interfaces and implementations of the auth module. func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index 015fbecf0d95..98a411c01105 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -70,11 +70,6 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command { return cli.GetTxCmd(ab.ac) } -// GetQueryCmd returns the module's root query command. Currently, this is a no-op. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} - // AppModule extends the AppModuleBasic implementation by implementing the // AppModule interface. type AppModule struct { diff --git a/x/bank/module.go b/x/bank/module.go index ef52a77fd1fa..592af3c4791b 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -84,11 +84,6 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command { return cli.NewTxCmd(ab.ac) } -// GetQueryCmd returns no root query command for the bank module. -func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} - // RegisterInterfaces registers interfaces and implementations of the bank module. func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) diff --git a/x/consensus/module.go b/x/consensus/module.go index cc11ac50681c..ec30b7b8e86d 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -6,7 +6,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" "google.golang.org/grpc" modulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" @@ -67,16 +66,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g } } -// GetTxCmd returns the root tx command -func (AppModuleBasic) GetTxCmd() *cobra.Command { - return nil -} - -// GetQueryCmd returns no root query command -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} - // RegisterInterfaces registers interfaces and implementations of the bank module. func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) diff --git a/x/crisis/module.go b/x/crisis/module.go index a7e0147a4227..1a821e8e4e78 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -80,9 +80,6 @@ func (b AppModuleBasic) GetTxCmd() *cobra.Command { return cli.NewTxCmd() } -// GetQueryCmd returns no root query command for the crisis module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil } - // RegisterInterfaces registers interfaces and implementations of the crisis // module. func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { diff --git a/x/distribution/module.go b/x/distribution/module.go index 493cfcd21f3f..30cc0b799d2a 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -82,11 +82,6 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command { return cli.NewTxCmd(ab.ac) } -// GetQueryCmd returns the root query command for the distribution module. -func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} - // RegisterInterfaces implements InterfaceModule func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { types.RegisterInterfaces(registry) diff --git a/x/evidence/go.mod b/x/evidence/go.mod index e7825e2a6861..8c30708ea4ff 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -8,12 +8,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/math v1.0.1 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.20230620151856-3aab81f45d55 + github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230709172657-53a07864b68f github.com/cosmos/gogoproto v1.4.10 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 @@ -84,6 +84,7 @@ require ( github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/hashicorp/go-hclog v1.5.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect + github.com/hashicorp/go-metrics v0.5.1 // indirect github.com/hashicorp/go-plugin v1.4.10 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/hashicorp/hcl v1.0.0 // indirect diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 2a6acbccc920..6afeba214e08 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -45,8 +45,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= @@ -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.20230620151856-3aab81f45d55 h1:qEWSMjCeg+ChbOh9VEJbxg8qFa33DLuVUunROeD5l00= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230620151856-3aab81f45d55/go.mod h1:/HloC8xR6Kwtj5ieHSbje4B39aObp43aRp2V12UR+9c= +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/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= @@ -431,6 +431,8 @@ github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVH github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-metrics v0.5.1 h1:rfPwUqFU6uZXNvGl4hzjY8LEBsqFVU4si1H9/Hqck/U= +github.com/hashicorp/go-metrics v0.5.1/go.mod h1:KEjodfebIOuBYSAe/bHTm+HChmKSxAOXPBieMLYozDE= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-plugin v1.4.10 h1:xUbmA4jC6Dq163/fWcp8P3JuHilrHHMLNRxzGQJ9hNk= diff --git a/x/evidence/module.go b/x/evidence/module.go index c44db6d7f48e..42092f0c6c9b 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -94,11 +94,6 @@ func (a AppModuleBasic) GetTxCmd() *cobra.Command { return cli.GetTxCmd(evidenceCLIHandlers) } -// GetQueryCmd returns the evidence module's root query command. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} - // RegisterInterfaces registers the evidence module's interface types func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 11e76cde9b31..a058bf913e2b 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -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/math v1.0.1 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.50.0-alpha.1 + github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230709172657-53a07864b68f github.com/cosmos/gogoproto v1.4.10 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index c691dc8153e7..ea7b60f01da3 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -45,8 +45,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= @@ -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.50.0-alpha.1 h1:7ERS+ZW1tTly/DLfUwjMB6h80wtlNGBcFjI2Eb9eZIU= -github.com/cosmos/cosmos-sdk v0.50.0-alpha.1/go.mod h1:xee+suLR+WgtzSQBr0jjXQsvb1FIteMfnEzbr2Lk+4w= +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/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= diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 19de021ba880..06813b1573cf 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -98,11 +98,6 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command { return cli.GetTxCmd(ab.ac) } -// GetQueryCmd returns no root query command for the feegrant module. -func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} - // ---------------------------------------------------------------------------- // AppModule // ---------------------------------------------------------------------------- diff --git a/x/genutil/module.go b/x/genutil/module.go index 182aceabb4fd..7bf648eb8127 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -6,7 +6,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" modulev1 "cosmossdk.io/api/cosmos/genutil/module/v1" "cosmossdk.io/core/appmodule" @@ -68,12 +67,6 @@ func (b AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, txEncodingConfig cl func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) { } -// GetTxCmd returns no root tx command for the genutil module. -func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil } - -// GetQueryCmd returns no root query command for the genutil module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil } - // AppModule implements an application module for the genutil module. type AppModule struct { AppModuleBasic diff --git a/x/mint/module.go b/x/mint/module.go index 609c36c2dcfe..211ce814d2d7 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -7,7 +7,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" modulev1 "cosmossdk.io/api/cosmos/mint/module/v1" "cosmossdk.io/core/appmodule" @@ -80,14 +79,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g } } -// GetTxCmd returns no root tx command for the mint module. -func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil } - -// GetQueryCmd returns the root query command for the mint module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} - // AppModule implements an application module for the mint module. type AppModule struct { AppModuleBasic diff --git a/x/nft/go.mod b/x/nft/go.mod index bdfb08c4daee..44b2103bb1c5 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -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/math v1.0.1 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.20230614103911-b3da8bb4e801 + github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230709172657-53a07864b68f github.com/cosmos/gogoproto v1.4.10 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 @@ -82,6 +82,7 @@ require ( github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/hashicorp/go-hclog v1.5.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect + github.com/hashicorp/go-metrics v0.5.1 // indirect github.com/hashicorp/go-plugin v1.4.10 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/hashicorp/hcl v1.0.0 // indirect diff --git a/x/nft/go.sum b/x/nft/go.sum index 0f66ce2154d6..3382cf9da95b 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -45,8 +45,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= @@ -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.20230614103911-b3da8bb4e801 h1:Qg0EgcEYtN0RWmxaFWTTCeMDfnbHB6UEzHucafy14i8= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230614103911-b3da8bb4e801/go.mod h1:VwFzgpv4z/Mrx+0sQpWwURCHx4h/iAalMdKIe3VEyBw= +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/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= @@ -430,6 +430,8 @@ github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVH github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-metrics v0.5.1 h1:rfPwUqFU6uZXNvGl4hzjY8LEBsqFVU4si1H9/Hqck/U= +github.com/hashicorp/go-metrics v0.5.1/go.mod h1:KEjodfebIOuBYSAe/bHTm+HChmKSxAOXPBieMLYozDE= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-plugin v1.4.10 h1:xUbmA4jC6Dq163/fWcp8P3JuHilrHHMLNRxzGQJ9hNk= diff --git a/x/nft/module/module.go b/x/nft/module/module.go index 81fe806b3a6d..203ccbdd3fb7 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -84,12 +84,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux } } -// GetQueryCmd returns a no-op command for the nft module. -// Queries for NFT are registered by autocli. -func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} - // GetTxCmd returns the transaction commands for the nft module func (AppModuleBasic) GetTxCmd() *cobra.Command { return cli.GetTxCmd() diff --git a/x/params/module.go b/x/params/module.go index 3a9cc709bcb2..778f846c4949 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -52,9 +52,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g } } -// GetTxCmd returns no root tx command for the params module. -func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil } - // GetQueryCmd returns no root query command for the params module. func (AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.NewQueryCmd() diff --git a/x/staking/module.go b/x/staking/module.go index affb0e957774..bcfe0aa29b2e 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -93,11 +93,6 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command { return cli.NewTxCmd() } -// GetQueryCmd returns no root query command for the staking module. -func (ab AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} - // AppModule implements an application module for the staking module. type AppModule struct { AppModuleBasic From ba163e0fd064efbc6acbae033aed176735de7736 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 10 Jul 2023 17:21:58 +0200 Subject: [PATCH 5/7] feat(circuit): autocli query support (#16906) --- x/circuit/autocli.go | 35 ++++++++++ x/circuit/client/cli/query.go | 121 ---------------------------------- x/circuit/go.mod | 5 +- x/circuit/go.sum | 10 +-- x/circuit/module.go | 5 -- 5 files changed, 44 insertions(+), 132 deletions(-) create mode 100644 x/circuit/autocli.go delete mode 100644 x/circuit/client/cli/query.go diff --git a/x/circuit/autocli.go b/x/circuit/autocli.go new file mode 100644 index 000000000000..50254dbc1024 --- /dev/null +++ b/x/circuit/autocli.go @@ -0,0 +1,35 @@ +package circuit + +import ( + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + circuitv1 "cosmossdk.io/api/cosmos/circuit/v1" +) + +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: circuitv1.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Account", + Use: "account [address]", + Short: "Query a specific account's permissions", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}}, + }, + { + RpcMethod: "Accounts", + Use: "accounts", + Short: "Query all account permissions", + }, + { + RpcMethod: "DisabledList", + Use: "disabled-list", + Short: "Query a list of all disabled message types", + }, + }, + }, + Tx: &autocliv1.ServiceCommandDescriptor{ + Service: circuitv1.Query_ServiceDesc.ServiceName, + }, + } +} diff --git a/x/circuit/client/cli/query.go b/x/circuit/client/cli/query.go deleted file mode 100644 index f54bec090975..000000000000 --- a/x/circuit/client/cli/query.go +++ /dev/null @@ -1,121 +0,0 @@ -package cli - -import ( - "github.com/spf13/cobra" - - "cosmossdk.io/x/circuit/types" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// GetQueryCmd returns the parent command for all circuit CLI query commands. -func GetQueryCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Querying commands for the circuit module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand( - GetDisabeListCmd(), - GetAccountCmd(), - GetAccountsCmd(), - ) - - return cmd -} - -func GetDisabeListCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "disabled-list", - Short: "Query for all disabled message types", - 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) - - res, err := queryClient.DisabledList(cmd.Context(), &types.QueryDisabledListRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -func GetAccountCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "account [address]", - Short: "Query for account permissions", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - addr, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.Account(cmd.Context(), &types.QueryAccountRequest{Address: addr.String()}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -func GetAccountsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "accounts", - Short: "Query for all account permissions", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.Accounts(cmd.Context(), &types.QueryAccountsRequest{Pagination: pageReq}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/circuit/go.mod b/x/circuit/go.mod index 84e13ec33f35..40ecb99b97f1 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -12,7 +12,7 @@ require ( cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c github.com/cockroachdb/errors v1.10.0 github.com/cometbft/cometbft v0.38.0-rc2 - github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230614103911-b3da8bb4e801 + 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 @@ -23,7 +23,7 @@ require ( ) require ( - cosmossdk.io/log v1.1.0 // indirect + cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca // indirect cosmossdk.io/x/tx v0.8.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect @@ -82,6 +82,7 @@ require ( github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/hashicorp/go-hclog v1.5.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect + github.com/hashicorp/go-metrics v0.5.1 // indirect github.com/hashicorp/go-plugin v1.4.10 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/hashicorp/hcl v1.0.0 // indirect diff --git a/x/circuit/go.sum b/x/circuit/go.sum index c34165445092..a59a4e91ae64 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -45,8 +45,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= @@ -170,8 +170,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.20230614103911-b3da8bb4e801 h1:Qg0EgcEYtN0RWmxaFWTTCeMDfnbHB6UEzHucafy14i8= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230614103911-b3da8bb4e801/go.mod h1:VwFzgpv4z/Mrx+0sQpWwURCHx4h/iAalMdKIe3VEyBw= +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= @@ -421,6 +421,8 @@ github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVH github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-metrics v0.5.1 h1:rfPwUqFU6uZXNvGl4hzjY8LEBsqFVU4si1H9/Hqck/U= +github.com/hashicorp/go-metrics v0.5.1/go.mod h1:KEjodfebIOuBYSAe/bHTm+HChmKSxAOXPBieMLYozDE= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-plugin v1.4.10 h1:xUbmA4jC6Dq163/fWcp8P3JuHilrHHMLNRxzGQJ9hNk= diff --git a/x/circuit/module.go b/x/circuit/module.go index 406bd2930056..0937ff71e854 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -79,11 +79,6 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command { return cli.NewTxCmd() } -// GetQueryCmd returns no root query command for the circuit module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() -} - // RegisterInterfaces registers interfaces and implementations of the circuit module. func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) From 7b1cd3c75afa92be01c10ab556fba04db3415c90 Mon Sep 17 00:00:00 2001 From: Rootul P Date: Mon, 10 Jul 2023 17:02:33 -0400 Subject: [PATCH 6/7] docs: describe `x/gov` usage on Cosmos Hub (#16910) --- x/gov/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/gov/README.md b/x/gov/README.md index 245d29053f77..d1b3024def48 100644 --- a/x/gov/README.md +++ b/x/gov/README.md @@ -23,7 +23,7 @@ they don't vote themselves. * **Claiming deposit:** Users that deposited on proposals can recover their deposits if the proposal was accepted or rejected. If the proposal was vetoed, or never entered voting period, the deposit is burned. -This module will be used in the Cosmos Hub, the first Hub in the Cosmos network. +This module is in use on the Cosmos Hub (a.k.a [gaia](https://github.com/cosmos/gaia)). Features that may be added in the future are described in [Future Improvements](#future-improvements). ## Contents From 1f470fcff74e071fa35bc45ec7222776fc5ae6c2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 Jul 2023 08:29:14 +0200 Subject: [PATCH 7/7] build(deps): Bump semver from 5.7.1 to 5.7.2 in /docs (#16916) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/package-lock.json | 144 ++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/docs/package-lock.json b/docs/package-lock.json index b9bb98634bb3..6ba4ae32d6f3 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -244,9 +244,9 @@ } }, "node_modules/@babel/core/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -318,9 +318,9 @@ } }, "node_modules/@babel/helper-compilation-targets/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -377,9 +377,9 @@ } }, "node_modules/@babel/helper-define-polyfill-provider/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -1630,9 +1630,9 @@ } }, "node_modules/@babel/plugin-transform-runtime/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -1842,9 +1842,9 @@ } }, "node_modules/@babel/preset-env/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -2793,9 +2793,9 @@ } }, "node_modules/@mdx-js/mdx/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "bin": { "semver": "bin/semver" } @@ -3987,9 +3987,9 @@ } }, "node_modules/babel-plugin-polyfill-corejs2/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -7702,9 +7702,9 @@ } }, "node_modules/make-dir/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -8340,9 +8340,9 @@ } }, "node_modules/package-json/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -10019,9 +10019,9 @@ } }, "node_modules/remark-mdx/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "bin": { "semver": "bin/semver" } @@ -10456,9 +10456,9 @@ } }, "node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dependencies": { "lru-cache": "^6.0.0" }, @@ -10481,9 +10481,9 @@ } }, "node_modules/semver-diff/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -12997,9 +12997,9 @@ }, "dependencies": { "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==" } } }, @@ -13054,9 +13054,9 @@ }, "dependencies": { "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==" } } }, @@ -13097,9 +13097,9 @@ }, "dependencies": { "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==" } } }, @@ -13910,9 +13910,9 @@ }, "dependencies": { "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==" } } }, @@ -14067,9 +14067,9 @@ }, "dependencies": { "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==" } } }, @@ -14785,9 +14785,9 @@ } }, "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==" }, "source-map": { "version": "0.5.7", @@ -15724,9 +15724,9 @@ }, "dependencies": { "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==" } } }, @@ -18389,9 +18389,9 @@ }, "dependencies": { "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==" } } }, @@ -18829,9 +18829,9 @@ }, "dependencies": { "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==" } } }, @@ -19985,9 +19985,9 @@ } }, "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==" }, "source-map": { "version": "0.5.7", @@ -20300,9 +20300,9 @@ } }, "semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "requires": { "lru-cache": "^6.0.0" } @@ -20316,9 +20316,9 @@ }, "dependencies": { "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==" } } },