Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(x/staking)!: KVStoreService, return errors and use context.Context #16324

Merged
merged 31 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1c52980
progress
facundomedica May 26, 2023
d4fade6
progress
facundomedica May 28, 2023
5b4b629
progress
facundomedica May 28, 2023
14fc4eb
progress
facundomedica May 24, 2023
fd1e21b
keep fixing
facundomedica May 29, 2023
8938c68
fix tests
facundomedica May 29, 2023
b17abe1
fix app.go
facundomedica May 29, 2023
2831abc
fix conflicts
facundomedica May 30, 2023
b6a9389
remove errcheck lint
facundomedica May 30, 2023
477b7e4
Merge branch 'main' into facu/kvstore-staking2
facundomedica May 30, 2023
f44e2bb
fix linter issues
facundomedica May 30, 2023
d127f05
last linter issue
facundomedica May 30, 2023
1fe8e4e
Merge branch 'main' into facu/kvstore-staking2
facundomedica May 31, 2023
c92b553
Merge branch 'main' into facu/kvstore-staking2
facundomedica May 31, 2023
692db95
lint fixes, handle errors
facundomedica Jun 2, 2023
f3b3ef1
Merge branch 'main' into facu/kvstore-staking2
facundomedica Jun 2, 2023
f7949fb
more lint
facundomedica Jun 2, 2023
8e309ec
Merge branch 'facu/kvstore-staking2' of https://github.com/cosmos/cos…
facundomedica Jun 2, 2023
038dbea
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into facu…
facundomedica Jun 9, 2023
77cf72e
errcheck
facundomedica Jun 9, 2023
f19bc00
errcheck
facundomedica Jun 9, 2023
376fe22
remove unnecessary line
facundomedica Jun 9, 2023
0b38327
cl++
facundomedica Jun 12, 2023
7f5e8be
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into facu…
facundomedica Jun 12, 2023
db5ca9b
Merge branch 'main' into facu/kvstore-staking2
facundomedica Jun 12, 2023
4afb620
Merge branch 'main' into facu/kvstore-staking2
facundomedica Jun 13, 2023
1111e0b
merge main, fix conflixt
facundomedica Jun 16, 2023
f3a77eb
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into facu…
facundomedica Jun 16, 2023
a221287
fix test
facundomedica Jun 16, 2023
648b690
fix test
facundomedica Jun 16, 2023
83ced36
Merge branch 'main' into facu/kvstore-staking2
alexanderbez Jun 16, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (x/staking) [#16324](https://github.com/cosmos/cosmos-sdk/pull/16324) `NewKeeper` now takes a `KVStoreService` instead of a `StoreKey`, and methods in the `Keeper` now take a `context.Context` instead of a `sdk.Context` and return an `error`. Notable changes:
* `Validator` method now returns `types.ErrNoValidatorFound` instead of `nil` when not found.
* (x/distribution) [#16440](https://github.com/cosmos/cosmos-sdk/pull/16440) use collections for `DelegatorWithdrawAddresState`:
* remove `Keeper`: `SetDelegatorWithdrawAddr`, `DeleteDelegatorWithdrawAddr`, `IterateDelegatorWithdrawAddrs`.
* (x/distribution) [#16459](https://github.com/cosmos/cosmos-sdk/pull/16459) use collections for `ValidatorCurrentRewards` state management:
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func NewSimApp(
logger,
)
app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appCodec, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), app.AccountKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.MintKeeper = mintkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[minttypes.StoreKey]), app.StakingKeeper, app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String())

Expand Down
27 changes: 20 additions & 7 deletions simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,20 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
/* Handle fee distribution state. */

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
err := app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
return false
})
if err != nil {
panic(err)
}

// withdraw all delegator rewards
dels := app.StakingKeeper.GetAllDelegations(ctx)
dels, err := app.StakingKeeper.GetAllDelegations(ctx)
if err != nil {
panic(err)
}

for _, delegation := range dels {
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
if err != nil {
Expand Down Expand Up @@ -156,7 +163,10 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetRedelegation(ctx, red)
err = app.StakingKeeper.SetRedelegation(ctx, red)
if err != nil {
panic(err)
}
return false
})

