Fix query signing-info panic (#3417)
This commit is contained in:
commit
75c3a44a0d
|
@ -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
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue