fix tests broken by moving away from coin enum

This commit is contained in:
julian 2024-05-15 15:39:43 -06:00
parent 91f71ce760
commit da44ab9109
8 changed files with 342 additions and 175 deletions

View file

@ -1,5 +1,7 @@
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:stackwallet/utilities/address_utils.dart'; import 'package:stackwallet/utilities/address_utils.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
void main() { void main() {
const String firoAddress = "a6ESWKz7szru5syLtYAPRhHLdKvMq3Yt1j"; const String firoAddress = "a6ESWKz7szru5syLtYAPRhHLdKvMq3Yt1j";
@ -38,7 +40,7 @@ void main() {
"scheme": "bitcoin", "scheme": "bitcoin",
"address": firoAddress, "address": firoAddress,
"amount": "50.1", "amount": "50.1",
"message": "eggs are good!" "message": "eggs are good!",
}); });
}); });
@ -66,11 +68,13 @@ void main() {
"something", "something",
"who", "who",
"green", "green",
"seven" "seven",
]; ];
final result = AddressUtils.encodeQRSeedData(list); final result = AddressUtils.encodeQRSeedData(list);
expect(result, expect(
'{"mnemonic":["hello","word","something","who","green","seven"]}'); result,
'{"mnemonic":["hello","word","something","who","green","seven"]}',
);
}); });
test("decode a valid json string to Map<String, dynamic>", () { test("decode a valid json string to Map<String, dynamic>", () {
@ -78,7 +82,7 @@ void main() {
'{"mnemonic":["hello","word","something","who","green","seven"]}'; '{"mnemonic":["hello","word","something","who","green","seven"]}';
final result = AddressUtils.decodeQRSeedData(jsonString); final result = AddressUtils.decodeQRSeedData(jsonString);
expect(result, { expect(result, {
"mnemonic": ["hello", "word", "something", "who", "green", "seven"] "mnemonic": ["hello", "word", "something", "who", "green", "seven"],
}); });
}); });
@ -90,21 +94,32 @@ void main() {
}); });
test("build a uri string with empty params", () { test("build a uri string with empty params", () {
expect(AddressUtils.buildUriString(Coin.firo, firoAddress, {}), expect(
"firo:$firoAddress"); AddressUtils.buildUriString(
Firo(CryptoCurrencyNetwork.main), firoAddress, {}),
"firo:$firoAddress",
);
}); });
test("build a uri string with one param", () { test("build a uri string with one param", () {
expect( expect(
AddressUtils.buildUriString( AddressUtils.buildUriString(
Coin.firo, firoAddress, {"amount": "10.0123"}), Firo(CryptoCurrencyNetwork.main),
"firo:$firoAddress?amount=10.0123"); firoAddress,
{"amount": "10.0123"},
),
"firo:$firoAddress?amount=10.0123",
);
}); });
test("build a uri string with some params", () { test("build a uri string with some params", () {
expect( expect(
AddressUtils.buildUriString(Coin.firo, firoAddress, AddressUtils.buildUriString(
{"amount": "10.0123", "message": "Some kind of message!"}), Firo(CryptoCurrencyNetwork.main),
"firo:$firoAddress?amount=10.0123&message=Some+kind+of+message%21"); firoAddress,
{"amount": "10.0123", "message": "Some kind of message!"},
),
"firo:$firoAddress?amount=10.0123&message=Some+kind+of+message%21",
);
}); });
} }

View file

