Skip to content

Commit

Permalink
fix: handle amounts over int64 limits
Browse files Browse the repository at this point in the history
  • Loading branch information
JimLarson committed Jun 14, 2021
1 parent ceeeeee commit fabfacb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions golang/cosmos/x/vbank/vbank.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ func rewardRate(pool sdk.Coins, blocks int64) sdk.Coins {
coins := make([]sdk.Coin, 0)
if blocks > 0 {
for _, coin := range pool {
amt := coin.Amount.Int64()
if amt == 0 {
if coin.IsZero() {
continue
}
// divide by blocks, rounding fractions up
rate := (amt-1)/blocks + 1
coins = append(coins, sdk.NewInt64Coin(coin.GetDenom(), rate))
// (coin.Amount - 1)/blocks + 1
rate := coin.Amount.SubRaw(1).QuoRaw(blocks).AddRaw(1)
coins = append(coins, sdk.NewCoin(coin.GetDenom(), rate))
}
}
return sdk.NewCoins(coins...)
Expand Down
11 changes: 11 additions & 0 deletions golang/cosmos/x/vbank/vbank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ func Test_Receive_GiveToFeeCollector(t *testing.T) {
sdk.NewInt64Coin("stickers", 1),
),
},
{
name: "big",
duration: 1000 * 1000,
rewardPool: sdk.NewCoins(),
feeAmount: "123456789123456789123456789",
feeDenom: "yoctoquatloos",
wantMintCoins: "123456789123456789123456789yoctoquatloos",
wantRate: sdk.NewCoins(
sdk.NewCoin("yoctoquatloos", sdk.NewInt(123456789123456789).MulRaw(1000).AddRaw(124)),
),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit fabfacb

Please sign in to comment.