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: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() {
const String firoAddress = "a6ESWKz7szru5syLtYAPRhHLdKvMq3Yt1j";
@ -38,7 +40,7 @@ void main() {
"scheme": "bitcoin",
"address": firoAddress,
"amount": "50.1",
"message": "eggs are good!"
"message": "eggs are good!",
});
});
@ -66,11 +68,13 @@ void main() {
"something",
"who",
"green",
"seven"
"seven",
];
final result = AddressUtils.encodeQRSeedData(list);
expect(result,
'{"mnemonic":["hello","word","something","who","green","seven"]}');
expect(
result,
'{"mnemonic":["hello","word","something","who","green","seven"]}',
);
});
test("decode a valid json string to Map<String, dynamic>", () {
@ -78,7 +82,7 @@ void main() {
'{"mnemonic":["hello","word","something","who","green","seven"]}';
final result = AddressUtils.decodeQRSeedData(jsonString);
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", () {
expect(AddressUtils.buildUriString(Coin.firo, firoAddress, {}),
"firo:$firoAddress");
expect(
AddressUtils.buildUriString(
Firo(CryptoCurrencyNetwork.main), firoAddress, {}),
"firo:$firoAddress",
);
});
test("build a uri string with one param", () {
expect(
AddressUtils.buildUriString(
Coin.firo, firoAddress, {"amount": "10.0123"}),
"firo:$firoAddress?amount=10.0123");
AddressUtils.buildUriString(
Firo(CryptoCurrencyNetwork.main),
firoAddress,
{"amount": "10.0123"},
),
"firo:$firoAddress?amount=10.0123",
);
});
test("build a uri string with some params", () {
expect(
AddressUtils.buildUriString(Coin.firo, firoAddress,
{"amount": "10.0123", "message": "Some kind of message!"}),
"firo:$firoAddress?amount=10.0123&message=Some+kind+of+message%21");
AddressUtils.buildUriString(
Firo(CryptoCurrencyNetwork.main),
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:stackwallet/electrumx_rpc/cached_electrumx_client.dart';
import 'package:stackwallet/electrumx_rpc/electrumx_client.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 'sample_data/get_anonymity_set_sample_data.dart';
@ -130,7 +131,9 @@ void main() {
expect(
() async => await cachedClient.getTransaction(
txHash: "some hash",
coin: Coin.firo,
cryptoCurrency: Firo(
CryptoCurrencyNetwork.main,
),
),
throwsA(isA<Exception>()));
});
@ -142,7 +145,11 @@ void main() {
bool didThrow = false;
try {
await cachedClient.clearSharedTransactionCache(coin: Coin.firo);
await cachedClient.clearSharedTransactionCache(
cryptoCurrency: Firo(
CryptoCurrencyNetwork.main,
),
);
} catch (_) {
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/wallet_sync_status_changed_event.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() {
test("NodeConnectionStatusChangedEvent", () async {
@ -12,12 +14,18 @@ void main() {
.listen((event) {
expect(event.newStatus, NodeConnectionStatus.connected);
expect(event.walletId, "some wallet ID");
expect(event.coin, Coin.bitcoin);
expect(event.coin, Bitcoin(CryptoCurrencyNetwork.main));
});
expect(
() => GlobalEventBus.instance.fire(NodeConnectionStatusChangedEvent(
NodeConnectionStatus.connected, "some wallet ID", Coin.bitcoin)),
returnsNormally);
() => GlobalEventBus.instance.fire(
NodeConnectionStatusChangedEvent(
NodeConnectionStatus.connected,
"some wallet ID",
Bitcoin(CryptoCurrencyNetwork.main),
),
),
returnsNormally,
);
listener.cancel();
});
@ -29,9 +37,10 @@ void main() {
expect(event.walletId, "some id");
});
expect(
() => GlobalEventBus.instance
.fire(RefreshPercentChangedEvent(0.5, "some id")),
returnsNormally);
() => GlobalEventBus.instance
.fire(RefreshPercentChangedEvent(0.5, "some id")),
returnsNormally,
);
listener.cancel();
});
@ -42,9 +51,10 @@ void main() {
expect(event.walletId, "wallet Id");
});
expect(
() => GlobalEventBus.instance
.fire(UpdatedInBackgroundEvent("some message string", "wallet Id")),
returnsNormally);
() => GlobalEventBus.instance
.fire(UpdatedInBackgroundEvent("some message string", "wallet Id")),
returnsNormally,
);
listener.cancel();
});
@ -54,12 +64,18 @@ void main() {
.listen((event) {
expect(event.newStatus, WalletSyncStatus.syncing);
expect(event.walletId, "wallet Id");
expect(event.coin, Coin.bitcoin);
expect(event.coin, Bitcoin(CryptoCurrencyNetwork.main));
});
expect(
() => GlobalEventBus.instance.fire(WalletSyncStatusChangedEvent(
WalletSyncStatus.syncing, "wallet Id", Coin.bitcoin)),
returnsNormally);
() => GlobalEventBus.instance.fire(
WalletSyncStatusChangedEvent(
WalletSyncStatus.syncing,
"wallet Id",
Bitcoin(CryptoCurrencyNetwork.main),
),
),
returnsNormally,
);
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/models/node_model.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/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() {
bool wasRegistered = false;
@ -24,7 +26,9 @@ void main() {
test("getPrimaryNodeFor", () {
final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore);
final node = service.getPrimaryNodeFor(coin: Coin.bitcoin);
final node = service.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
);
expect(node, null);
expect(fakeStore.interactions, 0);
});
@ -32,7 +36,9 @@ void main() {
test("setPrimaryNodeFor", () async {
final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore);
final node = service.getPrimaryNodeFor(coin: Coin.bitcoin);
final node = service.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
);
expect(node, null);
final node1 = NodeModel(
host: "host",
@ -46,20 +52,24 @@ void main() {
isDown: false,
);
await service.setPrimaryNodeFor(
coin: Coin.bitcoin,
coin: Bitcoin(CryptoCurrencyNetwork.main),
node: node1,
shouldNotifyListeners: true,
);
expect(service.getPrimaryNodeFor(coin: Coin.bitcoin).toString(),
node1.toString());
expect(
service
.getPrimaryNodeFor(currency: Bitcoin(CryptoCurrencyNetwork.main))
.toString(),
node1.toString(),
);
expect(fakeStore.interactions, 0);
});
test("getNodesFor", () {
final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore);
final nodes = service.getNodesFor(Coin.bitcoin);
final nodes = service.getNodesFor(Bitcoin(CryptoCurrencyNetwork.main));
expect(nodes.isEmpty, true);
expect(fakeStore.interactions, 0);
});
@ -83,7 +93,9 @@ void main() {
test("get failover nodes", () {
final fakeStore = FakeSecureStorage();
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(fakeStore.interactions, 0);
});
@ -100,7 +112,10 @@ void main() {
final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore);
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);
});
});
@ -148,11 +163,22 @@ void main() {
test("setPrimaryNodeFor and getPrimaryNodeFor", () async {
final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore);
expect(service.getPrimaryNodeFor(coin: Coin.bitcoin), null);
expect(
service.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
),
null,
);
await service.setPrimaryNodeFor(
coin: Coin.bitcoin, node: DefaultNodes.bitcoin);
expect(service.getPrimaryNodeFor(coin: Coin.bitcoin).toString(),
DefaultNodes.bitcoin.toString());
coin: Bitcoin(CryptoCurrencyNetwork.main),
node: Bitcoin(CryptoCurrencyNetwork.main).defaultNode,
);
expect(
service
.getPrimaryNodeFor(currency: Bitcoin(CryptoCurrencyNetwork.main))
.toString(),
Bitcoin(CryptoCurrencyNetwork.main).defaultNode.toString(),
);
expect(fakeStore.interactions, 0);
});
@ -160,11 +186,20 @@ void main() {
final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore);
await service.setPrimaryNodeFor(
coin: Coin.bitcoin, node: DefaultNodes.bitcoin);
coin: Bitcoin(CryptoCurrencyNetwork.main),
node: Bitcoin(CryptoCurrencyNetwork.main).defaultNode,
);
await service.setPrimaryNodeFor(
coin: Coin.monero, node: DefaultNodes.monero);
expect(service.primaryNodes.toString(),
[DefaultNodes.bitcoin, DefaultNodes.monero].toString());
coin: Monero(CryptoCurrencyNetwork.main),
node: Monero(CryptoCurrencyNetwork.main).defaultNode,
);
expect(
service.primaryNodes.toString(),
[
Bitcoin(CryptoCurrencyNetwork.main).defaultNode,
Monero(CryptoCurrencyNetwork.main).defaultNode,
].toString(),
);
expect(fakeStore.interactions, 0);
});
@ -172,7 +207,8 @@ void main() {
final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore);
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));
defaults.sort((a, b) => a.host.compareTo(b.host));
@ -186,7 +222,10 @@ void main() {
final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore);
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);
});
@ -194,7 +233,10 @@ void main() {
final fakeStore = FakeSecureStorage();
final service = NodeService(secureStorageInterface: fakeStore);
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.writes, 1);
});
@ -202,11 +244,20 @@ void main() {
group("Additional nodes in storage tests", () {
setUp(() async {
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>(
boxName: DB.boxNameNodeModels, key: nodeB.id, value: nodeB);
boxName: DB.boxNameNodeModels,
key: nodeB.id,
value: nodeB,
);
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 {
@ -220,11 +271,14 @@ void main() {
expect(service.nodes.length, currentLength);
expect(service.getNodeById(id: nodeA.id).toString(),
editedNode.toString());
expect(
(await service.getNodeById(id: nodeA.id)!.getPassword(fakeStore))!,
"123456");
service.getNodeById(id: nodeA.id).toString(),
editedNode.toString(),
);
expect(
(await service.getNodeById(id: nodeA.id)!.getPassword(fakeStore))!,
"123456",
);
expect(fakeStore.interactions, 2);
expect(fakeStore.reads, 1);
@ -237,9 +291,14 @@ void main() {
await service.delete(nodeB.id, true);
expect(service.nodes.length, DefaultNodes.all.length + 2);
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.deletes, 1);

View file

@ -2,6 +2,9 @@ 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/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() {
test("displayAmount BTC", () {
@ -14,7 +17,7 @@ void main() {
AmountUnit.normal.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.bitcoin,
coin: Bitcoin(CryptoCurrencyNetwork.main),
maxDecimalPlaces: 8,
),
"10.12345678 BTC",
@ -24,7 +27,7 @@ void main() {
AmountUnit.milli.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.bitcoin,
coin: Bitcoin(CryptoCurrencyNetwork.main),
maxDecimalPlaces: 8,
),
"10,123.45678 mBTC",
@ -34,7 +37,7 @@ void main() {
AmountUnit.micro.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.bitcoin,
coin: Bitcoin(CryptoCurrencyNetwork.main),
maxDecimalPlaces: 8,
),
"10,123,456.78 µBTC",
@ -44,7 +47,7 @@ void main() {
AmountUnit.nano.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.bitcoin,
coin: Bitcoin(CryptoCurrencyNetwork.main),
maxDecimalPlaces: 8,
),
"1,012,345,678 sats",
@ -55,16 +58,18 @@ void main() {
});
test("displayAmount ETH", () {
final eth = Ethereum(CryptoCurrencyNetwork.main);
final Amount amount = Amount.fromDecimal(
Decimal.parse("10.123456789123456789"),
fractionDigits: Coin.ethereum.decimals,
fractionDigits: eth.fractionDigits,
);
expect(
AmountUnit.normal.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.ethereum,
coin: eth,
maxDecimalPlaces: 8,
),
"~10.12345678 ETH",
@ -74,7 +79,7 @@ void main() {
AmountUnit.normal.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.ethereum,
coin: eth,
maxDecimalPlaces: 4,
),
"~10.1234 ETH",
@ -84,7 +89,7 @@ void main() {
AmountUnit.normal.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.ethereum,
coin: eth,
maxDecimalPlaces: 18,
),
"10.123456789123456789 ETH",
@ -94,7 +99,7 @@ void main() {
AmountUnit.milli.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.ethereum,
coin: eth,
maxDecimalPlaces: 9,
),
"~10,123.456789123 mETH",
@ -104,7 +109,7 @@ void main() {
AmountUnit.micro.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.ethereum,
coin: eth,
maxDecimalPlaces: 8,
),
"~10,123,456.78912345 µETH",
@ -114,7 +119,7 @@ void main() {
AmountUnit.nano.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.ethereum,
coin: eth,
maxDecimalPlaces: 1,
),
"~10,123,456,789.1 gwei",
@ -124,7 +129,7 @@ void main() {
AmountUnit.pico.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.ethereum,
coin: eth,
maxDecimalPlaces: 18,
),
"10,123,456,789,123.456789 mwei",
@ -134,7 +139,7 @@ void main() {
AmountUnit.femto.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.ethereum,
coin: eth,
maxDecimalPlaces: 4,
),
"10,123,456,789,123,456.789 kwei",
@ -144,7 +149,7 @@ void main() {
AmountUnit.atto.displayAmount(
amount: amount,
locale: "en_US",
coin: Coin.ethereum,
coin: eth,
maxDecimalPlaces: 1,
),
"10,123,456,789,123,456,789 wei",
@ -152,20 +157,21 @@ void main() {
});
test("parse eth string to amount", () {
final eth = Ethereum(CryptoCurrencyNetwork.main);
final Amount amount = Amount.fromDecimal(
Decimal.parse("10.123456789123456789"),
fractionDigits: Coin.ethereum.decimals,
fractionDigits: eth.fractionDigits,
);
expect(
AmountUnit.nano.tryParse(
"~10,123,456,789.1 gwei",
locale: "en_US",
coin: Coin.ethereum,
coin: eth,
),
Amount.fromDecimal(
Decimal.parse("10.1234567891"),
fractionDigits: Coin.ethereum.decimals,
fractionDigits: eth.fractionDigits,
),
);
@ -173,7 +179,7 @@ void main() {
AmountUnit.atto.tryParse(
"10,123,456,789,123,456,789 wei",
locale: "en_US",
coin: Coin.ethereum,
coin: eth,
),
amount,
);
@ -189,7 +195,7 @@ void main() {
AmountUnit.normal.tryParse(
"10.12345678 BTC",
locale: "en_US",
coin: Coin.bitcoin,
coin: Bitcoin(CryptoCurrencyNetwork.main),
),
amount,
);
@ -198,7 +204,7 @@ void main() {
AmountUnit.milli.tryParse(
"10,123.45678 mBTC",
locale: "en_US",
coin: Coin.bitcoin,
coin: Bitcoin(CryptoCurrencyNetwork.main),
),
amount,
);
@ -207,7 +213,7 @@ void main() {
AmountUnit.micro.tryParse(
"10,123,456.7822 µBTC",
locale: "en_US",
coin: Coin.bitcoin,
coin: Bitcoin(CryptoCurrencyNetwork.main),
),
amount,
);
@ -216,7 +222,7 @@ void main() {
AmountUnit.nano.tryParse(
"1,012,345,678 sats",
locale: "en_US",
coin: Coin.bitcoin,
coin: Bitcoin(CryptoCurrencyNetwork.main),
),
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/services/address_book_service.dart';
import 'package:stackwallet/themes/stack_colors.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 '../sample_data/theme_json.dart';
@ -33,10 +34,10 @@ void main() {
name: "John Doe",
addresses: [
ContactAddressEntry()
..coinName = Coin.bitcoincash.name
..coinName = Bitcoincash(CryptoCurrencyNetwork.main).identifier
..address = "some bch address"
..label = "Bills"
..other = null
..other = null,
],
isFavorite: true,
customId: '',
@ -69,7 +70,10 @@ void main() {
expect(find.text("John Doe"), 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) {
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/services/node_service.dart';
import 'package:stackwallet/themes/stack_colors.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_options_sheet.dart';
@ -22,29 +23,37 @@ void main() {
testWidgets("NodeCard builds inactive node correctly", (tester) async {
final nodeService = MockNodeService();
when(nodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).thenAnswer(
(realInvocation) => NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Stack Default",
id: "node id",
useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false));
when(
nodeService.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
),
).thenAnswer(
(realInvocation) => NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Stack Default",
id: "node id",
useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false,
),
);
when(nodeService.getNodeById(id: "node id")).thenAnswer((realInvocation) =>
NodeModel(
host: "127.0.0.1",
port: 2000,
name: "some other name",
id: "node id",
useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false));
when(nodeService.getNodeById(id: "node id")).thenAnswer(
(realInvocation) => NodeModel(
host: "127.0.0.1",
port: 2000,
name: "some other name",
id: "node id",
useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false,
),
);
await tester.pumpWidget(
ProviderScope(
@ -61,8 +70,11 @@ void main() {
),
],
),
home: const NodeCard(
nodeId: "node id", coin: Coin.bitcoin, popBackToRoute: ""),
home: NodeCard(
nodeId: "node id",
coin: Bitcoin(CryptoCurrencyNetwork.main),
popBackToRoute: "",
),
),
),
);
@ -73,7 +85,11 @@ void main() {
expect(find.text("Disconnected"), findsOneWidget);
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.addListener(any)).called(1);
verifyNoMoreInteractions(nodeService);
@ -82,29 +98,37 @@ void main() {
testWidgets("NodeCard builds active node correctly", (tester) async {
final nodeService = MockNodeService();
when(nodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).thenAnswer(
(realInvocation) => NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Some other node name",
id: "node id",
useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false));
when(
nodeService.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
),
).thenAnswer(
(realInvocation) => NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Some other node name",
id: "node id",
useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false,
),
);
when(nodeService.getNodeById(id: "node id")).thenAnswer((realInvocation) =>
NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Some other node name",
id: "node id",
useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false));
when(nodeService.getNodeById(id: "node id")).thenAnswer(
(realInvocation) => NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Some other node name",
id: "node id",
useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false,
),
);
await tester.pumpWidget(
ProviderScope(
@ -121,8 +145,11 @@ void main() {
),
],
),
home: const NodeCard(
nodeId: "node id", coin: Coin.bitcoin, popBackToRoute: ""),
home: NodeCard(
nodeId: "node id",
coin: Bitcoin(CryptoCurrencyNetwork.main),
popBackToRoute: "",
),
),
),
);
@ -133,7 +160,11 @@ void main() {
expect(find.byType(Text), findsNWidgets(2));
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.addListener(any)).called(1);
@ -143,29 +174,37 @@ void main() {
testWidgets("tap to open context menu on default node", (tester) async {
final nodeService = MockNodeService();
when(nodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).thenAnswer(
(realInvocation) => NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Stack Default",
id: "node id",
useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false));
when(
nodeService.getPrimaryNodeFor(
currency: Bitcoin(CryptoCurrencyNetwork.main),
),
).thenAnswer(
(realInvocation) => NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Stack Default",
id: "node id",
useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false,
),
);
when(nodeService.getNodeById(id: "node id")).thenAnswer((realInvocation) =>
NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Stack Default",
id: "node id",
useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false));
when(nodeService.getNodeById(id: "node id")).thenAnswer(
(realInvocation) => NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Stack Default",
id: "node id",
useSSL: true,
enabled: true,
coinName: "Bitcoin",
isFailover: false,
isDown: false,
),
);
await tester.pumpWidget(
ProviderScope(
@ -182,8 +221,11 @@ void main() {
),
],
),
home: const NodeCard(
nodeId: "node id", coin: Coin.bitcoin, popBackToRoute: ""),
home: NodeCard(
nodeId: "node id",
coin: Bitcoin(CryptoCurrencyNetwork.main),
popBackToRoute: "",
),
),
),
);
@ -202,7 +244,11 @@ void main() {
expect(find.text("Connect"), 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);
} else {
expect(find.text("Connect"), findsOneWidget);
@ -210,7 +256,11 @@ void main() {
expect(find.byType(NodeOptionsSheet), findsOneWidget);
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);
}

View file

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