Add testcase past max evidence age
This commit is contained in:
parent
14744cff20
commit
be4b140003
|
@ -76,7 +76,10 @@ func TestHandleDoubleSign(t *testing.T) {
|
||||||
_ = sk.Tick(ctx)
|
_ = sk.Tick(ctx)
|
||||||
require.Equal(t, ck.GetCoins(ctx, addr), sdk.Coins{{sk.GetParams(ctx).BondDenom, initCoins - amt}})
|
require.Equal(t, ck.GetCoins(ctx, addr), sdk.Coins{{sk.GetParams(ctx).BondDenom, initCoins - amt}})
|
||||||
require.Equal(t, sdk.NewRat(amt), sk.Validator(ctx, addr).GetPower())
|
require.Equal(t, sdk.NewRat(amt), sk.Validator(ctx, addr).GetPower())
|
||||||
keeper.handleDoubleSign(ctx, 0, 0, val)
|
keeper.handleDoubleSign(ctx, 0, 0, val) // double sign less than max age
|
||||||
|
require.Equal(t, sdk.NewRat(amt).Mul(sdk.NewRat(19).Quo(sdk.NewRat(20))), sk.Validator(ctx, addr).GetPower())
|
||||||
|
ctx = ctx.WithBlockHeader(abci.Header{Time: 300})
|
||||||
|
keeper.handleDoubleSign(ctx, 0, 0, val) // double sign past max age
|
||||||
require.Equal(t, sdk.NewRat(amt).Mul(sdk.NewRat(19).Quo(sdk.NewRat(20))), sk.Validator(ctx, addr).GetPower())
|
require.Equal(t, sdk.NewRat(amt).Mul(sdk.NewRat(19).Quo(sdk.NewRat(20))), sk.Validator(ctx, addr).GetPower())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -780,6 +780,7 @@ func (k Keeper) IterateDelegators(ctx sdk.Context, delAddr sdk.Address, fn func(
|
||||||
// slash a validator
|
// slash a validator
|
||||||
func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, height int64, fraction sdk.Rat) {
|
func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, height int64, fraction sdk.Rat) {
|
||||||
// TODO height ignored for now, see https://github.com/cosmos/cosmos-sdk/pull/1011#issuecomment-390253957
|
// TODO height ignored for now, see https://github.com/cosmos/cosmos-sdk/pull/1011#issuecomment-390253957
|
||||||
|
logger := ctx.Logger().With("module", "x/stake")
|
||||||
val, found := k.GetValidatorByPubKey(ctx, pubkey)
|
val, found := k.GetValidatorByPubKey(ctx, pubkey)
|
||||||
if !found {
|
if !found {
|
||||||
panic(fmt.Errorf("Attempted to slash a nonexistent validator with pubkey %s", pubkey))
|
panic(fmt.Errorf("Attempted to slash a nonexistent validator with pubkey %s", pubkey))
|
||||||
|
@ -789,7 +790,7 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, height int64, fract
|
||||||
val, pool, burned := val.removePoolShares(pool, sharesToRemove)
|
val, pool, burned := val.removePoolShares(pool, sharesToRemove)
|
||||||
k.setPool(ctx, pool) // update the pool
|
k.setPool(ctx, pool) // update the pool
|
||||||
k.updateValidator(ctx, val) // update the validator, possibly kicking it out
|
k.updateValidator(ctx, val) // update the validator, possibly kicking it out
|
||||||
ctx.Logger().With("module", "x/stake").Info(fmt.Sprintf("Validator %v slashed by fraction %v, removed %v shares and burned %d tokens", pubkey, fraction, sharesToRemove, burned))
|
logger.Info(fmt.Sprintf("Validator %v slashed by fraction %v, removed %v shares and burned %d tokens", pubkey, fraction, sharesToRemove, burned))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue