mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-29 21:55:58 +00:00
WIP: Fix failing tests
This commit is contained in:
parent
909436afdc
commit
d4cfea4bb7
3 changed files with 199 additions and 15 deletions
|
@ -1520,6 +1520,8 @@ class BitcoinCashWallet extends CoinServiceAPI {
|
|||
arrayKey += "P2SH";
|
||||
break;
|
||||
}
|
||||
|
||||
print("Array key is ${jsonEncode(arrayKey)}");
|
||||
final internalChainArray =
|
||||
DB.instance.get<dynamic>(boxName: walletId, key: arrayKey);
|
||||
return internalChainArray.last as String;
|
||||
|
@ -3072,6 +3074,38 @@ class BitcoinCashWallet extends CoinServiceAPI {
|
|||
await DB.instance
|
||||
.delete<dynamic>(key: 'changeIndexP2PKH_BACKUP', boxName: walletId);
|
||||
|
||||
// p2Sh
|
||||
final tempReceivingAddressesP2SH = DB.instance
|
||||
.get<dynamic>(boxName: walletId, key: 'receivingAddressesP2SH_BACKUP');
|
||||
final tempChangeAddressesP2SH = DB.instance
|
||||
.get<dynamic>(boxName: walletId, key: 'changeAddressesP2SH_BACKUP');
|
||||
final tempReceivingIndexP2SH = DB.instance
|
||||
.get<dynamic>(boxName: walletId, key: 'receivingIndexP2SH_BACKUP');
|
||||
final tempChangeIndexP2SH = DB.instance
|
||||
.get<dynamic>(boxName: walletId, key: 'changeIndexP2SH_BACKUP');
|
||||
await DB.instance.put<dynamic>(
|
||||
boxName: walletId,
|
||||
key: 'receivingAddressesP2SH',
|
||||
value: tempReceivingAddressesP2SH);
|
||||
await DB.instance.put<dynamic>(
|
||||
boxName: walletId,
|
||||
key: 'changeAddressesP2SH',
|
||||
value: tempChangeAddressesP2SH);
|
||||
await DB.instance.put<dynamic>(
|
||||
boxName: walletId,
|
||||
key: 'receivingIndexP2SH',
|
||||
value: tempReceivingIndexP2SH);
|
||||
await DB.instance.put<dynamic>(
|
||||
boxName: walletId, key: 'changeIndexP2SH', value: tempChangeIndexP2SH);
|
||||
await DB.instance.delete<dynamic>(
|
||||
key: 'receivingAddressesP2SH_BACKUP', boxName: walletId);
|
||||
await DB.instance
|
||||
.delete<dynamic>(key: 'changeAddressesP2SH_BACKUP', boxName: walletId);
|
||||
await DB.instance
|
||||
.delete<dynamic>(key: 'receivingIndexP2SH_BACKUP', boxName: walletId);
|
||||
await DB.instance
|
||||
.delete<dynamic>(key: 'changeIndexP2SH_BACKUP', boxName: walletId);
|
||||
|
||||
// P2PKH derivations
|
||||
final p2pkhReceiveDerivationsString = await _secureStore.read(
|
||||
key: "${walletId}_receiveDerivationsP2PKH_BACKUP");
|
||||
|
@ -3089,6 +3123,22 @@ class BitcoinCashWallet extends CoinServiceAPI {
|
|||
key: "${walletId}_receiveDerivationsP2PKH_BACKUP");
|
||||
await _secureStore.delete(key: "${walletId}_changeDerivationsP2PKH_BACKUP");
|
||||
|
||||
// P2SH derivations
|
||||
final p2shReceiveDerivationsString = await _secureStore.read(
|
||||
key: "${walletId}_receiveDerivationsP2SH_BACKUP");
|
||||
final p2shChangeDerivationsString = await _secureStore.read(
|
||||
key: "${walletId}_changeDerivationsP2SH_BACKUP");
|
||||
|
||||
await _secureStore.write(
|
||||
key: "${walletId}_receiveDerivationsP2SH",
|
||||
value: p2shReceiveDerivationsString);
|
||||
await _secureStore.write(
|
||||
key: "${walletId}_changeDerivationsP2SH",
|
||||
value: p2shChangeDerivationsString);
|
||||
|
||||
await _secureStore.delete(key: "${walletId}_receiveDerivationsP2SH_BACKUP");
|
||||
await _secureStore.delete(key: "${walletId}_changeDerivationsP2SH_BACKUP");
|
||||
|
||||
// UTXOs
|
||||
final utxoData = DB.instance
|
||||
.get<dynamic>(boxName: walletId, key: 'latest_utxo_model_BACKUP');
|
||||
|
@ -3141,6 +3191,43 @@ class BitcoinCashWallet extends CoinServiceAPI {
|
|||
await DB.instance
|
||||
.delete<dynamic>(key: 'changeIndexP2PKH', boxName: walletId);
|
||||
|
||||
// p2sh
|
||||
final tempReceivingAddressesP2SH = DB.instance
|
||||
.get<dynamic>(boxName: walletId, key: 'receivingAddressesP2SH');
|
||||
await DB.instance.put<dynamic>(
|
||||
boxName: walletId,
|
||||
key: 'receivingAddressesP2SH_BACKUP',
|
||||
value: tempReceivingAddressesP2SH);
|
||||
await DB.instance
|
||||
.delete<dynamic>(key: 'receivingAddressesP2SH', boxName: walletId);
|
||||
|
||||
final tempChangeAddressesP2SH =
|
||||
DB.instance.get<dynamic>(boxName: walletId, key: 'changeAddressesP2SH');
|
||||
await DB.instance.put<dynamic>(
|
||||
boxName: walletId,
|
||||
key: 'changeAddressesP2SH_BACKUP',
|
||||
value: tempChangeAddressesP2SH);
|
||||
await DB.instance
|
||||
.delete<dynamic>(key: 'changeAddressesP2SH', boxName: walletId);
|
||||
|
||||
final tempReceivingIndexP2SH =
|
||||
DB.instance.get<dynamic>(boxName: walletId, key: 'receivingIndexP2SH');
|
||||
await DB.instance.put<dynamic>(
|
||||
boxName: walletId,
|
||||
key: 'receivingIndexP2SH_BACKUP',
|
||||
value: tempReceivingIndexP2SH);
|
||||
await DB.instance
|
||||
.delete<dynamic>(key: 'receivingIndexP2SH', boxName: walletId);
|
||||
|
||||
final tempChangeIndexP2SH =
|
||||
DB.instance.get<dynamic>(boxName: walletId, key: 'changeIndexP2SH');
|
||||
await DB.instance.put<dynamic>(
|
||||
boxName: walletId,
|
||||
key: 'changeIndexP2SH_BACKUP',
|
||||
value: tempChangeIndexP2SH);
|
||||
await DB.instance
|
||||
.delete<dynamic>(key: 'changeIndexP2SH', boxName: walletId);
|
||||
|
||||
// P2PKH derivations
|
||||
final p2pkhReceiveDerivationsString =
|
||||
await _secureStore.read(key: "${walletId}_receiveDerivationsP2PKH");
|
||||
|
@ -3157,6 +3244,22 @@ class BitcoinCashWallet extends CoinServiceAPI {
|
|||
await _secureStore.delete(key: "${walletId}_receiveDerivationsP2PKH");
|
||||
await _secureStore.delete(key: "${walletId}_changeDerivationsP2PKH");
|
||||
|
||||
// P2SH derivations
|
||||
final p2shReceiveDerivationsString =
|
||||
await _secureStore.read(key: "${walletId}_receiveDerivationsP2SH");
|
||||
final p2shChangeDerivationsString =
|
||||
await _secureStore.read(key: "${walletId}_changeDerivationsP2SH");
|
||||
|
||||
await _secureStore.write(
|
||||
key: "${walletId}_receiveDerivationsP2SH_BACKUP",
|
||||
value: p2shReceiveDerivationsString);
|
||||
await _secureStore.write(
|
||||
key: "${walletId}_changeDerivationsP2SH_BACKUP",
|
||||
value: p2shChangeDerivationsString);
|
||||
|
||||
await _secureStore.delete(key: "${walletId}_receiveDerivationsP2SH");
|
||||
await _secureStore.delete(key: "${walletId}_changeDerivationsP2SH");
|
||||
|
||||
// UTXOs
|
||||
final utxoData =
|
||||
DB.instance.get<dynamic>(boxName: walletId, key: 'latest_utxo_model');
|
||||
|
|
|
@ -1,4 +1,21 @@
|
|||
final Map<String, List<dynamic>> historyBatchArgs0 = {
|
||||
"k_0_0": ["e47feb2ab9db7424d044dc5b2f29404ec35682dc7ea2100acab4b85eb15b8a84"],
|
||||
"k_0_1": ["ff7f0d2a4b8e2805706ece77f4e672550fe4c505a150c781639814338eda1734"],
|
||||
"k_0_2": ["68c84a2f0e8b52769e22270f9cf26bc1e3ffed55fe368e94c5d761403b86a7c5"],
|
||||
"k_0_3": ["7ec0c8c9b961e481a3fd05b997997929a36c174857ba4f06e8ba55b5a29670fd"],
|
||||
"k_0_4": ["42adc3dee3f1c8bc25384ab5254a75af64fc94b6e29d3ae6c0ccfb50c7910c88"],
|
||||
"k_0_5": ["d3e419ee2b5ef5969a76d3e5ae14a15fe2dfa26ac434de95b0616416e4dc8955"],
|
||||
"k_0_6": ["0cf8f653ae181c1a33d94787f7a34c0a95bd0465003488c1a6e7f81b87063573"],
|
||||
"k_0_7": ["8c8e647009329da2c508aa08b2b28b2f83932efca4ed5a6c1b29ccec37fda9c1"],
|
||||
"k_0_8": ["30c063757244ac50049d2604c7f9d671e9cbac53f4e76a9c1147112934336057"],
|
||||
"k_0_9": ["2440d59c1dc1fd6dde77f52d8cf4f8f799005f53e8027f10828ef1eee739694e"],
|
||||
"k_0_10": [
|
||||
"1a2e9fd10dc64048e1bf86c58c37611920facf486e80a36a60e20eb3496c3aad"
|
||||
],
|
||||
"k_0_11": ["052e9116071688691bf12f2db3154f72562d957cf058bce2b88a144d67968da0"]
|
||||
};
|
||||
|
||||
final Map<String, List<dynamic>> historyBatchArgs1 = {
|
||||
"k_0_0": ["4061323fc54ad0fd2fb6d3fd3af583068d7a733f562242a71e00ea7a82fb482b"],
|
||||
"k_0_1": ["04818da846fe5e03ac993d2e0c1ccc3848ff6073c3aba6a572df4efc5432ae8b"],
|
||||
"k_0_2": ["a0345933dd4146905a279f9aa35c867599fec2c52993a8f5da3a477acd0ebcfc"],
|
||||
|
@ -15,7 +32,24 @@ final Map<String, List<dynamic>> historyBatchArgs0 = {
|
|||
"k_0_11": ["e0b38e944c5343e67c807a334fcf4b6563a6311447c99a105a0cf2cc3594ad11"]
|
||||
};
|
||||
|
||||
final Map<String, List<dynamic>> historyBatchArgs1 = {
|
||||
final Map<String, List<dynamic>> historyBatchArgs2 = {
|
||||
"k_0_0": ["4694828a4841338b5921e10f9d97a9c6d2a4ff50593be21572391fefbd2179be"],
|
||||
"k_0_1": ["1c2336c32dc62f00862ee6a75643e01017c86edece10b5a9d7defbd5f66b0a80"],
|
||||
"k_0_2": ["e96b7f9655acc58d58ffc322626c9742f3941fef790e3d2836d5db74d3708427"],
|
||||
"k_0_3": ["abc8d1cf0dc8f66678eb0d322eb4f907cb2552cde74ace5201c4978787db91e4"],
|
||||
"k_0_4": ["421b02221022dd34081669fd21e7a9a83f8761e068f48b5291e0accf9d1b5867"],
|
||||
"k_0_5": ["1233abcc5848b1bcf6a561984f1f0596d270ef47320c281a5abf7a2098dd5902"],
|
||||
"k_0_6": ["963f002eddfb35100830f416c97605947a9df7ea885554923d6427b79d519079"],
|
||||
"k_0_7": ["8b511de883d14c0f40b8eed22c23432b3d9c97ce521c4ad94338189065ae3e94"],
|
||||
"k_0_8": ["954d176b775a925fcbceb36b717114b0f01af6ac082d89971379e789a4bba613"],
|
||||
"k_0_9": ["3c8c79404dba45b8228547a5b3da306e1cdc3438e02f9e6ec1c88ba2fb6ef6df"],
|
||||
"k_0_10": [
|
||||
"a253190f30e26c482d3864d675da927a9df20c52172826ea630ca3f600da4642"
|
||||
],
|
||||
"k_0_11": ["bd39e800a3822ebaa5e33938b29cff5fcf867def7c0ac6d65af350b737357f65"]
|
||||
};
|
||||
|
||||
final Map<String, List<dynamic>> historyBatchArgs3 = {
|
||||
"k_0_0": ["50550ac9d45b7484b41e32751326127f3e121354e3bceead3e5fd020c94c4fe1"],
|
||||
"k_0_1": ["f0c86f888f2aca0efaf1705247dbd1ebc02347c183e197310c9062ea2c9d2e34"],
|
||||
"k_0_2": ["f729a8b3d47b265bf78ee78216174f3f5ef44aedfebf2d3224f1afadcfd6b52b"],
|
||||
|
|
|
@ -1271,13 +1271,13 @@ void main() {
|
|||
}
|
||||
expect(didThrow, false);
|
||||
|
||||
verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(1);
|
||||
verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(2);
|
||||
verify(client?.getServerFeatures()).called(1);
|
||||
verifyNever(client?.ping()).called(0);
|
||||
|
||||
expect(secureStore?.interactions, 11);
|
||||
expect(secureStore?.reads, 7);
|
||||
expect(secureStore?.writes, 4);
|
||||
expect(secureStore?.interactions, 20);
|
||||
expect(secureStore?.reads, 13);
|
||||
expect(secureStore?.writes, 7);
|
||||
expect(secureStore?.deletes, 0);
|
||||
verifyNoMoreInteractions(client);
|
||||
verifyNoMoreInteractions(cachedClient);
|
||||
|
@ -1317,9 +1317,9 @@ void main() {
|
|||
verify(client?.getServerFeatures()).called(1);
|
||||
verifyNever(client?.ping()).called(0);
|
||||
|
||||
expect(secureStore?.interactions, 8);
|
||||
expect(secureStore?.reads, 5);
|
||||
expect(secureStore?.writes, 3);
|
||||
expect(secureStore?.interactions, 14);
|
||||
expect(secureStore?.reads, 9);
|
||||
expect(secureStore?.writes, 5);
|
||||
expect(secureStore?.deletes, 0);
|
||||
verifyNoMoreInteractions(client);
|
||||
verifyNoMoreInteractions(cachedClient);
|
||||
|
@ -1366,13 +1366,13 @@ void main() {
|
|||
}
|
||||
expect(didThrow, false);
|
||||
|
||||
verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(1);
|
||||
verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(2);
|
||||
verify(client?.getServerFeatures()).called(1);
|
||||
verifyNever(client?.ping()).called(0);
|
||||
|
||||
expect(secureStore?.interactions, 11);
|
||||
expect(secureStore?.reads, 7);
|
||||
expect(secureStore?.writes, 4);
|
||||
expect(secureStore?.interactions, 20);
|
||||
expect(secureStore?.reads, 13);
|
||||
expect(secureStore?.writes, 7);
|
||||
expect(secureStore?.deletes, 0);
|
||||
verifyNoMoreInteractions(client);
|
||||
verifyNoMoreInteractions(cachedClient);
|
||||
|
@ -1413,9 +1413,9 @@ void main() {
|
|||
verify(client?.getServerFeatures()).called(1);
|
||||
verifyNever(client?.ping()).called(0);
|
||||
|
||||
expect(secureStore?.interactions, 8);
|
||||
expect(secureStore?.reads, 5);
|
||||
expect(secureStore?.writes, 3);
|
||||
expect(secureStore?.interactions, 14);
|
||||
expect(secureStore?.reads, 9);
|
||||
expect(secureStore?.writes, 5);
|
||||
expect(secureStore?.deletes, 0);
|
||||
verifyNoMoreInteractions(client);
|
||||
verifyNoMoreInteractions(cachedClient);
|
||||
|
@ -2047,25 +2047,51 @@ void main() {
|
|||
final preChangeAddressesP2PKH = await wallet.get('changeAddressesP2PKH');
|
||||
final preReceivingIndexP2PKH = await wallet.get('receivingIndexP2PKH');
|
||||
final preChangeIndexP2PKH = await wallet.get('changeIndexP2PKH');
|
||||
|
||||
final preReceivingAddressesP2SH =
|
||||
await wallet.get('receivingAddressesP2SH');
|
||||
final preChangeAddressesP2SH = await wallet.get('changeAddressesP2SH');
|
||||
final preReceivingIndexP2SH = await wallet.get('receivingIndexP2PKH');
|
||||
final preChangeIndexP2SH = await wallet.get('changeIndexP2SH');
|
||||
|
||||
final preUtxoData = await wallet.get('latest_utxo_model');
|
||||
final preReceiveDerivationsStringP2PKH = await secureStore?.read(
|
||||
key: "${testWalletId}_receiveDerivationsP2PKH");
|
||||
final preChangeDerivationsStringP2PKH = await secureStore?.read(
|
||||
key: "${testWalletId}_changeDerivationsP2PKH");
|
||||
|
||||
final preReceiveDerivationsStringP2SH = await secureStore?.read(
|
||||
key: "${testWalletId}_receiveDerivationsP2SH");
|
||||
final preChangeDerivationsStringP2SH =
|
||||
await secureStore?.read(key: "${testWalletId}_changeDerivationsP2SH");
|
||||
|
||||
// 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(
|
||||
'receivingAddressesP2SH', ["some address", "some other address"]);
|
||||
await wallet
|
||||
.put('changeAddressesP2SH', ["some address", "some other address"]);
|
||||
|
||||
await wallet.put('receivingIndexP2PKH', 123);
|
||||
await wallet.put('changeIndexP2PKH', 123);
|
||||
|
||||
await wallet.put('receivingIndexP2SH', 123);
|
||||
await wallet.put('changeIndexP2SH', 123);
|
||||
|
||||
await secureStore?.write(
|
||||
key: "${testWalletId}_receiveDerivationsP2PKH", value: "{}");
|
||||
await secureStore?.write(
|
||||
key: "${testWalletId}_changeDerivationsP2PKH", value: "{}");
|
||||
|
||||
await secureStore?.write(
|
||||
key: "${testWalletId}_receiveDerivationsP2SH", value: "{}");
|
||||
await secureStore?.write(
|
||||
key: "${testWalletId}_changeDerivationsP2SH", value: "{}");
|
||||
|
||||
bool hasThrown = false;
|
||||
try {
|
||||
await bch?.fullRescan(2, 1000);
|
||||
|
@ -2080,20 +2106,41 @@ void main() {
|
|||
final changeAddressesP2PKH = await wallet.get('changeAddressesP2PKH');
|
||||
final receivingIndexP2PKH = await wallet.get('receivingIndexP2PKH');
|
||||
final changeIndexP2PKH = await wallet.get('changeIndexP2PKH');
|
||||
|
||||
final receivingAddressesP2SH = await wallet.get('receivingAddressesP2SH');
|
||||
final changeAddressesP2SH = await wallet.get('changeAddressesP2SH');
|
||||
final receivingIndexP2SH = await wallet.get('receivingIndexP2SH');
|
||||
final changeIndexP2SH = await wallet.get('changeIndexP2SH');
|
||||
|
||||
final utxoData = await wallet.get('latest_utxo_model');
|
||||
final receiveDerivationsStringP2PKH = await secureStore?.read(
|
||||
key: "${testWalletId}_receiveDerivationsP2PKH");
|
||||
final changeDerivationsStringP2PKH = await secureStore?.read(
|
||||
key: "${testWalletId}_changeDerivationsP2PKH");
|
||||
|
||||
final receiveDerivationsStringP2SH = await secureStore?.read(
|
||||
key: "${testWalletId}_receiveDerivationsP2SH");
|
||||
final changeDerivationsStringP2SH =
|
||||
await secureStore?.read(key: "${testWalletId}_changeDerivationsP2SH");
|
||||
|
||||
expect(preReceivingAddressesP2PKH, receivingAddressesP2PKH);
|
||||
expect(preChangeAddressesP2PKH, changeAddressesP2PKH);
|
||||
expect(preReceivingIndexP2PKH, receivingIndexP2PKH);
|
||||
expect(preChangeIndexP2PKH, changeIndexP2PKH);
|
||||
|
||||
expect(preReceivingAddressesP2SH, receivingAddressesP2SH);
|
||||
expect(preChangeAddressesP2SH, changeAddressesP2SH);
|
||||
expect(preReceivingIndexP2SH, receivingIndexP2SH);
|
||||
expect(preChangeIndexP2SH, changeIndexP2SH);
|
||||
|
||||
expect(preUtxoData, utxoData);
|
||||
|
||||
expect(preReceiveDerivationsStringP2PKH, receiveDerivationsStringP2PKH);
|
||||
expect(preChangeDerivationsStringP2PKH, changeDerivationsStringP2PKH);
|
||||
|
||||
expect(preReceiveDerivationsStringP2SH, receiveDerivationsStringP2SH);
|
||||
expect(preChangeDerivationsStringP2SH, changeDerivationsStringP2SH);
|
||||
|
||||
verify(client?.getServerFeatures()).called(1);
|
||||
verify(client?.getBatchHistory(args: historyBatchArgs0)).called(2);
|
||||
verify(client?.getBatchHistory(args: historyBatchArgs1)).called(2);
|
||||
|
|
Loading…
Reference in a new issue