| 1 | import "package:cake_wallet/core/amount_parsing_proxy.dart"; |
| 2 | import "package:cake_wallet/entities/bitcoin_amount_display_mode.dart"; |
| 3 | import "package:cw_core/crypto_currency.dart"; |
| 4 | import "package:flutter_test/flutter_test.dart"; |
| 5 | |
| 6 | void main() { |
| 7 | group("AmountParsingProxy", () { |
| 8 | group("BitcoinAmountDisplayMode.satoshi", () { |
| 9 | final amountParsingProxy = AmountParsingProxy(BitcoinAmountDisplayMode.satoshi); |
| 10 | |
| 11 | group("getCanonicalCryptoAmount", () { |
| 12 | test("Amount should be parsed from Satoshi for Bitcoin", () { |
| 13 | final amount = amountParsingProxy.getCanonicalCryptoAmount("100", CryptoCurrency.btc); |
| 14 | expect(amount, "0.000001"); |
| 15 | }); |
| 16 | |
| 17 | test("Amount should be parsed from Satoshi for Bitcoin Lightning", () { |
| 18 | final amount = amountParsingProxy.getCanonicalCryptoAmount("100", CryptoCurrency.btcln); |
| 19 | expect(amount, "0.000001"); |
| 20 | }); |
| 21 | |
| 22 | test("Amount should not be parsed from Satoshi for Ethereum", () { |
| 23 | final amount = amountParsingProxy.getCanonicalCryptoAmount("100", CryptoCurrency.eth); |
| 24 | expect(amount, "100"); |
| 25 | }); |
| 26 | }); |
| 27 | |
| 28 | group("getDisplayCryptoAmount", () { |
| 29 | test("Amount should be formated to Satoshi for Bitcoin", () { |
| 30 | final amount = amountParsingProxy.getDisplayCryptoAmount("0.000001", CryptoCurrency.btc); |
| 31 | expect(amount, "100"); |
| 32 | }); |
| 33 | |
| 34 | test("Amount should be formated to Satoshi for Bitcoin Lightning", () { |
| 35 | final amount = amountParsingProxy.getDisplayCryptoAmount("100", CryptoCurrency.btcln); |
| 36 | expect(amount, "10000000000"); |
| 37 | }); |
| 38 | |
| 39 | test("Amount should not be formated to Satoshi for Ethereum", () { |
| 40 | final amount = amountParsingProxy.getDisplayCryptoAmount("100", CryptoCurrency.eth); |
| 41 | expect(amount, "100"); |
| 42 | }); |
| 43 | }); |
| 44 | }); |
| 45 | |
| 46 | group("BitcoinAmountDisplayMode.bitcoin", () { |
| 47 | final amountParsingProxy = AmountParsingProxy(BitcoinAmountDisplayMode.bitcoin); |
| 48 | |
| 49 | group("getCanonicalCryptoAmount", () { |
| 50 | test("Amount should not change for Bitcoin", () { |
| 51 | final amount = |
| 52 | amountParsingProxy.getCanonicalCryptoAmount("0.000001", CryptoCurrency.btc); |
| 53 | expect(amount, "0.000001"); |
| 54 | }); |
| 55 | |
| 56 | test("Amount should not change for Bitcoin: potentially wrong input Satoshi", () { |
| 57 | final amount = amountParsingProxy.getCanonicalCryptoAmount("100", CryptoCurrency.btc); |
| 58 | expect(amount, "100"); |
| 59 | }); |
| 60 | |
| 61 | test("Amount should not change for Bitcoin", () { |
| 62 | final amount = |
| 63 | amountParsingProxy.getCanonicalCryptoAmount("0.000001", CryptoCurrency.btcln); |
| 64 | expect(amount, "0.000001"); |
| 65 | }); |
| 66 | |
| 67 | test("Amount should not change for Bitcoin Lightning: potentially wrong input Satoshi", () { |
| 68 | final amount = amountParsingProxy.getCanonicalCryptoAmount("100", CryptoCurrency.btcln); |
| 69 | expect(amount, "100"); |
| 70 | }); |
| 71 | |
| 72 | test("Amount should not change on ETH", () { |
| 73 | final amount = amountParsingProxy.getCanonicalCryptoAmount("100", CryptoCurrency.eth); |
| 74 | expect(amount, "100"); |
| 75 | }); |
| 76 | }); |
| 77 | |
| 78 | group("getDisplayCryptoAmount", () { |
| 79 | test("Amount should not be formated to Satoshi for Bitcoin", () { |
| 80 | final amount = amountParsingProxy.getDisplayCryptoAmount("0.000001", CryptoCurrency.btc); |
| 81 | expect(amount, "0.000001"); |
| 82 | }); |
| 83 | |
| 84 | test("Amount should not be formated to Satoshi for Bitcoin Lightning", () { |
| 85 | final amount = amountParsingProxy.getDisplayCryptoAmount("100", CryptoCurrency.btcln); |
| 86 | expect(amount, "100"); |
| 87 | }); |
| 88 | |
| 89 | test("Amount should not be formated to Satoshi for Ethereum", () { |
| 90 | final amount = amountParsingProxy.getDisplayCryptoAmount("100", CryptoCurrency.eth); |
| 91 | expect(amount, "100"); |
| 92 | }); |
| 93 | }); |
| 94 | }); |
| 95 | |
| 96 | group("BitcoinAmountDisplayMode.satoshiForLightning", () { |
| 97 | final amountParsingProxy = AmountParsingProxy(BitcoinAmountDisplayMode.satoshiForLightning); |
| 98 | |
| 99 | group("getCanonicalCryptoAmount", () { |
| 100 | test("Amount should not change for Bitcoin", () { |
| 101 | final amount = amountParsingProxy.getCanonicalCryptoAmount("100", CryptoCurrency.btc); |
| 102 | expect(amount, "100"); |
| 103 | }); |
| 104 | |
| 105 | test("Amount should get formated from Satoshi for Bitcoin Lightning", () { |
| 106 | final amount = amountParsingProxy.getCanonicalCryptoAmount("100", CryptoCurrency.btcln); |
| 107 | expect(amount, "0.000001"); |
| 108 | }); |
| 109 | |
| 110 | test("Amount should not change for Ethereum", () { |
| 111 | final amount = amountParsingProxy.getCanonicalCryptoAmount("100", CryptoCurrency.eth); |
| 112 | expect(amount, "100"); |
| 113 | }); |
| 114 | }); |
| 115 | |
| 116 | group("getDisplayCryptoAmount", () { |
| 117 | test("Amount should not be formated to Satoshi for Bitcoin", () { |
| 118 | final amount = amountParsingProxy.getDisplayCryptoAmount("0.000001", CryptoCurrency.btc); |
| 119 | expect(amount, "0.000001"); |
| 120 | }); |
| 121 | |
| 122 | test("Amount should be formated to Satoshi for Bitcoin Lightning", () { |
| 123 | final amount = |
| 124 | amountParsingProxy.getDisplayCryptoAmount("0.000001", CryptoCurrency.btcln); |
| 125 | expect(amount, "100"); |
| 126 | }); |
| 127 | |
| 128 | test("Amount should not be formated to Satoshi for Ethereum", () { |
| 129 | final amount = amountParsingProxy.getDisplayCryptoAmount("100", CryptoCurrency.eth); |
| 130 | expect(amount, "100"); |
| 131 | }); |
| 132 | }); |
| 133 | }); |
| 134 | }); |
| 135 | } |