This commit is contained in:
rigelrozanski 2018-09-20 20:10:26 -04:00
parent d36030424e
commit 0d9105cf7c
13 changed files with 115 additions and 82 deletions

View File

@ -132,9 +132,9 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
app.SetBeginBlocker(app.BeginBlocker) app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker) app.SetEndBlocker(app.EndBlocker)
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, app.feeCollectionKeeper)) app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, app.feeCollectionKeeper))
app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyIBC, app.keyStake, app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyIBC, app.keyStake, app.keyDistr,
app.keySlashing, app.keyGov, app.keyFeeCollection, app.keyParams) app.keySlashing, app.keyGov, app.keyFeeCollection, app.keyParams)
app.MountStoresTransient(app.tkeyParams, app.tkeyStake) app.MountStoresTransient(app.tkeyParams, app.tkeyStake, app.tkeyDistr)
err := app.LoadLatestVersion(app.keyMain) err := app.LoadLatestVersion(app.keyMain)
if err != nil { if err != nil {
cmn.Exit(err.Error()) cmn.Exit(err.Error())

View File

@ -13,7 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/version"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
distr "github.com/cosmos/cosmos-sdk/x/distribution" distrcmd "github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli" govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
ibccmd "github.com/cosmos/cosmos-sdk/x/ibc/client/cli" ibccmd "github.com/cosmos/cosmos-sdk/x/ibc/client/cli"
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
@ -109,8 +109,8 @@ func main() {
} }
distrCmd.AddCommand( distrCmd.AddCommand(
client.PostCommands( client.PostCommands(
distr.GetCmdWithdrawRewards(cdc), distrcmd.GetCmdWithdrawRewards(cdc),
distr.GetCmdSetWithdrawAddr(cdc), distrcmd.GetCmdSetWithdrawAddr(cdc),
)...) )...)
rootCmd.AddCommand( rootCmd.AddCommand(
distrCmd, distrCmd,

View File

@ -28,6 +28,11 @@ func (v Validator) GetPubKey() crypto.PubKey {
return nil return nil
} }
// Implements sdk.Validator
func (v Validator) GetConsAddr() sdk.ConsAddress {
return sdk.ConsAddress{}
}
// Implements sdk.Validator // Implements sdk.Validator
func (v Validator) GetTokens() sdk.Dec { func (v Validator) GetTokens() sdk.Dec {
return sdk.ZeroDec() return sdk.ZeroDec()
@ -43,6 +48,11 @@ func (v Validator) GetDelegatorShares() sdk.Dec {
return sdk.ZeroDec() return sdk.ZeroDec()
} }
// Implements sdk.Validator
func (v Validator) GetCommission() sdk.Dec {
return sdk.ZeroDec()
}
// Implements sdk.Validator // Implements sdk.Validator
func (v Validator) GetJailed() bool { func (v Validator) GetJailed() bool {
return false return false
@ -88,7 +98,12 @@ func (vs *ValidatorSet) Validator(ctx sdk.Context, addr sdk.ValAddress) sdk.Vali
} }
// ValidatorByPubKey implements sdk.ValidatorSet // ValidatorByPubKey implements sdk.ValidatorSet
func (vs *ValidatorSet) ValidatorByPubKey(ctx sdk.Context, pubkey crypto.PubKey) sdk.Validator { func (vs *ValidatorSet) ValidatorByConsPubKey(ctx sdk.Context, _ crypto.PubKey) sdk.Validator {
panic("not implemented")
}
// ValidatorByPubKey implements sdk.ValidatorSet
func (vs *ValidatorSet) ValidatorByConsAddr(ctx sdk.Context, _ sdk.ConsAddress) sdk.Validator {
panic("not implemented") panic("not implemented")
} }
@ -122,17 +137,17 @@ func (vs *ValidatorSet) RemoveValidator(addr sdk.AccAddress) {
} }
// Implements sdk.ValidatorSet // Implements sdk.ValidatorSet
func (vs *ValidatorSet) Slash(ctx sdk.Context, pubkey crypto.PubKey, height int64, power int64, amt sdk.Dec) { func (vs *ValidatorSet) Slash(ctx sdk.Context, _ sdk.ConsAddress, height int64, power int64, amt sdk.Dec) {
panic("not implemented") panic("not implemented")
} }
// Implements sdk.ValidatorSet // Implements sdk.ValidatorSet
func (vs *ValidatorSet) Jail(ctx sdk.Context, pubkey crypto.PubKey) { func (vs *ValidatorSet) Jail(_ sdk.Context, _ sdk.ConsAddress) {
panic("not implemented") panic("not implemented")
} }
// Implements sdk.ValidatorSet // Implements sdk.ValidatorSet
func (vs *ValidatorSet) Unjail(ctx sdk.Context, pubkey crypto.PubKey) { func (vs *ValidatorSet) Unjail(_ sdk.Context, _ sdk.ConsAddress) {
panic("not implemented") panic("not implemented")
} }

View File

@ -69,9 +69,10 @@ type ValidatorSet interface {
IterateValidatorsBonded(Context, IterateValidatorsBonded(Context,
func(index int64, validator Validator) (stop bool)) func(index int64, validator Validator) (stop bool))
Validator(Context, ValAddress) Validator // get a particular validator by operator Validator(Context, ValAddress) Validator // get a particular validator by operator
ValidatorByConsAddr(Context, ConsAddress) Validator // get a particular validator by consensus address ValidatorByConsPubKey(Context, crypto.PubKey) Validator // get a particular validator by consensus address
TotalPower(Context) Dec // total power of the validator set ValidatorByConsAddr(Context, ConsAddress) Validator // get a particular validator by consensus address
TotalPower(Context) Dec // total power of the validator set
// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction // slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
Slash(Context, ConsAddress, int64, int64, Dec) Slash(Context, ConsAddress, int64, int64, Dec)

View File

@ -2,7 +2,6 @@
package distribution package distribution
import ( import (
"github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
"github.com/cosmos/cosmos-sdk/x/distribution/keeper" "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
"github.com/cosmos/cosmos-sdk/x/distribution/tags" "github.com/cosmos/cosmos-sdk/x/distribution/tags"
"github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/distribution/types"
@ -50,9 +49,6 @@ var (
NewMsgWithdrawDelegatorRewardsAll = types.NewMsgWithdrawDelegatorRewardsAll NewMsgWithdrawDelegatorRewardsAll = types.NewMsgWithdrawDelegatorRewardsAll
NewMsgWithdrawDelegationReward = types.NewMsgWithdrawDelegatorReward NewMsgWithdrawDelegationReward = types.NewMsgWithdrawDelegatorReward
NewMsgWithdrawValidatorRewardsAll = types.NewMsgWithdrawValidatorRewardsAll NewMsgWithdrawValidatorRewardsAll = types.NewMsgWithdrawValidatorRewardsAll
GetCmdWithdrawRewards = cli.GetCmdWithdrawRewards
GetCmdSetWithdrawAddr = cli.GetCmdSetWithdrawAddr
) )
const ( const (

View File

@ -440,7 +440,7 @@ func TestTallyJailedValidator(t *testing.T) {
val2, found := sk.GetValidator(ctx, sdk.ValAddress(addrs[1])) val2, found := sk.GetValidator(ctx, sdk.ValAddress(addrs[1]))
require.True(t, found) require.True(t, found)
sk.Jail(ctx, val2.ConsPubKey) sk.Jail(ctx, sdk.ConsAddress(val2.ConsPubKey.Address()))
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText) proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
proposalID := proposal.GetProposalID() proposalID := proposal.GetProposalID()

View File

@ -29,6 +29,8 @@ type Hooks struct {
k Keeper k Keeper
} }
var _ sdk.StakingHooks = Hooks{}
// Return the wrapper struct // Return the wrapper struct
func (k Keeper) Hooks() Hooks { func (k Keeper) Hooks() Hooks {
return Hooks{k} return Hooks{k}
@ -43,3 +45,11 @@ func (h Hooks) OnValidatorBonded(ctx sdk.Context, address sdk.ConsAddress) {
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, address sdk.ConsAddress) { func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, address sdk.ConsAddress) {
h.k.onValidatorBeginUnbonding(ctx, address) h.k.onValidatorBeginUnbonding(ctx, address)
} }
// nolint - unused hooks
func (h Hooks) OnValidatorCreated(_ sdk.Context, _ sdk.ValAddress) {}
func (h Hooks) OnValidatorCommissionChange(_ sdk.Context, _ sdk.ValAddress) {}
func (h Hooks) OnValidatorRemoved(_ sdk.Context, _ sdk.ValAddress) {}
func (h Hooks) OnDelegationCreated(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}
func (h Hooks) OnDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}
func (h Hooks) OnDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}

View File

@ -78,6 +78,7 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractio
} }
// handle a validator signature, must be called once per validator per block // handle a validator signature, must be called once per validator per block
// TODO refactor to take in a consensus address, additionally should maybe just take in the pubkey too
// nolint gocyclo // nolint gocyclo
func (k Keeper) handleValidatorSignature(ctx sdk.Context, addr crypto.Address, power int64, signed bool) { func (k Keeper) handleValidatorSignature(ctx sdk.Context, addr crypto.Address, power int64, signed bool) {
logger := ctx.Logger().With("module", "x/slashing") logger := ctx.Logger().With("module", "x/slashing")

View File

@ -18,13 +18,16 @@ func init() {
defaultDoubleSignUnbondDuration = 60 * 60 defaultDoubleSignUnbondDuration = 60 * 60
} }
// ______________________________________________________________
// Test that a validator is slashed correctly // Test that a validator is slashed correctly
// when we discover evidence of infraction // when we discover evidence of infraction
// TODO fix this test to not be using the same pubkey/address for signing and operating, it's confusing
func TestHandleDoubleSign(t *testing.T) { func TestHandleDoubleSign(t *testing.T) {
// initial setup // initial setup
ctx, ck, sk, _, keeper := createTestInput(t) ctx, ck, sk, _, keeper := createTestInput(t)
sk = sk.WithValidatorHooks(keeper.ValidatorHooks()) sk = sk.WithHooks(keeper.Hooks())
amtInt := int64(100) amtInt := int64(100)
addr, val, amt := addrs[0], pks[0], sdk.NewInt(amtInt) addr, val, amt := addrs[0], pks[0], sdk.NewInt(amtInt)
got := stake.NewHandler(sk)(ctx, newTestMsgCreateValidator(addr, val, amt)) got := stake.NewHandler(sk)(ctx, newTestMsgCreateValidator(addr, val, amt))
@ -43,7 +46,7 @@ func TestHandleDoubleSign(t *testing.T) {
// should be jailed // should be jailed
require.True(t, sk.Validator(ctx, addr).GetJailed()) require.True(t, sk.Validator(ctx, addr).GetJailed())
// unjail to measure power // unjail to measure power
sk.Unjail(ctx, val) sk.Unjail(ctx, sdk.ConsAddress(addr)) // TODO distinguish cons address
// power should be reduced // power should be reduced
require.Equal( require.Equal(
t, sdk.NewDecFromInt(amt).Mul(sdk.NewDec(19).Quo(sdk.NewDec(20))), t, sdk.NewDecFromInt(amt).Mul(sdk.NewDec(19).Quo(sdk.NewDec(20))),
@ -61,14 +64,16 @@ func TestHandleDoubleSign(t *testing.T) {
// Test that the amount a validator is slashed for multiple double signs // Test that the amount a validator is slashed for multiple double signs
// is correctly capped by the slashing period in which they were committed // is correctly capped by the slashing period in which they were committed
// TODO properly distinguish between consensus and operator address is variable names
func TestSlashingPeriodCap(t *testing.T) { func TestSlashingPeriodCap(t *testing.T) {
// initial setup // initial setup
ctx, ck, sk, _, keeper := createTestInput(t) ctx, ck, sk, _, keeper := createTestInput(t)
sk = sk.WithValidatorHooks(keeper.ValidatorHooks()) sk = sk.WithHooks(keeper.Hooks())
amtInt := int64(100) amtInt := int64(100)
addr, val, amt := addrs[0], pks[0], sdk.NewInt(amtInt) addr, amt := addrs[0], sdk.NewInt(amtInt)
got := stake.NewHandler(sk)(ctx, newTestMsgCreateValidator(addr, val, amt)) valConsPubKey, valConsAddr := pks[0], sdk.ConsAddress(pks[0].Address())
got := stake.NewHandler(sk)(ctx, newTestMsgCreateValidator(addr, valConsPubKey, amt))
require.True(t, got.IsOK()) require.True(t, got.IsOK())
validatorUpdates := stake.EndBlocker(ctx, sk) validatorUpdates := stake.EndBlocker(ctx, sk)
keeper.AddValidators(ctx, validatorUpdates) keeper.AddValidators(ctx, validatorUpdates)
@ -76,39 +81,39 @@ func TestSlashingPeriodCap(t *testing.T) {
require.True(t, sdk.NewDecFromInt(amt).Equal(sk.Validator(ctx, addr).GetPower())) require.True(t, sdk.NewDecFromInt(amt).Equal(sk.Validator(ctx, addr).GetPower()))
// handle a signature to set signing info // handle a signature to set signing info
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, true) keeper.handleValidatorSignature(ctx, valConsPubKey.Address(), amtInt, true)
// double sign less than max age // double sign less than max age
keeper.handleDoubleSign(ctx, val.Address(), 0, time.Unix(0, 0), amtInt) keeper.handleDoubleSign(ctx, valConsPubKey.Address(), 0, time.Unix(0, 0), amtInt)
// should be jailed // should be jailed
require.True(t, sk.Validator(ctx, addr).GetJailed()) require.True(t, sk.Validator(ctx, addr).GetJailed())
// update block height // update block height
ctx = ctx.WithBlockHeight(int64(1)) ctx = ctx.WithBlockHeight(int64(1))
// unjail to measure power // unjail to measure power
sk.Unjail(ctx, val) sk.Unjail(ctx, valConsAddr)
// power should be reduced // power should be reduced
expectedPower := sdk.NewDecFromInt(amt).Mul(sdk.NewDec(19).Quo(sdk.NewDec(20))) expectedPower := sdk.NewDecFromInt(amt).Mul(sdk.NewDec(19).Quo(sdk.NewDec(20)))
require.Equal(t, expectedPower, sk.Validator(ctx, addr).GetPower()) require.Equal(t, expectedPower, sk.Validator(ctx, addr).GetPower())
// double sign again, same slashing period // double sign again, same slashing period
keeper.handleDoubleSign(ctx, val.Address(), 0, time.Unix(0, 0), amtInt) keeper.handleDoubleSign(ctx, valConsPubKey.Address(), 0, time.Unix(0, 0), amtInt)
// should be jailed // should be jailed
require.True(t, sk.Validator(ctx, addr).GetJailed()) require.True(t, sk.Validator(ctx, addr).GetJailed())
// update block height // update block height
ctx = ctx.WithBlockHeight(int64(2)) ctx = ctx.WithBlockHeight(int64(2))
// unjail to measure power // unjail to measure power
sk.Unjail(ctx, val) sk.Unjail(ctx, valConsAddr)
// power should be equal, no more should have been slashed // power should be equal, no more should have been slashed
expectedPower = sdk.NewDecFromInt(amt).Mul(sdk.NewDec(19).Quo(sdk.NewDec(20))) expectedPower = sdk.NewDecFromInt(amt).Mul(sdk.NewDec(19).Quo(sdk.NewDec(20)))
require.Equal(t, expectedPower, sk.Validator(ctx, addr).GetPower()) require.Equal(t, expectedPower, sk.Validator(ctx, addr).GetPower())
// double sign again, new slashing period // double sign again, new slashing period
keeper.handleDoubleSign(ctx, val.Address(), 2, time.Unix(0, 0), amtInt) keeper.handleDoubleSign(ctx, valConsPubKey.Address(), 2, time.Unix(0, 0), amtInt)
// should be jailed // should be jailed
require.True(t, sk.Validator(ctx, addr).GetJailed()) require.True(t, sk.Validator(ctx, addr).GetJailed())
// unjail to measure power // unjail to measure power
sk.Unjail(ctx, val) sk.Unjail(ctx, valConsAddr)
// power should be reduced // power should be reduced
expectedPower = sdk.NewDecFromInt(amt).Mul(sdk.NewDec(18).Quo(sdk.NewDec(20))) expectedPower = sdk.NewDecFromInt(amt).Mul(sdk.NewDec(18).Quo(sdk.NewDec(20)))
require.Equal(t, expectedPower, sk.Validator(ctx, addr).GetPower()) require.Equal(t, expectedPower, sk.Validator(ctx, addr).GetPower())
@ -120,7 +125,7 @@ func TestHandleAbsentValidator(t *testing.T) {
// initial setup // initial setup
ctx, ck, sk, _, keeper := createTestInput(t) ctx, ck, sk, _, keeper := createTestInput(t)
sk = sk.WithValidatorHooks(keeper.ValidatorHooks()) sk = sk.WithHooks(keeper.Hooks())
amtInt := int64(100) amtInt := int64(100)
addr, val, amt := addrs[0], pks[0], sdk.NewInt(amtInt) addr, val, amt := addrs[0], pks[0], sdk.NewInt(amtInt)
sh := stake.NewHandler(sk) sh := stake.NewHandler(sk)
@ -162,7 +167,7 @@ func TestHandleAbsentValidator(t *testing.T) {
require.Equal(t, keeper.SignedBlocksWindow(ctx)-keeper.MinSignedPerWindow(ctx), info.SignedBlocksCounter) require.Equal(t, keeper.SignedBlocksWindow(ctx)-keeper.MinSignedPerWindow(ctx), info.SignedBlocksCounter)
// validator should be bonded still // validator should be bonded still
validator, _ := sk.GetValidatorByPubKey(ctx, val) validator, _ := sk.GetValidatorByConsPubKey(ctx, val)
require.Equal(t, sdk.Bonded, validator.GetStatus()) require.Equal(t, sdk.Bonded, validator.GetStatus())
pool := sk.GetPool(ctx) pool := sk.GetPool(ctx)
require.Equal(t, amtInt, pool.BondedTokens.RoundInt64()) require.Equal(t, amtInt, pool.BondedTokens.RoundInt64())
@ -176,7 +181,7 @@ func TestHandleAbsentValidator(t *testing.T) {
require.Equal(t, keeper.SignedBlocksWindow(ctx)-keeper.MinSignedPerWindow(ctx)-1, info.SignedBlocksCounter) require.Equal(t, keeper.SignedBlocksWindow(ctx)-keeper.MinSignedPerWindow(ctx)-1, info.SignedBlocksCounter)
// validator should have been jailed // validator should have been jailed
validator, _ = sk.GetValidatorByPubKey(ctx, val) validator, _ = sk.GetValidatorByConsPubKey(ctx, val)
require.Equal(t, sdk.Unbonding, validator.GetStatus()) require.Equal(t, sdk.Unbonding, validator.GetStatus())
// unrevocation should fail prior to jail expiration // unrevocation should fail prior to jail expiration
@ -189,7 +194,7 @@ func TestHandleAbsentValidator(t *testing.T) {
require.True(t, got.IsOK()) require.True(t, got.IsOK())
// validator should be rebonded now // validator should be rebonded now
validator, _ = sk.GetValidatorByPubKey(ctx, val) validator, _ = sk.GetValidatorByConsPubKey(ctx, val)
require.Equal(t, sdk.Bonded, validator.GetStatus()) require.Equal(t, sdk.Bonded, validator.GetStatus())
// validator should have been slashed // validator should have been slashed
@ -207,7 +212,7 @@ func TestHandleAbsentValidator(t *testing.T) {
height++ height++
ctx = ctx.WithBlockHeight(height) ctx = ctx.WithBlockHeight(height)
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, false) keeper.handleValidatorSignature(ctx, val.Address(), amtInt, false)
validator, _ = sk.GetValidatorByPubKey(ctx, val) validator, _ = sk.GetValidatorByConsPubKey(ctx, val)
require.Equal(t, sdk.Bonded, validator.GetStatus()) require.Equal(t, sdk.Bonded, validator.GetStatus())
// 500 signed blocks // 500 signed blocks
@ -223,7 +228,7 @@ func TestHandleAbsentValidator(t *testing.T) {
ctx = ctx.WithBlockHeight(height) ctx = ctx.WithBlockHeight(height)
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, false) keeper.handleValidatorSignature(ctx, val.Address(), amtInt, false)
} }
validator, _ = sk.GetValidatorByPubKey(ctx, val) validator, _ = sk.GetValidatorByConsPubKey(ctx, val)
require.Equal(t, sdk.Unbonding, validator.GetStatus()) require.Equal(t, sdk.Unbonding, validator.GetStatus())
} }
@ -258,7 +263,7 @@ func TestHandleNewValidator(t *testing.T) {
require.Equal(t, time.Unix(0, 0).UTC(), info.JailedUntil) require.Equal(t, time.Unix(0, 0).UTC(), info.JailedUntil)
// validator should be bonded still, should not have been jailed or slashed // validator should be bonded still, should not have been jailed or slashed
validator, _ := sk.GetValidatorByPubKey(ctx, val) validator, _ := sk.GetValidatorByConsPubKey(ctx, val)
require.Equal(t, sdk.Bonded, validator.GetStatus()) require.Equal(t, sdk.Bonded, validator.GetStatus())
pool := sk.GetPool(ctx) pool := sk.GetPool(ctx)
require.Equal(t, int64(100), pool.BondedTokens.RoundInt64()) require.Equal(t, int64(100), pool.BondedTokens.RoundInt64())
@ -292,7 +297,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
} }
// validator should have been jailed and slashed // validator should have been jailed and slashed
validator, _ := sk.GetValidatorByPubKey(ctx, val) validator, _ := sk.GetValidatorByConsPubKey(ctx, val)
require.Equal(t, sdk.Unbonding, validator.GetStatus()) require.Equal(t, sdk.Unbonding, validator.GetStatus())
// validator should have been slashed // validator should have been slashed
@ -303,7 +308,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, false) keeper.handleValidatorSignature(ctx, val.Address(), amtInt, false)
// validator should not have been slashed twice // validator should not have been slashed twice
validator, _ = sk.GetValidatorByPubKey(ctx, val) validator, _ = sk.GetValidatorByConsPubKey(ctx, val)
require.Equal(t, amtInt-1, validator.GetTokens().RoundInt64()) require.Equal(t, amtInt-1, validator.GetTokens().RoundInt64())
} }

View File

@ -78,7 +78,7 @@ func TestBeginBlocker(t *testing.T) {
} }
// validator should be jailed // validator should be jailed
validator, found := sk.GetValidatorByPubKey(ctx, pk) validator, found := sk.GetValidatorByConsPubKey(ctx, pk)
require.True(t, found) require.True(t, found)
require.Equal(t, sdk.Unbonding, validator.GetStatus()) require.Equal(t, sdk.Unbonding, validator.GetStatus())
} }

View File

@ -81,8 +81,9 @@ func TestValidatorByPowerIndex(t *testing.T) {
require.True(t, got.IsOK(), "expected create-validator to be ok, got %v", got) require.True(t, got.IsOK(), "expected create-validator to be ok, got %v", got)
// slash and jail the first validator // slash and jail the first validator
keeper.Slash(ctx, keep.PKs[0], 0, initBond, sdk.NewDecWithPrec(5, 1)) consAddr0 := sdk.ConsAddress(keep.PKs[0].Address())
keeper.Jail(ctx, keep.PKs[0]) keeper.Slash(ctx, consAddr0, 0, initBond, sdk.NewDecWithPrec(5, 1))
keeper.Jail(ctx, consAddr0)
validator, found = keeper.GetValidator(ctx, validatorAddr) validator, found = keeper.GetValidator(ctx, validatorAddr)
require.True(t, found) require.True(t, found)
require.Equal(t, sdk.Unbonding, validator.Status) // ensure is unbonding require.Equal(t, sdk.Unbonding, validator.Status) // ensure is unbonding
@ -198,11 +199,12 @@ func TestLegacyValidatorDelegations(t *testing.T) {
setInstantUnbondPeriod(keeper, ctx) setInstantUnbondPeriod(keeper, ctx)
bondAmount := int64(10) bondAmount := int64(10)
valAddr, valPubKey := sdk.ValAddress(keep.Addrs[0]), keep.PKs[0] valAddr := sdk.ValAddress(keep.Addrs[0])
valConsPubKey, valConsAddr := keep.PKs[0], sdk.ConsAddress(keep.PKs[0].Address())
delAddr := keep.Addrs[1] delAddr := keep.Addrs[1]
// create validator // create validator
msgCreateVal := newTestMsgCreateValidator(valAddr, valPubKey, bondAmount) msgCreateVal := newTestMsgCreateValidator(valAddr, valConsPubKey, bondAmount)
got := handleMsgCreateValidator(ctx, msgCreateVal, keeper) got := handleMsgCreateValidator(ctx, msgCreateVal, keeper)
require.True(t, got.IsOK(), "expected create validator msg to be ok, got %v", got) require.True(t, got.IsOK(), "expected create validator msg to be ok, got %v", got)
@ -264,7 +266,7 @@ func TestLegacyValidatorDelegations(t *testing.T) {
require.Equal(t, bondAmount*2, validator.Tokens.RoundInt64()) require.Equal(t, bondAmount*2, validator.Tokens.RoundInt64())
// unjail the validator now that is has non-zero self-delegated shares // unjail the validator now that is has non-zero self-delegated shares
keeper.Unjail(ctx, valPubKey) keeper.Unjail(ctx, valConsAddr)
// verify the validator can now accept delegations // verify the validator can now accept delegations
msgDelegate = newTestMsgDelegate(delAddr, valAddr, bondAmount) msgDelegate = newTestMsgDelegate(delAddr, valAddr, bondAmount)
@ -911,6 +913,7 @@ func TestCliffValidator(t *testing.T) {
func TestBondUnbondRedelegateSlashTwice(t *testing.T) { func TestBondUnbondRedelegateSlashTwice(t *testing.T) {
ctx, _, keeper := keep.CreateTestInput(t, false, 1000) ctx, _, keeper := keep.CreateTestInput(t, false, 1000)
valA, valB, del := sdk.ValAddress(keep.Addrs[0]), sdk.ValAddress(keep.Addrs[1]), keep.Addrs[2] valA, valB, del := sdk.ValAddress(keep.Addrs[0]), sdk.ValAddress(keep.Addrs[1]), keep.Addrs[2]
consAddr0 := sdk.ConsAddress(keep.PKs[0].Address())
msgCreateValidator := newTestMsgCreateValidator(valA, keep.PKs[0], 10) msgCreateValidator := newTestMsgCreateValidator(valA, keep.PKs[0], 10)
got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper) got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
@ -944,7 +947,7 @@ func TestBondUnbondRedelegateSlashTwice(t *testing.T) {
require.Equal(t, sdk.NewDec(6), delegation.Shares) require.Equal(t, sdk.NewDec(6), delegation.Shares)
// slash the validator by half // slash the validator by half
keeper.Slash(ctx, keep.PKs[0], 0, 20, sdk.NewDecWithPrec(5, 1)) keeper.Slash(ctx, consAddr0, 0, 20, sdk.NewDecWithPrec(5, 1))
// unbonding delegation should have been slashed by half // unbonding delegation should have been slashed by half
unbonding, found := keeper.GetUnbondingDelegation(ctx, del, valA) unbonding, found := keeper.GetUnbondingDelegation(ctx, del, valA)
@ -968,7 +971,7 @@ func TestBondUnbondRedelegateSlashTwice(t *testing.T) {
// slash the validator for an infraction committed after the unbonding and redelegation begin // slash the validator for an infraction committed after the unbonding and redelegation begin
ctx = ctx.WithBlockHeight(3) ctx = ctx.WithBlockHeight(3)
keeper.Slash(ctx, keep.PKs[0], 2, 10, sdk.NewDecWithPrec(5, 1)) keeper.Slash(ctx, consAddr0, 2, 10, sdk.NewDecWithPrec(5, 1))
// unbonding delegation should be unchanged // unbonding delegation should be unchanged
unbonding, found = keeper.GetUnbondingDelegation(ctx, del, valA) unbonding, found = keeper.GetUnbondingDelegation(ctx, del, valA)

View File

@ -42,7 +42,7 @@ func TestRevocation(t *testing.T) {
// setup // setup
ctx, keeper, _ := setupHelper(t, 10) ctx, keeper, _ := setupHelper(t, 10)
addr := addrVals[0] addr := addrVals[0]
pk := PKs[0] consAddr := sdk.ConsAddress(PKs[0].Address())
// initial state // initial state
val, found := keeper.GetValidator(ctx, addr) val, found := keeper.GetValidator(ctx, addr)
@ -50,13 +50,13 @@ func TestRevocation(t *testing.T) {
require.False(t, val.GetJailed()) require.False(t, val.GetJailed())
// test jail // test jail
keeper.Jail(ctx, pk) keeper.Jail(ctx, consAddr)
val, found = keeper.GetValidator(ctx, addr) val, found = keeper.GetValidator(ctx, addr)
require.True(t, found) require.True(t, found)
require.True(t, val.GetJailed()) require.True(t, val.GetJailed())
// test unjail // test unjail
keeper.Unjail(ctx, pk) keeper.Unjail(ctx, consAddr)
val, found = keeper.GetValidator(ctx, addr) val, found = keeper.GetValidator(ctx, addr)
require.True(t, found) require.True(t, found)
require.False(t, val.GetJailed()) require.False(t, val.GetJailed())
@ -179,24 +179,24 @@ func TestSlashRedelegation(t *testing.T) {
// tests Slash at a future height (must panic) // tests Slash at a future height (must panic)
func TestSlashAtFutureHeight(t *testing.T) { func TestSlashAtFutureHeight(t *testing.T) {
ctx, keeper, _ := setupHelper(t, 10) ctx, keeper, _ := setupHelper(t, 10)
pk := PKs[0] consAddr := sdk.ConsAddress(PKs[0].Address())
fraction := sdk.NewDecWithPrec(5, 1) fraction := sdk.NewDecWithPrec(5, 1)
require.Panics(t, func() { keeper.Slash(ctx, pk, 1, 10, fraction) }) require.Panics(t, func() { keeper.Slash(ctx, consAddr, 1, 10, fraction) })
} }
// tests Slash at the current height // tests Slash at the current height
func TestSlashValidatorAtCurrentHeight(t *testing.T) { func TestSlashValidatorAtCurrentHeight(t *testing.T) {
ctx, keeper, _ := setupHelper(t, 10) ctx, keeper, _ := setupHelper(t, 10)
pk := PKs[0] consAddr := sdk.ConsAddress(PKs[0].Address())
fraction := sdk.NewDecWithPrec(5, 1) fraction := sdk.NewDecWithPrec(5, 1)
oldPool := keeper.GetPool(ctx) oldPool := keeper.GetPool(ctx)
validator, found := keeper.GetValidatorByConsPubKey(ctx, pk) validator, found := keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found) require.True(t, found)
keeper.Slash(ctx, pk, ctx.BlockHeight(), 10, fraction) keeper.Slash(ctx, consAddr, ctx.BlockHeight(), 10, fraction)
// read updated state // read updated state
validator, found = keeper.GetValidatorByConsPubKey(ctx, pk) validator, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found) require.True(t, found)
newPool := keeper.GetPool(ctx) newPool := keeper.GetPool(ctx)
@ -209,7 +209,7 @@ func TestSlashValidatorAtCurrentHeight(t *testing.T) {
// tests Slash at a previous height with an unbonding delegation // tests Slash at a previous height with an unbonding delegation
func TestSlashWithUnbondingDelegation(t *testing.T) { func TestSlashWithUnbondingDelegation(t *testing.T) {
ctx, keeper, params := setupHelper(t, 10) ctx, keeper, params := setupHelper(t, 10)
pk := PKs[0] consAddr := sdk.ConsAddress(PKs[0].Address())
fraction := sdk.NewDecWithPrec(5, 1) fraction := sdk.NewDecWithPrec(5, 1)
// set an unbonding delegation // set an unbonding delegation
@ -227,9 +227,9 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
// slash validator for the first time // slash validator for the first time
ctx = ctx.WithBlockHeight(12) ctx = ctx.WithBlockHeight(12)
oldPool := keeper.GetPool(ctx) oldPool := keeper.GetPool(ctx)
validator, found := keeper.GetValidatorByConsPubKey(ctx, pk) validator, found := keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found) require.True(t, found)
keeper.Slash(ctx, pk, 10, 10, fraction) keeper.Slash(ctx, consAddr, 10, 10, fraction)
// read updating unbonding delegation // read updating unbonding delegation
ubd, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0]) ubd, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
@ -241,7 +241,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
// bonded tokens burned // bonded tokens burned
require.Equal(t, int64(3), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64()) require.Equal(t, int64(3), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64())
// read updated validator // read updated validator
validator, found = keeper.GetValidatorByConsPubKey(ctx, pk) validator, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found) require.True(t, found)
// power decreased by 3 - 6 stake originally bonded at the time of infraction // power decreased by 3 - 6 stake originally bonded at the time of infraction
// was still bonded at the time of discovery and was slashed by half, 4 stake // was still bonded at the time of discovery and was slashed by half, 4 stake
@ -251,7 +251,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
// slash validator again // slash validator again
ctx = ctx.WithBlockHeight(13) ctx = ctx.WithBlockHeight(13)
keeper.Slash(ctx, pk, 9, 10, fraction) keeper.Slash(ctx, consAddr, 9, 10, fraction)
ubd, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0]) ubd, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
require.True(t, found) require.True(t, found)
// balance decreased again // balance decreased again
@ -261,7 +261,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
// bonded tokens burned again // bonded tokens burned again
require.Equal(t, int64(6), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64()) require.Equal(t, int64(6), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64())
// read updated validator // read updated validator
validator, found = keeper.GetValidatorByConsPubKey(ctx, pk) validator, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found) require.True(t, found)
// power decreased by 3 again // power decreased by 3 again
require.Equal(t, sdk.NewDec(4), validator.GetPower()) require.Equal(t, sdk.NewDec(4), validator.GetPower())
@ -271,7 +271,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
// on the unbonding delegation, but it will slash stake bonded since the infraction // on the unbonding delegation, but it will slash stake bonded since the infraction
// this may not be the desirable behaviour, ref https://github.com/cosmos/cosmos-sdk/issues/1440 // this may not be the desirable behaviour, ref https://github.com/cosmos/cosmos-sdk/issues/1440
ctx = ctx.WithBlockHeight(13) ctx = ctx.WithBlockHeight(13)
keeper.Slash(ctx, pk, 9, 10, fraction) keeper.Slash(ctx, consAddr, 9, 10, fraction)
ubd, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0]) ubd, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
require.True(t, found) require.True(t, found)
// balance unchanged // balance unchanged
@ -281,7 +281,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
// bonded tokens burned again // bonded tokens burned again
require.Equal(t, int64(9), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64()) require.Equal(t, int64(9), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64())
// read updated validator // read updated validator
validator, found = keeper.GetValidatorByConsPubKey(ctx, pk) validator, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found) require.True(t, found)
// power decreased by 3 again // power decreased by 3 again
require.Equal(t, sdk.NewDec(1), validator.GetPower()) require.Equal(t, sdk.NewDec(1), validator.GetPower())
@ -291,7 +291,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
// on the unbonding delegation, but it will slash stake bonded since the infraction // on the unbonding delegation, but it will slash stake bonded since the infraction
// this may not be the desirable behaviour, ref https://github.com/cosmos/cosmos-sdk/issues/1440 // this may not be the desirable behaviour, ref https://github.com/cosmos/cosmos-sdk/issues/1440
ctx = ctx.WithBlockHeight(13) ctx = ctx.WithBlockHeight(13)
keeper.Slash(ctx, pk, 9, 10, fraction) keeper.Slash(ctx, consAddr, 9, 10, fraction)
ubd, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0]) ubd, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
require.True(t, found) require.True(t, found)
// balance unchanged // balance unchanged
@ -303,14 +303,14 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
// read updated validator // read updated validator
// power decreased by 1 again, validator is out of stake // power decreased by 1 again, validator is out of stake
// ergo validator should have been removed from the store // ergo validator should have been removed from the store
_, found = keeper.GetValidatorByConsPubKey(ctx, pk) _, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.False(t, found) require.False(t, found)
} }
// tests Slash at a previous height with a redelegation // tests Slash at a previous height with a redelegation
func TestSlashWithRedelegation(t *testing.T) { func TestSlashWithRedelegation(t *testing.T) {
ctx, keeper, params := setupHelper(t, 10) ctx, keeper, params := setupHelper(t, 10)
pk := PKs[0] consAddr := sdk.ConsAddress(PKs[0].Address())
fraction := sdk.NewDecWithPrec(5, 1) fraction := sdk.NewDecWithPrec(5, 1)
// set a redelegation // set a redelegation
@ -343,9 +343,9 @@ func TestSlashWithRedelegation(t *testing.T) {
// slash validator // slash validator
ctx = ctx.WithBlockHeight(12) ctx = ctx.WithBlockHeight(12)
oldPool := keeper.GetPool(ctx) oldPool := keeper.GetPool(ctx)
validator, found := keeper.GetValidatorByConsPubKey(ctx, pk) validator, found := keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found) require.True(t, found)
keeper.Slash(ctx, pk, 10, 10, fraction) keeper.Slash(ctx, consAddr, 10, 10, fraction)
// read updating redelegation // read updating redelegation
rd, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1]) rd, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
@ -357,7 +357,7 @@ func TestSlashWithRedelegation(t *testing.T) {
// bonded tokens burned // bonded tokens burned
require.Equal(t, int64(5), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64()) require.Equal(t, int64(5), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64())
// read updated validator // read updated validator
validator, found = keeper.GetValidatorByConsPubKey(ctx, pk) validator, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found) require.True(t, found)
// power decreased by 2 - 4 stake originally bonded at the time of infraction // power decreased by 2 - 4 stake originally bonded at the time of infraction
// was still bonded at the time of discovery and was slashed by half, 4 stake // was still bonded at the time of discovery and was slashed by half, 4 stake
@ -367,9 +367,9 @@ func TestSlashWithRedelegation(t *testing.T) {
// slash the validator again // slash the validator again
ctx = ctx.WithBlockHeight(12) ctx = ctx.WithBlockHeight(12)
validator, found = keeper.GetValidatorByConsPubKey(ctx, pk) validator, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found) require.True(t, found)
require.NotPanics(t, func() { keeper.Slash(ctx, pk, 10, 10, sdk.OneDec()) }) require.NotPanics(t, func() { keeper.Slash(ctx, consAddr, 10, 10, sdk.OneDec()) })
// read updating redelegation // read updating redelegation
rd, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1]) rd, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
@ -381,16 +381,16 @@ func TestSlashWithRedelegation(t *testing.T) {
// seven bonded tokens burned // seven bonded tokens burned
require.Equal(t, int64(12), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64()) require.Equal(t, int64(12), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64())
// read updated validator // read updated validator
validator, found = keeper.GetValidatorByConsPubKey(ctx, pk) validator, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found) require.True(t, found)
// power decreased by 4 // power decreased by 4
require.Equal(t, sdk.NewDec(4), validator.GetPower()) require.Equal(t, sdk.NewDec(4), validator.GetPower())
// slash the validator again, by 100% // slash the validator again, by 100%
ctx = ctx.WithBlockHeight(12) ctx = ctx.WithBlockHeight(12)
validator, found = keeper.GetValidatorByConsPubKey(ctx, pk) validator, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found) require.True(t, found)
keeper.Slash(ctx, pk, 10, 10, sdk.OneDec()) keeper.Slash(ctx, consAddr, 10, 10, sdk.OneDec())
// read updating redelegation // read updating redelegation
rd, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1]) rd, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
@ -403,16 +403,16 @@ func TestSlashWithRedelegation(t *testing.T) {
require.Equal(t, int64(16), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64()) require.Equal(t, int64(16), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64())
// read updated validator // read updated validator
// validator decreased to zero power, should have been removed from the store // validator decreased to zero power, should have been removed from the store
_, found = keeper.GetValidatorByConsPubKey(ctx, pk) _, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.False(t, found) require.False(t, found)
// slash the validator again, by 100% // slash the validator again, by 100%
// no stake remains to be slashed // no stake remains to be slashed
ctx = ctx.WithBlockHeight(12) ctx = ctx.WithBlockHeight(12)
// validator no longer in the store // validator no longer in the store
_, found = keeper.GetValidatorByConsPubKey(ctx, pk) _, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.False(t, found) require.False(t, found)
keeper.Slash(ctx, pk, 10, 10, sdk.OneDec()) keeper.Slash(ctx, consAddr, 10, 10, sdk.OneDec())
// read updating redelegation // read updating redelegation
rd, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1]) rd, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
@ -425,7 +425,7 @@ func TestSlashWithRedelegation(t *testing.T) {
require.Equal(t, int64(16), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64()) require.Equal(t, int64(16), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64())
// read updated validator // read updated validator
// power still zero, still not in the store // power still zero, still not in the store
_, found = keeper.GetValidatorByConsPubKey(ctx, pk) _, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.False(t, found) require.False(t, found)
} }
@ -472,9 +472,10 @@ func TestSlashBoth(t *testing.T) {
// slash validator // slash validator
ctx = ctx.WithBlockHeight(12) ctx = ctx.WithBlockHeight(12)
oldPool := keeper.GetPool(ctx) oldPool := keeper.GetPool(ctx)
validator, found := keeper.GetValidatorByConsPubkey(ctx, PKs[0]) validator, found := keeper.GetValidatorByConsPubKey(ctx, PKs[0])
require.True(t, found) require.True(t, found)
keeper.Slash(ctx, PKs[0], 10, 10, fraction) consAddr0 := sdk.ConsAddres(PKs[0].Address())
keeper.Slash(ctx, consAddr0, 10, 10, fraction)
// read updating redelegation // read updating redelegation
rdA, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1]) rdA, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])

