update fullRescan succeeds test and sample data

This commit is contained in:
julian 2022-09-16 08:36:30 -06:00
parent fc6c2a705f
commit 5267d9198b
2 changed files with 16 additions and 115 deletions

View file

@ -16,20 +16,20 @@ final Map<String, List<dynamic>> historyBatchArgs0 = {
};
final Map<String, List<dynamic>> historyBatchArgs1 = {
"k_0_0": ["4061323fc54ad0fd2fb6d3fd3af583068d7a733f562242a71e00ea7a82fb482b"],
"k_0_1": ["04818da846fe5e03ac993d2e0c1ccc3848ff6073c3aba6a572df4efc5432ae8b"],
"k_0_2": ["a0345933dd4146905a279f9aa35c867599fec2c52993a8f5da3a477acd0ebcfc"],
"k_0_3": ["607bc74daf946bfd9d593606f4393e44555a3dd0b529ddd08a0422be7955912e"],
"k_0_4": ["449dfb82e6f09f7e190f21fe63aaad5ccb854ba1f44f0a6622f6d71fff19fc63"],
"k_0_5": ["3643e3fe26e0b08dcbc89c47efce3b3264f361160341e3c2a6c73681dde12d39"],
"k_0_6": ["6daca5039b35adcbe62441b68eaaa48e9b0a806ab5a34314bd394b9b5c9289e5"],
"k_0_7": ["113f3d214f202795fdc3dccc6942395812270e787abb88fe4ddfa14f33d62d6f"],
"k_0_8": ["5dea575b85959647509d2ab3c92cda3776a4deba444486a7925ae3b71306e7e3"],
"k_0_9": ["5e2e6d3b43dfa29fabf66879d9ba67e4bb2f9f7ed10cfbb75e0b445eb4b84287"],
"k_0_0": ["50550ac9d45b7484b41e32751326127f3e121354e3bceead3e5fd020c94c4fe1"],
"k_0_1": ["f0c86f888f2aca0efaf1705247dbd1ebc02347c183e197310c9062ea2c9d2e34"],
"k_0_2": ["f729a8b3d47b265bf78ee78216174f3f5ef44aedfebf2d3224f1afadcfd6b52b"],
"k_0_3": ["82f5da8c4d26af2898dbb947c6afb83b5ad92e609345f1b89819293dd7714c75"],
"k_0_4": ["b4d6bf5639a8cd368772c26da95173940510618023e8952eb8db70aeb1d59cd2"],
"k_0_5": ["12e0f3cb2bf44b80f3c34cfd3fadc2a39de2f4776bc2be5b7100126db1238983"],
"k_0_6": ["ed5351a1e390d6635fa1ccf594998eb82fa627caf93541f3d5f1021b90e75ec7"],
"k_0_7": ["97917c094ec3afcd1b41338e7c06774b2f76c7a430e486c0080a86a141f39723"],
"k_0_8": ["58f96c6274cd3b74d362a30778497cef65f0c657ce94bb8b274b802e47876e3c"],
"k_0_9": ["99fb86f164906c621a42ee2b224972b3ea8ce10dbc1bccecbbdb1a7582e2954a"],
"k_0_10": [
"1bfe42869b6b1e5efa1e1b47f382615e3d27e3e66e9cc8ae46b71ece067b4d37"
"555b8d6a03d2b93c381d2cda19fac11034bf5128ccbcbe5ff46b87f17969b4cb"
],
"k_0_11": ["e0b38e944c5343e67c807a334fcf4b6563a6311447c99a105a0cf2cc3594ad11"]
"k_0_11": ["9d0163f011c1259568c188c4770606b25c823f8b76bbd262c1c7f3095ed24620"]
};
final Map<String, List<Map<String, dynamic>>> historyBatchResponse = {

View file

@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:bitcoindart/bitcoindart.dart';
import 'package:decimal/decimal.dart';
import 'package:flutter_test/flutter_test.dart';
@ -20,8 +18,6 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'bitcoincash_history_sample_data.dart';
import 'bitcoincash_transaction_data_samples.dart';
import 'bitcoincash_utxo_sample_data.dart';
import 'bitcoincash_wallet_test.mocks.dart';
import 'bitcoincash_wallet_test_parameters.dart';
@ -1811,102 +1807,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.bitcoincash))
.thenAnswer((realInvocation) async {});
final wallet = await Hive.openBox(testWalletId);
// restore so we have something to rescan
await bch?.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 bch?.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.bitcoincash))
.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": {},
@ -2125,8 +2025,9 @@ void main() {
});
when(client?.getBatchHistory(args: historyBatchArgs0))
.thenAnswer((_) async => historyBatchResponse);
// when(client?.getBatchHistory(args: historyBatchArgs1))
// .thenAnswer((_) async => historyBatchResponse);
when(client?.getBatchHistory(args: historyBatchArgs1))
.thenAnswer((_) async => historyBatchResponse);
when(cachedClient?.clearSharedTransactionCache(coin: Coin.bitcoincash))
.thenAnswer((realInvocation) async {});
@ -2194,7 +2095,7 @@ 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: historyBatchArgs1)).called(2);
verify(cachedClient?.clearSharedTransactionCache(coin: Coin.bitcoincash))
.called(1);