From 26f22dbe4dd712f1df1271aa478f81fffd583003 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Mon, 28 May 2018 23:55:39 +0200 Subject: [PATCH] Test start height update --- x/slashing/handler.go | 10 +++++++++- x/slashing/keeper_test.go | 20 +++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/x/slashing/handler.go b/x/slashing/handler.go index e1d6607898..a3218f6e63 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -22,7 +22,9 @@ func handleMsgUnrevoke(ctx sdk.Context, msg MsgUnrevoke, k Keeper) sdk.Result { return ErrNoValidatorForAddress(k.codespace).Result() } - info, found := k.getValidatorSigningInfo(ctx, validator.GetPubKey().Address()) + addr := validator.GetPubKey().Address() + + info, found := k.getValidatorSigningInfo(ctx, addr) if !found { return ErrNoValidatorForAddress(k.codespace).Result() } @@ -35,9 +37,15 @@ func handleMsgUnrevoke(ctx sdk.Context, msg MsgUnrevoke, k Keeper) sdk.Result { return sdk.Result{} } + // Update the starting height (so the validator can't be immediately revoked again) + info.StartHeight = ctx.BlockHeight() + k.setValidatorSigningInfo(ctx, addr, info) + + // Unrevoke the validator k.stakeKeeper.Unrevoke(ctx, validator.GetPubKey()) tags := sdk.NewTags("action", []byte("unrevoke"), "validator", msg.ValidatorAddr.Bytes()) + return sdk.Result{ Tags: tags, } diff --git a/x/slashing/keeper_test.go b/x/slashing/keeper_test.go index 0919b0a20d..b6aad3e6ca 100644 --- a/x/slashing/keeper_test.go +++ b/x/slashing/keeper_test.go @@ -71,7 +71,6 @@ func TestHandleAbsentValidator(t *testing.T) { require.True(t, found) require.Equal(t, int64(0), info.StartHeight) require.Equal(t, SignedBlocksWindow-51, info.SignedBlocksCounter) - height++ // should have been revoked validator = sk.ValidatorByPubKey(ctx, val) require.Equal(t, sdk.Unbonded, validator.GetStatus()) @@ -85,4 +84,23 @@ func TestHandleAbsentValidator(t *testing.T) { // should have been slashed pool = sk.GetPool(ctx) require.Equal(t, int64(99), pool.BondedTokens) + // start height should have been changed + info, found = keeper.getValidatorSigningInfo(ctx, val.Address()) + require.True(t, found) + require.Equal(t, height, info.StartHeight) + require.Equal(t, SignedBlocksWindow-51, info.SignedBlocksCounter) + // should not be immediately revoked again + height++ + ctx = ctx.WithBlockHeight(height) + keeper.handleValidatorSignature(ctx, val, false) + validator = sk.ValidatorByPubKey(ctx, val) + require.Equal(t, sdk.Bonded, validator.GetStatus()) + // should be revoked again after 100 blocks + nextHeight := height + 100 + for ; height <= nextHeight; height++ { + ctx = ctx.WithBlockHeight(height) + keeper.handleValidatorSignature(ctx, val, false) + } + validator = sk.ValidatorByPubKey(ctx, val) + require.Equal(t, sdk.Unbonded, validator.GetStatus()) }