From 818fd1648194225ba00405dce63f8e72afd6f82d Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Mon, 28 Jan 2019 11:37:05 -0800 Subject: [PATCH 1/3] Fixes #3393 --- x/slashing/client/cli/query.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/x/slashing/client/cli/query.go b/x/slashing/client/cli/query.go index fa5f882cc69e..5354e6e23d9e 100644 --- a/x/slashing/client/cli/query.go +++ b/x/slashing/client/cli/query.go @@ -25,15 +25,20 @@ func GetCmdQuerySigningInfo(storeName string, cdc *codec.Codec) *cobra.Command { return err } - key := slashing.GetValidatorSigningInfoKey(sdk.ConsAddress(pk.Address())) + consAddr := sdk.ConsAddress(pk.Address()) + key := slashing.GetValidatorSigningInfoKey(consAddr) res, err := cliCtx.QueryStore(key, storeName) if err != nil { return err } + if len(res) == 0 { + return fmt.Errorf("Validator %s not found in slashing store", consAddr) + } + var signingInfo slashing.ValidatorSigningInfo - cdc.MustUnmarshalBinaryLengthPrefixed(res, signingInfo) + cdc.MustUnmarshalBinaryLengthPrefixed(res, &signingInfo) return cliCtx.PrintOutput(signingInfo) }, } From 75c24fda1cedd4d49e989f8b8f432d41a3316752 Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Mon, 28 Jan 2019 12:40:08 -0800 Subject: [PATCH 2/3] Add test/pending --- PENDING.md | 1 + cmd/gaia/cli_test/cli_test.go | 4 ++++ cmd/gaia/cli_test/test_helpers.go | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/PENDING.md b/PENDING.md index 3f5a4146c81e..bcb7fcd15214 100644 --- a/PENDING.md +++ b/PENDING.md @@ -46,6 +46,7 @@ BUG FIXES * Gaia REST API * Gaia CLI (`gaiacli`) + - [\#3417](https://github.com/cosmos/cosmos-sdk/pull/3417) Fix `q slashing signing-info` panic by ensuring safety of user input and properly returning not found error * Gaia diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 1d1655602247..092e09ec524e 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -977,4 +977,8 @@ func TestSlashingGetParams(t *testing.T) { require.Equal(t, time.Duration(120000000000), params.MaxEvidenceAge) require.Equal(t, int64(100), params.SignedBlocksWindow) require.Equal(t, sdk.NewDecWithPrec(5, 1), params.MinSignedPerWindow) + + sinfo := f.QuerySigningInfo(f.GDTendermint("show-validator")) + require.Equal(t, int64(0), sinfo.StartHeight) + require.False(t, sinfo.Tombstoned) } diff --git a/cmd/gaia/cli_test/test_helpers.go b/cmd/gaia/cli_test/test_helpers.go index 54f592f10bee..2d60ff292d83 100644 --- a/cmd/gaia/cli_test/test_helpers.go +++ b/cmd/gaia/cli_test/test_helpers.go @@ -196,6 +196,15 @@ func (f *Fixtures) GDStart(flags ...string) *tests.Process { return proc } +// GDTendermint returns the results of gaiad tendermint [query] +func (f *Fixtures) GDTendermint(query string) string { + cmd := fmt.Sprintf("gaiad tendermint %s --home=%s", query, f.GDHome) + success, stdout, stderr := executeWriteRetStdStreams(f.T, cmd) + require.Empty(f.T, stderr) + require.True(f.T, success) + return strings.TrimSpace(stdout) +} + //___________________________________________________________________________________ // gaiacli keys @@ -515,6 +524,18 @@ func (f *Fixtures) QueryGovDeposits(propsalID int, flags ...string) []gov.Deposi //___________________________________________________________________________________ // query slashing +// QuerySigningInfo returns the signing info for a validator +func (f *Fixtures) QuerySigningInfo(val string) slashing.ValidatorSigningInfo { + cmd := fmt.Sprintf("gaiacli query slashing signing-info %s %s", val, f.Flags()) + res, errStr := tests.ExecuteT(f.T, cmd, "") + require.Empty(f.T, errStr) + cdc := app.MakeCodec() + var sinfo slashing.ValidatorSigningInfo + err := cdc.UnmarshalJSON([]byte(res), &sinfo) + require.NoError(f.T, err) + return sinfo +} + // QuerySlashingParams is gaiacli query slashing params func (f *Fixtures) QuerySlashingParams() slashing.Params { cmd := fmt.Sprintf("gaiacli query slashing params %s", f.Flags()) From 17f67952dab6d6743291da317decabf5a05301ec Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Mon, 28 Jan 2019 13:08:42 -0800 Subject: [PATCH 3/3] loadGenesisDoc -> LoadGenesisDoc --- cmd/gaia/init/validate_genesis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/gaia/init/validate_genesis.go b/cmd/gaia/init/validate_genesis.go index ed0f6e0a05a2..5f5aae7099a3 100644 --- a/cmd/gaia/init/validate_genesis.go +++ b/cmd/gaia/init/validate_genesis.go @@ -32,7 +32,7 @@ func ValidateGenesisCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command { fmt.Fprintf(os.Stderr, "validating genesis file at %s\n", genesis) var genDoc types.GenesisDoc - if genDoc, err = loadGenesisDoc(cdc, genesis); err != nil { + if genDoc, err = LoadGenesisDoc(cdc, genesis); err != nil { return errors.Errorf("Error loading genesis doc from %s: %s", genesis, err.Error()) }