feat(evidence): autocli query support (backport #16625) (#16629)

Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
mergify[bot] 2023-06-21 08:36:54 +00:00 committed by GitHub
parent b6102fb6a8
commit 179c6c7451
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 46 additions and 181 deletions

View File

@ -13,7 +13,7 @@ require (
cosmossdk.io/tools/confix v0.0.0-20230614114324-f368ed5c62bc
cosmossdk.io/tools/rosetta v0.2.1-0.20230614114324-f368ed5c62bc
cosmossdk.io/x/circuit v0.0.0-20230614114324-f368ed5c62bc
cosmossdk.io/x/evidence v0.0.0-20230616204757-46e5f3fb0376
cosmossdk.io/x/evidence v0.0.0-20230621081736-53941657a96b
cosmossdk.io/x/feegrant v0.0.0-20230614114324-f368ed5c62bc
cosmossdk.io/x/nft v0.0.0-20230614114324-f368ed5c62bc
cosmossdk.io/x/tx v0.8.0

View File

@ -212,8 +212,8 @@ cosmossdk.io/tools/rosetta v0.2.1-0.20230614114324-f368ed5c62bc h1:7gFe3tRGqaA3s
cosmossdk.io/tools/rosetta v0.2.1-0.20230614114324-f368ed5c62bc/go.mod h1:l5qTTiHcPXf1m3iz7WuACKFmHW2ewAuIW/+ZcWcUm4Q=
cosmossdk.io/x/circuit v0.0.0-20230614114324-f368ed5c62bc h1:JwM4NDnE5nBZeLllLKPoftFtq0eztBWE0vlc3GDxmlk=
cosmossdk.io/x/circuit v0.0.0-20230614114324-f368ed5c62bc/go.mod h1:VcyU4WzhBXJr+XAAFyGMuR4/CjZLVYtj5EYIH4UwFv4=
cosmossdk.io/x/evidence v0.0.0-20230616204757-46e5f3fb0376 h1:6dgsdUP4yHokKLE99qZUT6i4BtYEuMSW2Of0ufYKyNE=
cosmossdk.io/x/evidence v0.0.0-20230616204757-46e5f3fb0376/go.mod h1:p6buH/50prKzlsCO4Wixv9rizvg4WRCatv/MqqcxoWI=
cosmossdk.io/x/evidence v0.0.0-20230621081736-53941657a96b h1:BkYpZA0W6h/t54HSZK3nOkmForYgPQMwKssRpHCQSPA=
cosmossdk.io/x/evidence v0.0.0-20230621081736-53941657a96b/go.mod h1:igv8Xw4Q1M8R1HIUSxVCk1MeAb5l/gZhz2Rbk2iS/oE=
cosmossdk.io/x/feegrant v0.0.0-20230614114324-f368ed5c62bc h1:Ycesi/NLYXvHrxrWee9PF46Rmek38B7M4UP9MMzCptk=
cosmossdk.io/x/feegrant v0.0.0-20230614114324-f368ed5c62bc/go.mod h1:OUQndoNT6o5MAtRBF9eCQx22nBVO+gHdyKYOcK6dAVo=
cosmossdk.io/x/nft v0.0.0-20230614114324-f368ed5c62bc h1:jSfbIQybYPjsHEoqxefBsS9kW+R9t2nmu4bsjeE2wGI=

View File

@ -12,7 +12,7 @@ require (
cosmossdk.io/math v1.0.1
cosmossdk.io/simapp v0.0.0-20230620040119-e078f1a49e8b
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c
cosmossdk.io/x/evidence v0.0.0-20230616204757-46e5f3fb0376
cosmossdk.io/x/evidence v0.0.0-20230621081736-53941657a96b
cosmossdk.io/x/feegrant v0.0.0-20230614114324-f368ed5c62bc
cosmossdk.io/x/nft v0.0.0-20230614114324-f368ed5c62bc // indirect
cosmossdk.io/x/tx v0.8.0

View File

@ -208,8 +208,8 @@ cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c h1:A+FMPW9GtfcPB
cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c/go.mod h1:RbYGvXCbz8uNBCXrwS9Z8SyydeWi+W5x5MZ33muyzMw=
cosmossdk.io/x/circuit v0.0.0-20230614114324-f368ed5c62bc h1:JwM4NDnE5nBZeLllLKPoftFtq0eztBWE0vlc3GDxmlk=
cosmossdk.io/x/circuit v0.0.0-20230614114324-f368ed5c62bc/go.mod h1:VcyU4WzhBXJr+XAAFyGMuR4/CjZLVYtj5EYIH4UwFv4=
cosmossdk.io/x/evidence v0.0.0-20230616204757-46e5f3fb0376 h1:6dgsdUP4yHokKLE99qZUT6i4BtYEuMSW2Of0ufYKyNE=
cosmossdk.io/x/evidence v0.0.0-20230616204757-46e5f3fb0376/go.mod h1:p6buH/50prKzlsCO4Wixv9rizvg4WRCatv/MqqcxoWI=
cosmossdk.io/x/evidence v0.0.0-20230621081736-53941657a96b h1:BkYpZA0W6h/t54HSZK3nOkmForYgPQMwKssRpHCQSPA=
cosmossdk.io/x/evidence v0.0.0-20230621081736-53941657a96b/go.mod h1:igv8Xw4Q1M8R1HIUSxVCk1MeAb5l/gZhz2Rbk2iS/oE=
cosmossdk.io/x/feegrant v0.0.0-20230614114324-f368ed5c62bc h1:Ycesi/NLYXvHrxrWee9PF46Rmek38B7M4UP9MMzCptk=
cosmossdk.io/x/feegrant v0.0.0-20230614114324-f368ed5c62bc/go.mod h1:OUQndoNT6o5MAtRBF9eCQx22nBVO+gHdyKYOcK6dAVo=
cosmossdk.io/x/nft v0.0.0-20230614114324-f368ed5c62bc h1:jSfbIQybYPjsHEoqxefBsS9kW+R9t2nmu4bsjeE2wGI=

View File

@ -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.

34
x/evidence/autocli.go Normal file
View File

@ -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),
},
},
},
}
}

View File

@ -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)
}

View File

@ -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)
})
}
}

View File

@ -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