updated doge tests to reflect speedup modifications

This commit is contained in:
julian 2022-09-12 11:35:26 -06:00
parent ea17eb5676
commit 4ebda4ad21
2 changed files with 112 additions and 102 deletions

View file

@ -1914,7 +1914,7 @@ class DogecoinWallet extends CoinServiceAPI {
batches[batchNumber] = {}; batches[batchNumber] = {};
} }
final scripthash = _convertToScriptHash(allAddresses[i], _network); final scripthash = _convertToScriptHash(allAddresses[i], _network);
final id = const Uuid().v1(); final id = Logger.isTestEnv ? "$i" : const Uuid().v1();
requestIdToAddressMap[id] = allAddresses[i]; requestIdToAddressMap[id] = allAddresses[i];
batches[batchNumber]!.addAll({ batches[batchNumber]!.addAll({
id: [scripthash] id: [scripthash]

View file

@ -20,8 +20,6 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'dogecoin_history_sample_data.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.mocks.dart';
import 'dogecoin_wallet_test_parameters.dart'; import 'dogecoin_wallet_test_parameters.dart';
@ -1853,102 +1851,6 @@ void main() {
// // verifyNoMoreInteractions(priceAPI); // // 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 { test("get mnemonic list", () async {
when(client?.getServerFeatures()).thenAnswer((_) async => { when(client?.getServerFeatures()).thenAnswer((_) async => {
"hosts": {}, "hosts": {},
@ -2118,7 +2020,19 @@ void main() {
when(client?.getBatchHistory(args: historyBatchArgs1)) when(client?.getBatchHistory(args: historyBatchArgs1))
.thenAnswer((_) async => historyBatchResponse); .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<dynamic>(testWalletId);
bool hasThrown = false; bool hasThrown = false;
try { try {
@ -2135,6 +2049,16 @@ void main() {
verify(client?.getServerFeatures()).called(1); verify(client?.getServerFeatures()).called(1);
verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1);
verify(client?.getBatchHistory(args: historyBatchArgs1)).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?.interactions, 6);
expect(secureStore?.writes, 3); expect(secureStore?.writes, 3);
@ -2165,7 +2089,19 @@ void main() {
when(cachedClient?.clearSharedTransactionCache(coin: Coin.dogecoin)) when(cachedClient?.clearSharedTransactionCache(coin: Coin.dogecoin))
.thenAnswer((realInvocation) async {}); .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<dynamic>(testWalletId);
// restore so we have something to rescan // restore so we have something to rescan
await doge?.recoverFromMnemonic( await doge?.recoverFromMnemonic(
@ -2230,6 +2166,16 @@ void main() {
verify(client?.getServerFeatures()).called(1); verify(client?.getServerFeatures()).called(1);
verify(client?.getBatchHistory(args: historyBatchArgs0)).called(2); verify(client?.getBatchHistory(args: historyBatchArgs0)).called(2);
verify(client?.getBatchHistory(args: historyBatchArgs1)).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)) verify(cachedClient?.clearSharedTransactionCache(coin: Coin.dogecoin))
.called(1); .called(1);
@ -2259,6 +2205,18 @@ void main() {
.thenAnswer((_) async => historyBatchResponse); .thenAnswer((_) async => historyBatchResponse);
when(client?.getBatchHistory(args: historyBatchArgs1)) when(client?.getBatchHistory(args: historyBatchArgs1))
.thenAnswer((_) async => historyBatchResponse); .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)) when(cachedClient?.clearSharedTransactionCache(coin: Coin.dogecoin))
.thenAnswer((realInvocation) async {}); .thenAnswer((realInvocation) async {});
@ -2318,7 +2276,17 @@ void main() {
verify(client?.getServerFeatures()).called(1); verify(client?.getServerFeatures()).called(1);
verify(client?.getBatchHistory(args: historyBatchArgs0)).called(2); 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)) verify(cachedClient?.clearSharedTransactionCache(coin: Coin.dogecoin))
.called(1); .called(1);
@ -2814,6 +2782,17 @@ void main() {
.thenAnswer((_) async => historyBatchResponse); .thenAnswer((_) async => historyBatchResponse);
when(client?.getBatchHistory(args: historyBatchArgs1)) when(client?.getBatchHistory(args: historyBatchArgs1))
.thenAnswer((_) async => historyBatchResponse); .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); final wallet = await Hive.openBox(testWalletId);
@ -2831,6 +2810,16 @@ void main() {
verify(client?.getServerFeatures()).called(1); verify(client?.getServerFeatures()).called(1);
verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1);
verify(client?.getBatchHistory(args: historyBatchArgs1)).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?.interactions, 6);
expect(secureStore?.writes, 3); expect(secureStore?.writes, 3);
@ -2859,6 +2848,17 @@ void main() {
.thenAnswer((_) async => historyBatchResponse); .thenAnswer((_) async => historyBatchResponse);
when(client?.getBatchHistory(args: historyBatchArgs1)) when(client?.getBatchHistory(args: historyBatchArgs1))
.thenAnswer((_) async => historyBatchResponse); .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"))) when(client?.getHistory(scripthash: anyNamed("scripthash")))
.thenThrow(Exception("some exception")); .thenThrow(Exception("some exception"));
@ -2876,6 +2876,16 @@ void main() {
verify(client?.getServerFeatures()).called(1); verify(client?.getServerFeatures()).called(1);
verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1);
verify(client?.getBatchHistory(args: historyBatchArgs1)).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?.getBlockHeadTip()).called(1);
verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(1); verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(1);