@ -4,8 +4,9 @@ import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:stackwallet/electrumx_rpc/cached_electrumx_client.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx_client.dart';
import 'package:stackwallet/electrumx_rpc/electrumx_client.dart'; import 'package:stackwallet/electrumx_rpc/electrumx_client.dart';
import 'package:stackwallet/utilities/prefs.dart'; import 'package:stackwallet/utilities/prefs.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
import 'cached_electrumx_test.mocks.dart'; import 'cached_electrumx_test.mocks.dart';
// import 'sample_data/get_anonymity_set_sample_data.dart'; // import 'sample_data/get_anonymity_set_sample_data.dart';
@ -130,7 +131,9 @@ void main() {
expect( expect(
() async => await cachedClient.getTransaction( () async => await cachedClient.getTransaction(
txHash: "some hash", txHash: "some hash",
coin: Coin.firo, cryptoCurrency: Firo(
CryptoCurrencyNetwork.main,
),
), ),
throwsA(isA<Exception>())); throwsA(isA<Exception>()));
}); });
@ -142,7 +145,11 @@ void main() {
bool didThrow = false; bool didThrow = false;
try { try {
await cachedClient.clearSharedTransactionCache(coin: Coin.firo); await cachedClient.clearSharedTransactionCache(
cryptoCurrency: Firo(
CryptoCurrencyNetwork.main,
),
);
} catch (_) { } catch (_) {
didThrow = true; didThrow = true;
} }

View file

@ -4,6 +4,8 @@ import 'package:stackwallet/services/event_bus/events/global/refresh_percent_cha
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart'; import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart'; import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
import 'package:stackwallet/services/event_bus/global_event_bus.dart'; import 'package:stackwallet/services/event_bus/global_event_bus.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
void main() { void main() {
test("NodeConnectionStatusChangedEvent", () async { test("NodeConnectionStatusChangedEvent", () async {
@ -12,12 +14,18 @@ void main() {
.listen((event) { .listen((event) {
expect(event.newStatus, NodeConnectionStatus.connected); expect(event.newStatus, NodeConnectionStatus.connected);
expect(event.walletId, "some wallet ID"); expect(event.walletId, "some wallet ID");
expect(event.coin, Coin.bitcoin); expect(event.coin, Bitcoin(CryptoCurrencyNetwork.main));
}); });
expect( expect(
() => GlobalEventBus.instance.fire(NodeConnectionStatusChangedEvent( () => GlobalEventBus.instance.fire(
NodeConnectionStatus.connected, "some wallet ID", Coin.bitcoin)), NodeConnectionStatusChangedEvent(
returnsNormally); NodeConnectionStatus.connected,
"some wallet ID",
Bitcoin(CryptoCurrencyNetwork.main),
),
),
returnsNormally,
);
listener.cancel(); listener.cancel();
}); });
@ -29,9 +37,10 @@ void main() {
expect(event.walletId, "some id"); expect(event.walletId, "some id");
}); });
expect( expect(
() => GlobalEventBus.instance () => GlobalEventBus.instance
.fire(RefreshPercentChangedEvent(0.5, "some id")), .fire(RefreshPercentChangedEvent(0.5, "some id")),
returnsNormally); returnsNormally,
);
listener.cancel(); listener.cancel();
}); });
@ -42,9 +51,10 @@ void main() {
expect(event.walletId, "wallet Id"); expect(event.walletId, "wallet Id");
}); });
expect( expect(
() => GlobalEventBus.instance () => GlobalEventBus.instance
.fire(UpdatedInBackgroundEvent("some message string", "wallet Id")), .fire(UpdatedInBackgroundEvent("some message string", "wallet Id")),
returnsNormally); returnsNormally,
);
listener.cancel(); listener.cancel();
}); });
@ -54,12 +64,18 @@ void main() {
.listen((event) { .listen((event) {
expect(event.newStatus, WalletSyncStatus.syncing); expect(event.newStatus, WalletSyncStatus.syncing);
expect(event.walletId, "wallet Id"); expect(event.walletId, "wallet Id");
expect(event.coin, Coin.bitcoin); expect(event.coin, Bitcoin(CryptoCurrencyNetwork.main));
}); });
expect( expect(
() => GlobalEventBus.instance.fire(WalletSyncStatusChangedEvent( () => GlobalEventBus.instance.fire(
WalletSyncStatus.syncing, "wallet Id", Coin.bitcoin)), WalletSyncStatusChangedEvent(
returnsNormally); WalletSyncStatus.syncing,
"wallet Id",
Bitcoin(CryptoCurrencyNetwork.main),
),
),
returnsNormally,
);
listener.cancel(); listener.cancel();
}); });
} }

View file