View File

@ -260,12 +260,13 @@ func TestSlashToZeroPowerRemoved(t *testing.T) {
require.Equal(t, sdk.Unbonded, validator.Status) require.Equal(t, sdk.Unbonded, validator.Status)
require.Equal(t, int64(100), validator.Tokens.RoundInt64()) require.Equal(t, int64(100), validator.Tokens.RoundInt64())
keeper.SetPool(ctx, pool) keeper.SetPool(ctx, pool)
keeper.SetValidatorByPubKeyIndex(ctx, validator) keeper.SetValidatorByConsAddr(ctx, validator)
validator = keeper.UpdateValidator(ctx, validator) validator = keeper.UpdateValidator(ctx, validator)
require.Equal(t, int64(100), validator.Tokens.RoundInt64(), "\nvalidator %v\npool %v", validator, pool) require.Equal(t, int64(100), validator.Tokens.RoundInt64(), "\nvalidator %v\npool %v", validator, pool)
// slash the validator by 100% // slash the validator by 100%
keeper.Slash(ctx, PKs[0], 0, 100, sdk.OneDec()) consAddr0 := sdk.ConsAddress(PKs[0].Address())
keeper.Slash(ctx, consAddr0, 0, 100, sdk.OneDec())
// validator should have been deleted // validator should have been deleted
_, found := keeper.GetValidator(ctx, addrVals[0]) _, found := keeper.GetValidator(ctx, addrVals[0])
require.False(t, found) require.False(t, found)