Enforce upper bound on MobileCoin/fiat entry.

This commit is contained in:
Alan Evans
2021-04-09 11:15:47 -03:00
parent 5daa027c10
commit 113393de8f
5 changed files with 49 additions and 30 deletions

View File

@@ -5,6 +5,7 @@ import org.whispersystems.signalservice.api.util.Uint64Util;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
@@ -97,6 +98,14 @@ public abstract class Money {
public static final Comparator<MobileCoin> DESCENDING = (x, y) -> y.amount.compareTo(x.amount);
public static final MobileCoin ZERO = new MobileCoin(BigInteger.ZERO);
public static final MobileCoin MAX_VALUE;
static {
byte[] bytes = new byte[8];
Arrays.fill(bytes, (byte) 0xff);
BigInteger max64Bit = new BigInteger(1, bytes);
MAX_VALUE = Money.picoMobileCoin(max64Bit);
}
private static final int PRECISION = 12;

View File

@@ -336,6 +336,11 @@ public final class MoneyTest_MobileCoin {
assertSame(Money.MobileCoin.ZERO, mobileCoin.toZero());
}
@Test
public void max_long_value() {
assertEquals("MOB:18446744073709551615", Money.MobileCoin.MAX_VALUE.serialize());
}
private static Money.MobileCoin mobileCoin2(double value) {
return Money.mobileCoin(BigDecimal.valueOf(value));
}