remove cast to int64 for amount multiplied by PowerReduction
This commit is contained in:
parent
03a46181c6
commit
be1012c8d1
|
@ -214,10 +214,10 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
validator, _ = app.StakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, stakingtypes.Unbonding, validator.GetStatus())
|
||||
|
||||
slashAmt := amt.ToDec().Mul(app.SlashingKeeper.SlashFractionDowntime(ctx)).RoundInt64()
|
||||
slashAmt := amt.ToDec().Mul(app.SlashingKeeper.SlashFractionDowntime(ctx)).RoundInt()
|
||||
|
||||
// validator should have been slashed
|
||||
require.Equal(t, amt.Int64()-slashAmt, validator.GetTokens().Int64())
|
||||
require.True(t, amt.Sub(slashAmt).Equal(validator.GetTokens()))
|
||||
|
||||
// 502nd block *also* missed (since the LastCommit would have still included the just-unbonded validator)
|
||||
height++
|
||||
|
@ -233,7 +233,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
|
||||
// validator should not have been slashed any more, since it was already jailed
|
||||
validator, _ = app.StakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, amt.Int64()-slashAmt, validator.GetTokens().Int64())
|
||||
require.True(t, amt.Sub(slashAmt).Equal(validator.GetTokens()))
|
||||
|
||||
// unrevocation should fail prior to jail expiration
|
||||
res, err := slh(ctx, types.NewMsgUnjail(addr))
|
||||
|
@ -254,7 +254,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
require.Equal(t, stakingtypes.Bonded, validator.GetStatus())
|
||||
|
||||
// validator should have been slashed
|
||||
require.Equal(t, amt.Int64()-slashAmt, app.BankKeeper.GetBalance(ctx, bondPool.GetAddress(), app.StakingKeeper.BondDenom(ctx)).Amount.Int64())
|
||||
require.True(t, amt.Sub(slashAmt).Equal(app.BankKeeper.GetBalance(ctx, bondPool.GetAddress(), app.StakingKeeper.BondDenom(ctx)).Amount))
|
||||
|
||||
// Validator start height should not have been changed
|
||||
info, found = app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(val.Address()))
|
||||
|
|
|
@ -117,7 +117,7 @@ func TestHandleNewValidator(t *testing.T) {
|
|||
require.Equal(t, stakingtypes.Bonded, validator.GetStatus())
|
||||
bondPool := app.StakingKeeper.GetBondedPool(ctx)
|
||||
expTokens := sdk.TokensFromConsensusPower(100)
|
||||
require.Equal(t, expTokens.Int64(), app.BankKeeper.GetBalance(ctx, bondPool.GetAddress(), app.StakingKeeper.BondDenom(ctx)).Amount.Int64())
|
||||
require.True(t, expTokens.Equal(app.BankKeeper.GetBalance(ctx, bondPool.GetAddress(), app.StakingKeeper.BondDenom(ctx)).Amount))
|
||||
}
|
||||
|
||||
// Test a jailed validator being "down" twice
|
||||
|
|
|
@ -281,7 +281,7 @@ func TestIncrementsMsgDelegate(t *testing.T) {
|
|||
require.Equal(t, bondAmount, bond.Shares.RoundInt())
|
||||
|
||||
bondedTokens := app.StakingKeeper.TotalBondedTokens(ctx)
|
||||
require.Equal(t, bondAmount.Int64(), bondedTokens.Int64())
|
||||
require.True(t, bondAmount.Equal(bondedTokens))
|
||||
|
||||
for i := int64(0); i < 5; i++ {
|
||||
ctx = ctx.WithBlockHeight(i)
|
||||
|
@ -436,13 +436,13 @@ func TestIncrementsMsgUnbond(t *testing.T) {
|
|||
gotDelegatorShares := validator.DelegatorShares.RoundInt()
|
||||
gotDelegatorAcc := app.BankKeeper.GetBalance(ctx, delegatorAddr, params.BondDenom).Amount
|
||||
|
||||
require.Equal(t, expBond.Int64(), gotBond.Int64(),
|
||||
require.True(t, expBond.Equal(gotBond),
|
||||
"i: %v\nexpBond: %v\ngotBond: %v\nvalidator: %v\nbond: %v\n",
|
||||
i, expBond, gotBond, validator, bond)
|
||||
require.Equal(t, expDelegatorShares.Int64(), gotDelegatorShares.Int64(),
|
||||
require.True(t, expDelegatorShares.Equal(gotDelegatorShares),
|
||||
"i: %v\nexpDelegatorShares: %v\ngotDelegatorShares: %v\nvalidator: %v\nbond: %v\n",
|
||||
i, expDelegatorShares, gotDelegatorShares, validator, bond)
|
||||
require.Equal(t, expDelegatorAcc.Int64(), gotDelegatorAcc.Int64(),
|
||||
require.True(t, expDelegatorAcc.Equal(gotDelegatorAcc),
|
||||
"i: %v\nexpDelegatorAcc: %v\ngotDelegatorAcc: %v\nvalidator: %v\nbond: %v\n",
|
||||
i, expDelegatorAcc, gotDelegatorAcc, validator, bond)
|
||||
}
|
||||
|
@ -740,7 +740,7 @@ func TestRedelegationPeriod(t *testing.T) {
|
|||
|
||||
// balance should have been subtracted after creation
|
||||
amt2 := app.BankKeeper.GetBalance(ctx, sdk.AccAddress(validatorAddr), denom).Amount
|
||||
require.Equal(t, amt1.Sub(sdk.NewInt(10)).Int64(), amt2.Int64(), "expected coins to be subtracted")
|
||||
require.True(t, amt1.Sub(sdk.NewInt(10)).Equal(amt2), "expected coins to be subtracted")
|
||||
|
||||
tstaking.CreateValidator(validatorAddr2, PKs[1], 10, true)
|
||||
bal1 := app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(validatorAddr))
|
||||
|
|
|
@ -90,13 +90,13 @@ func TestSlashUnbondingDelegation(t *testing.T) {
|
|||
|
||||
// unbonding started prior to the infraction height, stakw didn't contribute
|
||||
slashAmount := app.StakingKeeper.SlashUnbondingDelegation(ctx, ubd, 1, fraction)
|
||||
require.Equal(t, int64(0), slashAmount.Int64())
|
||||
require.True(t, slashAmount.Equal(sdk.NewInt(0)))
|
||||
|
||||
// after the expiration time, no longer eligible for slashing
|
||||
ctx = ctx.WithBlockHeader(tmproto.Header{Time: time.Unix(10, 0)})
|
||||
app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
|
||||
slashAmount = app.StakingKeeper.SlashUnbondingDelegation(ctx, ubd, 0, fraction)
|
||||
require.Equal(t, int64(0), slashAmount.Int64())
|
||||
require.True(t, slashAmount.Equal(sdk.NewInt(0)))
|
||||
|
||||
// test valid slash, before expiration timestamp and to which stake contributed
|
||||
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
|
||||
|
@ -104,7 +104,7 @@ func TestSlashUnbondingDelegation(t *testing.T) {
|
|||
ctx = ctx.WithBlockHeader(tmproto.Header{Time: time.Unix(0, 0)})
|
||||
app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
|
||||
slashAmount = app.StakingKeeper.SlashUnbondingDelegation(ctx, ubd, 0, fraction)
|
||||
require.Equal(t, int64(5), slashAmount.Int64())
|
||||
require.True(t, slashAmount.Equal(sdk.NewInt(5)))
|
||||
ubd, found := app.StakingKeeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
|
||||
require.True(t, found)
|
||||
require.Len(t, ubd.Entries, 1)
|
||||
|
@ -116,7 +116,7 @@ func TestSlashUnbondingDelegation(t *testing.T) {
|
|||
require.Equal(t, sdk.NewInt(5), ubd.Entries[0].Balance)
|
||||
newUnbondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress())
|
||||
diffTokens := oldUnbondedPoolBalances.Sub(newUnbondedPoolBalances)
|
||||
require.Equal(t, int64(5), diffTokens.AmountOf(app.StakingKeeper.BondDenom(ctx)).Int64())
|
||||
require.True(t, diffTokens.AmountOf(app.StakingKeeper.BondDenom(ctx)).Equal(sdk.NewInt(5)))
|
||||
}
|
||||
|
||||
// tests slashRedelegation
|
||||
|
@ -147,7 +147,7 @@ func TestSlashRedelegation(t *testing.T) {
|
|||
validator, found := app.StakingKeeper.GetValidator(ctx, addrVals[1])
|
||||
require.True(t, found)
|
||||
slashAmount := app.StakingKeeper.SlashRedelegation(ctx, validator, rd, 1, fraction)
|
||||
require.Equal(t, int64(0), slashAmount.Int64())
|
||||
require.True(t, slashAmount.Equal(sdk.NewInt(0)))
|
||||
|
||||
// after the expiration time, no longer eligible for slashing
|
||||
ctx = ctx.WithBlockHeader(tmproto.Header{Time: time.Unix(10, 0)})
|
||||
|
@ -155,7 +155,7 @@ func TestSlashRedelegation(t *testing.T) {
|
|||
validator, found = app.StakingKeeper.GetValidator(ctx, addrVals[1])
|
||||
require.True(t, found)
|
||||
slashAmount = app.StakingKeeper.SlashRedelegation(ctx, validator, rd, 0, fraction)
|
||||
require.Equal(t, int64(0), slashAmount.Int64())
|
||||
require.True(t, slashAmount.Equal(sdk.NewInt(0)))
|
||||
|
||||
balances = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
||||
|
||||
|
@ -165,7 +165,7 @@ func TestSlashRedelegation(t *testing.T) {
|
|||
validator, found = app.StakingKeeper.GetValidator(ctx, addrVals[1])
|
||||
require.True(t, found)
|
||||
slashAmount = app.StakingKeeper.SlashRedelegation(ctx, validator, rd, 0, fraction)
|
||||
require.Equal(t, int64(5), slashAmount.Int64())
|
||||
require.True(t, slashAmount.Equal(sdk.NewInt(5)))
|
||||
rd, found = app.StakingKeeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
||||
require.True(t, found)
|
||||
require.Len(t, rd.Entries, 1)
|
||||
|
|
|
@ -349,19 +349,19 @@ func TestGetValidatorSortingUnmixed(t *testing.T) {
|
|||
app, ctx, addrs, _ := bootstrapValidatorTest(t, 1000, 20)
|
||||
|
||||
// initialize some validators into the state
|
||||
amts := []int64{
|
||||
0,
|
||||
100 * sdk.PowerReduction.Int64(),
|
||||
1 * sdk.PowerReduction.Int64(),
|
||||
400 * sdk.PowerReduction.Int64(),
|
||||
200 * sdk.PowerReduction.Int64()}
|
||||
amts := []sdk.Int{
|
||||
sdk.NewIntFromUint64(0),
|
||||
sdk.PowerReduction.MulRaw(100),
|
||||
sdk.PowerReduction,
|
||||
sdk.PowerReduction.MulRaw(400),
|
||||
sdk.PowerReduction.MulRaw(200)}
|
||||
n := len(amts)
|
||||
var validators [5]types.Validator
|
||||
for i, amt := range amts {
|
||||
validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
|
||||
validators[i].Status = types.Bonded
|
||||
validators[i].Tokens = sdk.NewInt(amt)
|
||||
validators[i].DelegatorShares = sdk.NewDec(amt)
|
||||
validators[i].Tokens = amt
|
||||
validators[i].DelegatorShares = sdk.NewDecFromInt(amt)
|
||||
keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[i], true)
|
||||
}
|
||||
|
||||
|
@ -445,19 +445,19 @@ func TestGetValidatorSortingMixed(t *testing.T) {
|
|||
app.StakingKeeper.SetParams(ctx, params)
|
||||
|
||||
// initialize some validators into the state
|
||||
amts := []int64{
|
||||
0,
|
||||
100 * sdk.PowerReduction.Int64(),
|
||||
1 * sdk.PowerReduction.Int64(),
|
||||
400 * sdk.PowerReduction.Int64(),
|
||||
200 * sdk.PowerReduction.Int64()}
|
||||
amts := []sdk.Int{
|
||||
sdk.NewIntFromUint64(0),
|
||||
sdk.PowerReduction.MulRaw(100),
|
||||
sdk.PowerReduction,
|
||||
sdk.PowerReduction.MulRaw(400),
|
||||
sdk.PowerReduction.MulRaw(200)}
|
||||
|
||||
var validators [5]types.Validator
|
||||
for i, amt := range amts {
|
||||
validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
|
||||
validators[i].DelegatorShares = sdk.NewDec(amt)
|
||||
validators[i].DelegatorShares = sdk.NewDecFromInt(amt)
|
||||
validators[i].Status = types.Bonded
|
||||
validators[i].Tokens = sdk.NewInt(amt)
|
||||
validators[i].Tokens = amt
|
||||
keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[i], true)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue