From 74a25d5001fecb671504b3a774a8a2c1d884d90a Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 9 Dec 2022 10:41:54 -0600 Subject: [PATCH] recoverFromMnemonic using non empty seed on mainnet succeeds --- .../coins/particl/particl_wallet_test.dart | 148 +++++++++--------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/test/services/coins/particl/particl_wallet_test.dart b/test/services/coins/particl/particl_wallet_test.dart index 21e7226de..ccf6ae559 100644 --- a/test/services/coins/particl/particl_wallet_test.dart +++ b/test/services/coins/particl/particl_wallet_test.dart @@ -793,80 +793,80 @@ void main() { // verifyNoMoreInteractions(priceAPI); // }); - // test("recoverFromMnemonic using non empty seed on mainnet succeeds", - // () async { - // when(client?.getServerFeatures()).thenAnswer((_) async => { - // "hosts": {}, - // "pruning": null, - // "server_version": "Unit tests", - // "protocol_min": "1.4", - // "protocol_max": "1.4.2", - // "genesis_hash": GENESIS_HASH_MAINNET, - // "hash_function": "sha256", - // "services": [] - // }); - // when(client?.getBatchHistory(args: historyBatchArgs0)) - // .thenAnswer((_) async => historyBatchResponse); - // when(client?.getBatchHistory(args: historyBatchArgs1)) - // .thenAnswer((_) async => historyBatchResponse); - // when(client?.getBatchHistory(args: historyBatchArgs2)) - // .thenAnswer((_) async => historyBatchResponse); - // when(client?.getBatchHistory(args: historyBatchArgs3)) - // .thenAnswer((_) async => historyBatchResponse); - // when(client?.getBatchHistory(args: historyBatchArgs4)) - // .thenAnswer((_) async => historyBatchResponse); - // when(client?.getBatchHistory(args: historyBatchArgs5)) - // .thenAnswer((_) async => historyBatchResponse); - // - // List dynamicArgValues = []; - // - // when(client?.getBatchHistory(args: anyNamed("args"))) - // .thenAnswer((realInvocation) async { - // if (realInvocation.namedArguments.values.first.length == 1) { - // dynamicArgValues.add(realInvocation.namedArguments.values.first); - // } - // - // return historyBatchResponse; - // }); - // - // await Hive.openBox(testWalletId); - // - // bool hasThrown = false; - // try { - // await part?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000, - // height: 4000); - // } catch (_) { - // hasThrown = true; - // } - // expect(hasThrown, false); - // - // verify(client?.getServerFeatures()).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs2)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs3)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs4)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs5)).called(1); - // - // for (final arg in dynamicArgValues) { - // final map = Map>.from(arg as Map); - // verify(client?.getBatchHistory(args: map)).called(1); - // expect(activeScriptHashes.contains(map.values.first.first as String), - // true); - // } - // - // expect(secureStore.interactions, 10); // 14 - // expect(secureStore.writes, 5); // 7 - // expect(secureStore.reads, 5); // 7 - // expect(secureStore.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); + test("recoverFromMnemonic using non empty seed on mainnet succeeds", + () async { + when(client?.getServerFeatures()).thenAnswer((_) async => { + "hosts": {}, + "pruning": null, + "server_version": "Unit tests", + "protocol_min": "1.4", + "protocol_max": "1.4.2", + "genesis_hash": GENESIS_HASH_MAINNET, + "hash_function": "sha256", + "services": [] + }); + when(client?.getBatchHistory(args: historyBatchArgs0)) + .thenAnswer((_) async => historyBatchResponse); + when(client?.getBatchHistory(args: historyBatchArgs1)) + .thenAnswer((_) async => historyBatchResponse); + when(client?.getBatchHistory(args: historyBatchArgs2)) + .thenAnswer((_) async => historyBatchResponse); + when(client?.getBatchHistory(args: historyBatchArgs3)) + .thenAnswer((_) async => historyBatchResponse); + when(client?.getBatchHistory(args: historyBatchArgs4)) + .thenAnswer((_) async => historyBatchResponse); + when(client?.getBatchHistory(args: historyBatchArgs5)) + .thenAnswer((_) async => historyBatchResponse); + + List dynamicArgValues = []; + + when(client?.getBatchHistory(args: anyNamed("args"))) + .thenAnswer((realInvocation) async { + if (realInvocation.namedArguments.values.first.length == 1) { + dynamicArgValues.add(realInvocation.namedArguments.values.first); + } + + return historyBatchResponse; + }); + + await Hive.openBox(testWalletId); + + bool hasThrown = false; + try { + await part?.recoverFromMnemonic( + mnemonic: TEST_MNEMONIC, + maxUnusedAddressGap: 2, + maxNumberOfIndexesToCheck: 1000, + height: 4000); + } catch (_) { + hasThrown = true; + } + expect(hasThrown, false); + + verify(client?.getServerFeatures()).called(1); + // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); // TODO remove this def above + // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); // TODO remove this def above + verify(client?.getBatchHistory(args: historyBatchArgs2)).called(1); + verify(client?.getBatchHistory(args: historyBatchArgs3)).called(1); + verify(client?.getBatchHistory(args: historyBatchArgs4)).called(1); + verify(client?.getBatchHistory(args: historyBatchArgs5)).called(1); + + for (final arg in dynamicArgValues) { + final map = Map>.from(arg as Map); + verify(client?.getBatchHistory(args: map)).called(1); + expect(activeScriptHashes.contains(map.values.first.first as String), + true); + } + + expect(secureStore.interactions, 10); // 14 + expect(secureStore.writes, 5); // 7 + expect(secureStore.reads, 5); // 7 + expect(secureStore.deletes, 0); + + verifyNoMoreInteractions(client); + verifyNoMoreInteractions(cachedClient); + verifyNoMoreInteractions(priceAPI); + }); test("fullRescan succeeds", () async { when(client?.getServerFeatures()).thenAnswer((_) async => {