3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-13 10:45:51 +00:00

Make sure exchange rates are well defined.

This commit is contained in:
Andreas Schildbach 2015-06-06 12:50:05 +02:00
parent 81f2303434
commit cc0a00fbdd
2 changed files with 19 additions and 2 deletions

View File

@ -33,14 +33,16 @@ public class ExchangeRate implements Serializable {
/** Construct exchange rate. This amount of coin is worth that amount of fiat. */
public ExchangeRate(Coin coin, Fiat fiat) {
checkArgument(coin.isPositive());
checkArgument(fiat.isPositive());
checkArgument(fiat.currencyCode != null, "currency code required");
this.coin = coin;
this.fiat = fiat;
}
/** Construct exchange rate. One coin is worth this amount of fiat. */
public ExchangeRate(Fiat fiat) {
this.coin = Coin.COIN;
this.fiat = fiat;
this(Coin.COIN, fiat);
}
/**

View File

@ -74,4 +74,19 @@ public class ExchangeRateTest {
ExchangeRate rate = new ExchangeRate(Fiat.parseFiat("XXX", "1000000000"));
rate.coinToFiat(Coin.parseCoin("-1000000"));
}
@Test(expected = IllegalArgumentException.class)
public void constructMissingCurrencyCode() {
new ExchangeRate(Fiat.valueOf(null, 1));
}
@Test(expected = IllegalArgumentException.class)
public void constructNegativeCoin() {
new ExchangeRate(Coin.valueOf(-1), Fiat.valueOf("EUR", 1));
}
@Test(expected = IllegalArgumentException.class)
public void constructFiatCoin() {
new ExchangeRate(Fiat.valueOf("EUR", -1));
}
}