From 4ebda4ad214750a326d08879b0a395d8fac9cc6c Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 12 Sep 2022 11:35:26 -0600 Subject: [PATCH] updated doge tests to reflect speedup modifications --- .../coins/dogecoin/dogecoin_wallet.dart | 2 +- .../coins/dogecoin/dogecoin_wallet_test.dart | 212 +++++++++--------- 2 files changed, 112 insertions(+), 102 deletions(-) diff --git a/lib/services/coins/dogecoin/dogecoin_wallet.dart b/lib/services/coins/dogecoin/dogecoin_wallet.dart index c5a3ed8ac..0235a0c02 100644 --- a/lib/services/coins/dogecoin/dogecoin_wallet.dart +++ b/lib/services/coins/dogecoin/dogecoin_wallet.dart @@ -1914,7 +1914,7 @@ class DogecoinWallet extends CoinServiceAPI { batches[batchNumber] = {}; } final scripthash = _convertToScriptHash(allAddresses[i], _network); - final id = const Uuid().v1(); + final id = Logger.isTestEnv ? "$i" : const Uuid().v1(); requestIdToAddressMap[id] = allAddresses[i]; batches[batchNumber]!.addAll({ id: [scripthash] diff --git a/test/services/coins/dogecoin/dogecoin_wallet_test.dart b/test/services/coins/dogecoin/dogecoin_wallet_test.dart index e2eb90a7b..7fcb1cdbd 100644 --- a/test/services/coins/dogecoin/dogecoin_wallet_test.dart +++ b/test/services/coins/dogecoin/dogecoin_wallet_test.dart @@ -20,8 +20,6 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'dogecoin_history_sample_data.dart'; -import 'dogecoin_transaction_data_samples.dart'; -import 'dogecoin_utxo_sample_data.dart'; import 'dogecoin_wallet_test.mocks.dart'; import 'dogecoin_wallet_test_parameters.dart'; @@ -1853,102 +1851,6 @@ void main() { // // verifyNoMoreInteractions(priceAPI); // // }); - test("fullRescan 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(cachedClient?.clearSharedTransactionCache(coin: Coin.dogecoin)) - .thenAnswer((realInvocation) async {}); - - final wallet = await Hive.openBox(testWalletId); - - // restore so we have something to rescan - await doge?.recoverFromMnemonic( - mnemonic: TEST_MNEMONIC, - maxUnusedAddressGap: 2, - maxNumberOfIndexesToCheck: 1000, - height: 4000); - - // fetch valid wallet data - final preReceivingAddressesP2PKH = - await wallet.get('receivingAddressesP2PKH'); - final preChangeAddressesP2PKH = await wallet.get('changeAddressesP2PKH'); - final preReceivingIndexP2PKH = await wallet.get('receivingIndexP2PKH'); - final preChangeIndexP2PKH = await wallet.get('changeIndexP2PKH'); - final preUtxoData = await wallet.get('latest_utxo_model'); - final preReceiveDerivationsStringP2PKH = await secureStore?.read( - key: "${testWalletId}_receiveDerivationsP2PKH"); - final preChangeDerivationsStringP2PKH = await secureStore?.read( - key: "${testWalletId}_changeDerivationsP2PKH"); - - // destroy the data that the rescan will fix - await wallet.put( - 'receivingAddressesP2PKH', ["some address", "some other address"]); - await wallet - .put('changeAddressesP2PKH', ["some address", "some other address"]); - - await wallet.put('receivingIndexP2PKH', 123); - await wallet.put('changeIndexP2PKH', 123); - await secureStore?.write( - key: "${testWalletId}_receiveDerivationsP2PKH", value: "{}"); - await secureStore?.write( - key: "${testWalletId}_changeDerivationsP2PKH", value: "{}"); - - bool hasThrown = false; - try { - await doge?.fullRescan(2, 1000); - } catch (_) { - hasThrown = true; - } - expect(hasThrown, false); - - // fetch wallet data again - final receivingAddressesP2PKH = - await wallet.get('receivingAddressesP2PKH'); - final changeAddressesP2PKH = await wallet.get('changeAddressesP2PKH'); - final receivingIndexP2PKH = await wallet.get('receivingIndexP2PKH'); - final changeIndexP2PKH = await wallet.get('changeIndexP2PKH'); - final utxoData = await wallet.get('latest_utxo_model'); - final receiveDerivationsStringP2PKH = await secureStore?.read( - key: "${testWalletId}_receiveDerivationsP2PKH"); - final changeDerivationsStringP2PKH = await secureStore?.read( - key: "${testWalletId}_changeDerivationsP2PKH"); - - expect(preReceivingAddressesP2PKH, receivingAddressesP2PKH); - expect(preChangeAddressesP2PKH, changeAddressesP2PKH); - expect(preReceivingIndexP2PKH, receivingIndexP2PKH); - expect(preChangeIndexP2PKH, changeIndexP2PKH); - expect(preUtxoData, utxoData); - expect(preReceiveDerivationsStringP2PKH, receiveDerivationsStringP2PKH); - expect(preChangeDerivationsStringP2PKH, changeDerivationsStringP2PKH); - - verify(client?.getServerFeatures()).called(1); - verify(client?.getBatchHistory(args: historyBatchArgs0)).called(2); - verify(client?.getBatchHistory(args: historyBatchArgs1)).called(2); - verify(cachedClient?.clearSharedTransactionCache(coin: Coin.dogecoin)) - .called(1); - - expect(secureStore?.writes, 9); - expect(secureStore?.reads, 12); - expect(secureStore?.deletes, 2); - - verifyNoMoreInteractions(client); - verifyNoMoreInteractions(cachedClient); - verifyNoMoreInteractions(tracker); - verifyNoMoreInteractions(priceAPI); - }); - test("get mnemonic list", () async { when(client?.getServerFeatures()).thenAnswer((_) async => { "hosts": {}, @@ -2118,7 +2020,19 @@ void main() { when(client?.getBatchHistory(args: historyBatchArgs1)) .thenAnswer((_) async => historyBatchResponse); - final wallet = await Hive.openBox(testWalletId); + when(client?.getBatchHistory(args: { + "0": [ + "c82d4ac9697408d423d59dc53267f6474bbd4c22c55fd42ba766e80c6068e7dc" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "80badd62a8dd884cc7f61d962484564929340debb27f88fef270e553306a030c" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + final wallet = await Hive.openBox(testWalletId); bool hasThrown = false; try { @@ -2135,6 +2049,16 @@ void main() { verify(client?.getServerFeatures()).called(1); verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); + verify(client?.getBatchHistory(args: { + "0": [ + "c82d4ac9697408d423d59dc53267f6474bbd4c22c55fd42ba766e80c6068e7dc" + ] + })).called(1); + verify(client?.getBatchHistory(args: { + "0": [ + "80badd62a8dd884cc7f61d962484564929340debb27f88fef270e553306a030c" + ] + })).called(1); expect(secureStore?.interactions, 6); expect(secureStore?.writes, 3); @@ -2165,7 +2089,19 @@ void main() { when(cachedClient?.clearSharedTransactionCache(coin: Coin.dogecoin)) .thenAnswer((realInvocation) async {}); - final wallet = await Hive.openBox(testWalletId); + when(client?.getBatchHistory(args: { + "0": [ + "c82d4ac9697408d423d59dc53267f6474bbd4c22c55fd42ba766e80c6068e7dc" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "80badd62a8dd884cc7f61d962484564929340debb27f88fef270e553306a030c" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + final wallet = await Hive.openBox(testWalletId); // restore so we have something to rescan await doge?.recoverFromMnemonic( @@ -2230,6 +2166,16 @@ void main() { verify(client?.getServerFeatures()).called(1); verify(client?.getBatchHistory(args: historyBatchArgs0)).called(2); verify(client?.getBatchHistory(args: historyBatchArgs1)).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "c82d4ac9697408d423d59dc53267f6474bbd4c22c55fd42ba766e80c6068e7dc" + ] + })).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "80badd62a8dd884cc7f61d962484564929340debb27f88fef270e553306a030c" + ] + })).called(2); verify(cachedClient?.clearSharedTransactionCache(coin: Coin.dogecoin)) .called(1); @@ -2259,6 +2205,18 @@ void main() { .thenAnswer((_) async => historyBatchResponse); when(client?.getBatchHistory(args: historyBatchArgs1)) .thenAnswer((_) async => historyBatchResponse); + + when(client?.getBatchHistory(args: { + "0": [ + "c82d4ac9697408d423d59dc53267f6474bbd4c22c55fd42ba766e80c6068e7dc" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "80badd62a8dd884cc7f61d962484564929340debb27f88fef270e553306a030c" + ] + })).thenAnswer((realInvocation) async => {"0": []}); when(cachedClient?.clearSharedTransactionCache(coin: Coin.dogecoin)) .thenAnswer((realInvocation) async {}); @@ -2318,7 +2276,17 @@ void main() { verify(client?.getServerFeatures()).called(1); verify(client?.getBatchHistory(args: historyBatchArgs0)).called(2); - verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); + verify(client?.getBatchHistory(args: historyBatchArgs1)).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "c82d4ac9697408d423d59dc53267f6474bbd4c22c55fd42ba766e80c6068e7dc" + ] + })).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "80badd62a8dd884cc7f61d962484564929340debb27f88fef270e553306a030c" + ] + })).called(1); verify(cachedClient?.clearSharedTransactionCache(coin: Coin.dogecoin)) .called(1); @@ -2814,6 +2782,17 @@ void main() { .thenAnswer((_) async => historyBatchResponse); when(client?.getBatchHistory(args: historyBatchArgs1)) .thenAnswer((_) async => historyBatchResponse); + when(client?.getBatchHistory(args: { + "0": [ + "c82d4ac9697408d423d59dc53267f6474bbd4c22c55fd42ba766e80c6068e7dc" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "80badd62a8dd884cc7f61d962484564929340debb27f88fef270e553306a030c" + ] + })).thenAnswer((realInvocation) async => {"0": []}); final wallet = await Hive.openBox(testWalletId); @@ -2831,6 +2810,16 @@ void main() { verify(client?.getServerFeatures()).called(1); verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); + verify(client?.getBatchHistory(args: { + "0": [ + "c82d4ac9697408d423d59dc53267f6474bbd4c22c55fd42ba766e80c6068e7dc" + ] + })).called(1); + verify(client?.getBatchHistory(args: { + "0": [ + "80badd62a8dd884cc7f61d962484564929340debb27f88fef270e553306a030c" + ] + })).called(1); expect(secureStore?.interactions, 6); expect(secureStore?.writes, 3); @@ -2859,6 +2848,17 @@ void main() { .thenAnswer((_) async => historyBatchResponse); when(client?.getBatchHistory(args: historyBatchArgs1)) .thenAnswer((_) async => historyBatchResponse); + when(client?.getBatchHistory(args: { + "0": [ + "c82d4ac9697408d423d59dc53267f6474bbd4c22c55fd42ba766e80c6068e7dc" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "80badd62a8dd884cc7f61d962484564929340debb27f88fef270e553306a030c" + ] + })).thenAnswer((realInvocation) async => {"0": []}); when(client?.getHistory(scripthash: anyNamed("scripthash"))) .thenThrow(Exception("some exception")); @@ -2876,6 +2876,16 @@ void main() { verify(client?.getServerFeatures()).called(1); verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); + verify(client?.getBatchHistory(args: { + "0": [ + "c82d4ac9697408d423d59dc53267f6474bbd4c22c55fd42ba766e80c6068e7dc" + ] + })).called(1); + verify(client?.getBatchHistory(args: { + "0": [ + "80badd62a8dd884cc7f61d962484564929340debb27f88fef270e553306a030c" + ] + })).called(1); verify(client?.getBlockHeadTip()).called(1); verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(1);