Expand All @@ -165,7 +175,10 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
err = app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
if err != nil {
panic(err)
}
return false
})

Expand All @@ -177,8 +190,8 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
if !found {
validator, err := app.StakingKeeper.GetValidator(ctx, addr)
if err != nil {
panic("expected validator, not found")
}

Expand All @@ -196,7 +209,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
return
}

_, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
_, err = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 5 additions & 1 deletion simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,12 @@ func AddTestAddrsIncremental(app *SimApp, ctx sdk.Context, accNum int, accAmt sd

func addTestAddrs(app *SimApp, ctx sdk.Context, accNum int, accAmt sdkmath.Int, strategy simtestutil.GenerateAccountStrategy) []sdk.AccAddress {
testAddrs := strategy(accNum)
bondDenom, err := app.StakingKeeper.BondDenom(ctx)
if err != nil {
panic(err)
}

initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt))
initCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, accAmt))

for _, addr := range testAddrs {
initAccountWithCoins(app, ctx, addr, initCoins)
Expand Down
112 changes: 76 additions & 36 deletions tests/integration/auth/migrations/v2/store_test.go

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions tests/integration/distribution/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func initFixture(t testing.TB) *fixture {
log.NewNopLogger(),
)

stakingKeeper := stakingkeeper.NewKeeper(cdc, keys[stakingtypes.StoreKey], accountKeeper, bankKeeper, authority.String())
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())

distrKeeper := distrkeeper.NewKeeper(
cdc, runtime.NewKVStoreService(keys[distrtypes.StoreKey]), accountKeeper, bankKeeper, stakingKeeper, distrtypes.ModuleName, authority.String(),
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestMsgWithdrawDelegatorReward(t *testing.T) {
ValidatorAddress: f.valAddr.String(),
},
expErr: true,
expErrMsg: "no delegation distribution info",
expErrMsg: "no delegation for (address, validator) tuple",
},
{
name: "validator with no delegations",
Expand All @@ -254,7 +254,7 @@ func TestMsgWithdrawDelegatorReward(t *testing.T) {
ValidatorAddress: sdk.ValAddress(sdk.AccAddress(PKS[2].Address())).String(),
},
expErr: true,
expErrMsg: "no validator distribution info",
expErrMsg: "validator does not exist",
},
{
name: "valid msg",
Expand Down Expand Up @@ -891,6 +891,9 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
f.bankKeeper.MintCoins(f.sdkCtx, distrtypes.ModuleName, amt)
f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, distrtypes.ModuleName, addr, amt)

bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
require.NoError(t, err)

testCases := []struct {
name string
msg *distrtypes.MsgDepositValidatorRewardsPool
Expand All @@ -902,7 +905,7 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
msg: &distrtypes.MsgDepositValidatorRewardsPool{
Depositor: addr.String(),
ValidatorAddress: valAddr1.String(),
Amount: sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), sdk.NewInt(100))),
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(100))),
},
},
{
Expand All @@ -918,7 +921,7 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
msg: &distrtypes.MsgDepositValidatorRewardsPool{
Depositor: addr.String(),
ValidatorAddress: sdk.ValAddress([]byte("addr1_______________")).String(),
Amount: sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), sdk.NewInt(100))),
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(100))),
},
expErr: true,
expErrMsg: "validator does not exist",
Expand Down
62 changes: 38 additions & 24 deletions tests/integration/evidence/keeper/infraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func initFixture(t testing.TB) *fixture {
log.NewNopLogger(),
)

stakingKeeper := stakingkeeper.NewKeeper(cdc, keys[stakingtypes.StoreKey], accountKeeper, bankKeeper, authority.String())
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())

slashingKeeper := slashingkeeper.NewKeeper(cdc, codec.NewLegacyAmino(), runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), stakingKeeper, authority.String())

