use on-chain params on tests + fix tests + add new tests for power reduction change
This commit is contained in:
@@ -21,7 +21,7 @@ func TestBeginBlocker(t *testing.T) {
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
|
||||
pks := simapp.CreateTestPubKeys(1)
|
||||
simapp.AddTestAddrsFromPubKeys(app, ctx, pks, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
simapp.AddTestAddrsFromPubKeys(app, ctx, pks, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
addr, pk := sdk.ValAddress(pks[0].Address()), pks[0]
|
||||
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestExportAndInitGenesis(t *testing.T) {
|
||||
|
||||
app.SlashingKeeper.SetParams(ctx, testslashing.TestParams())
|
||||
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
|
||||
info1 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]), int64(4), int64(3),
|
||||
time.Now().UTC().Add(100000000000), false, int64(10))
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestCannotUnjailUnlessJailed(t *testing.T) {
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
pks := simapp.CreateTestPubKeys(1)
|
||||
simapp.AddTestAddrsFromPubKeys(app, ctx, pks, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
simapp.AddTestAddrsFromPubKeys(app, ctx, pks, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
|
||||
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
|
||||
slh := slashing.NewHandler(app.SlashingKeeper)
|
||||
@@ -52,12 +52,12 @@ func TestCannotUnjailUnlessMeetMinSelfDelegation(t *testing.T) {
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
pks := simapp.CreateTestPubKeys(1)
|
||||
simapp.AddTestAddrsFromPubKeys(app, ctx, pks, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
simapp.AddTestAddrsFromPubKeys(app, ctx, pks, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
|
||||
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
|
||||
slh := slashing.NewHandler(app.SlashingKeeper)
|
||||
addr, val := sdk.ValAddress(pks[0].Address()), pks[0]
|
||||
amt := sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)
|
||||
amt := app.StakingKeeper.TokensFromConsensusPower(ctx, 100)
|
||||
msg := tstaking.CreateValidatorMsg(addr, val, amt)
|
||||
msg.MinSelfDelegation = amt
|
||||
tstaking.Handle(msg, true)
|
||||
@@ -84,7 +84,7 @@ func TestJailedValidatorDelegations(t *testing.T) {
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{Time: time.Unix(0, 0)})
|
||||
pks := simapp.CreateTestPubKeys(3)
|
||||
|
||||
simapp.AddTestAddrsFromPubKeys(app, ctx, pks, sdk.TokensFromConsensusPower(20, sdk.DefaultPowerReduction))
|
||||
simapp.AddTestAddrsFromPubKeys(app, ctx, pks, app.StakingKeeper.TokensFromConsensusPower(ctx, 20))
|
||||
app.SlashingKeeper.SetParams(ctx, testslashing.TestParams())
|
||||
|
||||
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
|
||||
@@ -145,7 +145,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{Time: time.Unix(0, 0)})
|
||||
pks := simapp.CreateTestPubKeys(1)
|
||||
simapp.AddTestAddrsFromPubKeys(app, ctx, pks, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
simapp.AddTestAddrsFromPubKeys(app, ctx, pks, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
app.SlashingKeeper.SetParams(ctx, testslashing.TestParams())
|
||||
|
||||
power := int64(100)
|
||||
|
||||
@@ -35,7 +35,7 @@ func (suite *SlashingTestSuite) SetupTest() {
|
||||
app.BankKeeper.SetParams(ctx, banktypes.DefaultParams())
|
||||
app.SlashingKeeper.SetParams(ctx, testslashing.TestParams())
|
||||
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
|
||||
info1 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]), int64(4), int64(3),
|
||||
time.Unix(2, 0), false, int64(10))
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
p.MaxValidators = 5
|
||||
app.StakingKeeper.SetParams(ctx, p)
|
||||
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 6, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 6, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
valAddrs := simapp.ConvertAddrsToValAddrs(addrDels)
|
||||
pks := simapp.CreateTestPubKeys(6)
|
||||
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
|
||||
@@ -39,7 +39,7 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
|
||||
// create a 6th validator with less power than the cliff validator (won't be bonded)
|
||||
addr, val := valAddrs[5], pks[5]
|
||||
amt := sdk.TokensFromConsensusPower(50, sdk.DefaultPowerReduction)
|
||||
amt := app.StakingKeeper.TokensFromConsensusPower(ctx, 50)
|
||||
msg := tstaking.CreateValidatorMsg(addr, val, amt)
|
||||
msg.MinSelfDelegation = amt
|
||||
tstaking.Handle(msg, true)
|
||||
@@ -51,7 +51,7 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
|
||||
// unbond below minimum self-delegation
|
||||
require.Equal(t, p.BondDenom, tstaking.Denom)
|
||||
tstaking.Undelegate(sdk.AccAddress(addr), addr, sdk.TokensFromConsensusPower(1, sdk.DefaultPowerReduction), true)
|
||||
tstaking.Undelegate(sdk.AccAddress(addr), addr, app.StakingKeeper.TokensFromConsensusPower(ctx, 1), true)
|
||||
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
|
||||
@@ -83,7 +83,7 @@ func TestHandleNewValidator(t *testing.T) {
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
valAddrs := simapp.ConvertAddrsToValAddrs(addrDels)
|
||||
pks := simapp.CreateTestPubKeys(1)
|
||||
addr, val := valAddrs[0], pks[0]
|
||||
@@ -116,7 +116,7 @@ func TestHandleNewValidator(t *testing.T) {
|
||||
validator, _ := app.StakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, stakingtypes.Bonded, validator.GetStatus())
|
||||
bondPool := app.StakingKeeper.GetBondedPool(ctx)
|
||||
expTokens := sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)
|
||||
expTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 100)
|
||||
require.True(t, expTokens.Equal(app.BankKeeper.GetBalance(ctx, bondPool.GetAddress(), app.StakingKeeper.BondDenom(ctx)).Amount))
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
valAddrs := simapp.ConvertAddrsToValAddrs(addrDels)
|
||||
pks := simapp.CreateTestPubKeys(1)
|
||||
addr, val := valAddrs[0], pks[0]
|
||||
@@ -159,7 +159,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
|
||||
require.Equal(t, stakingtypes.Unbonding, validator.GetStatus())
|
||||
|
||||
// validator should have been slashed
|
||||
resultingTokens := amt.Sub(sdk.TokensFromConsensusPower(1, sdk.DefaultPowerReduction))
|
||||
resultingTokens := amt.Sub(app.StakingKeeper.TokensFromConsensusPower(ctx, 1))
|
||||
require.Equal(t, resultingTokens, validator.GetTokens())
|
||||
|
||||
// another block missed
|
||||
@@ -188,7 +188,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
||||
power := int64(100)
|
||||
|
||||
pks := simapp.CreateTestPubKeys(3)
|
||||
simapp.AddTestAddrsFromPubKeys(app, ctx, pks, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
simapp.AddTestAddrsFromPubKeys(app, ctx, pks, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
|
||||
addr, val := pks[0].Address(), pks[0]
|
||||
consAddr := sdk.ConsAddress(addr)
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
func TestGetSetValidatorSigningInfo(t *testing.T) {
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
|
||||
info, found := app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0]))
|
||||
require.False(t, found)
|
||||
@@ -39,7 +39,7 @@ func TestGetSetValidatorSigningInfo(t *testing.T) {
|
||||
func TestGetSetValidatorMissedBlockBitArray(t *testing.T) {
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
|
||||
missed := app.SlashingKeeper.GetValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(addrDels[0]), 0)
|
||||
require.False(t, missed) // treat empty key as not missed
|
||||
@@ -51,7 +51,7 @@ func TestGetSetValidatorMissedBlockBitArray(t *testing.T) {
|
||||
func TestTombstoned(t *testing.T) {
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
|
||||
require.Panics(t, func() { app.SlashingKeeper.Tombstone(ctx, sdk.ConsAddress(addrDels[0])) })
|
||||
require.False(t, app.SlashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(addrDels[0])))
|
||||
@@ -75,7 +75,7 @@ func TestTombstoned(t *testing.T) {
|
||||
func TestJailUntil(t *testing.T) {
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction))
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, app.StakingKeeper.TokensFromConsensusPower(ctx, 200))
|
||||
|
||||
require.Panics(t, func() { app.SlashingKeeper.JailUntil(ctx, sdk.ConsAddress(addrDels[0]), time.Now()) })
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ func TestSimulateMsgUnjail(t *testing.T) {
|
||||
app.StakingKeeper.Jail(ctx, val0ConsAddress)
|
||||
|
||||
// setup self delegation
|
||||
delTokens := sdk.TokensFromConsensusPower(2, sdk.DefaultPowerReduction)
|
||||
delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 2)
|
||||
validator0, issuedShares := validator0.AddTokensFromDel(delTokens)
|
||||
val0AccAddress, err := sdk.ValAddressFromBech32(validator0.OperatorAddress)
|
||||
require.NoError(t, err)
|
||||
@@ -116,7 +116,7 @@ func createTestApp(isCheckTx bool) (*simapp.SimApp, sdk.Context) {
|
||||
func getTestingAccounts(t *testing.T, r *rand.Rand, app *simapp.SimApp, ctx sdk.Context, n int) []simtypes.Account {
|
||||
accounts := simtypes.RandomAccounts(r, n)
|
||||
|
||||
initAmt := sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
|
||||
initAmt := app.StakingKeeper.TokensFromConsensusPower(ctx, 200)
|
||||
initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))
|
||||
|
||||
// add coins to the accounts
|
||||
|
||||
Reference in New Issue
Block a user