Address PR comments: test descriptions & NewValidatorSigningInfo

This commit is contained in:
Christopher Goes 2018-06-11 21:47:35 +02:00
parent b9c1bcbd74
commit ee17b7c9cc
No known key found for this signature in database
GPG Key ID: E828D98232D328D3
3 changed files with 19 additions and 2 deletions

View File

@ -58,8 +58,8 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, pubkey crypto.PubKey,
// Will use the 0-value default signing info if not present, except for start height
signInfo, found := k.getValidatorSigningInfo(ctx, address)
if !found {
// If this validator has never been seen before, set the start height
signInfo.StartHeight = height
// If this validator has never been seen before, construct a new SigningInfo with the correct start height
signInfo = NewValidatorSigningInfo(height, 0, 0, 0)
}
index := signInfo.IndexOffset % SignedBlocksWindow
signInfo.IndexOffset++

View File

@ -11,6 +11,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/stake"
)
// Test that a validator is slashed correctly
// when we discover evidence of equivocation
func TestHandleDoubleSign(t *testing.T) {
// initial setup
@ -32,6 +34,8 @@ func TestHandleDoubleSign(t *testing.T) {
require.Equal(t, sdk.NewRat(amt).Mul(sdk.NewRat(19).Quo(sdk.NewRat(20))), sk.Validator(ctx, addr).GetPower())
}
// Test a validator through uptime, downtime, revocation,
// unrevocation, starting height reset, and revocation again
func TestHandleAbsentValidator(t *testing.T) {
// initial setup
@ -130,6 +134,9 @@ func TestHandleAbsentValidator(t *testing.T) {
require.Equal(t, sdk.Unbonded, validator.GetStatus())
}
// Test a new validator entering the validator set
// Ensure that SigningInfo.StartHeight is set correctly
// and that they are not immediately revoked
func TestHandleNewValidator(t *testing.T) {
// initial setup
ctx, ck, sk, keeper := createTestInput(t)

View File

@ -47,6 +47,16 @@ func (k Keeper) setValidatorSigningBitArray(ctx sdk.Context, address sdk.Address
store.Set(GetValidatorSigningBitArrayKey(address, index), bz)
}
// Construct a new `ValidatorSigningInfo` struct
func NewValidatorSigningInfo(startHeight int64, indexOffset int64, jailedUntil int64, signedBlocksCounter int64) ValidatorSigningInfo {
return ValidatorSigningInfo{
StartHeight: startHeight,
IndexOffset: indexOffset,
JailedUntil: jailedUntil,
SignedBlocksCounter: signedBlocksCounter,
}
}
// Signing info for a validator
type ValidatorSigningInfo struct {
StartHeight int64 `json:"start_height"` // height at which validator was first a candidate OR was unrevoked