diff --git a/x/evidence/CHANGELOG.md b/x/evidence/CHANGELOG.md index 1f1cf2d4f844..73fda10775d4 100644 --- a/x/evidence/CHANGELOG.md +++ b/x/evidence/CHANGELOG.md @@ -27,7 +27,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features -* (x/evidence) [14724](https://github.com/cosmos/cosmos-sdk/pull/14724) The `x/evidence` module is extracted to have a separate go.mod file which allows it be a standalone module. +* (x/evidence) [14724](https://github.com/cosmos/cosmos-sdk/pull/14724) The `x/evidence` module is extracted to have a separate go.mod file which allows it be a standalone module. * (keeper) [#15420](https://github.com/cosmos/cosmos-sdk/pull/15420) Move `BeginBlocker` to the keeper folder & make HandleEquivocation private ### API Breaking Changes @@ -36,3 +36,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (keeper) [#15825](https://github.com/cosmos/cosmos-sdk/pull/15825) Evidence constructor now requires an `address.Codec` (`import "cosmossdk.io/core/address"`) * [#16336](https://github.com/cosmos/cosmos-sdk/pull/16336) Use collections for state management: * Removed: keeper `SetEvidence`, `GetEvidence`, `IterateEvidences`, `GetAllEvidences`, `MustMarshalEvidence`, `MustUnmarshalEvidence`, `MarshalEvidence`, `UnmarshalEvidence` + +### Client Breaking Changes + +* [#16625](https://github.com/cosmos/cosmos-sdk/pull/16625) The `simd q evidence evidence` command supports only querying an evidence by hash. For querying all evidences, use `simd q evidence list` instad. diff --git a/x/evidence/autocli.go b/x/evidence/autocli.go new file mode 100644 index 000000000000..cd3fda9bce6e --- /dev/null +++ b/x/evidence/autocli.go @@ -0,0 +1,34 @@ +package evidence + +import ( + "fmt" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + evidencev1beta1 "cosmossdk.io/api/cosmos/evidence/v1beta1" + + "github.com/cosmos/cosmos-sdk/version" +) + +// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: evidencev1beta1.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Evidence", + Use: "evidence [hash]", + Short: "Query for evidence by hash", + Example: fmt.Sprintf("%s query evidence DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660", version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "hash"}}, + }, + { + RpcMethod: "AllEvidence", + Use: "list", + Short: "Query all (paginated) submitted evidence", + Example: fmt.Sprintf("%s query evidence --page=2 --page-limit=50", version.AppName), + }, + }, + }, + } +} diff --git a/x/evidence/client/cli/query.go b/x/evidence/client/cli/query.go deleted file mode 100644 index 3692ee5acdca..000000000000 --- a/x/evidence/client/cli/query.go +++ /dev/null @@ -1,92 +0,0 @@ -package cli - -import ( - "context" - "fmt" - "strings" - - "cosmossdk.io/x/evidence/types" - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/types/query" - "github.com/cosmos/cosmos-sdk/version" -) - -// GetQueryCmd returns the CLI command with all evidence module query commands -// mounted. -func GetQueryCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Query for evidence by hash or for all (paginated) submitted evidence", - Long: strings.TrimSpace( - fmt.Sprintf(`Query for specific submitted evidence by hash or query for all (paginated) evidence: - -Example: -$ %s query %s DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660 -$ %s query %s --page=2 --limit=50 -`, - version.AppName, types.ModuleName, version.AppName, types.ModuleName, - ), - ), - Args: cobra.MaximumNArgs(1), - SuggestionsMinimumDistance: 2, - RunE: QueryEvidenceCmd(), - } - - flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "evidence") - - return cmd -} - -// QueryEvidenceCmd returns the command handler for evidence querying. Evidence -// can be queried for by hash or paginated evidence can be returned. -func QueryEvidenceCmd() func(*cobra.Command, []string) error { - return func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - if len(args) > 0 { - return queryEvidence(clientCtx, args[0]) - } - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - return queryAllEvidence(clientCtx, pageReq) - } -} - -// queryEvidence queries for a single evidence by the given hash. -func queryEvidence(clientCtx client.Context, hash string) error { - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryEvidenceRequest{Hash: hash} - res, err := queryClient.Evidence(context.Background(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res.Evidence) -} - -// queryAllEvidence returns all evidences. -func queryAllEvidence(clientCtx client.Context, pageReq *query.PageRequest) error { - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryAllEvidenceRequest{ - Pagination: pageReq, - } - - res, err := queryClient.AllEvidence(context.Background(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) -} diff --git a/x/evidence/client/cli/query_test.go b/x/evidence/client/cli/query_test.go deleted file mode 100644 index 5567d0427e5b..000000000000 --- a/x/evidence/client/cli/query_test.go +++ /dev/null @@ -1,81 +0,0 @@ -package cli_test - -import ( - "context" - "fmt" - "io" - "strings" - "testing" - - "cosmossdk.io/x/evidence" - "cosmossdk.io/x/evidence/client/cli" - rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" -) - -func TestGetQueryCmd(t *testing.T) { - encCfg := testutilmod.MakeTestEncodingConfig(evidence.AppModuleBasic{}) - kr := keyring.NewInMemory(encCfg.Codec) - baseCtx := client.Context{}. - WithKeyring(kr). - WithTxConfig(encCfg.TxConfig). - WithCodec(encCfg.Codec). - WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}). - WithAccountRetriever(client.MockAccountRetriever{}). - WithOutput(io.Discard). - WithChainID("test-chain") - - testCases := map[string]struct { - args []string - expectedOutput string - expectErrMsg string - }{ - "invalid args": { - []string{"foo", "bar"}, - "", - "accepts at most 1 arg(s)", - }, - "all evidence (default pagination)": { - []string{}, - "evidence: []\npagination: null", - "", - }, - "all evidence (json output)": { - []string{ - fmt.Sprintf("--%s=json", flags.FlagOutput), - }, - `{"evidence":[],"pagination":null}`, - "", - }, - } - - for name, tc := range testCases { - tc := tc - - t.Run(name, func(t *testing.T) { - ctx := svrcmd.CreateExecuteContext(context.Background()) - - cmd := cli.GetQueryCmd() - cmd.SetContext(ctx) - cmd.SetArgs(tc.args) - require.NoError(t, client.SetCmdClientContextHandler(baseCtx, cmd)) - - out, err := clitestutil.ExecTestCLICmd(baseCtx, cmd, tc.args) - if tc.expectErrMsg != "" { - require.Error(t, err) - require.Contains(t, err.Error(), tc.expectErrMsg) - } else { - require.NoError(t, err) - } - - require.Contains(t, strings.TrimSpace(out.String()), tc.expectedOutput) - }) - } -} diff --git a/x/evidence/go.mod b/x/evidence/go.mod index 7da4a0553117..23be74128a4f 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -13,7 +13,7 @@ require ( cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c github.com/cometbft/cometbft v0.38.0-rc1 github.com/cosmos/cosmos-proto v1.0.0-beta.3 - github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230616095813-1111e0b51118 + github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230620151856-3aab81f45d55 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/evidence/go.sum b/x/evidence/go.sum index 97435f5c341c..59deb52a03e6 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -175,10 +175,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0 github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U= github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.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.20230616095813-1111e0b51118 h1:XIBDrJ25Sv4nnO6LspwXQkiMYnlo7j52XCl2KzBMjoQ= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230616095813-1111e0b51118/go.mod h1:dtE3e607fUxLeDcDwSzKycM0lat8U5BbK/wsAmFk7HI= +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/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/evidence/module.go b/x/evidence/module.go index 5dbee9d7c1ec..9e23dfbccd9d 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -97,7 +97,7 @@ func (a AppModuleBasic) GetTxCmd() *cobra.Command { // GetQueryCmd returns the evidence module's root query command. func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() + return nil } // RegisterInterfaces registers the evidence module's interface types