diff --git a/PENDING.md b/PENDING.md index aaa663f10834..a684ea8820e6 100644 --- a/PENDING.md +++ b/PENDING.md @@ -47,6 +47,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 51d26833fe03..845f4c95dfb8 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -977,6 +977,10 @@ 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) } func TestValidateGenesis(t *testing.T) { diff --git a/cmd/gaia/cli_test/test_helpers.go b/cmd/gaia/cli_test/test_helpers.go index 1be9004754de..9b42e592b88a 100644 --- a/cmd/gaia/cli_test/test_helpers.go +++ b/cmd/gaia/cli_test/test_helpers.go @@ -196,7 +196,16 @@ func (f *Fixtures) GDStart(flags ...string) *tests.Process { return proc } -// ValidateGenesis runs gaiad validate-genesi +// 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) +} + +// ValidateGenesis runs gaiad validate-genesis func (f *Fixtures) ValidateGenesis() { cmd := fmt.Sprintf("gaiad validate-genesis --home=%s", f.GDHome) executeWriteCheckErr(f.T, cmd) @@ -521,6 +530,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()) 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()) } 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) }, }