feat: add endblocker with valsetupdate type (#15829)
This commit is contained in:
@@ -25,7 +25,6 @@ import (
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
|
||||
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil"
|
||||
)
|
||||
@@ -100,7 +99,7 @@ func TestHandleDoubleSign(t *testing.T) {
|
||||
selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, true)
|
||||
|
||||
// execute end-blocker and verify validator attributes
|
||||
staking.EndBlocker(ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
assert.DeepEqual(t,
|
||||
f.bankKeeper.GetAllBalances(ctx, sdk.AccAddress(operatorAddr)).String(),
|
||||
sdk.NewCoins(sdk.NewCoin(stakingParams.BondDenom, initAmt.Sub(selfDelegation))).String(),
|
||||
@@ -172,7 +171,7 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {
|
||||
amt := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, true)
|
||||
|
||||
// execute end-blocker and verify validator attributes
|
||||
staking.EndBlocker(ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
assert.DeepEqual(t,
|
||||
f.bankKeeper.GetAllBalances(ctx, sdk.AccAddress(operatorAddr)),
|
||||
sdk.NewCoins(sdk.NewCoin(stakingParams.BondDenom, initAmt.Sub(amt))),
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
@@ -73,7 +72,7 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[1], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[1]), stakingtypes.Unbonded, val2, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[2], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[2]), stakingtypes.Unbonded, val3, true)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
app.StakingKeeper.EndBlocker(ctx)
|
||||
|
||||
return addrs, valAddrs
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
@@ -271,7 +270,7 @@ func TestTallyDelgatorOverride(t *testing.T) {
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[4], delTokens, stakingtypes.Unbonded, val1, true)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
app.StakingKeeper.EndBlocker(ctx)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp, "", "test", "description", addrs[0], false)
|
||||
@@ -309,7 +308,7 @@ func TestTallyDelgatorInherit(t *testing.T) {
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
app.StakingKeeper.EndBlocker(ctx)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp, "", "test", "description", addrs[0], false)
|
||||
@@ -350,7 +349,7 @@ func TestTallyDelgatorMultipleOverride(t *testing.T) {
|
||||
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
app.StakingKeeper.EndBlocker(ctx)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp, "", "test", "description", addrs[0], false)
|
||||
@@ -394,7 +393,7 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {
|
||||
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
app.StakingKeeper.EndBlocker(ctx)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp, "", "test", "description", addrs[0], false)
|
||||
@@ -435,7 +434,7 @@ func TestTallyJailedValidator(t *testing.T) {
|
||||
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
app.StakingKeeper.EndBlocker(ctx)
|
||||
|
||||
consAddr, err := val2.GetConsAddr()
|
||||
assert.NilError(t, err)
|
||||
|
||||
@@ -5,12 +5,12 @@ import (
|
||||
"time"
|
||||
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
|
||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
|
||||
@@ -79,7 +79,7 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
tstaking.CreateValidatorWithValPower(addr, val, 100, true)
|
||||
}
|
||||
|
||||
staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
f.ctx = f.ctx.WithBlockHeight(f.ctx.BlockHeight() + 1)
|
||||
|
||||
// create a 6th validator with less power than the cliff validator (won't be bonded)
|
||||
@@ -91,7 +91,7 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, res != nil)
|
||||
|
||||
staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
f.ctx = f.ctx.WithBlockHeight(f.ctx.BlockHeight() + 1)
|
||||
|
||||
tstaking.CheckValidator(addr, stakingtypes.Unbonded, false)
|
||||
@@ -100,7 +100,7 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
assert.Equal(t, p.BondDenom, tstaking.Denom)
|
||||
tstaking.Undelegate(sdk.AccAddress(addr), addr, f.stakingKeeper.TokensFromConsensusPower(f.ctx, 1), true)
|
||||
|
||||
staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
f.ctx = f.ctx.WithBlockHeight(f.ctx.BlockHeight() + 1)
|
||||
|
||||
// verify that validator is jailed
|
||||
@@ -109,12 +109,12 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
// verify we cannot unjail (yet)
|
||||
assert.ErrorContains(t, f.slashingKeeper.Unjail(f.ctx, addr), "cannot be unjailed")
|
||||
|
||||
staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
f.ctx = f.ctx.WithBlockHeight(f.ctx.BlockHeight() + 1)
|
||||
// bond to meet minimum self-delegation
|
||||
tstaking.DelegateWithPower(sdk.AccAddress(addr), addr, 1)
|
||||
|
||||
staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
f.ctx = f.ctx.WithBlockHeight(f.ctx.BlockHeight() + 1)
|
||||
|
||||
// verify we can immediately unjail
|
||||
@@ -140,7 +140,7 @@ func TestHandleNewValidator(t *testing.T) {
|
||||
// Validator created
|
||||
amt := tstaking.CreateValidatorWithValPower(addr, val, 100, true)
|
||||
|
||||
staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
assert.DeepEqual(
|
||||
t, f.bankKeeper.GetAllBalances(f.ctx, sdk.AccAddress(addr)),
|
||||
sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.GetParams(f.ctx).BondDenom, InitTokens.Sub(amt))),
|
||||
@@ -184,7 +184,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
|
||||
|
||||
amt := tstaking.CreateValidatorWithValPower(addr, val, power, true)
|
||||
|
||||
staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
|
||||
// 1000 first blocks OK
|
||||
height := int64(0)
|
||||
@@ -200,7 +200,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
|
||||
}
|
||||
|
||||
// end block
|
||||
staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
|
||||
// validator should have been jailed and slashed
|
||||
validator, _ := f.stakingKeeper.GetValidatorByConsAddr(f.ctx, sdk.GetConsAddress(val))
|
||||
@@ -240,7 +240,8 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
||||
valAddr := sdk.ValAddress(addr)
|
||||
|
||||
tstaking.CreateValidatorWithValPower(valAddr, val, power, true)
|
||||
validatorUpdates := staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
validatorUpdates, err := f.stakingKeeper.EndBlocker(f.ctx)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 2, len(validatorUpdates))
|
||||
tstaking.CheckValidator(valAddr, stakingtypes.Bonded, false)
|
||||
|
||||
@@ -253,7 +254,8 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
||||
|
||||
// kick first validator out of validator set
|
||||
tstaking.CreateValidatorWithValPower(sdk.ValAddress(pks[1].Address()), pks[1], power+1, true)
|
||||
validatorUpdates = staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
validatorUpdates, err = f.stakingKeeper.EndBlocker(f.ctx)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 2, len(validatorUpdates))
|
||||
tstaking.CheckValidator(sdk.ValAddress(pks[1].Address()), stakingtypes.Bonded, false)
|
||||
tstaking.CheckValidator(valAddr, stakingtypes.Unbonding, false)
|
||||
@@ -265,7 +267,8 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
||||
// validator added back in
|
||||
tstaking.DelegateWithPower(sdk.AccAddress(pks[2].Address()), valAddr, 50)
|
||||
|
||||
validatorUpdates = staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
validatorUpdates, err = f.stakingKeeper.EndBlocker(f.ctx)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 2, len(validatorUpdates))
|
||||
tstaking.CheckValidator(valAddr, stakingtypes.Bonded, false)
|
||||
newPower := power + 50
|
||||
@@ -287,7 +290,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
||||
}
|
||||
|
||||
// should now be jailed & kicked
|
||||
staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
tstaking.CheckValidator(valAddr, stakingtypes.Unbonding, true)
|
||||
|
||||
// check all the signing information
|
||||
@@ -307,7 +310,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
||||
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), newPower, true)
|
||||
|
||||
// validator should not be kicked since we reset counter/array when it was jailed
|
||||
staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
tstaking.CheckValidator(valAddr, stakingtypes.Bonded, false)
|
||||
|
||||
// check start height is correctly set
|
||||
@@ -323,6 +326,6 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
||||
}
|
||||
|
||||
// validator should now be jailed & kicked
|
||||
staking.EndBlocker(f.ctx, f.stakingKeeper)
|
||||
f.stakingKeeper.EndBlocker(f.ctx)
|
||||
tstaking.CheckValidator(valAddr, stakingtypes.Unbonding, true)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
@@ -48,7 +47,7 @@ func bootstrapValidatorTest(t testing.TB, power int64, numAddrs int) (*simapp.Si
|
||||
assert.NilError(t, err)
|
||||
|
||||
// end block to unbond genesis validator
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
app.StakingKeeper.EndBlocker(ctx)
|
||||
|
||||
return app, ctx, addrDels, addrVals
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user