Expand Down Expand Up @@ -164,35 +164,40 @@ func TestHandleDoubleSign(t *testing.T) {
populateValidators(t, f)

power := int64(100)
stakingParams := f.stakingKeeper.GetParams(ctx)
operatorAddr, val := valAddresses[0], pubkeys[0]
stakingParams, err := f.stakingKeeper.GetParams(ctx)
assert.NilError(t, err)
operatorAddr, valpubkey := valAddresses[0], pubkeys[0]
tstaking := stakingtestutil.NewHelper(t, ctx, f.stakingKeeper)

selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, true)
selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, valpubkey, power, true)

// execute end-blocker and verify validator attributes
_, err := f.stakingKeeper.EndBlocker(f.sdkCtx)
_, err = f.stakingKeeper.EndBlocker(f.sdkCtx)
assert.NilError(t, err)
assert.DeepEqual(t,
f.bankKeeper.GetAllBalances(ctx, sdk.AccAddress(operatorAddr)).String(),
sdk.NewCoins(sdk.NewCoin(stakingParams.BondDenom, initAmt.Sub(selfDelegation))).String(),
)
assert.DeepEqual(t, selfDelegation, f.stakingKeeper.Validator(ctx, operatorAddr).GetBondedTokens())
val, err := f.stakingKeeper.Validator(ctx, operatorAddr)
assert.NilError(t, err)
assert.DeepEqual(t, selfDelegation, val.GetBondedTokens())

assert.NilError(t, f.slashingKeeper.AddPubkey(f.sdkCtx, val))
assert.NilError(t, f.slashingKeeper.AddPubkey(f.sdkCtx, valpubkey))

info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(val.Address()), f.sdkCtx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
f.slashingKeeper.SetValidatorSigningInfo(f.sdkCtx, sdk.ConsAddress(val.Address()), info)
info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(valpubkey.Address()), f.sdkCtx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
f.slashingKeeper.SetValidatorSigningInfo(f.sdkCtx, sdk.ConsAddress(valpubkey.Address()), info)

// handle a signature to set signing info
f.slashingKeeper.HandleValidatorSignature(ctx, val.Address(), selfDelegation.Int64(), comet.BlockIDFlagCommit)
f.slashingKeeper.HandleValidatorSignature(ctx, valpubkey.Address(), selfDelegation.Int64(), comet.BlockIDFlagCommit)

// double sign less than max age
oldTokens := f.stakingKeeper.Validator(ctx, operatorAddr).GetTokens()
val, err = f.stakingKeeper.Validator(ctx, operatorAddr)
assert.NilError(t, err)
oldTokens := val.GetTokens()

nci := NewCometInfo(abci.RequestFinalizeBlock{
Misbehavior: []abci.Misbehavior{{
Validator: abci.Validator{Address: val.Address(), Power: power},
Validator: abci.Validator{Address: valpubkey.Address(), Power: power},
Type: abci.MisbehaviorType_DUPLICATE_VOTE,
Time: time.Now().UTC(),
Height: 1,
Expand All @@ -203,18 +208,22 @@ func TestHandleDoubleSign(t *testing.T) {
assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx.WithCometInfo(nci)))

// should be jailed and tombstoned
assert.Assert(t, f.stakingKeeper.Validator(ctx, operatorAddr).IsJailed())
assert.Assert(t, f.slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(val.Address())))
val, err = f.stakingKeeper.Validator(ctx, operatorAddr)
assert.NilError(t, err)
assert.Assert(t, val.IsJailed())
assert.Assert(t, f.slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(valpubkey.Address())))

// tokens should be decreased
newTokens := f.stakingKeeper.Validator(ctx, operatorAddr).GetTokens()
newTokens := val.GetTokens()
assert.Assert(t, newTokens.LT(oldTokens))

// submit duplicate evidence
assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx))

// tokens should be the same (capped slash)
assert.Assert(t, f.stakingKeeper.Validator(ctx, operatorAddr).GetTokens().Equal(newTokens))
val, err = f.stakingKeeper.Validator(ctx, operatorAddr)
assert.NilError(t, err)
assert.Assert(t, val.GetTokens().Equal(newTokens))

