Skip to content

Commit

Permalink
Merge pull request #771 from HaoyangLiu/haoyang/develop
Browse files Browse the repository at this point in the history
R4R: fix failed unit tests for slashing
  • Loading branch information
HaoyangLiu authored Dec 5, 2018
2 parents 14bdb81 + 73765f7 commit 7cf7e42
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions modules/stake/keeper/slash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ func TestSlashUnbondingDelegation(t *testing.T) {
keeper.SetUnbondingDelegation(ctx, ubd)

// unbonding started prior to the infraction height, stake didn't contribute
slashAmount := keeper.slashUnbondingDelegation(ctx, ubd, 1, fraction)
slashAmount, _ := keeper.slashUnbondingDelegation(ctx, ubd, 1, fraction)
require.Equal(t, int64(0), slashAmount.RoundInt64())

// after the expiration time, no longer eligible for slashing
ctx = ctx.WithBlockHeader(abci.Header{Time: time.Unix(10, 0)})
keeper.SetUnbondingDelegation(ctx, ubd)
slashAmount = keeper.slashUnbondingDelegation(ctx, ubd, 0, fraction)
slashAmount, _ = keeper.slashUnbondingDelegation(ctx, ubd, 0, fraction)
require.Equal(t, int64(0), slashAmount.RoundInt64())

// test valid slash, before expiration timestamp and to which stake contributed
oldPool := keeper.GetPool(ctx)
ctx = ctx.WithBlockHeader(abci.Header{Time: time.Unix(0, 0)})
keeper.SetUnbondingDelegation(ctx, ubd)
slashAmount = keeper.slashUnbondingDelegation(ctx, ubd, 0, fraction)
slashAmount, _ = keeper.slashUnbondingDelegation(ctx, ubd, 0, fraction)
require.Equal(t, int64(5), slashAmount.RoundInt64())
ubd, found := keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
require.True(t, found)
Expand Down Expand Up @@ -141,15 +141,15 @@ func TestSlashRedelegation(t *testing.T) {
// started redelegating prior to the current height, stake didn't contribute to infraction
validator, found := keeper.GetValidator(ctx, addrVals[1])
require.True(t, found)
slashAmount := keeper.slashRedelegation(ctx, validator, rd, 1, fraction)
slashAmount, _ := keeper.slashRedelegation(ctx, validator, rd, 1, fraction)
require.Equal(t, sdk.ZeroDec(), slashAmount)

// after the expiration time, no longer eligible for slashing
ctx = ctx.WithBlockHeader(abci.Header{Time: time.Unix(10, 0)})
keeper.SetRedelegation(ctx, rd)
validator, found = keeper.GetValidator(ctx, addrVals[1])
require.True(t, found)
slashAmount = keeper.slashRedelegation(ctx, validator, rd, 0, fraction)
slashAmount, _ = keeper.slashRedelegation(ctx, validator, rd, 0, fraction)
require.Equal(t, sdk.ZeroDec(), slashAmount)

// test valid slash, before expiration timestamp and to which stake contributed
Expand All @@ -158,7 +158,7 @@ func TestSlashRedelegation(t *testing.T) {
keeper.SetRedelegation(ctx, rd)
validator, found = keeper.GetValidator(ctx, addrVals[1])
require.True(t, found)
slashAmount = keeper.slashRedelegation(ctx, validator, rd, 0, fraction)
slashAmount, _ = keeper.slashRedelegation(ctx, validator, rd, 0, fraction)
require.Equal(t, sdk.NewDecFromInt(sdk.NewIntWithDecimal(5, 18)), slashAmount)
rd, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
require.True(t, found)
Expand Down

0 comments on commit 7cf7e42

Please sign in to comment.