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

R4R: Validator Power Dec-> Int #2958

Merged
merged 20 commits into from
Jan 2, 2019
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
slashing test fixes minor
  • Loading branch information
rigelrozanski committed Nov 30, 2018
commit 2105432032dd94da7439f8b1c5216ed25483dfd2
16 changes: 8 additions & 8 deletions x/slashing/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func TestSlashingPeriodCap(t *testing.T) {
// end block
stake.EndBlocker(ctx, sk)
// power should be reduced
expectedPower := sdk.NewDecFromInt(amt).Mul(sdk.NewDec(19).Quo(sdk.NewDec(20)))
require.Equal(t, expectedPower, sk.Validator(ctx, operatorAddr).GetPower())
expectedPower := amt.Mul(sdk.NewInt(19)).Div(sdk.NewInt(20))
require.True(sdk.IntEq(t, expectedPower, sk.Validator(ctx, operatorAddr).GetPower()))

// double sign again, same slashing period
keeper.handleDoubleSign(ctx, valConsAddr, 1, time.Unix(0, 0), amtInt)
Expand All @@ -117,8 +117,8 @@ func TestSlashingPeriodCap(t *testing.T) {
// end block
stake.EndBlocker(ctx, sk)
// power should be equal, no more should have been slashed
expectedPower = sdk.NewDecFromInt(amt).Mul(sdk.NewDec(19).Quo(sdk.NewDec(20)))
require.Equal(t, expectedPower, sk.Validator(ctx, operatorAddr).GetPower())
expectedPower = amt.Mul(sdk.NewInt(19)).Div(sdk.NewInt(20))
require.True(sdk.IntEq(t, expectedPower, sk.Validator(ctx, operatorAddr).GetPower()))

// double sign again, new slashing period
keeper.handleDoubleSign(ctx, valConsAddr, 3, time.Unix(0, 0), amtInt)
Expand All @@ -129,8 +129,8 @@ func TestSlashingPeriodCap(t *testing.T) {
// end block
stake.EndBlocker(ctx, sk)
// power should be reduced
expectedPower = sdk.NewDecFromInt(amt).Mul(sdk.NewDec(18).Quo(sdk.NewDec(20)))
require.Equal(t, expectedPower, sk.Validator(ctx, operatorAddr).GetPower())
expectedPower = amt.Mul(sdk.NewInt(18)).Div(sdk.NewInt(20))
require.True(sdk.IntEq(t, expectedPower, sk.Validator(ctx, operatorAddr).GetPower()))
}

// Test a validator through uptime, downtime, revocation,
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestHandleAbsentValidator(t *testing.T) {
validator, _ := sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
require.Equal(t, sdk.Bonded, validator.GetStatus())
pool := sk.GetPool(ctx)
require.Equal(sdk.IntEq(t, amt, pool.BondedTokens))
require.True(sdk.IntEq(t, amt, pool.BondedTokens))

// 501st block missed
ctx = ctx.WithBlockHeight(height)
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestHandleNewValidator(t *testing.T) {
t, ck.GetCoins(ctx, sdk.AccAddress(addr)),
sdk.Coins{sdk.NewCoin(sk.GetParams(ctx).BondDenom, initCoins.SubRaw(amt))},
)
require.Equal(t, sdk.NewDec(amt), sk.Validator(ctx, addr).GetPower())
require.Equal(t, amt, sk.Validator(ctx, addr).GetPower().Int64())

// Now a validator, for two blocks
keeper.handleValidatorSignature(ctx, val.Address(), 100, true)
Expand Down