// jump to past the unbonding period
ctx = ctx.WithBlockTime(time.Unix(1, 0).Add(stakingParams.UnbondingTime))
Expand Down Expand Up @@ -247,25 +256,28 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {
populateValidators(t, f)

power := int64(100)
stakingParams := f.stakingKeeper.GetParams(ctx)
operatorAddr, val := valAddresses[0], pubkeys[0]
stakingParams, err := f.stakingKeeper.GetParams(ctx)
assert.NilError(t, err)
operatorAddr, valpubkey := valAddresses[0], pubkeys[0]

tstaking := stakingtestutil.NewHelper(t, ctx, f.stakingKeeper)

amt := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, true)
amt := tstaking.CreateValidatorWithValPower(operatorAddr, valpubkey, power, true)

// execute end-blocker and verify validator attributes
_, err := f.stakingKeeper.EndBlocker(f.sdkCtx)
_, err = f.stakingKeeper.EndBlocker(f.sdkCtx)
assert.NilError(t, err)
assert.DeepEqual(t,
f.bankKeeper.GetAllBalances(ctx, sdk.AccAddress(operatorAddr)),
sdk.NewCoins(sdk.NewCoin(stakingParams.BondDenom, initAmt.Sub(amt))),
)
assert.DeepEqual(t, amt, f.stakingKeeper.Validator(ctx, operatorAddr).GetBondedTokens())
val, err := f.stakingKeeper.Validator(ctx, operatorAddr)
assert.NilError(t, err)
assert.DeepEqual(t, amt, val.GetBondedTokens())

nci := NewCometInfo(abci.RequestFinalizeBlock{
Misbehavior: []abci.Misbehavior{{
Validator: abci.Validator{Address: val.Address(), Power: power},
Validator: abci.Validator{Address: valpubkey.Address(), Power: power},
Type: abci.MisbehaviorType_DUPLICATE_VOTE,
Time: ctx.BlockTime(),
Height: 0,
Expand All @@ -282,8 +294,10 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {

assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx))

assert.Assert(t, f.stakingKeeper.Validator(ctx, operatorAddr).IsJailed() == false)
assert.Assert(t, f.slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(val.Address())) == false)
val, err = f.stakingKeeper.Validator(ctx, operatorAddr)
assert.NilError(t, err)
assert.Assert(t, val.IsJailed() == false)
assert.Assert(t, f.slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(valpubkey.Address())) == false)
}

func populateValidators(t assert.TestingT, f *fixture) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/gov/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func initFixture(t testing.TB) *fixture {
log.NewNopLogger(),
)

stakingKeeper := stakingkeeper.NewKeeper(cdc, keys[stakingtypes.StoreKey], accountKeeper, bankKeeper, authority.String())
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())

// set default staking params
stakingKeeper.SetParams(newCtx, stakingtypes.DefaultParams())
Expand Down
40 changes: 24 additions & 16 deletions tests/integration/slashing/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func initFixture(t testing.TB) *fixture {
log.NewNopLogger(),
)

stakingKeeper := stakingkeeper.NewKeeper(cdc, keys[stakingtypes.StoreKey], accountKeeper, bankKeeper, authority.String())
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())

slashingKeeper := slashingkeeper.NewKeeper(cdc, &codec.LegacyAmino{}, runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), stakingKeeper, authority.String())

