diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index d017bfb5e..fa08f11be 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -366,8 +366,8 @@ class BitcoinCashWallet extends CoinServiceAPI { longMutex = true; Map> p2pkhReceiveDerivations = {}; - Map> p2pkhChangeDerivations = {}; Map> p2shReceiveDerivations = {}; + Map> p2pkhChangeDerivations = {}; Map> p2shChangeDerivations = {}; final root = await compute(getBip32RootWrapper, Tuple2(mnemonic, _network)); @@ -395,12 +395,13 @@ class BitcoinCashWallet extends CoinServiceAPI { .log("checking receiving addresses...", level: LogLevel.Info); final resultReceive44 = _checkGaps(maxNumberOfIndexesToCheck, maxUnusedAddressGap, txCountBatchSize, root, DerivePathType.bip44, 0); + final resultReceive49 = _checkGaps(maxNumberOfIndexesToCheck, maxUnusedAddressGap, txCountBatchSize, root, DerivePathType.bip49, 0); Logging.instance .log("checking change addresses...", level: LogLevel.Info); - + // change addresses final resultChange44 = _checkGaps(maxNumberOfIndexesToCheck, maxUnusedAddressGap, txCountBatchSize, root, DerivePathType.bip44, 1); @@ -447,7 +448,6 @@ class BitcoinCashWallet extends CoinServiceAPI { derivePathType: DerivePathType.bip49, derivationsToAdd: p2shReceiveDerivations); } - if (p2pkhChangeDerivations.isNotEmpty) { await addDerivations( chain: 1, @@ -507,7 +507,8 @@ class BitcoinCashWallet extends CoinServiceAPI { boxName: walletId, key: 'changeAddressesP2SH', value: p2shChangeAddressArray); - + await DB.instance.put( + boxName: walletId, key: 'changeIndexP2PKH', value: p2pkhChangeIndex); await DB.instance.put( boxName: walletId, key: 'receivingIndexP2PKH', @@ -516,12 +517,8 @@ class BitcoinCashWallet extends CoinServiceAPI { boxName: walletId, key: 'receivingIndexP2SH', value: p2shReceiveIndex); - - await DB.instance.put( - boxName: walletId, key: 'changeIndexP2PKH', value: p2pkhChangeIndex); await DB.instance.put( boxName: walletId, key: 'changeIndexP2SH', value: p2shChangeIndex); - await DB.instance .put(boxName: walletId, key: "id", value: _walletId); await DB.instance @@ -607,7 +604,7 @@ class BitcoinCashWallet extends CoinServiceAPI { // get address tx counts final counts = await _getBatchTxCount(addresses: txCountCallArgs); - + print("Counts $counts"); // check and add appropriate addresses for (int k = 0; k < txCountBatchSize; k++) { int count = counts["${_id}_$k"]!; diff --git a/test/services/coins/bitcoincash/bitcoincash_history_sample_data.dart b/test/services/coins/bitcoincash/bitcoincash_history_sample_data.dart index a238a3f6e..de4c18633 100644 --- a/test/services/coins/bitcoincash/bitcoincash_history_sample_data.dart +++ b/test/services/coins/bitcoincash/bitcoincash_history_sample_data.dart @@ -1,21 +1,4 @@ final Map> 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> historyBatchArgs1 = { "k_0_0": ["4061323fc54ad0fd2fb6d3fd3af583068d7a733f562242a71e00ea7a82fb482b"], "k_0_1": ["04818da846fe5e03ac993d2e0c1ccc3848ff6073c3aba6a572df4efc5432ae8b"], "k_0_2": ["a0345933dd4146905a279f9aa35c867599fec2c52993a8f5da3a477acd0ebcfc"], @@ -32,24 +15,7 @@ final Map> historyBatchArgs1 = { "k_0_11": ["e0b38e944c5343e67c807a334fcf4b6563a6311447c99a105a0cf2cc3594ad11"] }; -final Map> 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> historyBatchArgs3 = { +final Map> historyBatchArgs1 = { "k_0_0": ["50550ac9d45b7484b41e32751326127f3e121354e3bceead3e5fd020c94c4fe1"], "k_0_1": ["f0c86f888f2aca0efaf1705247dbd1ebc02347c183e197310c9062ea2c9d2e34"], "k_0_2": ["f729a8b3d47b265bf78ee78216174f3f5ef44aedfebf2d3224f1afadcfd6b52b"], @@ -66,6 +32,40 @@ final Map> historyBatchArgs3 = { "k_0_11": ["9d0163f011c1259568c188c4770606b25c823f8b76bbd262c1c7f3095ed24620"] }; +final Map> historyBatchArgs2 = { + "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> historyBatchArgs3 = { + "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>> historyBatchResponse = { "k_0_0": [], "s_0_0": [{}, {}], diff --git a/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart b/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart index b595eeac0..6fd081b70 100644 --- a/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart +++ b/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart @@ -1832,6 +1832,10 @@ void main() { .thenAnswer((_) async => emptyHistoryBatchResponse); when(client?.getBatchHistory(args: historyBatchArgs1)) .thenAnswer((_) async => emptyHistoryBatchResponse); + when(client?.getBatchHistory(args: historyBatchArgs2)) + .thenAnswer((_) async => emptyHistoryBatchResponse); + when(client?.getBatchHistory(args: historyBatchArgs3)) + .thenAnswer((_) async => emptyHistoryBatchResponse); final wallet = await Hive.openBox(testWalletId); @@ -1847,6 +1851,8 @@ 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: historyBatchArgs2)).called(1); + verify(client?.getBatchHistory(args: historyBatchArgs3)).called(1); verifyNoMoreInteractions(client); verifyNoMoreInteractions(cachedClient); @@ -1989,6 +1995,7 @@ void main() { .thenAnswer((_) async => historyBatchResponse); when(client?.getBatchHistory(args: historyBatchArgs3)) .thenAnswer((_) async => historyBatchResponse); + final wallet = await Hive.openBox(testWalletId); bool hasThrown = false; @@ -2035,10 +2042,34 @@ void main() { .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(cachedClient?.clearSharedTransactionCache(coin: Coin.bitcoincash)) .thenAnswer((realInvocation) async {}); + when(client?.getBatchHistory(args: { + "0": [ + "04818da846fe5e03ac993d2e0c1ccc3848ff6073c3aba6a572df4efc5432ae8b" + ] + })).thenAnswer((_) async => {"0": []}); + when(client?.getBatchHistory(args: { + "0": [ + "f0c86f888f2aca0efaf1705247dbd1ebc02347c183e197310c9062ea2c9d2e34" + ] + })).thenAnswer((_) async => {"0": []}); + when(client?.getBatchHistory(args: { + "0": [ + "ff7f0d2a4b8e2805706ece77f4e672550fe4c505a150c781639814338eda1734" + ] + })).thenAnswer((_) async => {"0": []}); + when(client?.getBatchHistory(args: { + "0": [ + "1c2336c32dc62f00862ee6a75643e01017c86edece10b5a9d7defbd5f66b0a80" + ] + })).thenAnswer((_) async => {"0": []}); + final wallet = await Hive.openBox(testWalletId); // restore so we have something to rescan @@ -2151,12 +2182,35 @@ 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: historyBatchArgs2)).called(2); + verify(client?.getBatchHistory(args: historyBatchArgs3)).called(2); verify(cachedClient?.clearSharedTransactionCache(coin: Coin.bitcoincash)) .called(1); - expect(secureStore?.writes, 9); - expect(secureStore?.reads, 12); - expect(secureStore?.deletes, 2); + verify(client?.getBatchHistory(args: { + "0": [ + "04818da846fe5e03ac993d2e0c1ccc3848ff6073c3aba6a572df4efc5432ae8b" + ] + })).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "f0c86f888f2aca0efaf1705247dbd1ebc02347c183e197310c9062ea2c9d2e34" + ] + })).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "ff7f0d2a4b8e2805706ece77f4e672550fe4c505a150c781639814338eda1734" + ] + })).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "1c2336c32dc62f00862ee6a75643e01017c86edece10b5a9d7defbd5f66b0a80" + ] + })).called(2); + + expect(secureStore?.writes, 17); + expect(secureStore?.reads, 22); + expect(secureStore?.deletes, 4); verifyNoMoreInteractions(client); verifyNoMoreInteractions(cachedClient); @@ -2180,19 +2234,33 @@ void main() { .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(cachedClient?.clearSharedTransactionCache(coin: Coin.bitcoincash)) + .thenAnswer((realInvocation) async {}); + when(client?.getBatchHistory(args: { "0": [ "04818da846fe5e03ac993d2e0c1ccc3848ff6073c3aba6a572df4efc5432ae8b" ] })).thenAnswer((realInvocation) async => {"0": []}); - when(client?.getBatchHistory(args: { "0": [ "f0c86f888f2aca0efaf1705247dbd1ebc02347c183e197310c9062ea2c9d2e34" ] - })).thenAnswer((realInvocation) async => {"0": []}); - when(cachedClient?.clearSharedTransactionCache(coin: Coin.dogecoin)) - .thenAnswer((realInvocation) async {}); + })).thenAnswer((_) async => {"0": []}); + when(client?.getBatchHistory(args: { + "0": [ + "ff7f0d2a4b8e2805706ece77f4e672550fe4c505a150c781639814338eda1734" + ] + })).thenAnswer((_) async => {"0": []}); + when(client?.getBatchHistory(args: { + "0": [ + "1c2336c32dc62f00862ee6a75643e01017c86edece10b5a9d7defbd5f66b0a80" + ] + })).thenAnswer((_) async => {"0": []}); final wallet = await Hive.openBox(testWalletId); @@ -2250,13 +2318,36 @@ 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: historyBatchArgs2)).called(2); + verify(client?.getBatchHistory(args: historyBatchArgs3)).called(2); verify(cachedClient?.clearSharedTransactionCache(coin: Coin.bitcoincash)) .called(1); - expect(secureStore?.writes, 7); - expect(secureStore?.reads, 12); - expect(secureStore?.deletes, 4); + verify(client?.getBatchHistory(args: { + "0": [ + "04818da846fe5e03ac993d2e0c1ccc3848ff6073c3aba6a572df4efc5432ae8b" + ] + })).called(1); + verify(client?.getBatchHistory(args: { + "0": [ + "f0c86f888f2aca0efaf1705247dbd1ebc02347c183e197310c9062ea2c9d2e34" + ] + })).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "ff7f0d2a4b8e2805706ece77f4e672550fe4c505a150c781639814338eda1734" + ] + })).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "1c2336c32dc62f00862ee6a75643e01017c86edece10b5a9d7defbd5f66b0a80" + ] + })).called(2); + + expect(secureStore?.writes, 13); + expect(secureStore?.reads, 18); + expect(secureStore?.deletes, 8); }); // // test("fetchBuildTxData succeeds", () async {