mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-05 11:57:41 +00:00
154 lines
3.3 KiB
Dart
154 lines
3.3 KiB
Dart
import 'package:decimal/decimal.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
|
import 'package:stackwallet/utilities/amount/amount_unit.dart';
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
void main() {
|
|
test("displayAmount BTC", () {
|
|
final Amount amount = Amount(
|
|
rawValue: BigInt.from(1012345678),
|
|
fractionDigits: 8,
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.normal.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.bitcoin,
|
|
maxDecimalPlaces: 8,
|
|
),
|
|
"10.12345678 BTC",
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.milli.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.bitcoin,
|
|
maxDecimalPlaces: 8,
|
|
),
|
|
"10123.45678 mBTC",
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.micro.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.bitcoin,
|
|
maxDecimalPlaces: 8,
|
|
),
|
|
"10123456.78 µBTC",
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.nano.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.bitcoin,
|
|
maxDecimalPlaces: 8,
|
|
),
|
|
"1012345678 sats",
|
|
);
|
|
final dec = Decimal.parse("10.123456789123456789");
|
|
|
|
expect(dec.toString(), "10.123456789123456789");
|
|
});
|
|
|
|
test("displayAmount ETH", () {
|
|
final Amount amount = Amount.fromDecimal(
|
|
Decimal.parse("10.123456789123456789"),
|
|
fractionDigits: Coin.ethereum.decimals,
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.normal.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.ethereum,
|
|
maxDecimalPlaces: 8,
|
|
),
|
|
"~10.12345678 ETH",
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.normal.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.ethereum,
|
|
maxDecimalPlaces: 4,
|
|
),
|
|
"~10.1234 ETH",
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.normal.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.ethereum,
|
|
maxDecimalPlaces: 18,
|
|
),
|
|
"10.123456789123456789 ETH",
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.milli.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.ethereum,
|
|
maxDecimalPlaces: 9,
|
|
),
|
|
"~10123.456789123 mETH",
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.micro.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.ethereum,
|
|
maxDecimalPlaces: 8,
|
|
),
|
|
"~10123456.78912345 µETH",
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.nano.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.ethereum,
|
|
maxDecimalPlaces: 1,
|
|
),
|
|
"~10123456789.1 gwei",
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.pico.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.ethereum,
|
|
maxDecimalPlaces: 18,
|
|
),
|
|
"10123456789123.456789 mwei",
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.femto.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.ethereum,
|
|
maxDecimalPlaces: 4,
|
|
),
|
|
"10123456789123456.789 kwei",
|
|
);
|
|
|
|
expect(
|
|
AmountUnit.atto.displayAmount(
|
|
amount: amount,
|
|
locale: "en_US",
|
|
coin: Coin.ethereum,
|
|
maxDecimalPlaces: 1,
|
|
),
|
|
"10123456789123456789 wei",
|
|
);
|
|
});
|
|
}
|