Expand Down Expand Up @@ -133,7 +133,8 @@ func TestUnJailNotBonded(t *testing.T) {
t.Parallel()
f := initFixture(t)

p := f.stakingKeeper.GetParams(f.ctx)
p, err := f.stakingKeeper.GetParams(f.ctx)
assert.NilError(t, err)
p.MaxValidators = 5
f.stakingKeeper.SetParams(f.ctx, p)

Expand Down Expand Up @@ -212,47 +213,53 @@ func TestHandleNewValidator(t *testing.T) {
f := initFixture(t)

pks := simtestutil.CreateTestPubKeys(1)
addr, val := f.valAddrs[0], pks[0]
addr, valpubkey := f.valAddrs[0], pks[0]
tstaking := stakingtestutil.NewHelper(t, f.ctx, f.stakingKeeper)
signedBlocksWindow, err := f.slashingKeeper.SignedBlocksWindow(f.ctx)
assert.NilError(t, err)
f.ctx = f.ctx.WithBlockHeight(signedBlocksWindow + 1)

assert.NilError(t, f.slashingKeeper.AddPubkey(f.ctx, pks[0]))

info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(val.Address()), f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
err = f.slashingKeeper.SetValidatorSigningInfo(f.ctx, sdk.ConsAddress(val.Address()), info)
assert.NilError(t, err)
info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(valpubkey.Address()), f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
assert.NilError(t, f.slashingKeeper.SetValidatorSigningInfo(f.ctx, sdk.ConsAddress(valpubkey.Address()), info))

// Validator created
amt := tstaking.CreateValidatorWithValPower(addr, val, 100, true)
amt := tstaking.CreateValidatorWithValPower(addr, valpubkey, 100, true)

_, err = f.stakingKeeper.EndBlocker(f.ctx)
assert.NilError(t, err)
require.NoError(t, err)

bondDenom, err := f.stakingKeeper.BondDenom(f.ctx)
require.NoError(t, err)

assert.DeepEqual(
t, f.bankKeeper.GetAllBalances(f.ctx, sdk.AccAddress(addr)),
sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.GetParams(f.ctx).BondDenom, testutil.InitTokens.Sub(amt))),
sdk.NewCoins(sdk.NewCoin(bondDenom, testutil.InitTokens.Sub(amt))),
)
assert.DeepEqual(t, amt, f.stakingKeeper.Validator(f.ctx, addr).GetBondedTokens())

val, err := f.stakingKeeper.Validator(f.ctx, addr)
require.NoError(t, err)
assert.DeepEqual(t, amt, val.GetBondedTokens())

// Now a validator, for two blocks
assert.NilError(t, f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), 100, comet.BlockIDFlagCommit))
assert.NilError(t, f.slashingKeeper.HandleValidatorSignature(f.ctx, valpubkey.Address(), 100, comet.BlockIDFlagCommit))
f.ctx = f.ctx.WithBlockHeight(signedBlocksWindow + 2)
assert.NilError(t, f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), 100, comet.BlockIDFlagAbsent))
assert.NilError(t, f.slashingKeeper.HandleValidatorSignature(f.ctx, valpubkey.Address(), 100, comet.BlockIDFlagAbsent))

info, found := f.slashingKeeper.GetValidatorSigningInfo(f.ctx, sdk.ConsAddress(val.Address()))
info, found := f.slashingKeeper.GetValidatorSigningInfo(f.ctx, sdk.ConsAddress(valpubkey.Address()))
assert.Assert(t, found)
assert.Equal(t, signedBlocksWindow+1, info.StartHeight)
assert.Equal(t, int64(2), info.IndexOffset)
assert.Equal(t, int64(1), info.MissedBlocksCounter)
assert.Equal(t, time.Unix(0, 0).UTC(), info.JailedUntil)

// validator should be bonded still, should not have been jailed or slashed
validator, _ := f.stakingKeeper.GetValidatorByConsAddr(f.ctx, sdk.GetConsAddress(val))
validator, _ := f.stakingKeeper.GetValidatorByConsAddr(f.ctx, sdk.GetConsAddress(valpubkey))
assert.Equal(t, stakingtypes.Bonded, validator.GetStatus())
bondPool := f.stakingKeeper.GetBondedPool(f.ctx)
expTokens := f.stakingKeeper.TokensFromConsensusPower(f.ctx, 100)
assert.Assert(t, expTokens.Equal(f.bankKeeper.GetBalance(f.ctx, bondPool.GetAddress(), f.stakingKeeper.BondDenom(f.ctx)).Amount))
assert.Assert(t, expTokens.Equal(f.bankKeeper.GetBalance(f.ctx, bondPool.GetAddress(), bondDenom).Amount))
}

// Test a jailed validator being "down" twice
Expand Down Expand Up @@ -326,7 +333,8 @@ func TestValidatorDippingInAndOut(t *testing.T) {
t.Parallel()
f := initFixture(t)

params := f.stakingKeeper.GetParams(f.ctx)
params, err := f.stakingKeeper.GetParams(f.ctx)
require.NoError(t, err)
params.MaxValidators = 1
f.stakingKeeper.SetParams(f.ctx, params)
power := int64(100)
Expand Down
Loading