mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-12 10:15:52 +00:00
Improve Coin range check to cope with Long.MIN_VALUE correctly
This commit is contained in:
parent
f40785fbdf
commit
bb368c9543
@ -82,8 +82,10 @@ public final class Coin implements Monetary, Comparable<Coin>, Serializable {
|
|||||||
*/
|
*/
|
||||||
public final long value;
|
public final long value;
|
||||||
|
|
||||||
|
private final long MAX_SATOSHIS = COIN_VALUE * NetworkParameters.MAX_COINS;
|
||||||
|
|
||||||
private Coin(final long satoshis) {
|
private Coin(final long satoshis) {
|
||||||
checkArgument(Math.abs(satoshis) <= COIN_VALUE * NetworkParameters.MAX_COINS,
|
checkArgument(-MAX_SATOSHIS <= satoshis && satoshis <= MAX_SATOSHIS,
|
||||||
"%s satoshis exceeds maximum possible quantity of Bitcoin.", satoshis);
|
"%s satoshis exceeds maximum possible quantity of Bitcoin.", satoshis);
|
||||||
this.value = satoshis;
|
this.value = satoshis;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,11 @@ public class CoinTest {
|
|||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
valueOf(Long.MIN_VALUE);
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException e) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
valueOf(1, -1);
|
valueOf(1, -1);
|
||||||
fail();
|
fail();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user