Skip to content

Commit

Permalink
test cover fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelrozanski committed Nov 22, 2018
1 parent d41eeb1 commit fffc100
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
9 changes: 9 additions & 0 deletions types/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ func NewDecFromStr(str string) (d Dec, err Error) {
return Dec{combined}, nil
}

// Decimal from string, panic on error
func MustNewDecFromStr(s string) Dec {
dec, err := NewDecFromStr(s)
if err != nil {
panic(err)
}
return dec
}

//______________________________________________________________________________________________
//nolint
func (d Dec) IsNil() bool { return d.Int == nil } // is decimal nil
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/types/dec_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (coins DecCoins) MulDec(d sdk.Dec) DecCoins {
return res
}

// divide all the coins by a multiple
// divide all the coins by a decimal
func (coins DecCoins) QuoDec(d sdk.Dec) DecCoins {
res := make([]DecCoin, len(coins))
for i, coin := range coins {
Expand Down
5 changes: 5 additions & 0 deletions x/distribution/types/delegator_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func (di DelegationDistInfo) WithdrawRewards(wc WithdrawContext, vi ValidatorDis
di.DelPoolWithdrawalHeight = wc.Height
withdrawalTokens := vi.DelPool.MulDec(accum.Quo(vi.DelAccum.Accum))

fmt.Printf("debug vi.DelPool: %v\n", vi.DelPool)
fmt.Printf("debug withdrawalTokens: %v\n", withdrawalTokens)
fmt.Printf("debug vi.DelAccum.Accum: %v\n", vi.DelAccum.Accum)
fmt.Printf("debug accum: %v\n", accum)

// defensive check for impossible accum ratios
if accum.GT(vi.DelAccum.Accum) {
panic(fmt.Sprintf("accum > vi.DelAccum.Accum:\n"+
Expand Down
5 changes: 3 additions & 2 deletions x/distribution/types/delegator_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func TestWithdrawRewards(t *testing.T) {
assert.Equal(t, height, di2.DelPoolWithdrawalHeight)
assert.True(sdk.DecEq(t, sdk.NewDec(1800), fp.TotalValAccum.Accum))
assert.True(sdk.DecEq(t, sdk.NewDec(1800), fp.ValPool[0].Amount))
assert.True(sdk.DecEq(t, sdk.NewDec(49), vi.DelPool[0].Amount))
// NOTE minor rounding error
assert.True(sdk.DecEq(t, sdk.MustNewDecFromStr("48.9999999951"), vi.DelPool[0].Amount))
assert.True(sdk.DecEq(t, sdk.NewDec(4), vi.ValCommission[0].Amount))
assert.True(sdk.DecEq(t, sdk.NewDec(98), rewardRecv2[0].Amount))
assert.True(sdk.DecEq(t, sdk.MustNewDecFromStr("98.0000000049"), rewardRecv2[0].Amount))
}

0 comments on commit fffc100

Please sign in to comment.