@ -4,9 +4,11 @@ import 'package:hive_test/hive_test.dart';
import 'package:stackwallet/db/hive/db.dart'; import 'package:stackwallet/db/hive/db.dart';
import 'package:stackwallet/models/node_model.dart'; import 'package:stackwallet/models/node_model.dart';
import 'package:stackwallet/services/node_service.dart'; import 'package:stackwallet/services/node_service.dart';
import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/supported_coins.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/monero.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
void main() { void main() {
bool wasRegistered = false; bool wasRegistered = false;
@ -24,7 +26,9 @@ void main() {
test("getPrimaryNodeFor", () { test("getPrimaryNodeFor", () {
final fakeStore = FakeSecureStorage(); final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore); final service = NodeService(secureStorageInterface: fakeStore);
final node = service.getPrimaryNodeFor(coin: Coin.bitcoin); final node = service.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
);
expect(node, null); expect(node, null);
expect(fakeStore.interactions, 0); expect(fakeStore.interactions, 0);
}); });
@ -32,7 +36,9 @@ void main() {
test("setPrimaryNodeFor", () async { test("setPrimaryNodeFor", () async {
final fakeStore = FakeSecureStorage(); final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore); final service = NodeService(secureStorageInterface: fakeStore);
final node = service.getPrimaryNodeFor(coin: Coin.bitcoin); final node = service.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
);
expect(node, null); expect(node, null);
final node1 = NodeModel( final node1 = NodeModel(
host: "host", host: "host",
@ -46,20 +52,24 @@ void main() {
isDown: false, isDown: false,
); );
await service.setPrimaryNodeFor( await service.setPrimaryNodeFor(
coin: Coin.bitcoin, coin: Bitcoin(CryptoCurrencyNetwork.main),
node: node1, node: node1,
shouldNotifyListeners: true, shouldNotifyListeners: true,
); );
expect(service.getPrimaryNodeFor(coin: Coin.bitcoin).toString(), expect(
node1.toString()); service
.getPrimaryNodeFor(currency: Bitcoin(CryptoCurrencyNetwork.main))
.toString(),
node1.toString(),
);
expect(fakeStore.interactions, 0); expect(fakeStore.interactions, 0);
}); });
test("getNodesFor", () { test("getNodesFor", () {
final fakeStore = FakeSecureStorage(); final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore); final service = NodeService(secureStorageInterface: fakeStore);
final nodes = service.getNodesFor(Coin.bitcoin); final nodes = service.getNodesFor(Bitcoin(CryptoCurrencyNetwork.main));
expect(nodes.isEmpty, true); expect(nodes.isEmpty, true);
expect(fakeStore.interactions, 0); expect(fakeStore.interactions, 0);
}); });
@ -83,7 +93,9 @@ void main() {
test("get failover nodes", () { test("get failover nodes", () {
final fakeStore = FakeSecureStorage(); final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore); final service = NodeService(secureStorageInterface: fakeStore);
final nodes = service.failoverNodesFor(coin: Coin.bitcoin); final nodes = service.failoverNodesFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
);
expect(nodes.isEmpty, true); expect(nodes.isEmpty, true);
expect(fakeStore.interactions, 0); expect(fakeStore.interactions, 0);
}); });
@ -100,7 +112,10 @@ void main() {
final fakeStore = FakeSecureStorage(); final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore); final service = NodeService(secureStorageInterface: fakeStore);
await service.updateDefaults(); await service.updateDefaults();
expect(service.nodes.length, DefaultNodes.all.length); expect(
service.nodes.length,
SupportedCoins.cryptocurrencies.map((e) => e.defaultNode).length,
);
expect(fakeStore.interactions, 0); expect(fakeStore.interactions, 0);
}); });
}); });
@ -148,11 +163,22 @@ void main() {
test("setPrimaryNodeFor and getPrimaryNodeFor", () async { test("setPrimaryNodeFor and getPrimaryNodeFor", () async {
final fakeStore = FakeSecureStorage(); final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore); final service = NodeService(secureStorageInterface: fakeStore);
expect(service.getPrimaryNodeFor(coin: Coin.bitcoin), null); expect(
service.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
),
null,
);
await service.setPrimaryNodeFor( await service.setPrimaryNodeFor(
coin: Coin.bitcoin, node: DefaultNodes.bitcoin); coin: Bitcoin(CryptoCurrencyNetwork.main),
expect(service.getPrimaryNodeFor(coin: Coin.bitcoin).toString(), node: Bitcoin(CryptoCurrencyNetwork.main).defaultNode,
DefaultNodes.bitcoin.toString()); );
expect(
service
.getPrimaryNodeFor(currency: Bitcoin(CryptoCurrencyNetwork.main))
.toString(),
Bitcoin(CryptoCurrencyNetwork.main).defaultNode.toString(),
);
expect(fakeStore.interactions, 0); expect(fakeStore.interactions, 0);
}); });
@ -160,11 +186,20 @@ void main() {
final fakeStore = FakeSecureStorage(); final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore); final service = NodeService(secureStorageInterface: fakeStore);
await service.setPrimaryNodeFor( await service.setPrimaryNodeFor(
coin: Coin.bitcoin, node: DefaultNodes.bitcoin); coin: Bitcoin(CryptoCurrencyNetwork.main),
node: Bitcoin(CryptoCurrencyNetwork.main).defaultNode,
);
await service.setPrimaryNodeFor( await service.setPrimaryNodeFor(
coin: Coin.monero, node: DefaultNodes.monero); coin: Monero(CryptoCurrencyNetwork.main),
expect(service.primaryNodes.toString(), node: Monero(CryptoCurrencyNetwork.main).defaultNode,
[DefaultNodes.bitcoin, DefaultNodes.monero].toString()); );
expect(
service.primaryNodes.toString(),
[
Bitcoin(CryptoCurrencyNetwork.main).defaultNode,
Monero(CryptoCurrencyNetwork.main).defaultNode,
].toString(),
);
expect(fakeStore.interactions, 0); expect(fakeStore.interactions, 0);
}); });
@ -172,7 +207,8 @@ void main() {
final fakeStore = FakeSecureStorage(); final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore); final service = NodeService(secureStorageInterface: fakeStore);
final nodes = service.nodes; final nodes = service.nodes;
final defaults = DefaultNodes.all; final defaults =
SupportedCoins.cryptocurrencies.map((e) => e.defaultNode).toList();
nodes.sort((a, b) => a.host.compareTo(b.host)); nodes.sort((a, b) => a.host.compareTo(b.host));
defaults.sort((a, b) => a.host.compareTo(b.host)); defaults.sort((a, b) => a.host.compareTo(b.host));
@ -186,7 +222,10 @@ void main() {
final fakeStore = FakeSecureStorage(); final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore); final service = NodeService(secureStorageInterface: fakeStore);
await service.add(nodeA, null, true); await service.add(nodeA, null, true);
expect(service.nodes.length, DefaultNodes.all.length + 1); expect(
service.nodes.length,
SupportedCoins.cryptocurrencies.map((e) => e.defaultNode).length + 1,
);
expect(fakeStore.interactions, 0); expect(fakeStore.interactions, 0);
}); });
@ -194,7 +233,10 @@ void main() {
final fakeStore = FakeSecureStorage(); final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore); final service = NodeService(secureStorageInterface: fakeStore);
await service.add(nodeA, "some password", true); await service.add(nodeA, "some password", true);
expect(service.nodes.length, DefaultNodes.all.length + 1); expect(
service.nodes.length,
SupportedCoins.cryptocurrencies.map((e) => e.defaultNode).length + 1,
);
expect(fakeStore.interactions, 1); expect(fakeStore.interactions, 1);
expect(fakeStore.writes, 1); expect(fakeStore.writes, 1);
}); });
@ -202,11 +244,20 @@ void main() {
group("Additional nodes in storage tests", () { group("Additional nodes in storage tests", () {
setUp(() async { setUp(() async {
await DB.instance.put<NodeModel>( await DB.instance.put<NodeModel>(
boxName: DB.boxNameNodeModels, key: nodeA.id, value: nodeA); boxName: DB.boxNameNodeModels,
key: nodeA.id,
value: nodeA,
);
await DB.instance.put<NodeModel>( await DB.instance.put<NodeModel>(
boxName: DB.boxNameNodeModels, key: nodeB.id, value: nodeB); boxName: DB.boxNameNodeModels,
key: nodeB.id,
value: nodeB,
);
await DB.instance.put<NodeModel>( await DB.instance.put<NodeModel>(
boxName: DB.boxNameNodeModels, key: nodeC.id, value: nodeC); boxName: DB.boxNameNodeModels,
key: nodeC.id,
value: nodeC,
);
}); });
test("edit a node with a password", () async { test("edit a node with a password", () async {
@ -220,11 +271,14 @@ void main() {
expect(service.nodes.length, currentLength); expect(service.nodes.length, currentLength);
expect(service.getNodeById(id: nodeA.id).toString(),
editedNode.toString());
expect( expect(
(await service.getNodeById(id: nodeA.id)!.getPassword(fakeStore))!, service.getNodeById(id: nodeA.id).toString(),
"123456"); editedNode.toString(),
);
expect(
(await service.getNodeById(id: nodeA.id)!.getPassword(fakeStore))!,
"123456",
);
expect(fakeStore.interactions, 2); expect(fakeStore.interactions, 2);
expect(fakeStore.reads, 1); expect(fakeStore.reads, 1);
@ -237,9 +291,14 @@ void main() {
await service.delete(nodeB.id, true); await service.delete(nodeB.id, true);
expect(service.nodes.length, DefaultNodes.all.length + 2);
expect( expect(
service.nodes.where((element) => element.id == nodeB.id).length, 0); service.nodes.length,
SupportedCoins.cryptocurrencies.map((e) => e.defaultNode).length + 2,
);
expect(
service.nodes.where((element) => element.id == nodeB.id).length,
0,
);
expect(fakeStore.interactions, 1); expect(fakeStore.interactions, 1);
expect(fakeStore.deletes, 1); expect(fakeStore.deletes, 1);

View file

@ -2,6 +2,9 @@ import 'package:decimal/decimal.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/utilities/amount/amount_unit.dart'; import 'package:stackwallet/utilities/amount/amount_unit.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/ethereum.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
void main() { void main() {
test("displayAmount BTC", () { test("displayAmount BTC", () {
@ -14,7 +17,7 @@ void main() {
AmountUnit.normal.displayAmount( AmountUnit.normal.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.bitcoin, coin: Bitcoin(CryptoCurrencyNetwork.main),
maxDecimalPlaces: 8, maxDecimalPlaces: 8,
), ),
"10.12345678 BTC", "10.12345678 BTC",
@ -24,7 +27,7 @@ void main() {
AmountUnit.milli.displayAmount( AmountUnit.milli.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.bitcoin, coin: Bitcoin(CryptoCurrencyNetwork.main),
maxDecimalPlaces: 8, maxDecimalPlaces: 8,
), ),
"10,123.45678 mBTC", "10,123.45678 mBTC",
@ -34,7 +37,7 @@ void main() {
AmountUnit.micro.displayAmount( AmountUnit.micro.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.bitcoin, coin: Bitcoin(CryptoCurrencyNetwork.main),
maxDecimalPlaces: 8, maxDecimalPlaces: 8,
), ),
"10,123,456.78 µBTC", "10,123,456.78 µBTC",
@ -44,7 +47,7 @@ void main() {
AmountUnit.nano.displayAmount( AmountUnit.nano.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.bitcoin, coin: Bitcoin(CryptoCurrencyNetwork.main),
maxDecimalPlaces: 8, maxDecimalPlaces: 8,
), ),
"1,012,345,678 sats", "1,012,345,678 sats",
@ -55,16 +58,18 @@ void main() {
}); });
test("displayAmount ETH", () { test("displayAmount ETH", () {
final eth = Ethereum(CryptoCurrencyNetwork.main);
final Amount amount = Amount.fromDecimal( final Amount amount = Amount.fromDecimal(
Decimal.parse("10.123456789123456789"), Decimal.parse("10.123456789123456789"),
fractionDigits: Coin.ethereum.decimals, fractionDigits: eth.fractionDigits,
); );
expect( expect(
AmountUnit.normal.displayAmount( AmountUnit.normal.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.ethereum, coin: eth,
maxDecimalPlaces: 8, maxDecimalPlaces: 8,
), ),
"~10.12345678 ETH", "~10.12345678 ETH",
@ -74,7 +79,7 @@ void main() {
AmountUnit.normal.displayAmount( AmountUnit.normal.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.ethereum, coin: eth,
maxDecimalPlaces: 4, maxDecimalPlaces: 4,
), ),
"~10.1234 ETH", "~10.1234 ETH",
@ -84,7 +89,7 @@ void main() {
AmountUnit.normal.displayAmount( AmountUnit.normal.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.ethereum, coin: eth,
maxDecimalPlaces: 18, maxDecimalPlaces: 18,
), ),
"10.123456789123456789 ETH", "10.123456789123456789 ETH",
@ -94,7 +99,7 @@ void main() {
AmountUnit.milli.displayAmount( AmountUnit.milli.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.ethereum, coin: eth,
maxDecimalPlaces: 9, maxDecimalPlaces: 9,
), ),
"~10,123.456789123 mETH", "~10,123.456789123 mETH",
@ -104,7 +109,7 @@ void main() {
AmountUnit.micro.displayAmount( AmountUnit.micro.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.ethereum, coin: eth,
maxDecimalPlaces: 8, maxDecimalPlaces: 8,
), ),
"~10,123,456.78912345 µETH", "~10,123,456.78912345 µETH",
@ -114,7 +119,7 @@ void main() {
AmountUnit.nano.displayAmount( AmountUnit.nano.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.ethereum, coin: eth,
maxDecimalPlaces: 1, maxDecimalPlaces: 1,
), ),
"~10,123,456,789.1 gwei", "~10,123,456,789.1 gwei",
@ -124,7 +129,7 @@ void main() {
AmountUnit.pico.displayAmount( AmountUnit.pico.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.ethereum, coin: eth,
maxDecimalPlaces: 18, maxDecimalPlaces: 18,
), ),
"10,123,456,789,123.456789 mwei", "10,123,456,789,123.456789 mwei",
@ -134,7 +139,7 @@ void main() {
AmountUnit.femto.displayAmount( AmountUnit.femto.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.ethereum, coin: eth,
maxDecimalPlaces: 4, maxDecimalPlaces: 4,
), ),
"10,123,456,789,123,456.789 kwei", "10,123,456,789,123,456.789 kwei",
@ -144,7 +149,7 @@ void main() {
AmountUnit.atto.displayAmount( AmountUnit.atto.displayAmount(
amount: amount, amount: amount,
locale: "en_US", locale: "en_US",
coin: Coin.ethereum, coin: eth,
maxDecimalPlaces: 1, maxDecimalPlaces: 1,
), ),
"10,123,456,789,123,456,789 wei", "10,123,456,789,123,456,789 wei",
@ -152,20 +157,21 @@ void main() {
}); });
test("parse eth string to amount", () { test("parse eth string to amount", () {
final eth = Ethereum(CryptoCurrencyNetwork.main);
final Amount amount = Amount.fromDecimal( final Amount amount = Amount.fromDecimal(
Decimal.parse("10.123456789123456789"), Decimal.parse("10.123456789123456789"),
fractionDigits: Coin.ethereum.decimals, fractionDigits: eth.fractionDigits,
); );
expect( expect(
AmountUnit.nano.tryParse( AmountUnit.nano.tryParse(
"~10,123,456,789.1 gwei", "~10,123,456,789.1 gwei",
locale: "en_US", locale: "en_US",
coin: Coin.ethereum, coin: eth,
), ),
Amount.fromDecimal( Amount.fromDecimal(
Decimal.parse("10.1234567891"), Decimal.parse("10.1234567891"),
fractionDigits: Coin.ethereum.decimals, fractionDigits: eth.fractionDigits,
), ),
); );
@ -173,7 +179,7 @@ void main() {
AmountUnit.atto.tryParse( AmountUnit.atto.tryParse(
"10,123,456,789,123,456,789 wei", "10,123,456,789,123,456,789 wei",
locale: "en_US", locale: "en_US",
coin: Coin.ethereum, coin: eth,
), ),
amount, amount,
); );
@ -189,7 +195,7 @@ void main() {
AmountUnit.normal.tryParse( AmountUnit.normal.tryParse(
"10.12345678 BTC", "10.12345678 BTC",
locale: "en_US", locale: "en_US",
coin: Coin.bitcoin, coin: Bitcoin(CryptoCurrencyNetwork.main),
), ),
amount, amount,
); );
@ -198,7 +204,7 @@ void main() {
AmountUnit.milli.tryParse( AmountUnit.milli.tryParse(
"10,123.45678 mBTC", "10,123.45678 mBTC",
locale: "en_US", locale: "en_US",
coin: Coin.bitcoin, coin: Bitcoin(CryptoCurrencyNetwork.main),
), ),
amount, amount,
); );
@ -207,7 +213,7 @@ void main() {
AmountUnit.micro.tryParse( AmountUnit.micro.tryParse(
"10,123,456.7822 µBTC", "10,123,456.7822 µBTC",
locale: "en_US", locale: "en_US",
coin: Coin.bitcoin, coin: Bitcoin(CryptoCurrencyNetwork.main),
), ),
amount, amount,
); );
@ -216,7 +222,7 @@ void main() {
AmountUnit.nano.tryParse( AmountUnit.nano.tryParse(
"1,012,345,678 sats", "1,012,345,678 sats",
locale: "en_US", locale: "en_US",
coin: Coin.bitcoin, coin: Bitcoin(CryptoCurrencyNetwork.main),
), ),
amount, amount,
); );

View file

@ -11,8 +11,9 @@ import 'package:stackwallet/pages/address_book_views/subviews/contact_popup.dart
import 'package:stackwallet/providers/global/address_book_service_provider.dart'; import 'package:stackwallet/providers/global/address_book_service_provider.dart';
import 'package:stackwallet/services/address_book_service.dart'; import 'package:stackwallet/services/address_book_service.dart';
import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/bitcoincash.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
import 'package:stackwallet/widgets/address_book_card.dart'; import 'package:stackwallet/widgets/address_book_card.dart';
import '../sample_data/theme_json.dart'; import '../sample_data/theme_json.dart';
@ -33,10 +34,10 @@ void main() {
name: "John Doe", name: "John Doe",
addresses: [ addresses: [
ContactAddressEntry() ContactAddressEntry()
..coinName = Coin.bitcoincash.name ..coinName = Bitcoincash(CryptoCurrencyNetwork.main).identifier
..address = "some bch address" ..address = "some bch address"
..label = "Bills" ..label = "Bills"
..other = null ..other = null,
], ],
isFavorite: true, isFavorite: true,
customId: '', customId: '',
@ -69,7 +70,10 @@ void main() {
expect(find.text("John Doe"), findsOneWidget); expect(find.text("John Doe"), findsOneWidget);
expect(find.text("BCH"), findsOneWidget); expect(find.text("BCH"), findsOneWidget);
expect(find.text(Coin.bitcoincash.ticker), findsOneWidget); expect(
find.text(Bitcoincash(CryptoCurrencyNetwork.main).ticker),
findsOneWidget,
);
if (Platform.isIOS || Platform.isAndroid) { if (Platform.isIOS || Platform.isAndroid) {
await widgetTester.tap(find.byType(RawMaterialButton)); await widgetTester.tap(find.byType(RawMaterialButton));

View file

@ -9,8 +9,9 @@ import 'package:stackwallet/models/node_model.dart';
import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/services/node_service.dart'; import 'package:stackwallet/services/node_service.dart';
import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
import 'package:stackwallet/widgets/node_card.dart'; import 'package:stackwallet/widgets/node_card.dart';
import 'package:stackwallet/widgets/node_options_sheet.dart'; import 'package:stackwallet/widgets/node_options_sheet.dart';
@ -22,29 +23,37 @@ void main() {
testWidgets("NodeCard builds inactive node correctly", (tester) async { testWidgets("NodeCard builds inactive node correctly", (tester) async {
final nodeService = MockNodeService(); final nodeService = MockNodeService();
when(nodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).thenAnswer( when(
(realInvocation) => NodeModel( nodeService.getPrimaryNodeFor(
host: "127.0.0.1", currency: Bitcoin(CryptoCurrencyNetwork.main),
port: 2000, ),
name: "Stack Default", ).thenAnswer(
id: "node id", (realInvocation) => NodeModel(
useSSL: true, host: "127.0.0.1",
enabled: true, port: 2000,
coinName: "Bitcoin", name: "Stack Default",
isFailover: false, id: "node id",
isDown: false)); useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false,
),
);
when(nodeService.getNodeById(id: "node id")).thenAnswer((realInvocation) => when(nodeService.getNodeById(id: "node id")).thenAnswer(
NodeModel( (realInvocation) => NodeModel(
host: "127.0.0.1", host: "127.0.0.1",
port: 2000, port: 2000,
name: "some other name", name: "some other name",
id: "node id", id: "node id",
useSSL: true, useSSL: true,
enabled: true, enabled: true,
coinName: "Bitcoin", coinName: "Bitcoin",
isFailover: false, isFailover: false,
isDown: false)); isDown: false,
),
);
await tester.pumpWidget( await tester.pumpWidget(
ProviderScope( ProviderScope(
@ -61,8 +70,11 @@ void main() {
), ),
], ],
), ),
home: const NodeCard( home: NodeCard(
nodeId: "node id", coin: Coin.bitcoin, popBackToRoute: ""), nodeId: "node id",
coin: Bitcoin(CryptoCurrencyNetwork.main),
popBackToRoute: "",
),
), ),
), ),
); );
@ -73,7 +85,11 @@ void main() {
expect(find.text("Disconnected"), findsOneWidget); expect(find.text("Disconnected"), findsOneWidget);
expect(find.byType(SvgPicture), findsWidgets); expect(find.byType(SvgPicture), findsWidgets);
verify(nodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).called(1); verify(
nodeService.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
),
).called(1);
verify(nodeService.getNodeById(id: "node id")).called(1); verify(nodeService.getNodeById(id: "node id")).called(1);
verify(nodeService.addListener(any)).called(1); verify(nodeService.addListener(any)).called(1);
verifyNoMoreInteractions(nodeService); verifyNoMoreInteractions(nodeService);
@ -82,29 +98,37 @@ void main() {
testWidgets("NodeCard builds active node correctly", (tester) async { testWidgets("NodeCard builds active node correctly", (tester) async {
final nodeService = MockNodeService(); final nodeService = MockNodeService();
when(nodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).thenAnswer( when(
(realInvocation) => NodeModel( nodeService.getPrimaryNodeFor(
host: "127.0.0.1", currency: Bitcoin(CryptoCurrencyNetwork.main),
port: 2000, ),
name: "Some other node name", ).thenAnswer(
id: "node id", (realInvocation) => NodeModel(
useSSL: true, host: "127.0.0.1",
enabled: true, port: 2000,
coinName: "Bitcoin", name: "Some other node name",
isFailover: false, id: "node id",
isDown: false)); useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false,
),
);
when(nodeService.getNodeById(id: "node id")).thenAnswer((realInvocation) => when(nodeService.getNodeById(id: "node id")).thenAnswer(
NodeModel( (realInvocation) => NodeModel(
host: "127.0.0.1", host: "127.0.0.1",
port: 2000, port: 2000,
name: "Some other node name", name: "Some other node name",
id: "node id", id: "node id",
useSSL: true, useSSL: true,
enabled: true, enabled: true,
coinName: "Bitcoin", coinName: "Bitcoin",
isFailover: false, isFailover: false,
isDown: false)); isDown: false,
),
);
await tester.pumpWidget( await tester.pumpWidget(
ProviderScope( ProviderScope(
@ -121,8 +145,11 @@ void main() {
), ),
], ],
), ),
home: const NodeCard( home: NodeCard(
nodeId: "node id", coin: Coin.bitcoin, popBackToRoute: ""), nodeId: "node id",
coin: Bitcoin(CryptoCurrencyNetwork.main),
popBackToRoute: "",
),
), ),
), ),
); );
@ -133,7 +160,11 @@ void main() {
expect(find.byType(Text), findsNWidgets(2)); expect(find.byType(Text), findsNWidgets(2));
expect(find.byType(SvgPicture), findsWidgets); expect(find.byType(SvgPicture), findsWidgets);
verify(nodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).called(1); verify(
nodeService.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
),
).called(1);
verify(nodeService.getNodeById(id: "node id")).called(1); verify(nodeService.getNodeById(id: "node id")).called(1);
verify(nodeService.addListener(any)).called(1); verify(nodeService.addListener(any)).called(1);
@ -143,29 +174,37 @@ void main() {
testWidgets("tap to open context menu on default node", (tester) async { testWidgets("tap to open context menu on default node", (tester) async {
final nodeService = MockNodeService(); final nodeService = MockNodeService();
when(nodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).thenAnswer( when(
(realInvocation) => NodeModel( nodeService.getPrimaryNodeFor(
host: "127.0.0.1", currency: Bitcoin(CryptoCurrencyNetwork.main),
port: 2000, ),
name: "Stack Default", ).thenAnswer(
id: "node id", (realInvocation) => NodeModel(
useSSL: true, host: "127.0.0.1",
enabled: true, port: 2000,
coinName: "Bitcoin", name: "Stack Default",
isFailover: false, id: "node id",
isDown: false)); useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false,
),
);
when(nodeService.getNodeById(id: "node id")).thenAnswer((realInvocation) => when(nodeService.getNodeById(id: "node id")).thenAnswer(
NodeModel( (realInvocation) => NodeModel(
host: "127.0.0.1", host: "127.0.0.1",
port: 2000, port: 2000,
name: "Stack Default", name: "Stack Default",
id: "node id", id: "node id",
useSSL: true, useSSL: true,
enabled: true, enabled: true,
coinName: "Bitcoin", coinName: "Bitcoin",
isFailover: false, isFailover: false,
isDown: false)); isDown: false,
),
);
await tester.pumpWidget( await tester.pumpWidget(
ProviderScope( ProviderScope(
@ -182,8 +221,11 @@ void main() {
), ),
], ],
), ),
home: const NodeCard( home: NodeCard(
nodeId: "node id", coin: Coin.bitcoin, popBackToRoute: ""), nodeId: "node id",
coin: Bitcoin(CryptoCurrencyNetwork.main),
popBackToRoute: "",
),
), ),
), ),
); );
@ -202,7 +244,11 @@ void main() {
expect(find.text("Connect"), findsNothing); expect(find.text("Connect"), findsNothing);
expect(find.text("Details"), findsNothing); expect(find.text("Details"), findsNothing);
verify(nodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).called(1); verify(
nodeService.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
),
).called(1);
verify(nodeService.getNodeById(id: "node id")).called(1); verify(nodeService.getNodeById(id: "node id")).called(1);
} else { } else {
expect(find.text("Connect"), findsOneWidget); expect(find.text("Connect"), findsOneWidget);
@ -210,7 +256,11 @@ void main() {
expect(find.byType(NodeOptionsSheet), findsOneWidget); expect(find.byType(NodeOptionsSheet), findsOneWidget);
expect(find.byType(Text), findsNWidgets(7)); expect(find.byType(Text), findsNWidgets(7));
verify(nodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).called(2); verify(
nodeService.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
),
).called(2);
verify(nodeService.getNodeById(id: "node id")).called(2); verify(nodeService.getNodeById(id: "node id")).called(2);
} }

View file

@ -11,8 +11,9 @@ import 'package:stackwallet/services/node_service.dart';
import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/services/tor_service.dart';
import 'package:stackwallet/services/wallets.dart'; import 'package:stackwallet/services/wallets.dart';
import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/prefs.dart'; import 'package:stackwallet/utilities/prefs.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
import 'package:stackwallet/widgets/node_options_sheet.dart'; import 'package:stackwallet/widgets/node_options_sheet.dart';
import '../sample_data/theme_json.dart'; import '../sample_data/theme_json.dart';
@ -37,8 +38,9 @@ void main() {
isFailover: false, isFailover: false,
isDown: false)); isDown: false));
when(mockNodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).thenAnswer( when(mockNodeService.getPrimaryNodeFor(
(realInvocation) => NodeModel( currency: Bitcoin(CryptoCurrencyNetwork.main)))
.thenAnswer((realInvocation) => NodeModel(
host: "127.0.0.1", host: "127.0.0.1",
port: 2000, port: 2000,
name: "Some other name", name: "Some other name",
@ -66,8 +68,10 @@ void main() {
), ),
], ],
), ),
home: const NodeOptionsSheet( home: NodeOptionsSheet(
nodeId: "node id", coin: Coin.bitcoin, popBackToRoute: ""), nodeId: "node id",
coin: Bitcoin(CryptoCurrencyNetwork.main),
popBackToRoute: ""),
), ),
), ),
); );
@ -80,7 +84,9 @@ void main() {
expect(find.text("Details"), findsOneWidget); expect(find.text("Details"), findsOneWidget);
expect(find.text("Connect"), findsOneWidget); expect(find.text("Connect"), findsOneWidget);
verify(mockNodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).called(1); verify(mockNodeService.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main)))
.called(1);
verify(mockNodeService.getNodeById(id: "node id")).called(1); verify(mockNodeService.getNodeById(id: "node id")).called(1);
verify(mockNodeService.addListener(any)).called(1); verify(mockNodeService.addListener(any)).called(1);
verifyNoMoreInteractions(mockNodeService); verifyNoMoreInteractions(mockNodeService);
@ -107,7 +113,9 @@ void main() {
), ),
); );
when(mockNodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).thenAnswer( when(mockNodeService.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main)))
.thenAnswer(
(_) => NodeModel( (_) => NodeModel(
host: "127.0.0.1", host: "127.0.0.1",
port: 2000, port: 2000,
@ -146,9 +154,9 @@ void main() {
} }
return null; return null;
}, },
home: const NodeOptionsSheet( home: NodeOptionsSheet(
nodeId: "node id", nodeId: "node id",
coin: Coin.bitcoin, coin: Bitcoin(CryptoCurrencyNetwork.main),
popBackToRoute: "coinNodes", popBackToRoute: "coinNodes",
), ),
), ),
@ -182,7 +190,9 @@ void main() {
), ),
); );
when(mockNodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).thenAnswer( when(mockNodeService.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main)))
.thenAnswer(
(_) => NodeModel( (_) => NodeModel(
host: "127.0.0.1", host: "127.0.0.1",
port: 2000, port: 2000,
@ -214,9 +224,9 @@ void main() {
), ),
], ],
), ),
home: const NodeOptionsSheet( home: NodeOptionsSheet(
nodeId: "node id", nodeId: "node id",
coin: Coin.bitcoin, coin: Bitcoin(CryptoCurrencyNetwork.main),
popBackToRoute: "", popBackToRoute: "",
), ),
), ),