Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 0 additions & 62 deletions tests/integration/slashing/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,68 +76,6 @@ func (s *KeeperTestSuite) SetupTest() {
s.msgServer = slashingkeeper.NewMsgServerImpl(s.slashingKeeper)
}

func (s *KeeperTestSuite) TestUnJailNotBonded() {
ctx := s.ctx

p := s.stakingKeeper.GetParams(ctx)
p.MaxValidators = 5
s.stakingKeeper.SetParams(ctx, p)

addrDels := simtestutil.AddTestAddrsIncremental(s.bankKeeper, s.stakingKeeper, ctx, 6, s.stakingKeeper.TokensFromConsensusPower(ctx, 200))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrDels)
pks := simtestutil.CreateTestPubKeys(6)
tstaking := stakingtestutil.NewHelper(s.T(), ctx, s.stakingKeeper)

// create max (5) validators all with the same power
for i := uint32(0); i < p.MaxValidators; i++ {
addr, val := valAddrs[i], pks[i]
tstaking.CreateValidatorWithValPower(addr, val, 100, true)
}

staking.EndBlocker(ctx, s.stakingKeeper)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)

// create a 6th validator with less power than the cliff validator (won't be bonded)
addr, val := valAddrs[5], pks[5]
amt := s.stakingKeeper.TokensFromConsensusPower(ctx, 50)
msg := tstaking.CreateValidatorMsg(addr, val, amt)
msg.MinSelfDelegation = amt
res, err := tstaking.CreateValidatorWithMsg(sdk.WrapSDKContext(ctx), msg)
s.Require().NoError(err)
s.Require().NotNil(res)

staking.EndBlocker(ctx, s.stakingKeeper)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)

tstaking.CheckValidator(addr, stakingtypes.Unbonded, false)

// unbond below minimum self-delegation
s.Require().Equal(p.BondDenom, tstaking.Denom)
tstaking.Undelegate(sdk.AccAddress(addr), addr, s.stakingKeeper.TokensFromConsensusPower(ctx, 1), true)

staking.EndBlocker(ctx, s.stakingKeeper)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)

// verify that validator is jailed
tstaking.CheckValidator(addr, -1, true)

// verify we cannot unjail (yet)
s.Require().Error(s.slashingKeeper.Unjail(ctx, addr))

staking.EndBlocker(ctx, s.stakingKeeper)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
// bond to meet minimum self-delegation
tstaking.DelegateWithPower(sdk.AccAddress(addr), addr, 1)

staking.EndBlocker(ctx, s.stakingKeeper)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)

// verify we can immediately unjail
s.Require().NoError(s.slashingKeeper.Unjail(ctx, addr))

tstaking.CheckValidator(addr, -1, false)
}

// Test a new validator entering the validator set
// Ensure that SigningInfo.StartHeight is set correctly
// and that they are not immediately jailed
Expand Down
4 changes: 4 additions & 0 deletions x/slashing/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ func (h Hooks) BeforeValidatorSlashed(_ sdk.Context, _ sdk.ValAddress, _ sdk.Dec
func (h Hooks) AfterUnbondingInitiated(_ sdk.Context, _ uint64) error {
return nil
}

func (h Hooks) BeforeTokenizeShareRecordRemoved(_ sdk.Context, _ uint64) error {
return nil
}
9 changes: 0 additions & 9 deletions x/slashing/keeper/unjail.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
)

Expand All @@ -20,14 +19,6 @@ func (k Keeper) Unjail(ctx sdk.Context, validatorAddr sdk.ValAddress) error {
return types.ErrMissingSelfDelegation
}

tokens := validator.TokensFromShares(selfDel.GetShares()).TruncateInt()
minSelfBond := validator.GetMinSelfDelegation()
if tokens.LT(minSelfBond) {
return sdkerrors.Wrapf(
types.ErrSelfDelegationTooLowToUnjail, "%s less than %s", tokens, minSelfBond,
)
}

// cannot be unjailed if not jailed
if !validator.IsJailed() {
return types.ErrValidatorNotJailed
Expand Down
6 changes: 4 additions & 2 deletions x/slashing/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ func (suite *SimTestSuite) TestSimulateMsgUnjail() {
suite.Require().NoError(err)

// setup validator0 by consensus address
suite.stakingKeeper.SetValidatorByConsAddr(ctx, validator0)
err = suite.stakingKeeper.SetValidatorByConsAddr(ctx, validator0)
suite.Require().NoError(err)
val0ConsAddress, err := validator0.GetConsAddr()
suite.Require().NoError(err)
info := types.NewValidatorSigningInfo(val0ConsAddress, int64(4), int64(3),
Expand Down Expand Up @@ -178,7 +179,8 @@ func (suite *SimTestSuite) TestSimulateMsgUnjail() {
suite.Require().NoError(err)

var msg types.MsgUnjail
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
err = types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
suite.Require().NoError(err)

suite.Require().True(operationMsg.OK)
suite.Require().Equal(types.TypeMsgUnjail, msg.Type())
Expand Down