From 3430333eb2f251a4de638f3dca8d7c39f582636c Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 22 Jun 2023 19:59:35 -0600 Subject: [PATCH 1/9] feat(slashing): add autocli config --- x/slashing/autocli.go | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 x/slashing/autocli.go diff --git a/x/slashing/autocli.go b/x/slashing/autocli.go new file mode 100644 index 000000000000..b158a723aa74 --- /dev/null +++ b/x/slashing/autocli.go @@ -0,0 +1,48 @@ +package slashing + +import ( + "strings" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + slashingv1beta "cosmossdk.io/api/cosmos/slashing/v1beta1" +) + +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: slashingv1beta.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Params", + Use: "params", + Short: "Query the current slashing parameters", + Long: strings.TrimSpace(`Query genesis parameters for the slashing module: + +$ query slashing params +`), + }, + { + RpcMethod: "SigningInfo", + Use: "signing-info [validator-conspub]", + Short: "Query a validator's signing information", + Long: strings.TrimSpace(`Use a validators' consensus public key to find the signing-info for that validator: + +$ query slashing signing-info '{"@type":"/cosmos.crypto.ed25519.PubKey","key":"OauFcTKbN5Lx3fJL689cikXBqe+hcp6Y+x0rYUdR9Jk="}' +`), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "cons_address"}, + }, + }, + { + RpcMethod: "SigningInfos", + Use: "signing-infos", + Short: "Query signing information of all validators", + Long: strings.TrimSpace(`signing infos of validators: + +$ query slashing signing-infos +`), + }, + }, + }, + } +} From e71c57723cee9c7c7b3b2ac0a28658bcd040cfbd Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 22 Jun 2023 20:00:27 -0600 Subject: [PATCH 2/9] delete unesesary tests --- x/slashing/client/cli/query.go | 141 -------------------------- x/slashing/client/cli/query_test.go | 148 ---------------------------- 2 files changed, 289 deletions(-) delete mode 100644 x/slashing/client/cli/query.go delete mode 100644 x/slashing/client/cli/query_test.go diff --git a/x/slashing/client/cli/query.go b/x/slashing/client/cli/query.go deleted file mode 100644 index 500a490d64eb..000000000000 --- a/x/slashing/client/cli/query.go +++ /dev/null @@ -1,141 +0,0 @@ -package cli - -import ( - "strings" - - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/types" -) - -// GetQueryCmd returns the cli query commands for this module -func GetQueryCmd() *cobra.Command { - // Group slashing queries under a subcommand - slashingQueryCmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Querying commands for the slashing module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - slashingQueryCmd.AddCommand( - GetCmdQuerySigningInfo(), - GetCmdQueryParams(), - GetCmdQuerySigningInfos(), - ) - - return slashingQueryCmd -} - -// GetCmdQuerySigningInfo implements the command to query signing info. -func GetCmdQuerySigningInfo() *cobra.Command { - cmd := &cobra.Command{ - Use: "signing-info [validator-conspub]", - Short: "Query a validator's signing information", - Long: strings.TrimSpace(`Use a validators' consensus public key to find the signing-info for that validator: - -$ query slashing signing-info '{"@type":"/cosmos.crypto.ed25519.PubKey","key":"OauFcTKbN5Lx3fJL689cikXBqe+hcp6Y+x0rYUdR9Jk="}' -`), - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - var pk cryptotypes.PubKey - if err := clientCtx.Codec.UnmarshalInterfaceJSON([]byte(args[0]), &pk); err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - consAddr := sdk.ConsAddress(pk.Address()) - params := &types.QuerySigningInfoRequest{ConsAddress: consAddr.String()} - res, err := queryClient.SigningInfo(cmd.Context(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(&res.ValSigningInfo) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// GetCmdQuerySigningInfos implements the command to query signing infos. -func GetCmdQuerySigningInfos() *cobra.Command { - cmd := &cobra.Command{ - Use: "signing-infos", - Short: "Query signing information of all validators", - Long: strings.TrimSpace(`signing infos of validators: - -$ query slashing signing-infos -`), - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := types.NewQueryClient(clientCtx) - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - params := &types.QuerySigningInfosRequest{Pagination: pageReq} - res, err := queryClient.SigningInfos(cmd.Context(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - flags.AddPaginationFlagsToCmd(cmd, "signing infos") - - return cmd -} - -// GetCmdQueryParams implements a command to fetch slashing parameters. -func GetCmdQueryParams() *cobra.Command { - cmd := &cobra.Command{ - Use: "params", - Short: "Query the current slashing parameters", - Args: cobra.NoArgs, - Long: strings.TrimSpace(`Query genesis parameters for the slashing module: - -$ query slashing params -`), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryParamsRequest{} - res, err := queryClient.Params(cmd.Context(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(&res.Params) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/slashing/client/cli/query_test.go b/x/slashing/client/cli/query_test.go deleted file mode 100644 index 0779025cfc99..000000000000 --- a/x/slashing/client/cli/query_test.go +++ /dev/null @@ -1,148 +0,0 @@ -package cli_test - -import ( - "fmt" - "io" - "testing" - - abci "github.com/cometbft/cometbft/abci/types" - rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" - "github.com/stretchr/testify/suite" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/crypto/types" - 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/slashing" - "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" -) - -type CLITestSuite struct { - suite.Suite - - kr keyring.Keyring - baseCtx client.Context - clientCtx client.Context - encCfg testutilmod.TestEncodingConfig - - pub types.PubKey - addr sdk.AccAddress -} - -func TestCLITestSuite(t *testing.T) { - suite.Run(t, new(CLITestSuite)) -} - -func (s *CLITestSuite) SetupSuite() { - s.T().Log("setting up integration test suite") - - s.encCfg = testutilmod.MakeTestEncodingConfig(slashing.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). - WithChainID("test-chain") - - ctxGen := func() client.Context { - bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ - Value: bz, - }) - - return s.baseCtx.WithClient(c) - } - s.clientCtx = ctxGen() - - k, _, err := s.clientCtx.Keyring.NewMnemonic("NewValidator", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) - s.Require().NoError(err) - - pub, err := k.GetPubKey() - s.Require().NoError(err) - - s.pub = pub - s.addr = sdk.AccAddress(pub.Address()) -} - -func (s *CLITestSuite) TestGetCmdQuerySigningInfo() { - pubKeyBz, err := s.encCfg.Codec.MarshalInterfaceJSON(s.pub) - s.Require().NoError(err) - pubKeyStr := string(pubKeyBz) - - testCases := []struct { - name string - args []string - expectErr bool - }{ - {"invalid address", []string{"foo"}, true}, - { - "valid address (json output)", - []string{ - pubKeyStr, - fmt.Sprintf("--%s=json", flags.FlagOutput), - fmt.Sprintf("--%s=1", flags.FlagHeight), - }, - false, - }, - { - "valid address (text output)", - []string{ - pubKeyStr, - fmt.Sprintf("--%s=text", flags.FlagOutput), - fmt.Sprintf("--%s=1", flags.FlagHeight), - }, - false, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQuerySigningInfo() - clientCtx := s.clientCtx - - _, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - if tc.expectErr { - s.Require().Error(err) - } else { - s.Require().NoError(err) - } - }) - } -} - -func (s *CLITestSuite) TestGetCmdQueryParams() { - testCases := []struct { - name string - args []string - }{ - { - "json output", - []string{fmt.Sprintf("--%s=json", flags.FlagOutput)}, - }, - { - "text output", - []string{fmt.Sprintf("--%s=text", flags.FlagOutput)}, - }, - } - - for _, tc := range testCases { - tc := tc - - s.Run(tc.name, func() { - cmd := cli.GetCmdQueryParams() - clientCtx := s.clientCtx - - _, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) - s.Require().NoError(err) - }) - } -} From 4f69ae3a860b9d1365d86e7b9b7bbbe90aa2677d Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Thu, 22 Jun 2023 20:04:34 -0600 Subject: [PATCH 3/9] delete unesesary tests --- x/slashing/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/slashing/module.go b/x/slashing/module.go index e050fb0041bf..4d4a0e1a04da 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -90,7 +90,7 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command { // GetQueryCmd returns no root query command for the slashing module. func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() + return nil } // AppModule implements an application module for the slashing module. From 8c627a507cafa5d4197744232e76f3485b4f4c15 Mon Sep 17 00:00:00 2001 From: Jeancarlo Date: Sun, 25 Jun 2023 16:46:00 -0600 Subject: [PATCH 4/9] delete unesesary tests --- x/slashing/client/cli/tx_test.go | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/x/slashing/client/cli/tx_test.go b/x/slashing/client/cli/tx_test.go index c3b5d3803e5c..02703b42c927 100644 --- a/x/slashing/client/cli/tx_test.go +++ b/x/slashing/client/cli/tx_test.go @@ -2,15 +2,77 @@ package cli_test import ( "fmt" + "io" + "testing" + + abci "github.com/cometbft/cometbft/abci/types" + 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/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/crypto/types" 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/slashing" "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" ) +type CLITestSuite struct { + suite.Suite + + kr keyring.Keyring + baseCtx client.Context + clientCtx client.Context + encCfg testutilmod.TestEncodingConfig + + pub types.PubKey + addr sdk.AccAddress +} + +func TestCLITestSuite(t *testing.T) { + suite.Run(t, new(CLITestSuite)) +} + +func (s *CLITestSuite) SetupSuite() { + s.T().Log("setting up integration test suite") + + s.encCfg = testutilmod.MakeTestEncodingConfig(slashing.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). + WithChainID("test-chain") + + ctxGen := func() client.Context { + bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) + c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ + Value: bz, + }) + + return s.baseCtx.WithClient(c) + } + s.clientCtx = ctxGen() + + k, _, err := s.clientCtx.Keyring.NewMnemonic("NewValidator", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) + s.Require().NoError(err) + + pub, err := k.GetPubKey() + s.Require().NoError(err) + + s.pub = pub + s.addr = sdk.AccAddress(pub.Address()) +} + func (s *CLITestSuite) TestNewUnjailTxCmd() { val := s.addr testCases := []struct { From bb16a5075af1b66a1846e80f7a1237aad8fbd256 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 11 Jul 2023 16:57:44 +0200 Subject: [PATCH 5/9] updates --- x/slashing/autocli.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/x/slashing/autocli.go b/x/slashing/autocli.go index b158a723aa74..1862c8dba676 100644 --- a/x/slashing/autocli.go +++ b/x/slashing/autocli.go @@ -1,10 +1,11 @@ package slashing import ( - "strings" + "fmt" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" slashingv1beta "cosmossdk.io/api/cosmos/slashing/v1beta1" + "github.com/cosmos/cosmos-sdk/version" ) func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { @@ -16,19 +17,13 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { RpcMethod: "Params", Use: "params", Short: "Query the current slashing parameters", - Long: strings.TrimSpace(`Query genesis parameters for the slashing module: - -$ query slashing params -`), }, { RpcMethod: "SigningInfo", Use: "signing-info [validator-conspub]", Short: "Query a validator's signing information", - Long: strings.TrimSpace(`Use a validators' consensus public key to find the signing-info for that validator: - -$ query slashing signing-info '{"@type":"/cosmos.crypto.ed25519.PubKey","key":"OauFcTKbN5Lx3fJL689cikXBqe+hcp6Y+x0rYUdR9Jk="}' -`), + Long: "Query a validator's signing information, the validator consensus public key can be got with ' comet show-validator'", + Example: fmt.Sprintf(`%s query slashing signing-info '{"@type":"/cosmos.crypto.ed25519.PubKey","key":"OauFcTKbN5Lx3fJL689cikXBqe+hcp6Y+x0rYUdR9Jk="'`, version.AppName), PositionalArgs: []*autocliv1.PositionalArgDescriptor{ {ProtoField: "cons_address"}, }, @@ -37,10 +32,6 @@ $ query slashing signing-info '{"@type":"/cosmos.crypto.ed25519.PubKey"," RpcMethod: "SigningInfos", Use: "signing-infos", Short: "Query signing information of all validators", - Long: strings.TrimSpace(`signing infos of validators: - -$ query slashing signing-infos -`), }, }, }, From 24a8d3b467eb7fa31a0c03024a228bd63c35a628 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 11 Jul 2023 17:05:21 +0200 Subject: [PATCH 6/9] updates --- x/slashing/autocli.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/slashing/autocli.go b/x/slashing/autocli.go index 1862c8dba676..2bcb4844fba7 100644 --- a/x/slashing/autocli.go +++ b/x/slashing/autocli.go @@ -23,7 +23,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Use: "signing-info [validator-conspub]", Short: "Query a validator's signing information", Long: "Query a validator's signing information, the validator consensus public key can be got with ' comet show-validator'", - Example: fmt.Sprintf(`%s query slashing signing-info '{"@type":"/cosmos.crypto.ed25519.PubKey","key":"OauFcTKbN5Lx3fJL689cikXBqe+hcp6Y+x0rYUdR9Jk="'`, version.AppName), + Example: fmt.Sprintf(`%s query slashing signing-info '{"@type":"/cosmos.crypto.ed25519.PubKey","key":"OauFcTKbN5Lx3fJL689cikXBqe+hcp6Y+x0rYUdR9Jk="}'`, version.AppName), PositionalArgs: []*autocliv1.PositionalArgDescriptor{ {ProtoField: "cons_address"}, }, From a7ae54982705134e6ab8ee7c1a866a4b03d95884 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 14 Jul 2023 13:10:38 +0200 Subject: [PATCH 7/9] updates --- x/slashing/autocli.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/slashing/autocli.go b/x/slashing/autocli.go index 2bcb4844fba7..33507c218576 100644 --- a/x/slashing/autocli.go +++ b/x/slashing/autocli.go @@ -20,9 +20,9 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { }, { RpcMethod: "SigningInfo", - Use: "signing-info [validator-conspub]", + Use: "signing-info [validator-conspub/address]", Short: "Query a validator's signing information", - Long: "Query a validator's signing information, the validator consensus public key can be got with ' comet show-validator'", + Long: "Query a validator's signing information, with a pubkey (' comet show-validator') or a validator consensus address", Example: fmt.Sprintf(`%s query slashing signing-info '{"@type":"/cosmos.crypto.ed25519.PubKey","key":"OauFcTKbN5Lx3fJL689cikXBqe+hcp6Y+x0rYUdR9Jk="}'`, version.AppName), PositionalArgs: []*autocliv1.PositionalArgDescriptor{ {ProtoField: "cons_address"}, From d2beda3e2e269f173960e2287a07bd6e22bf42ca Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sat, 15 Jul 2023 00:35:32 +0200 Subject: [PATCH 8/9] lint fix --- x/slashing/autocli.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/slashing/autocli.go b/x/slashing/autocli.go index 33507c218576..641aa5d9d3c2 100644 --- a/x/slashing/autocli.go +++ b/x/slashing/autocli.go @@ -5,6 +5,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" slashingv1beta "cosmossdk.io/api/cosmos/slashing/v1beta1" + "github.com/cosmos/cosmos-sdk/version" ) From 9489a3fa02c00302787f3bea9440cbcacb6300ef Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sat, 15 Jul 2023 00:39:27 +0200 Subject: [PATCH 9/9] updates --- x/slashing/module.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x/slashing/module.go b/x/slashing/module.go index 437f43252844..1a28a7c3c4a8 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -88,11 +88,6 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command { return cli.NewTxCmd() } -// GetQueryCmd returns no root query command for the slashing module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil -} - // AppModule implements an application module for the slashing module. type AppModule struct { AppModuleBasic