From 0ce49eacc2f40edc76fefbd830d5d614aebfdda8 Mon Sep 17 00:00:00 2001 From: Likho Date: Sun, 18 Sep 2022 11:02:06 +0200 Subject: [PATCH 1/7] Remove custom mock, makes no difference --- test/services/coins/bitcoincash/bitcoincash_wallet_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart b/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart index c625dd4b7..87d26cf43 100644 --- a/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart +++ b/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart @@ -21,8 +21,8 @@ import 'bitcoincash_history_sample_data.dart'; import 'bitcoincash_wallet_test.mocks.dart'; import 'bitcoincash_wallet_test_parameters.dart'; -@GenerateMocks([CachedElectrumX, PriceAPI, TransactionNotificationTracker], - customMocks: [MockSpec(returnNullOnMissingStub: true)]) +@GenerateMocks( + [ElectrumX, CachedElectrumX, PriceAPI, TransactionNotificationTracker]) void main() { group("bitcoincash constants", () { test("bitcoincash minimum confirmations", () async { From d032690101f9cb53070aaafec1a7a7e85f8b6165 Mon Sep 17 00:00:00 2001 From: Likho Date: Mon, 19 Sep 2022 15:38:32 +0200 Subject: [PATCH 2/7] WIP: Testing nmc and bch --- .../add_edit_node_view.dart | 1 + .../coins/namecoin/namecoin_wallet.dart | 7 +- lib/utilities/block_explorers.dart | 3 + .../namecoin_history_sample_data.dart | 98 +- .../coins/namecoin/namecoin_wallet_test.dart | 3033 +---------------- 5 files changed, 204 insertions(+), 2938 deletions(-) diff --git a/lib/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart b/lib/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart index 0cb47b7ff..def35b800 100644 --- a/lib/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart +++ b/lib/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart @@ -532,6 +532,7 @@ class _NodeFormState extends ConsumerState { case Coin.namecoin: case Coin.bitcoincash: case Coin.bitcoinTestNet: + case Coin.bitcoincashTestnet: case Coin.firoTestNet: case Coin.dogecoinTestNet: return false; diff --git a/lib/services/coins/namecoin/namecoin_wallet.dart b/lib/services/coins/namecoin/namecoin_wallet.dart index 379fda4e2..cf241d07a 100644 --- a/lib/services/coins/namecoin/namecoin_wallet.dart +++ b/lib/services/coins/namecoin/namecoin_wallet.dart @@ -48,6 +48,8 @@ const int DUST_LIMIT = 1000000; const String GENESIS_HASH_MAINNET = "000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770"; +const String GENESIS_HASH_TESTNET = + "00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"; enum DerivePathType { bip44, bip49, bip84 } @@ -2033,15 +2035,18 @@ class NamecoinWallet extends CoinServiceAPI { }) async { try { final Map> args = {}; + print("Address $addresses"); for (final entry in addresses.entries) { args[entry.key] = [_convertToScriptHash(entry.value, _network)]; } + print("Args ${jsonEncode(args)}"); final response = await electrumXClient.getBatchHistory(args: args); - + print("Response ${jsonEncode(response)}"); final Map result = {}; for (final entry in response.entries) { result[entry.key] = entry.value.length; } + return result; } catch (e, s) { Logging.instance.log( diff --git a/lib/utilities/block_explorers.dart b/lib/utilities/block_explorers.dart index 78afe5f7f..bf619d88f 100644 --- a/lib/utilities/block_explorers.dart +++ b/lib/utilities/block_explorers.dart @@ -24,6 +24,9 @@ Uri getBlockExplorerTransactionUrlFor({ return Uri.parse("https://testexplorer.firo.org/tx/$txid"); case Coin.bitcoincash: return Uri.parse("https://blockchair.com/bitcoin-cash/transaction/$txid"); + case Coin.bitcoincashTestnet: + return Uri.parse( + "https://blockexplorer.one/bitcoin-cash/testnet/tx/$txid"); case Coin.namecoin: return Uri.parse("https://chainz.cryptoid.info/nmc/tx.dws?$txid.htm"); } diff --git a/test/services/coins/namecoin/namecoin_history_sample_data.dart b/test/services/coins/namecoin/namecoin_history_sample_data.dart index baa0535ec..a22764a9b 100644 --- a/test/services/coins/namecoin/namecoin_history_sample_data.dart +++ b/test/services/coins/namecoin/namecoin_history_sample_data.dart @@ -1,13 +1,101 @@ final Map> historyBatchArgs0 = { - "k_0_0": ["bd84ae7e09414b0ccf5dcbf70a1f89f2fd42119a98af35dd4ecc80210fed0487"], - "k_0_1": ["3ef543d0887c3e9f9924f1b2d3b21410d0238937364663ed3414a2c2ddf4ccc6"] + "k_0_0": ["d17132f41b2d55c730db5b27db721020abbd4a5087c15edcccbaa106eef8cbf3"], + "k_0_1": ["cd3dd4abe4f9efc7149ba334d2d6790020331805b0bd5c7ed89a3ac6a22f10b9"], + "k_0_2": ["82a12031d679c9dd3124047742dc22c2c7c03afa9644bddf55d4c95da41bca1c"], + "k_0_3": ["bbe10c5d3c102fd805770ed2d6c5438dce42c04d3f87e3260056d04245b17ddd"], + "k_0_4": ["d9ca5255516f963d8f348911451e2c69489a70dec7f34a4810ee8b0e32fcb04d"], + "k_0_5": ["2284461fd01b17e7443775e39b19f4378a063ff148938d2e4191cea3fd80368d"], + "k_0_6": ["cd3c32fddbf265410c34a58fefcc849b02fc16978d75e501f88f9effcbecd8fe"], + "k_0_7": ["a3bcc0c3c4a140fbcc4c4f4dff18790d8a2d5f868821f47460f68f0426291b57"], + "k_0_8": ["e400f9431798c87ea35ea19b265d9e56a73fd44c239957d9947ae79e16718fb4"], + "k_0_9": ["1fe8bb16b49725bf3703274e205a4695c398e664284cc68d92d15087a54da299"], + "k_0_10": [ + "2fabf8d61308c8b2d914489a9f02f669ed9fa68047666815cf1f3cd1bb5d8819" + ], + "k_0_11": ["42a567d344189430afe7d45d6854ef6e9d256d9ef4186afd31a1a5ff90a6a0dd"] }; final Map> historyBatchArgs1 = { - "k_0_0": ["dffa9543852197f9fb90f8adafaab8a0b9b4925e9ada8c6bdcaf00bf2e9f60d7"], - "k_0_1": ["71b56532e9e7321bd8c30d0f8b14530743049d2f3edd5623065c46eee1dda04d"] + "k_0_0": ["bcf7aec7c10dfba33ce80149300a7c4fe66460c1dd05503b5df5780884498186"], + "k_0_1": ["587943864cefed4f1643a5ee2ce2b3c13a0c6ad7c435373f0ac328e144a15c1e"], + "k_0_2": ["fe6ad514f7427782f964b25995a90a3233589904b88f66a2d0e73e2560c9af7c"], + "k_0_3": ["6b962c5f9b4cfc004c74c5ab849304c405b02fc0e2f34ee17c185984f13c9da4"], + "k_0_4": ["720b79fab9a163ce6534828e8a673c5bf600161eba92c2b81555e79add59994c"], + "k_0_5": ["a10f4cf239abd4bcdb03dbe40b5c1d57ae3a7982adf8f177d481feb0ad3a52cd"], + "k_0_6": ["061f28e17ba1a56404b08a5899163011c7d6317e534ccd8e4d38911574f574b0"], + "k_0_7": ["ffc6297d487a13cb80689c448a3aef16cbd367a503d236d0aebd7218cc568e88"], + "k_0_8": ["f4a6c41fc432300509f97ca68db3b9d802d29f90c35a429e3886c480cdce44a2"], + "k_0_9": ["52f3bf96d02cd7e8c631b8ef36262994a3ec658427b930197ed004c8599cd7fd"], + "k_0_10": [ + "7993aef51bebe79bae2d29b775c499f390e99fdb6b9accb8034f657b6e72927a" + ], + "k_0_11": ["430214c9805d90c6a8c4489187db08157a93e60509e96b518dc8b5ba3d567206"] }; final Map> historyBatchArgs2 = { - "k_0_0": ["c7e700f7e23a85bbdd9de86d502322a933607ee7ea7e16adaf02e477cdd849b9"] + "k_0_0": ["afe5085dd514032810d5b266007557ba8a0f4bee84535cb10754c6d46ab8689b"], + "k_0_1": ["dd63fc12f5e6c1ada2cf3c941d1648e6d561ce4024747bb2117d72112d83287c"], + "k_0_2": ["e65d4274e8edc5cc1e7b676652e2e13b0b00648d15cf13caa982ecd6a67731ba"], + "k_0_3": ["6c69ca274f7d7f2fae882a87bcee93d9429328995c5bc6b326b548b4cefcaa9f"], + "k_0_4": ["86f1a5e17dc42c27cdb0dff8a41c2434575ab05ed2f3689fd7b674677e5ea446"], + "k_0_5": ["a5d9b8df5b80c56e6053497a8c89a37267010926e80e0d225a019b78673a7aa7"], + "k_0_6": ["a0030024518874720b82b38d965fb5b3083d9f42fab40e6be4797c789eeb06f2"], + "k_0_7": ["f20077f7c6a6b92a1f75bbbad8dbece9ae4609cfdfc85e40ccac7d463bdfd6e0"], + "k_0_8": ["07b7bb4020c377e0741587efe9c0b3931e2e45f667bc6f1fa81a8f15fbe86ce4"], + "k_0_9": ["ca0322fc293f6e4d8c8adac178ed4aaedbd9acd2ec84acaaf1529f9ab7bda6d2"], + "k_0_10": [ + "06df1d13aa43375775d7d2838595a0c4c642f8af15b06a99d5115d9236e9a79e" + ], + "k_0_11": ["1a146c5a8dd5bf49faca3c6f65c9d955d361c6c00893c48d69cf7ff42c7b387b"] +}; + +final Map> historyBatchArgs3 = { + "k_0_0": ["5c2c77a3671417c5831c336805770344b81e6c7ef0d873c986ba65a7bacd5f68"], + "k_0_1": ["c068e7fa4aa0b8a63114f6d11c047ca4be6a8fa333eb0dac48506e8f150af73b"], + "k_0_2": ["f430c440e90c48b9e4c7e5356083e7c1495b7cad53f39ebba64cca9fb3d05c82"], + "k_0_3": ["30a7ac6789383f7f6def9a927f3b6fb661cf9406fec71a1d118c7d86052382fb"], + "k_0_4": ["a797225a9155417ab18e16b9d7ce9bf4962ae5c05df572a33c60b36a0523f257"], + "k_0_5": ["24d1e3ac9e53727d943688e67eb5c000d993e9c3cf9585d630624197fb73bed3"], + "k_0_6": ["d667a44404519649cb65632d6a3be948a1f0971025c96cb4211943d301fe0d3e"], + "k_0_7": ["be8da400f004546b528fb989c14a88324b8b0c2d5680cf080ae1e1dac4401f68"], + "k_0_8": ["addfa7682c0a2461ab0e82b3c9302b38986b442a1a76c3c839b6c2f0eaa805fe"], + "k_0_9": ["98bb3aab55f4f305fd9994334b8dd3321eda50b25fad2ef3e636714b650d0bb0"], + "k_0_10": [ + "bee1eee20d7169d03ce68d340a17f4598f589920513ec19c458db45399639a9f" + ], + "k_0_11": ["928a988dd65d100d1677a0478abfcd4d2a70aabb0812c58a2b1b4b51c395ed54"] +}; + +final Map> historyBatchArgs4 = { + "k_0_0": ["6bbfd9c1c28d6984646db4736196f67f2d1075894bb1d8990294ca7d663bece6"], + "k_0_1": ["42d6e40636f4740f9c7f95ef0bbc2a4c17f54da2bc98a32a622e2bf73eb675c3"], + "k_0_2": ["191c977174dc50a57628aea6684c428d3a5e90bbe16c4e412be51b0cfc589d38"], + "k_0_3": ["0daaf61564fd07a25ef106d958216992896f931f5bed4fbf56cc3f94443dc164"], + "k_0_4": ["ac5aca40fed2903def31c9ef1d60874247cdcc5b85238c7a1d83c67d2924d6b9"], + "k_0_5": ["c4102ff0556d863b4bab9d8232fe1f0c0fde4b6e4fe23064b4ecd0958f9726cc"], + "k_0_6": ["1c4bd1554e4992e5914dcd8f3e13927ffd46302dfdcbd2dca0cfd47c040c4256"], + "k_0_7": ["eaf5562ebef7cafa58e2c1fc4ae023e5ae8dd71ee637b08c4bc7e274e401a9a4"], + "k_0_8": ["06f7f55c221fee1b36284b5360155b8380cb9d7172b7e28eb37c61b7ebb6f227"], + "k_0_9": ["7e7ca801131ec1c5797f2c4aa46908ee50e9958cf1cbf53c2481d110800c3d6d"], + "k_0_10": [ + "3895e073aa034add7d2589bfdd1e54f6b9a8d7688d63fff0c3aac7950c6f9697" + ], + "k_0_11": ["ec17dd7c4fe8fbcfce94e9237d3c7ed7f5c91a45b1a060406e206df7e814b006"] +}; + +final Map> historyBatchArgs5 = { + "k_0_0": ["83b744ccb88827d544081c1a03ea782a7d00d6224ff9fddb7d0fbad399e1cae7"], + "k_0_1": ["86906979fc9107d06d560275d7de8305b69d7189c3206ac9070ad76e6abff874"], + "k_0_2": ["5baba32b1899d5e740838559ef39b7d8e9ba302bd24b732eeedd4c0e6ec65b51"], + "k_0_3": ["9892eb48394b0e155f63879fb89c3b068fcc071fed2e5cb11fe0729b85b53d67"], + "k_0_4": ["64192782cdaecb5e2a871a2d0fb3f541873e4750cd4e7d28e4d858ab40664a36"], + "k_0_5": ["4047ff48e96d25628acfeaec6ca75c1a668c54fd70a14414827cb59976a3b666"], + "k_0_6": ["299e8bc634ef6438c5bf99c12c2340c77c56ab974ffd767e77c17994e5cfaef8"], + "k_0_7": ["ab649fa14452563b385eb025e0b4cf2dd869c02fcdf2ec0f72725bbe2adaa3bd"], + "k_0_8": ["6be1ca4f8ee923e32137b6cdae324b841a0a60afbee4f4ae457fe31f29e001a6"], + "k_0_9": ["2a99ceea87df667135cc1801682d2c5dc7b95b7efadc48e156345ba46f4c0dc6"], + "k_0_10": [ + "9304094916a19040d3c8f10df90dae1144d1f09ac9e676e66bb76341c70388ac" + ], + "k_0_11": ["01b12fb2ea2533226471dfa863133ce390e3e13a804734e8af995a45aa7c7582"] }; final Map>> historyBatchResponse = { diff --git a/test/services/coins/namecoin/namecoin_wallet_test.dart b/test/services/coins/namecoin/namecoin_wallet_test.dart index 82238310b..0e6b50d52 100644 --- a/test/services/coins/namecoin/namecoin_wallet_test.dart +++ b/test/services/coins/namecoin/namecoin_wallet_test.dart @@ -7,6 +7,7 @@ import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart'; import 'package:stackwallet/electrumx_rpc/electrumx.dart'; +import 'package:stackwallet/hive/db.dart'; import 'package:stackwallet/models/paymint/fee_object_model.dart'; import 'package:stackwallet/models/paymint/transactions_model.dart'; import 'package:stackwallet/models/paymint/utxo_model.dart'; @@ -31,11 +32,11 @@ void main() { expect(MINIMUM_CONFIRMATIONS, 2); }); test("namecoin dust limit", () async { - expect(DUST_LIMIT, 294); + expect(DUST_LIMIT, 1000000); }); test("namecoin mainnet genesis block hash", () async { expect(GENESIS_HASH_MAINNET, - "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"); + "000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770"); }); }); @@ -46,10 +47,10 @@ void main() { }); group("bip32 node/root", () { - // test("getBip32Root", () { - // final root = getBip32Root(TEST_MNEMONIC, namecoin); - // expect(root.toWIF(), ROOT_WIF); - // }); + test("getBip32Root", () { + final root = getBip32Root(TEST_MNEMONIC, namecoin); + expect(root.toWIF(), ROOT_WIF); + }); // test("getBip32NodeFromRoot", () { // final root = getBip32Root(TEST_MNEMONIC, namecoin); @@ -95,97 +96,6 @@ void main() { // }); }); - // group("validate testnet namecoin addresses", () { - // MockElectrumX? client; - // MockCachedElectrumX? cachedClient; - // MockPriceAPI? priceAPI; - // FakeSecureStorage? secureStore; - // MockTransactionNotificationTracker? tracker; - // - // NamecoinWallet? testnetWallet; - // - // setUp(() { - // client = MockElectrumX(); - // cachedClient = MockCachedElectrumX(); - // priceAPI = MockPriceAPI(); - // secureStore = FakeSecureStorage(); - // tracker = MockTransactionNotificationTracker(); - // - // testnetWallet = NamecoinWallet( - // walletId: "validateAddressTestNet", - // walletName: "validateAddressTestNet", - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // }); - // - // test("valid testnet namecoin legacy/p2pkh address", () { - // expect( - // testnetWallet?.validateAddress("mhqpGtwhcR6gFuuRjLTpHo41919QfuGy8Y"), - // true); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("valid testnet namecoin p2sh-p2wpkh address", () { - // expect( - // testnetWallet?.validateAddress("2Mugf9hpSYdQPPLNtWiU2utCi6cM9v5Pnro"), - // true); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("valid testnet namecoin p2wpkh address", () { - // expect( - // testnetWallet - // ?.validateAddress("tb1qzzlm6mnc8k54mx6akehl8p9ray8r439va5ndyq"), - // true); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("invalid testnet namecoin legacy/p2pkh address", () { - // expect( - // testnetWallet?.validateAddress("16YB85zQHjro7fqjR2hMcwdQWCX8jNVtr5"), - // false); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("invalid testnet namecoin p2sh-p2wpkh address", () { - // expect( - // testnetWallet?.validateAddress("3Ns8HuQmkyyKnVixk2yQtG7pN3GcJ6xctk"), - // false); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("invalid testnet namecoin p2wpkh address", () { - // expect( - // testnetWallet - // ?.validateAddress("bc1qc5ymmsay89r6gr4fy2kklvrkuvzyln4shdvjhf"), - // false); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // }); - group("validate mainnet namecoin addresses", () { MockElectrumX? client; MockCachedElectrumX? cachedClient; @@ -214,35 +124,11 @@ void main() { ); }); - // test("valid mainnet legacy/p2pkh address type", () { - // expect( - // mainnetWallet?.addressType( - // address: "nc1qmdt0fxhpwx7x5ymmm9gvh229adu0kmtukfcsjk"), - // DerivePathType.bip44); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(tracker); - // verifyNoMoreInteractions(priceAPI); - // }); - - // test("valid mainnet p2sh-p2wpkh address type", () { - // expect( - // mainnetWallet?.addressType( - // address: "3Ns8HuQmkyyKnVixk2yQtG7pN3GcJ6xctk"), - // DerivePathType.bip49); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(tracker); - // verifyNoMoreInteractions(priceAPI); - // }); - - test("valid mainnet bech32 p2wpkh address type", () { + test("valid mainnet legacy/p2pkh address type", () { expect( mainnetWallet?.addressType( - address: "bc1qc5ymmsay89r6gr4fy2kklvrkuvzyln4shdvjhf"), - DerivePathType.bip84); + address: "N673DDbjPcrNgJmrhJ1xQXF9LLizQzvjEs"), + DerivePathType.bip44); expect(secureStore?.interactions, 0); verifyNoMoreInteractions(client); verifyNoMoreInteractions(cachedClient); @@ -250,17 +136,17 @@ void main() { verifyNoMoreInteractions(priceAPI); }); - // test("invalid base58 address type", () { - // expect( - // () => mainnetWallet?.addressType( - // address: "mhqpGtwhcR6gFuuRjLTpHo41919QfuGy8Y"), - // throwsArgumentError); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(tracker); - // verifyNoMoreInteractions(priceAPI); - // }); + test("valid mainnet bech32 p2wpkh address type", () { + expect( + mainnetWallet?.addressType( + address: "nc1q6k4x8ye6865z3rc8zkt8gyu52na7njqt6hsk4v"), + DerivePathType.bip84); + expect(secureStore?.interactions, 0); + verifyNoMoreInteractions(client); + verifyNoMoreInteractions(cachedClient); + verifyNoMoreInteractions(tracker); + verifyNoMoreInteractions(priceAPI); + }); test("invalid bech32 address type", () { expect( @@ -285,74 +171,6 @@ void main() { verifyNoMoreInteractions(tracker); verifyNoMoreInteractions(priceAPI); }); - - // test("valid mainnet namecoin legacy/p2pkh address", () { - // expect( - // mainnetWallet?.validateAddress("16YB85zQHjro7fqjR2hMcwdQWCX8jNVtr5"), - // true); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(tracker); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("valid mainnet namecoin p2sh-p2wpkh address", () { - // expect( - // mainnetWallet?.validateAddress("3Ns8HuQmkyyKnVixk2yQtG7pN3GcJ6xctk"), - // true); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(tracker); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("valid mainnet namecoin p2wpkh address", () { - // expect( - // mainnetWallet - // ?.validateAddress("bc1qc5ymmsay89r6gr4fy2kklvrkuvzyln4shdvjhf"), - // true); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(tracker); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("invalid mainnet namecoin legacy/p2pkh address", () { - // expect( - // mainnetWallet?.validateAddress("mhqpGtwhcR6gFuuRjLTpHo41919QfuGy8Y"), - // false); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(tracker); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("invalid mainnet namecoin p2sh-p2wpkh address", () { - // expect( - // mainnetWallet?.validateAddress("2Mugf9hpSYdQPPLNtWiU2utCi6cM9v5Pnro"), - // false); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(tracker); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("invalid mainnet namecoin p2wpkh address", () { - // expect( - // mainnetWallet - // ?.validateAddress("tb1qzzlm6mnc8k54mx6akehl8p9ray8r439va5ndyq"), - // false); - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(tracker); - // verifyNoMoreInteractions(priceAPI); - // }); }); group("testNetworkConnection", () { @@ -362,7 +180,7 @@ void main() { FakeSecureStorage? secureStore; MockTransactionNotificationTracker? tracker; - NamecoinWallet? btc; + NamecoinWallet? nmc; setUp(() { client = MockElectrumX(); @@ -371,7 +189,7 @@ void main() { secureStore = FakeSecureStorage(); tracker = MockTransactionNotificationTracker(); - btc = NamecoinWallet( + nmc = NamecoinWallet( walletId: "testNetworkConnection", walletName: "testNetworkConnection", coin: Coin.namecoin, @@ -385,7 +203,7 @@ void main() { test("attempted connection fails due to server error", () async { when(client?.ping()).thenAnswer((_) async => false); - final bool? result = await btc?.testNetworkConnection(); + final bool? result = await nmc?.testNetworkConnection(); expect(result, false); expect(secureStore?.interactions, 0); verify(client?.ping()).called(1); @@ -396,7 +214,7 @@ void main() { test("attempted connection fails due to exception", () async { when(client?.ping()).thenThrow(Exception); - final bool? result = await btc?.testNetworkConnection(); + final bool? result = await nmc?.testNetworkConnection(); expect(result, false); expect(secureStore?.interactions, 0); verify(client?.ping()).called(1); @@ -407,7 +225,7 @@ void main() { test("attempted connection test success", () async { when(client?.ping()).thenAnswer((_) async => true); - final bool? result = await btc?.testNetworkConnection(); + final bool? result = await nmc?.testNetworkConnection(); expect(result, true); expect(secureStore?.interactions, 0); verify(client?.ping()).called(1); @@ -418,8 +236,8 @@ void main() { }); group("basic getters, setters, and functions", () { - final testWalletId = "BTCtestWalletID"; - final testWalletName = "BTCWallet"; + final testWalletId = "NMCtestWalletID"; + final testWalletName = "NMCWallet"; MockElectrumX? client; MockCachedElectrumX? cachedClient; @@ -427,7 +245,7 @@ void main() { FakeSecureStorage? secureStore; MockTransactionNotificationTracker? tracker; - NamecoinWallet? btc; + NamecoinWallet? nmc; setUp(() async { client = MockElectrumX(); @@ -436,7 +254,7 @@ void main() { secureStore = FakeSecureStorage(); tracker = MockTransactionNotificationTracker(); - btc = NamecoinWallet( + nmc = NamecoinWallet( walletId: testWalletId, walletName: testWalletName, coin: Coin.namecoin, @@ -457,17 +275,17 @@ void main() { }); test("get networkType test", () async { - btc = NamecoinWallet( + nmc = NamecoinWallet( walletId: testWalletId, walletName: testWalletName, - coin: Coin.bitcoinTestNet, + coin: Coin.namecoin, client: client!, cachedClient: cachedClient!, tracker: tracker!, priceAPI: priceAPI, secureStore: secureStore, ); - expect(Coin.bitcoinTestNet, Coin.bitcoinTestNet); + expect(Coin.namecoin, Coin.namecoin); expect(secureStore?.interactions, 0); verifyNoMoreInteractions(client); verifyNoMoreInteractions(cachedClient); @@ -500,8 +318,8 @@ void main() { test("get and set walletName", () async { expect(Coin.namecoin, Coin.namecoin); - btc?.walletName = "new name"; - expect(btc?.walletName, "new name"); + nmc?.walletName = "new name"; + expect(nmc?.walletName, "new name"); expect(secureStore?.interactions, 0); verifyNoMoreInteractions(client); verifyNoMoreInteractions(cachedClient); @@ -509,14 +327,14 @@ void main() { }); test("estimateTxFee", () async { - expect(btc?.estimateTxFee(vSize: 356, feeRatePerKB: 1), 356); - expect(btc?.estimateTxFee(vSize: 356, feeRatePerKB: 900), 356); - expect(btc?.estimateTxFee(vSize: 356, feeRatePerKB: 999), 356); - expect(btc?.estimateTxFee(vSize: 356, feeRatePerKB: 1000), 356); - expect(btc?.estimateTxFee(vSize: 356, feeRatePerKB: 1001), 712); - expect(btc?.estimateTxFee(vSize: 356, feeRatePerKB: 1699), 712); - expect(btc?.estimateTxFee(vSize: 356, feeRatePerKB: 2000), 712); - expect(btc?.estimateTxFee(vSize: 356, feeRatePerKB: 12345), 4628); + expect(nmc?.estimateTxFee(vSize: 356, feeRatePerKB: 1), 356); + expect(nmc?.estimateTxFee(vSize: 356, feeRatePerKB: 900), 356); + expect(nmc?.estimateTxFee(vSize: 356, feeRatePerKB: 999), 356); + expect(nmc?.estimateTxFee(vSize: 356, feeRatePerKB: 1000), 356); + expect(nmc?.estimateTxFee(vSize: 356, feeRatePerKB: 1001), 712); + expect(nmc?.estimateTxFee(vSize: 356, feeRatePerKB: 1699), 712); + expect(nmc?.estimateTxFee(vSize: 356, feeRatePerKB: 2000), 712); + expect(nmc?.estimateTxFee(vSize: 356, feeRatePerKB: 12345), 4628); expect(secureStore?.interactions, 0); verifyNoMoreInteractions(client); verifyNoMoreInteractions(cachedClient); @@ -531,7 +349,7 @@ void main() { "server_version": "Unit tests", "protocol_min": "1.4", "protocol_max": "1.4.2", - "genesis_hash": GENESIS_HASH_TESTNET, + "genesis_hash": GENESIS_HASH_MAINNET, "hash_function": "sha256", "services": [] }); @@ -542,7 +360,7 @@ void main() { when(client?.estimateFee(blocks: 20)) .thenAnswer((realInvocation) async => Decimal.ten); - final fees = await btc?.fees; + final fees = await nmc?.fees; expect(fees, isA()); expect(fees?.slow, 1000000000); expect(fees?.medium, 100000000); @@ -578,7 +396,7 @@ void main() { bool didThrow = false; try { - await btc?.fees; + await nmc?.fees; } catch (_) { didThrow = true; } @@ -613,7 +431,7 @@ void main() { // when(client?.estimateFee(blocks: 1)) // .thenAnswer((realInvocation) async => Decimal.ten); // - // final maxFee = await btc?.maxFee; + // final maxFee = await nmc?.maxFee; // expect(maxFee, 1000000000); // // verify(client?.estimateFee(blocks: 1)).called(1); @@ -627,9 +445,9 @@ void main() { // }); }); - group("Bitcoin service class functions that depend on shared storage", () { - final testWalletId = "BTCtestWalletID"; - final testWalletName = "BTCWallet"; + group("Namecoin service class functions that depend on shared storage", () { + final testWalletId = "NMCtestWalletID"; + final testWalletName = "NMCWallet"; bool hiveAdaptersRegistered = false; @@ -639,7 +457,7 @@ void main() { FakeSecureStorage? secureStore; MockTransactionNotificationTracker? tracker; - NamecoinWallet? btc; + NamecoinWallet? nmc; setUp(() async { await setUpTestHive(); @@ -668,7 +486,7 @@ void main() { secureStore = FakeSecureStorage(); tracker = MockTransactionNotificationTracker(); - btc = NamecoinWallet( + nmc = NamecoinWallet( walletId: testWalletId, walletName: testWalletName, coin: Coin.namecoin, @@ -682,7 +500,7 @@ void main() { // test("initializeWallet no network", () async { // when(client?.ping()).thenAnswer((_) async => false); - // expect(await btc?.initializeWallet(), false); + // expect(await nmc?.initializeWallet(), false); // expect(secureStore?.interactions, 0); // verify(client?.ping()).called(1); // verifyNoMoreInteractions(client); @@ -693,7 +511,7 @@ void main() { // test("initializeWallet no network exception", () async { // when(client?.ping()).thenThrow(Exception("Network connection failed")); // final wallets = await Hive.openBox(testWalletId); - // expect(await btc?.initializeExisting(), false); + // expect(await nmc?.initializeExisting(), false); // expect(secureStore?.interactions, 0); // verify(client?.ping()).called(1); // verifyNoMoreInteractions(client); @@ -713,10 +531,10 @@ void main() { "hash_function": "sha256", "services": [] }); - // await btc?.initializeNew(); + // await nmc?.initializeNew(); final wallets = await Hive.openBox(testWalletId); - expectLater(() => btc?.initializeExisting(), throwsA(isA())) + expectLater(() => nmc?.initializeExisting(), throwsA(isA())) .then((_) { expect(secureStore?.interactions, 0); // verify(client?.ping()).called(1); @@ -743,7 +561,7 @@ void main() { key: "${testWalletId}_mnemonic", value: "some mnemonic"); final wallets = await Hive.openBox(testWalletId); - expectLater(() => btc?.initializeExisting(), throwsA(isA())) + expectLater(() => nmc?.initializeExisting(), throwsA(isA())) .then((_) { expect(secureStore?.interactions, 1); // verify(client?.ping()).called(1); @@ -754,1352 +572,6 @@ void main() { }); }); - // test("initializeWallet testnet throws bad network", () async { - // when(client?.ping()).thenAnswer((_) async => true); - // 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": [] - // }); - // - // btc = NamecoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // - // expectLater(() => btc?.initializeWallet(), throwsA(isA())) - // .then((_) { - // expect(secureStore?.interactions, 0); - // verify(client?.ping()).called(1); - // verify(client?.getServerFeatures()).called(1); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // }); - - // test("getCurrentNode", () async { - // // when(priceAPI.getBitcoinPrice(baseCurrency: "USD")) - // // .thenAnswer((realInvocation) async => Decimal.fromInt(10)); - // when(client?.ping()).thenAnswer((_) async => true); - // 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": [] - // }); - // expect(await btc?.initializeWallet(), true); - // - // bool didThrow = false; - // try { - // await btc?.getCurrentNode(); - // } catch (_) { - // didThrow = true; - // } - // // expect no nodes on a fresh wallet unless set in db externally - // expect(didThrow, true); - // - // // set node - // final wallet = await Hive.openBox(testWalletId); - // await wallet.put("nodes", { - // "default": { - // "id": "some nodeID", - // "ipAddress": "some address", - // "port": "9000", - // "useSSL": true, - // } - // }); - // await wallet.put("activeNodeID_Bitcoin", "default"); - // - // // try fetching again - // final node = await btc?.getCurrentNode(); - // expect(node.toString(), - // "ElectrumXNode: {address: some address, port: 9000, name: default, useSSL: true}"); - // - // verify(client?.ping()).called(1); - // verify(client?.getServerFeatures()).called(1); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("initializeWallet new main net wallet", () async { - // // when(priceAPI.getBitcoinPrice(baseCurrency: "USD")) - // // .thenAnswer((realInvocation) async => Decimal.fromInt(10)); - // when(client?.ping()).thenAnswer((_) async => true); - // 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": [] - // }); - // expect(await btc?.initializeWallet(), true); - // - // final wallet = await Hive.openBox(testWalletId); - // - // expect(await wallet.get("addressBookEntries"), {}); - // expect(await wallet.get('notes'), null); - // expect(await wallet.get("id"), testWalletId); - // expect(await wallet.get("preferredFiatCurrency"), null); - // expect(await wallet.get("blocked_tx_hashes"), ["0xdefault"]); - // - // final changeAddressesP2PKH = await wallet.get("changeAddressesP2PKH"); - // expect(changeAddressesP2PKH, isA>()); - // expect(changeAddressesP2PKH.length, 1); - // expect(await wallet.get("changeIndexP2PKH"), 0); - // final changeAddressesP2SH = await wallet.get("changeAddressesP2SH"); - // expect(changeAddressesP2SH, isA>()); - // expect(changeAddressesP2SH.length, 1); - // expect(await wallet.get("changeIndexP2SH"), 0); - // final changeAddressesP2WPKH = await wallet.get("changeAddressesP2WPKH"); - // expect(changeAddressesP2WPKH, isA>()); - // expect(changeAddressesP2WPKH.length, 1); - // expect(await wallet.get("changeIndexP2WPKH"), 0); - // - // final receivingAddressesP2PKH = - // await wallet.get("receivingAddressesP2PKH"); - // expect(receivingAddressesP2PKH, isA>()); - // expect(receivingAddressesP2PKH.length, 1); - // expect(await wallet.get("receivingIndexP2PKH"), 0); - // final receivingAddressesP2SH = await wallet.get("receivingAddressesP2SH"); - // expect(receivingAddressesP2SH, isA>()); - // expect(receivingAddressesP2SH.length, 1); - // expect(await wallet.get("receivingIndexP2SH"), 0); - // final receivingAddressesP2WPKH = - // await wallet.get("receivingAddressesP2WPKH"); - // expect(receivingAddressesP2WPKH, isA>()); - // expect(receivingAddressesP2WPKH.length, 1); - // expect(await wallet.get("receivingIndexP2WPKH"), 0); - // - // final p2pkhReceiveDerivations = jsonDecode(await secureStore?.read( - // key: "${testWalletId}_receiveDerivationsP2PKH")); - // expect(p2pkhReceiveDerivations.length, 1); - // final p2shReceiveDerivations = jsonDecode(await secureStore.read( - // key: "${testWalletId}_receiveDerivationsP2SH")); - // expect(p2shReceiveDerivations.length, 1); - // final p2wpkhReceiveDerivations = jsonDecode(await secureStore.read( - // key: "${testWalletId}_receiveDerivationsP2WPKH")); - // expect(p2wpkhReceiveDerivations.length, 1); - // - // final p2pkhChangeDerivations = jsonDecode(await secureStore.read( - // key: "${testWalletId}_changeDerivationsP2PKH")); - // expect(p2pkhChangeDerivations.length, 1); - // final p2shChangeDerivations = jsonDecode( - // await secureStore.read(key: "${testWalletId}_changeDerivationsP2SH")); - // expect(p2shChangeDerivations.length, 1); - // final p2wpkhChangeDerivations = jsonDecode(await secureStore.read( - // key: "${testWalletId}_changeDerivationsP2WPKH")); - // expect(p2wpkhChangeDerivations.length, 1); - // - // expect(secureStore?.interactions, 26); // 20 in reality + 6 in this test - // expect(secureStore?.reads, 19); // 13 in reality + 6 in this test - // expect(secureStore?.writes, 7); - // expect(secureStore?.deletes, 0); - // verify(client?.ping()).called(1); - // verify(client?.getServerFeatures()).called(1); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("initializeWallet existing main net wallet", () async { - // // when(priceAPI.getBitcoinPrice(baseCurrency: "USD")) - // // .thenAnswer((realInvocation) async => Decimal.fromInt(10)); - // when(client?.ping()).thenAnswer((_) async => true); - // when(client?.getBatchHistory(args: anyNamed("args"))) - // .thenAnswer((_) 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": [] - // }); - // // init new wallet - // expect(await btc?.initializeWallet(), true); - // - // // fetch data to compare later - // final newWallet = await Hive.openBox(testWalletId); - // - // final addressBookEntries = await newWallet.get("addressBookEntries"); - // final notes = await newWallet.get('notes'); - // final wID = await newWallet.get("id"); - // final currency = await newWallet.get("preferredFiatCurrency"); - // final blockedHashes = await newWallet.get("blocked_tx_hashes"); - // - // final changeAddressesP2PKH = await newWallet.get("changeAddressesP2PKH"); - // final changeIndexP2PKH = await newWallet.get("changeIndexP2PKH"); - // final changeAddressesP2SH = await newWallet.get("changeAddressesP2SH"); - // final changeIndexP2SH = await newWallet.get("changeIndexP2SH"); - // final changeAddressesP2WPKH = - // await newWallet.get("changeAddressesP2WPKH"); - // final changeIndexP2WPKH = await newWallet.get("changeIndexP2WPKH"); - // - // final receivingAddressesP2PKH = - // await newWallet.get("receivingAddressesP2PKH"); - // final receivingIndexP2PKH = await newWallet.get("receivingIndexP2PKH"); - // final receivingAddressesP2SH = - // await newWallet.get("receivingAddressesP2SH"); - // final receivingIndexP2SH = await newWallet.get("receivingIndexP2SH"); - // final receivingAddressesP2WPKH = - // await newWallet.get("receivingAddressesP2WPKH"); - // final receivingIndexP2WPKH = await newWallet.get("receivingIndexP2WPKH"); - // - // final p2pkhReceiveDerivations = jsonDecode(await secureStore.read( - // key: "${testWalletId}_receiveDerivationsP2PKH")); - // final p2shReceiveDerivations = jsonDecode(await secureStore.read( - // key: "${testWalletId}_receiveDerivationsP2SH")); - // final p2wpkhReceiveDerivations = jsonDecode(await secureStore.read( - // key: "${testWalletId}_receiveDerivationsP2WPKH")); - // - // final p2pkhChangeDerivations = jsonDecode(await secureStore.read( - // key: "${testWalletId}_changeDerivationsP2PKH")); - // final p2shChangeDerivations = jsonDecode( - // await secureStore.read(key: "${testWalletId}_changeDerivationsP2SH")); - // final p2wpkhChangeDerivations = jsonDecode(await secureStore.read( - // key: "${testWalletId}_changeDerivationsP2WPKH")); - // - // // exit new wallet - // await btc?.exit(); - // - // // open existing/created wallet - // btc = NamecoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.namecoin, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // - // // init existing - // expect(await btc?.initializeWallet(), true); - // - // // compare data to ensure state matches state of previously closed wallet - // final wallet = await Hive.openBox(testWalletId); - // - // expect(await wallet.get("addressBookEntries"), addressBookEntries); - // expect(await wallet.get('notes'), notes); - // expect(await wallet.get("id"), wID); - // expect(await wallet.get("preferredFiatCurrency"), currency); - // expect(await wallet.get("blocked_tx_hashes"), blockedHashes); - // - // expect(await wallet.get("changeAddressesP2PKH"), changeAddressesP2PKH); - // expect(await wallet.get("changeIndexP2PKH"), changeIndexP2PKH); - // expect(await wallet.get("changeAddressesP2SH"), changeAddressesP2SH); - // expect(await wallet.get("changeIndexP2SH"), changeIndexP2SH); - // expect(await wallet.get("changeAddressesP2WPKH"), changeAddressesP2WPKH); - // expect(await wallet.get("changeIndexP2WPKH"), changeIndexP2WPKH); - // - // expect( - // await wallet.get("receivingAddressesP2PKH"), receivingAddressesP2PKH); - // expect(await wallet.get("receivingIndexP2PKH"), receivingIndexP2PKH); - // expect( - // await wallet.get("receivingAddressesP2SH"), receivingAddressesP2SH); - // expect(await wallet.get("receivingIndexP2SH"), receivingIndexP2SH); - // expect(await wallet.get("receivingAddressesP2WPKH"), - // receivingAddressesP2WPKH); - // expect(await wallet.get("receivingIndexP2WPKH"), receivingIndexP2WPKH); - // - // expect( - // jsonDecode(await secureStore.read( - // key: "${testWalletId}_receiveDerivationsP2PKH")), - // p2pkhReceiveDerivations); - // expect( - // jsonDecode(await secureStore.read( - // key: "${testWalletId}_receiveDerivationsP2SH")), - // p2shReceiveDerivations); - // expect( - // jsonDecode(await secureStore.read( - // key: "${testWalletId}_receiveDerivationsP2WPKH")), - // p2wpkhReceiveDerivations); - // - // expect( - // jsonDecode(await secureStore.read( - // key: "${testWalletId}_changeDerivationsP2PKH")), - // p2pkhChangeDerivations); - // expect( - // jsonDecode(await secureStore.read( - // key: "${testWalletId}_changeDerivationsP2SH")), - // p2shChangeDerivations); - // expect( - // jsonDecode(await secureStore.read( - // key: "${testWalletId}_changeDerivationsP2WPKH")), - // p2wpkhChangeDerivations); - // - // expect(secureStore?.interactions, 32); // 20 in reality + 12 in this test - // expect(secureStore?.reads, 25); // 13 in reality + 12 in this test - // expect(secureStore?.writes, 7); - // expect(secureStore?.deletes, 0); - // verify(client?.ping()).called(2); - // verify(client?.getServerFeatures()).called(1); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // // test("get fiatPrice", () async { - // // // when(priceAPI.getBitcoinPrice(baseCurrency: "USD")) - // // // .thenAnswer((realInvocation) async => Decimal.fromInt(10)); - // // await Hive.openBox(testWalletId); - // // expect(await btc.basePrice, Decimal.fromInt(10)); - // // verify(priceAPI.getBitcoinPrice(baseCurrency: "USD")).called(1); - // // verifyNoMoreInteractions(client); - // // verifyNoMoreInteractions(cachedClient); - // // verifyNoMoreInteractions(priceAPI); - // // }); - // - // test("get current receiving addresses", () async { - // btc = NamecoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // when(client?.ping()).thenAnswer((_) async => true); - // 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_TESTNET, - // "hash_function": "sha256", - // "services": [] - // }); - // await btc?.initializeWallet(); - // expect( - // Address.validateAddress(await btc!.currentReceivingAddress, testnet), - // true); - // expect( - // Address.validateAddress( - // await btc!.currentReceivingAddressP2SH, testnet), - // true); - // expect( - // Address.validateAddress( - // await btc!.currentLegacyReceivingAddress, testnet), - // true); - // - // verify(client?.ping()).called(1); - // verify(client?.getServerFeatures()).called(1); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("get allOwnAddresses", () async { - // btc = NamecoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // when(client?.ping()).thenAnswer((_) async => true); - // 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_TESTNET, - // "hash_function": "sha256", - // "services": [] - // }); - // await btc?.initializeWallet(); - // final addresses = await btc?.allOwnAddresses; - // expect(addresses, isA>()); - // expect(addresses?.length, 6); - // - // for (int i = 0; i < 6; i++) { - // expect(Address.validateAddress(addresses[i], testnet), true); - // } - // - // verify(client?.ping()).called(1); - // verify(client?.getServerFeatures()).called(1); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - - // test("get utxos and balances", () async { - // btc = NamecoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // when(client?.ping()).thenAnswer((_) async => true); - // 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_TESTNET, - // "hash_function": "sha256", - // "services": [] - // }); - // - // when(client?.getBatchUTXOs(args: anyNamed("args"))) - // .thenAnswer((_) async => batchGetUTXOResponse0); - // - // when(client?.estimateFee(blocks: 10)) - // .thenAnswer((realInvocation) async => Decimal.zero); - // when(client?.estimateFee(blocks: 5)) - // .thenAnswer((realInvocation) async => Decimal.one); - // when(client?.estimateFee(blocks: 1)) - // .thenAnswer((realInvocation) async => Decimal.ten); - // // when(priceAPI.getBitcoinPrice(baseCurrency: "USD")) - // // .thenAnswer((realInvocation) async => Decimal.fromInt(10)); - // - // when(cachedClient?.getTransaction( - // txHash: tx1.txid, - // coin: Coin.bitcoinTestNet, - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx1Raw); - // when(cachedClient?.getTransaction( - // txHash: tx2.txid, - // coin: Coin.bitcoinTestNet, - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx2Raw); - // when(cachedClient?.getTransaction( - // txHash: tx3.txid, - // coin: Coin.bitcoinTestNet, - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx3Raw); - // when(cachedClient?.getTransaction( - // txHash: tx4.txid, - // coin: Coin.bitcoinTestNet, - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx4Raw); - // - // await btc?.initializeNew(); - // await btc?.initializeExisting(); - // final utxoData = await btc?.utxoData; - // expect(utxoData, isA()); - // expect(utxoData.toString(), - // r"{totalUserCurrency: $0.0076497, satoshiBalance: 76497, bitcoinBalance: 0.00076497, unspentOutputArray: [{txid: 88b7b5077d940dde1bc63eba37a09dec8e7b9dad14c183a2e879a21b6ec0ac1c, vout: 0, value: 17000, fiat: $0.0017, blocked: false, status: {confirmed: true, blockHash: 00000000000000198ca8300deab26c5c1ec1df0da5afd30c9faabd340d8fc194, blockHeight: 437146, blockTime: 1652994245, confirmations: 100}}, {txid: b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528, vout: 0, value: 36037, fiat: $0.0036037, blocked: false, status: {confirmed: false, blockHash: 000000000000003db63ad679a539f2088dcc97a149c99ca790ce0c5f7b5acff0, blockHeight: 441696, blockTime: 1652923129, confirmations: 0}}, {txid: dcca229760b44834478f0b266c9b3f5801e0139fdecacdc0820e447289a006d3, vout: 1, value: 14714, fiat: $0.0014714, blocked: false, status: {confirmed: false, blockHash: 0000000000000030bec9bc58a3ab4857de1cc63cfed74204a6be57f125fb2fa7, blockHeight: 437146, blockTime: 1652888705, confirmations: 0}}, {txid: b39bac02b65af46a49e2985278fe24ca00dd5d627395d88f53e35568a04e10fa, vout: 0, value: 8746, fiat: $0.0008746, blocked: false, status: {confirmed: true, blockHash: 0000000039b80e9a10b7bcaf0f193b51cb870a4febe9b427c1f41a3f42eaa80b, blockHeight: 441696, blockTime: 1652993683, confirmations: 22861}}]}"); - // - // final outputs = await btc?.unspentOutputs; - // expect(outputs, isA>()); - // expect(outputs?.length, 4); - // - // final availableBalance = await btc?.availableBalance; - // expect(availableBalance, Decimal.parse("0.00025746")); - // - // final totalBalance = await btc?.totalBalance; - // expect(totalBalance, Decimal.parse("0.00076497")); - // - // final pendingBalance = await btc?.pendingBalance; - // expect(pendingBalance, Decimal.parse("0.00050751")); - // - // final balanceMinusMaxFee = await btc?.balanceMinusMaxFee; - // expect(balanceMinusMaxFee, Decimal.parse("-9.99974254")); - // - // verify(client?.ping()).called(1); - // verify(client?.getServerFeatures()).called(1); - // verify(client?.estimateFee(blocks: 1)).called(1); - // verify(client?.estimateFee(blocks: 5)).called(1); - // verify(client?.estimateFee(blocks: 10)).called(1); - // verify(client?.getBatchUTXOs(args: anyNamed("args"))).called(1); - // // verify(priceAPI.getBitcoinPrice(baseCurrency: "USD")).called(1); - // verify(cachedClient?.getTransaction( - // txHash: tx1.txid, - // coin: Coin.bitcoinTestNet, - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // txHash: tx2.txid, - // coin: Coin.bitcoinTestNet, - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // txHash: tx3.txid, - // coin: Coin.bitcoinTestNet, - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // txHash: tx4.txid, - // coin: Coin.bitcoinTestNet, - // callOutSideMainIsolate: false)) - // .called(1); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - - // test("get utxos - multiple batches", () async { - // btc = NamecoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // when(client?.ping()).thenAnswer((_) async => true); - // 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_TESTNET, - // "hash_function": "sha256", - // "services": [] - // }); - // - // when(client?.getBatchUTXOs(args: anyNamed("args"))) - // .thenAnswer((_) async => {}); - // - // // when(priceAPI.getBitcoinPrice(baseCurrency: "USD")) - // // .thenAnswer((realInvocation) async => Decimal.fromInt(10)); - // - // await btc?.initializeNew(); - // await btc?.initializeExisting(); - // - // // add some extra addresses to make sure we have more than the single batch size of 10 - // final wallet = await Hive.openBox(DB); - // final addresses = await wallet.get("receivingAddressesP2WPKH"); - // addresses.add("tb1qpfl2uz3jvazy9wr4vqhwluyhgtd29rsmghpqxp"); - // addresses.add("tb1qznt3psdpcyz8lwj7xxl6q78hjw2mj095nd4gxu"); - // addresses.add("tb1q7yjjyh9h4uy7j0wdtcmptw3g083kxrqlvgjz86"); - // addresses.add("tb1qt05shktwcq7kgxccva20cfwt47kav9s6n8yr9p"); - // addresses.add("tb1q4nk5wdylywl4dg2a45naae7u08vtgyujqfrv58"); - // addresses.add("tb1qxwccgfq9tmd6lx823cuejuea9wdzpaml9wkapm"); - // addresses.add("tb1qk88negkdqusr8tpj0hpvs98lq6ka4vyw6kfnqf"); - // addresses.add("tb1qw0jzneqwp0t4ah9w3za4k9d8d4tz8y3zxqmtgx"); - // addresses.add("tb1qccqjlpndx46sv7t6uurlyyjre5vwjfdzzlf2vd"); - // addresses.add("tb1q3hfpe69rrhr5348xd04rfz9g3h22yk64pwur8v"); - // addresses.add("tb1q4rp373202aur96a28lp0pmts6kp456nka45e7d"); - // await wallet.put("receivingAddressesP2WPKH", addresses); - // - // final utxoData = await btc?.utxoData; - // expect(utxoData, isA()); - // - // final outputs = await btc?.unspentOutputs; - // expect(outputs, isA>()); - // expect(outputs?.length, 0); - // - // verify(client?.ping()).called(1); - // verify(client?.getServerFeatures()).called(1); - // verify(client?.getBatchUTXOs(args: anyNamed("args"))).called(2); - // // verify(priceAPI.getBitcoinPrice(baseCurrency: "USD")).called(1); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("get utxos fails", () async { - // btc = NamecoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // when(client?.ping()).thenAnswer((_) async => true); - // 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_TESTNET, - // "hash_function": "sha256", - // "services": [] - // }); - // - // when(client?.getBatchUTXOs(args: anyNamed("args"))) - // .thenThrow(Exception("some exception")); - // - // await btc?.initializeWallet(); - // final utxoData = await btc?.utxoData; - // expect(utxoData, isA()); - // expect(utxoData.toString(), - // r"{totalUserCurrency: $0.00, satoshiBalance: 0, bitcoinBalance: 0, unspentOutputArray: []}"); - // - // final outputs = await btc?.unspentOutputs; - // expect(outputs, isA>()); - // expect(outputs?.length, 0); - // - // verify(client?.ping()).called(1); - // verify(client?.getServerFeatures()).called(1); - // verify(client?.getBatchUTXOs(args: anyNamed("args"))).called(1); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("chain height fetch, update, and get", () async { - // btc = NamecoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // when(client?.ping()).thenAnswer((_) async => true); - // 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_TESTNET, - // "hash_function": "sha256", - // "services": [] - // }); - // await btc?.initializeWallet(); - // - // // get stored - // expect(await btc?.storedChainHeight, 0); - // - // // fetch fails - // when(client?.getBlockHeadTip()).thenThrow(Exception("Some exception")); - // expect(await btc?.chainHeight, -1); - // - // // fetch succeeds - // when(client?.getBlockHeadTip()).thenAnswer((realInvocation) async => { - // "height": 100, - // "hex": "some block hex", - // }); - // expect(await btc?.chainHeight, 100); - // - // // update - // await btc?.updateStoredChainHeight(newHeight: 1000); - // - // // fetch updated - // expect(await btc?.storedChainHeight, 1000); - // - // verify(client?.ping()).called(1); - // verify(client?.getServerFeatures()).called(1); - // verify(client?.getBlockHeadTip()).called(2); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("fetch and update useBiometrics", () async { - // // get - // expect(await btc?.useBiometrics, false); - // - // // then update - // await btc?.updateBiometricsUsage(true); - // - // // finally check updated - // expect(await btc?.useBiometrics, true); - // - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("getTxCount succeeds", () async { - // when(client?.getHistory( - // scripthash: - // "4e94cc7b4a85791445260ae4403233b6a4784185f9716d73f136c6642615fce9")) - // .thenAnswer((realInvocation) async => [ - // { - // "height": 200004, - // "tx_hash": - // "acc3758bd2a26f869fcc67d48ff30b96464d476bca82c1cd6656e7d506816412" - // }, - // { - // "height": 215008, - // "tx_hash": - // "f3e1bf48975b8d6060a9de8884296abb80be618dc00ae3cb2f6cee3085e09403" - // } - // ]); - // - // final count = - // await btc?.getTxCount(address: "3Ns8HuQmkyyKnVixk2yQtG7pN3GcJ6xctk"); - // - // expect(count, 2); - // - // verify(client?.getHistory( - // scripthash: - // "4e94cc7b4a85791445260ae4403233b6a4784185f9716d73f136c6642615fce9")) - // .called(1); - // - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("getTxCount fails", () async { - // when(client?.getHistory( - // scripthash: - // "4e94cc7b4a85791445260ae4403233b6a4784185f9716d73f136c6642615fce9")) - // .thenThrow(Exception("some exception")); - // - // bool didThrow = false; - // try { - // await btc?.getTxCount(address: "3Ns8HuQmkyyKnVixk2yQtG7pN3GcJ6xctk"); - // } catch (_) { - // didThrow = true; - // } - // expect(didThrow, true); - // - // verify(client?.getHistory( - // scripthash: - // "4e94cc7b4a85791445260ae4403233b6a4784185f9716d73f136c6642615fce9")) - // .called(1); - // - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("_checkCurrentReceivingAddressesForTransactions succeeds", () async { - // when(client?.ping()).thenAnswer((_) async => true); - // 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?.getHistory(scripthash: anyNamed("scripthash"))) - // .thenAnswer((realInvocation) async => [ - // { - // "height": 200004, - // "tx_hash": - // "acc3758bd2a26f869fcc67d48ff30b96464d476bca82c1cd6656e7d506816412" - // }, - // { - // "height": 215008, - // "tx_hash": - // "f3e1bf48975b8d6060a9de8884296abb80be618dc00ae3cb2f6cee3085e09403" - // } - // ]); - // - // await btc?.initializeWallet(); - // - // bool didThrow = false; - // try { - // await btc?.checkCurrentReceivingAddressesForTransactions(); - // } catch (_) { - // didThrow = true; - // } - // expect(didThrow, false); - // - // verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(3); - // verify(client?.getServerFeatures()).called(1); - // verify(client?.ping()).called(1); - // - // expect(secureStore?.interactions, 29); - // expect(secureStore?.reads, 19); - // expect(secureStore?.writes, 10); - // expect(secureStore?.deletes, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - - // test("_checkCurrentReceivingAddressesForTransactions fails", () async { - // when(client?.ping()).thenAnswer((_) async => true); - // 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?.getHistory(scripthash: anyNamed("scripthash"))) - // .thenThrow(Exception("some exception")); - // final wallet = await Hive.openBox(testWalletId); - // - // await btc?.initializeNew(); - // await btc?.initializeExisting(); - // - // bool didThrow = false; - // try { - // await btc?.checkCurrentReceivingAddressesForTransactions(); - // } catch (_) { - // didThrow = true; - // } - // expect(didThrow, true); - // - // verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(1); - // verify(client?.getServerFeatures()).called(1); - // verify(client?.ping()).called(1); - // - // expect(secureStore?.interactions, 20); - // expect(secureStore?.reads, 13); - // expect(secureStore?.writes, 7); - // expect(secureStore?.deletes, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - - // test("_checkCurrentChangeAddressesForTransactions succeeds", () async { - // when(client?.ping()).thenAnswer((_) async => true); - // 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?.getHistory(scripthash: anyNamed("scripthash"))) - // .thenAnswer((realInvocation) async => [ - // { - // "height": 200004, - // "tx_hash": - // "acc3758bd2a26f869fcc67d48ff30b96464d476bca82c1cd6656e7d506816412" - // }, - // { - // "height": 215008, - // "tx_hash": - // "f3e1bf48975b8d6060a9de8884296abb80be618dc00ae3cb2f6cee3085e09403" - // } - // ]); - // - // await btc?.initializeWallet(); - // - // bool didThrow = false; - // try { - // await btc?.checkCurrentChangeAddressesForTransactions(); - // } catch (_) { - // didThrow = true; - // } - // expect(didThrow, false); - // - // verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(3); - // verify(client?.getServerFeatures()).called(1); - // verify(client?.ping()).called(1); - // - // expect(secureStore?.interactions, 29); - // expect(secureStore?.reads, 19); - // expect(secureStore?.writes, 10); - // expect(secureStore?.deletes, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("_checkCurrentChangeAddressesForTransactions fails", () async { - // when(client?.ping()).thenAnswer((_) async => true); - // 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?.getHistory(scripthash: anyNamed("scripthash"))) - // .thenThrow(Exception("some exception")); - // - // await btc?.initializeWallet(); - // - // bool didThrow = false; - // try { - // await btc?.checkCurrentChangeAddressesForTransactions(); - // } catch (_) { - // didThrow = true; - // } - // expect(didThrow, true); - // - // verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(1); - // verify(client?.getServerFeatures()).called(1); - // verify(client?.ping()).called(1); - // - // expect(secureStore?.interactions, 20); - // expect(secureStore?.reads, 13); - // expect(secureStore?.writes, 7); - // expect(secureStore?.deletes, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("getAllTxsToWatch", () async { - // TestWidgetsFlutterBinding.ensureInitialized(); - // var notifications = {"show": 0}; - // const MethodChannel('dexterous.com/flutter/local_notifications') - // .setMockMethodCallHandler((call) async { - // notifications[call.method]++; - // }); - // - // btc?.pastUnconfirmedTxs = { - // "88b7b5077d940dde1bc63eba37a09dec8e7b9dad14c183a2e879a21b6ec0ac1c", - // "b39bac02b65af46a49e2985278fe24ca00dd5d627395d88f53e35568a04e10fa", - // }; - // - // await btc?.getAllTxsToWatch(transactionData); - // expect(notifications.length, 1); - // expect(notifications["show"], 3); - // - // expect(btc?.unconfirmedTxs, { - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // 'dcca229760b44834478f0b266c9b3f5801e0139fdecacdc0820e447289a006d3', - // }); - // - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("refreshIfThereIsNewData true A", () async { - // when(client?.getTransaction( - // tx_hash: - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // )).thenAnswer((_) async => tx2Raw); - // when(client?.getTransaction( - // tx_hash: - // "88b7b5077d940dde1bc63eba37a09dec8e7b9dad14c183a2e879a21b6ec0ac1c", - // )).thenAnswer((_) async => tx1Raw); - // - // btc = NamecoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // final wallet = await Hive.openBox(testWalletId); - // await wallet.put('receivingAddressesP2PKH', []); - // await wallet.put('receivingAddressesP2SH', [ - // "2Mv83bPh2HzPRXptuQg9ejbKpSp87Zi52zT", - // ]); - // await wallet.put('receivingAddressesP2WPKH', [ - // "tb1q3ywehep0ykrkaqkt0hrgsqyns4mnz2ls8nxfzg", - // ]); - // - // await wallet.put('changeAddressesP2PKH', []); - // await wallet.put('changeAddressesP2SH', []); - // await wallet.put('changeAddressesP2WPKH', []); - // - // btc?.unconfirmedTxs = { - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // "88b7b5077d940dde1bc63eba37a09dec8e7b9dad14c183a2e879a21b6ec0ac1c" - // }; - // - // final result = await btc?.refreshIfThereIsNewData(); - // - // expect(result, true); - // - // verify(client?.getTransaction( - // tx_hash: - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // )).called(1); - // verify(client.getTransaction( - // tx_hash: - // "88b7b5077d940dde1bc63eba37a09dec8e7b9dad14c183a2e879a21b6ec0ac1c", - // )).called(1); - // - // expect(secureStore.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("refreshIfThereIsNewData true B", () async { - // // when(priceAPI.getBitcoinPrice(baseCurrency: "USD")) - // // .thenAnswer((_) async => Decimal.fromInt(10)); - // - // when(client?.getBatchHistory(args: anyNamed("args"))) - // .thenAnswer((realInvocation) async { - // final uuids = Map>.from( - // realInvocation.namedArguments.values.first) - // .keys - // .toList(growable: false); - // return { - // uuids[0]: [ - // { - // "tx_hash": - // "dcca229760b44834478f0b266c9b3f5801e0139fdecacdc0820e447289a006d3", - // "height": 2226003 - // }, - // { - // "tx_hash": - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // "height": 2226102 - // } - // ], - // uuids[1]: [ - // { - // "tx_hash": - // "88b7b5077d940dde1bc63eba37a09dec8e7b9dad14c183a2e879a21b6ec0ac1c", - // "height": 2226326 - // } - // ], - // }; - // }); - // - // when(client?.getTransaction( - // tx_hash: - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // )).thenAnswer((_) async => tx2Raw); - // when(client?.getTransaction( - // tx_hash: - // "88b7b5077d940dde1bc63eba37a09dec8e7b9dad14c183a2e879a21b6ec0ac1c", - // )).thenAnswer((_) async => tx1Raw); - // - // when(cachedClient?.getTransaction( - // tx_hash: - // "dcca229760b44834478f0b266c9b3f5801e0139fdecacdc0820e447289a006d3", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx3Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx3Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "88b7b5077d940dde1bc63eba37a09dec8e7b9dad14c183a2e879a21b6ec0ac1c", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx1Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "6261002b30122ab3b2ba8c481134e8a3ce08a3a1a429b8ebb3f28228b100ac1a", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx5Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "717080fc0054f655260b1591a0059bf377a589a98284173d20a1c8f3316c086e", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx6Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "1baec51e7630e3640ccf0e34f160c8ad3eb6021ecafe3618a1afae328f320f53", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx7Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "b39bac02b65af46a49e2985278fe24ca00dd5d627395d88f53e35568a04e10fa", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx4Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "46b1f19763ac68e39b8218429f4e29b150f850901562fe44a05fade9e0acd65f", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx8Raw); - // - // btc = NamecoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // final wallet = await Hive.openBox(testWalletId); - // await wallet.put('receivingAddressesP2PKH', []); - // await wallet.put('receivingAddressesP2SH', [ - // "2Mv83bPh2HzPRXptuQg9ejbKpSp87Zi52zT", - // ]); - // await wallet.put('receivingAddressesP2WPKH', [ - // "tb1q3ywehep0ykrkaqkt0hrgsqyns4mnz2ls8nxfzg", - // ]); - // - // await wallet.put('changeAddressesP2PKH', []); - // await wallet.put('changeAddressesP2SH', []); - // await wallet.put('changeAddressesP2WPKH', []); - // - // btc.unconfirmedTxs = { - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // }; - // - // final result = await btc?.refreshIfThereIsNewData(); - // - // expect(result, true); - // - // verify(client?.getBatchHistory(args: anyNamed("args"))).called(2); - // verify(client?.getTransaction( - // tx_hash: - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // )).called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: anyNamed("tx_hash"), - // verbose: true, - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .called(9); - // // verify(priceAPI.getBitcoinPrice(baseCurrency: "USD")).called(1); - // - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("refreshIfThereIsNewData false A", () async { - // // when(priceAPI.getBitcoinPrice(baseCurrency: "USD")) - // // .thenAnswer((_) async => Decimal.fromInt(10)); - // - // when(client?.getBatchHistory(args: anyNamed("args"))) - // .thenAnswer((realInvocation) async { - // final uuids = Map>.from( - // realInvocation.namedArguments.values.first) - // .keys - // .toList(growable: false); - // return { - // uuids[0]: [ - // { - // "tx_hash": - // "dcca229760b44834478f0b266c9b3f5801e0139fdecacdc0820e447289a006d3", - // "height": 2226003 - // }, - // { - // "tx_hash": - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // "height": 2226102 - // } - // ], - // uuids[1]: [ - // { - // "tx_hash": - // "88b7b5077d940dde1bc63eba37a09dec8e7b9dad14c183a2e879a21b6ec0ac1c", - // "height": 2226326 - // } - // ], - // }; - // }); - // - // when(client?.getTransaction( - // tx_hash: - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // )).thenAnswer((_) async => tx2Raw); - // when(client?.getTransaction( - // tx_hash: - // "88b7b5077d940dde1bc63eba37a09dec8e7b9dad14c183a2e879a21b6ec0ac1c", - // )).thenAnswer((_) async => tx1Raw); - // - // when(cachedClient?.getTransaction( - // tx_hash: - // "dcca229760b44834478f0b266c9b3f5801e0139fdecacdc0820e447289a006d3", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx3Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx2Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "88b7b5077d940dde1bc63eba37a09dec8e7b9dad14c183a2e879a21b6ec0ac1c", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx1Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "6261002b30122ab3b2ba8c481134e8a3ce08a3a1a429b8ebb3f28228b100ac1a", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx5Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "717080fc0054f655260b1591a0059bf377a589a98284173d20a1c8f3316c086e", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx6Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "1baec51e7630e3640ccf0e34f160c8ad3eb6021ecafe3618a1afae328f320f53", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx7Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "b39bac02b65af46a49e2985278fe24ca00dd5d627395d88f53e35568a04e10fa", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx4Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "46b1f19763ac68e39b8218429f4e29b150f850901562fe44a05fade9e0acd65f", - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx8Raw); - // - // btc = NamecoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // final wallet = await Hive.openBox(testWalletId); - // await wallet.put('receivingAddressesP2PKH', []); - // await wallet.put('receivingAddressesP2SH', [ - // "2Mv83bPh2HzPRXptuQg9ejbKpSp87Zi52zT", - // ]); - // await wallet.put('receivingAddressesP2WPKH', [ - // "tb1q3ywehep0ykrkaqkt0hrgsqyns4mnz2ls8nxfzg", - // ]); - // - // await wallet.put('changeAddressesP2PKH', []); - // await wallet.put('changeAddressesP2SH', []); - // await wallet.put('changeAddressesP2WPKH', []); - // - // btc?.unconfirmedTxs = { - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // }; - // - // final result = await btc?.refreshIfThereIsNewData(); - // - // expect(result, false); - // - // verify(client?.getBatchHistory(args: anyNamed("args"))).called(2); - // verify(client?.getTransaction( - // tx_hash: - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // )).called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: anyNamed("tx_hash"), - // verbose: true, - // coinName: "tBitcoin", - // callOutSideMainIsolate: false)) - // .called(15); - // // verify(priceAPI.getBitcoinPrice(baseCurrency: "USD")).called(1); - // - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - - // test("refreshIfThereIsNewData false B", () async { - // when(client?.getBatchHistory(args: anyNamed("args"))) - // .thenThrow(Exception("some exception")); - // - // when(client?.getTransaction( - // txHash: - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // )).thenAnswer((_) async => tx2Raw); - // - // btc = NamecoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // priceAPI: priceAPI, - // secureStore: secureStore, - // ); - // final wallet = await Hive.openBox(testWalletId); - // await wallet.put('receivingAddressesP2PKH', []); - // await wallet.put('receivingAddressesP2SH', [ - // "2Mv83bPh2HzPRXptuQg9ejbKpSp87Zi52zT", - // ]); - // await wallet.put('receivingAddressesP2WPKH', [ - // "tb1q3ywehep0ykrkaqkt0hrgsqyns4mnz2ls8nxfzg", - // ]); - // - // await wallet.put('changeAddressesP2PKH', []); - // await wallet.put('changeAddressesP2SH', []); - // await wallet.put('changeAddressesP2WPKH', []); - // - // btc?.txTracker = { - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // }; - // - // // btc?.unconfirmedTxs = { - // // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // // }; - // - // final result = await btc?.refreshIfThereIsNewData(); - // - // expect(result, false); - // - // verify(client?.getBatchHistory(args: anyNamed("args"))).called(1); - // verify(client?.getTransaction( - // txHash: - // "b2f75a017a7435f1b8c2e080a865275d8f80699bba68d8dce99a94606e7b3528", - // )).called(1); - // - // expect(secureStore?.interactions, 0); - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - test( "recoverFromMnemonic using empty seed on mainnet fails due to bad genesis hash match", () async { @@ -2116,51 +588,7 @@ void main() { bool hasThrown = false; try { - await btc?.recoverFromMnemonic( - mnemonic: TEST_MNEMONIC, - maxUnusedAddressGap: 2, - maxNumberOfIndexesToCheck: 1000, - height: 4000); - } catch (_) { - hasThrown = true; - } - expect(hasThrown, true); - - verify(client?.getServerFeatures()).called(1); - - expect(secureStore?.interactions, 0); - verifyNoMoreInteractions(client); - verifyNoMoreInteractions(cachedClient); - verifyNoMoreInteractions(priceAPI); - }); - - test( - "recoverFromMnemonic using empty seed on testnet fails due to bad genesis hash match", - () async { - btc = NamecoinWallet( - walletId: testWalletId, - walletName: testWalletName, - coin: Coin.bitcoinTestNet, - client: client!, - cachedClient: cachedClient!, - tracker: tracker!, - priceAPI: priceAPI, - secureStore: secureStore, - ); - 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": [] - }); - - bool hasThrown = false; - try { - await btc?.recoverFromMnemonic( + await nmc?.recoverFromMnemonic( mnemonic: TEST_MNEMONIC, maxUnusedAddressGap: 2, maxNumberOfIndexesToCheck: 1000, @@ -2197,7 +625,7 @@ void main() { bool hasThrown = false; try { - await btc?.recoverFromMnemonic( + await nmc?.recoverFromMnemonic( mnemonic: TEST_MNEMONIC, maxUnusedAddressGap: 2, maxNumberOfIndexesToCheck: 1000, @@ -2238,11 +666,11 @@ void main() { .thenAnswer((_) async => emptyHistoryBatchResponse); when(client?.getBatchHistory(args: historyBatchArgs5)) .thenAnswer((_) async => emptyHistoryBatchResponse); - // await DB.instance.init(); + await DB.instance.init(); final wallet = await Hive.openBox(testWalletId); bool hasThrown = false; try { - await btc?.recoverFromMnemonic( + await nmc?.recoverFromMnemonic( mnemonic: TEST_MNEMONIC, maxUnusedAddressGap: 2, maxNumberOfIndexesToCheck: 1000, @@ -2296,13 +724,13 @@ void main() { final wallet = await Hive.openBox(testWalletId); - await btc?.recoverFromMnemonic( + await nmc?.recoverFromMnemonic( mnemonic: TEST_MNEMONIC, maxUnusedAddressGap: 2, maxNumberOfIndexesToCheck: 1000, height: 4000); - expect(await btc?.mnemonic, TEST_MNEMONIC.split(" ")); + expect(await nmc?.mnemonic, TEST_MNEMONIC.split(" ")); verify(client?.getServerFeatures()).called(1); verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); @@ -2333,14 +761,14 @@ 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(client?.getBatchHistory(args: historyBatchArgs4)) - .thenAnswer((_) async => historyBatchResponse); - when(client?.getBatchHistory(args: historyBatchArgs5)) - .thenAnswer((_) async => historyBatchResponse); + // when(client?.getBatchHistory(args: historyBatchArgs2)) + // .thenAnswer((_) async => historyBatchResponse); + // when(client?.getBatchHistory(args: historyBatchArgs3)) + // .thenAnswer((_) async => historyBatchResponse); + // when(client?.getBatchHistory(args: historyBatchArgs4)) + // .thenAnswer((_) async => historyBatchResponse); + // when(client?.getBatchHistory(args: historyBatchArgs5)) + // .thenAnswer((_) async => historyBatchResponse); List dynamicArgValues = []; @@ -2357,7 +785,7 @@ void main() { bool hasThrown = false; try { - await btc?.recoverFromMnemonic( + await nmc?.recoverFromMnemonic( mnemonic: TEST_MNEMONIC, maxUnusedAddressGap: 2, maxNumberOfIndexesToCheck: 1000, @@ -2433,7 +861,7 @@ void main() { final wallet = await Hive.openBox(testWalletId); // restore so we have something to rescan - await btc?.recoverFromMnemonic( + await nmc?.recoverFromMnemonic( mnemonic: TEST_MNEMONIC, maxUnusedAddressGap: 2, maxNumberOfIndexesToCheck: 1000, @@ -2504,7 +932,7 @@ void main() { bool hasThrown = false; try { - await btc?.fullRescan(2, 1000); + await nmc?.fullRescan(2, 1000); } catch (_) { hasThrown = true; } @@ -2627,7 +1055,7 @@ void main() { final wallet = await Hive.openBox(testWalletId); // restore so we have something to rescan - await btc?.recoverFromMnemonic( + await nmc?.recoverFromMnemonic( mnemonic: TEST_MNEMONIC, maxUnusedAddressGap: 2, maxNumberOfIndexesToCheck: 1000, @@ -2669,7 +1097,7 @@ void main() { bool hasThrown = false; try { - await btc?.fullRescan(2, 1000); + await nmc?.fullRescan(2, 1000); } catch (_) { hasThrown = true; } @@ -2751,1265 +1179,6 @@ void main() { verifyNoMoreInteractions(priceAPI); }); - // test("fetchBuildTxData 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?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx9Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx10Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx11Raw); - // - // // recover to fill data - // await btc?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000); - // - // // modify addresses to trigger all change code branches - // final chg44 = await secureStore?.read( - // key: testWalletId + "_changeDerivationsP2PKH"); - // await secureStore?.write( - // key: testWalletId + "_changeDerivationsP2PKH", - // value: chg44?.replaceFirst("1vFHF5q21GccoBwrB4zEUAs9i3Bfx797U", - // "16FuTPaeRSPVxxCnwQmdyx2PQWxX6HWzhQ")); - // final chg49 = - // await secureStore?.read(key: testWalletId + "_changeDerivationsP2SH"); - // await secureStore?.write( - // key: testWalletId + "_changeDerivationsP2SH", - // value: chg49?.replaceFirst("3ANTVqufTH1tLAuoQHhng8jndRsA9hcNy7", - // "36NvZTcMsMowbt78wPzJaHHWaNiyR73Y4g")); - // final chg84 = await secureStore?.read( - // key: testWalletId + "_changeDerivationsP2WPKH"); - // await secureStore?.write( - // key: testWalletId + "_changeDerivationsP2WPKH", - // value: chg84?.replaceFirst( - // "bc1qn2x7h96kufgfjxtkhsnq03jqwqde8zasffqvd2", - // "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - // - // final data = await btc?.fetchBuildTxData(utxoList); - // - // expect(data?.length, 3); - // expect( - // data?["2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703"] - // ?.length, - // 2); - // expect( - // data?["ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7"] - // .length, - // 3); - // expect( - // data?["3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4"] - // .length, - // 2); - // expect( - // data?["2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703"] - // ["output"], - // isA()); - // expect( - // data?["ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7"] - // ["output"], - // isA()); - // expect( - // data?["3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4"] - // ["output"], - // isA()); - // expect( - // data?["2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703"] - // ["keyPair"], - // isA()); - // expect( - // data?["ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7"] - // ["keyPair"], - // isA()); - // expect( - // data?["3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4"] - // ["keyPair"], - // isA()); - // expect( - // data?["ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7"] - // ["redeemScript"], - // isA()); - // - // // modify addresses to trigger all receiving code branches - // final rcv44 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2PKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2PKH", - // value: rcv44?.replaceFirst("1RMSPixoLPuaXuhR2v4HsUMcRjLncKDaw", - // "16FuTPaeRSPVxxCnwQmdyx2PQWxX6HWzhQ")); - // final rcv49 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2SH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2SH", - // value: rcv49?.replaceFirst("3AV74rKfibWmvX34F99yEvUcG4LLQ9jZZk", - // "36NvZTcMsMowbt78wPzJaHHWaNiyR73Y4g")); - // final rcv84 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2WPKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2WPKH", - // value: rcv84?.replaceFirst( - // "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", - // "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - // - // final data2 = await btc?.fetchBuildTxData(utxoList); - // - // expect(data2?.length, 3); - // expect( - // data2?["2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703"] - // .length, - // 2); - // expect( - // data2?["ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7"] - // .length, - // 3); - // expect( - // data2?["3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4"] - // .length, - // 2); - // expect( - // data2?["2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703"] - // ["output"], - // isA()); - // expect( - // data2?["ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7"] - // ["output"], - // isA()); - // expect( - // data2?["3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4"] - // ["output"], - // isA()); - // expect( - // data2?["2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703"] - // ["keyPair"], - // isA()); - // expect( - // data2?["ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7"] - // ["keyPair"], - // isA()); - // expect( - // data2?["3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4"] - // ["keyPair"], - // isA()); - // expect( - // data2?["ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7"] - // ["redeemScript"], - // isA()); - // - // verify(client?.getServerFeatures()).called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(2); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(2); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(2); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // - // expect(secureStore?.interactions, 38); - // expect(secureStore?.writes, 13); - // expect(secureStore?.reads, 25); - // expect(secureStore?.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("fetchBuildTxData throws", () 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?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx9Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx10Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenThrow(Exception("some exception")); - // - // // recover to fill data - // await btc?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000); - // - // bool didThrow = false; - // try { - // await btc?.fetchBuildTxData(utxoList); - // } catch (_) { - // didThrow = true; - // } - // expect(didThrow, true); - // - // verify(client?.getServerFeatures()).called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // - // expect(secureStore?.interactions, 14); - // expect(secureStore?.writes, 7); - // expect(secureStore?.reads, 7); - // expect(secureStore?.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("build transaction 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?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx9Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx10Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx11Raw); - // - // // recover to fill data - // await btc?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000); - // - // // modify addresses to properly mock data to build a tx - // final rcv44 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2PKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2PKH", - // value: rcv44?.replaceFirst("1RMSPixoLPuaXuhR2v4HsUMcRjLncKDaw", - // "16FuTPaeRSPVxxCnwQmdyx2PQWxX6HWzhQ")); - // final rcv49 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2SH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2SH", - // value: rcv49?.replaceFirst("3AV74rKfibWmvX34F99yEvUcG4LLQ9jZZk", - // "36NvZTcMsMowbt78wPzJaHHWaNiyR73Y4g")); - // final rcv84 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2WPKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2WPKH", - // value: rcv84?.replaceFirst( - // "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", - // "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - // - // final data = await btc?.fetchBuildTxData(utxoList); - // - // final txData = await btc?.buildTransaction( - // utxosToUse: utxoList, - // utxoSigningData: data!, - // recipients: ["bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc"], - // satoshiAmounts: [13000]); - // - // expect(txData?.length, 2); - // expect(txData?["hex"], isA()); - // expect(txData?["vSize"], isA()); - // - // verify(client?.getServerFeatures()).called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // - // expect(secureStore?.interactions, 26); - // expect(secureStore?.writes, 10); - // expect(secureStore?.reads, 16); - // expect(secureStore?.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("build transaction fails", () 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?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx9Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx10Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx11Raw); - // - // // recover to fill data - // await btc?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000); - // - // // modify addresses to properly mock data to build a tx - // final rcv44 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2PKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2PKH", - // value: rcv44?.replaceFirst("1RMSPixoLPuaXuhR2v4HsUMcRjLncKDaw", - // "16FuTPaeRSPVxxCnwQmdyx2PQWxX6HWzhQ")); - // final rcv49 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2SH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2SH", - // value: rcv49?.replaceFirst("3AV74rKfibWmvX34F99yEvUcG4LLQ9jZZk", - // "36NvZTcMsMowbt78wPzJaHHWaNiyR73Y4g")); - // final rcv84 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2WPKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2WPKH", - // value: rcv84?.replaceFirst( - // "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", - // "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - // - // final data = await btc?.fetchBuildTxData(utxoList); - // - // // give bad data toi build tx - // data["ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7"] - // ["keyPair"] = null; - // - // bool didThrow = false; - // try { - // await btc?.buildTransaction( - // utxosToUse: utxoList, - // utxoSigningData: data!, - // recipients: ["bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc"], - // satoshiAmounts: [13000]); - // } catch (_) { - // didThrow = true; - // } - // expect(didThrow, true); - // - // verify(client?.getServerFeatures()).called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // - // expect(secureStore?.interactions, 26); - // expect(secureStore?.writes, 10); - // expect(secureStore?.reads, 16); - // expect(secureStore?.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("two output coinSelection 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(client?.getHistory(scripthash: anyNamed("scripthash"))) - // .thenAnswer((_) async => [ - // {"height": 1000, "tx_hash": "some tx hash"} - // ]); - // when(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx9Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx10Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx11Raw); - // - // // recover to fill data - // await btc?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000); - // - // // modify addresses to properly mock data to build a tx - // final rcv44 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2PKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2PKH", - // value: rcv44?.replaceFirst("1RMSPixoLPuaXuhR2v4HsUMcRjLncKDaw", - // "16FuTPaeRSPVxxCnwQmdyx2PQWxX6HWzhQ")); - // final rcv49 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2SH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2SH", - // value: rcv49?.replaceFirst("3AV74rKfibWmvX34F99yEvUcG4LLQ9jZZk", - // "36NvZTcMsMowbt78wPzJaHHWaNiyR73Y4g")); - // final rcv84 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2WPKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2WPKH", - // value: rcv84?.replaceFirst( - // "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", - // "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - // - // final result = await btc?.coinSelection( - // 18000, 1000, "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc", - // utxos: utxoList); - // - // expect(result, isA>()); - // expect(result.length > 0, true); - // - // verify(client?.getServerFeatures()).called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(1); - // - // expect(secureStore?.interactions, 29); - // expect(secureStore?.writes, 11); - // expect(secureStore?.reads, 18); - // expect(secureStore?.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("one output option A coinSelection", () 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(client?.getHistory(scripthash: anyNamed("scripthash"))) - // .thenAnswer((_) async => [ - // {"height": 1000, "tx_hash": "some tx hash"} - // ]); - // when(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx9Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx10Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx11Raw); - // - // // recover to fill data - // await btc?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000); - // - // // modify addresses to properly mock data to build a tx - // final rcv44 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2PKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2PKH", - // value: rcv44?.replaceFirst("1RMSPixoLPuaXuhR2v4HsUMcRjLncKDaw", - // "16FuTPaeRSPVxxCnwQmdyx2PQWxX6HWzhQ")); - // final rcv49 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2SH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2SH", - // value: rcv49?.replaceFirst("3AV74rKfibWmvX34F99yEvUcG4LLQ9jZZk", - // "36NvZTcMsMowbt78wPzJaHHWaNiyR73Y4g")); - // final rcv84 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2WPKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2WPKH", - // value: rcv84?.replaceFirst( - // "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", - // "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - // - // final result = await btc?.coinSelection( - // 18500, 1000, "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc", - // utxos: utxoList); - // - // expect(result, isA>()); - // expect(result.length > 0, true); - // - // verify(client?.getServerFeatures()).called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // - // expect(secureStore?.interactions, 26); - // expect(secureStore?.writes, 10); - // expect(secureStore?.reads, 16); - // expect(secureStore?.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("one output option B coinSelection", () 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(client?.getHistory(scripthash: anyNamed("scripthash"))) - // .thenAnswer((_) async => [ - // {"height": 1000, "tx_hash": "some tx hash"} - // ]); - // when(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx9Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx10Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx11Raw); - // - // // recover to fill data - // await btc?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000); - // - // // modify addresses to properly mock data to build a tx - // final rcv44 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2PKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2PKH", - // value: rcv44?.replaceFirst("1RMSPixoLPuaXuhR2v4HsUMcRjLncKDaw", - // "16FuTPaeRSPVxxCnwQmdyx2PQWxX6HWzhQ")); - // final rcv49 = - // await secureStore?.read(key: testWalletId + "_receiveDerivationsP2SH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2SH", - // value: rcv49?.replaceFirst("3AV74rKfibWmvX34F99yEvUcG4LLQ9jZZk", - // "36NvZTcMsMowbt78wPzJaHHWaNiyR73Y4g")); - // final rcv84 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2WPKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2WPKH", - // value: rcv84?.replaceFirst( - // "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", - // "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - // - // final result = await btc?.coinSelection( - // 18651, 1000, "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc", - // utxos: utxoList); - // - // expect(result, isA>()); - // expect(result.length > 0, true); - // - // verify(client?.getServerFeatures()).called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // - // expect(secureStore?.interactions, 26); - // expect(secureStore?.writes, 10); - // expect(secureStore?.reads, 16); - // expect(secureStore?.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("insufficient funds option A coinSelection", () 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); - // - // // recover to fill data - // await btc?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000); - // - // // modify addresses to properly mock data to build a tx - // final rcv44 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2PKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2PKH", - // value: rcv44?.replaceFirst("1RMSPixoLPuaXuhR2v4HsUMcRjLncKDaw", - // "16FuTPaeRSPVxxCnwQmdyx2PQWxX6HWzhQ")); - // final rcv49 = - // await secureStore?.read(key: testWalletId + "_receiveDerivationsP2SH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2SH", - // value: rcv49?.replaceFirst("3AV74rKfibWmvX34F99yEvUcG4LLQ9jZZk", - // "36NvZTcMsMowbt78wPzJaHHWaNiyR73Y4g")); - // final rcv84 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2WPKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2WPKH", - // value: rcv84?.replaceFirst( - // "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", - // "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - // - // final result = await btc?.coinSelection( - // 20000, 1000, "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc", - // utxos: utxoList); - // - // expect(result, 1); - // - // verify(client?.getServerFeatures()).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // - // expect(secureStore?.interactions, 20); - // expect(secureStore?.writes, 10); - // expect(secureStore?.reads, 10); - // expect(secureStore?.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("insufficient funds option B coinSelection", () 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); - // - // // recover to fill data - // await btc?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000); - // - // // modify addresses to properly mock data to build a tx - // final rcv44 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2PKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2PKH", - // value: rcv44?.replaceFirst("1RMSPixoLPuaXuhR2v4HsUMcRjLncKDaw", - // "16FuTPaeRSPVxxCnwQmdyx2PQWxX6HWzhQ")); - // final rcv49 = - // await secureStore?.read(key: testWalletId + "_receiveDerivationsP2SH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2SH", - // value: rcv49?.replaceFirst("3AV74rKfibWmvX34F99yEvUcG4LLQ9jZZk", - // "36NvZTcMsMowbt78wPzJaHHWaNiyR73Y4g")); - // final rcv84 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2WPKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2WPKH", - // value: rcv84?.replaceFirst( - // "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", - // "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - // - // final result = await btc?.coinSelection( - // 19000, 1000, "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc", - // utxos: utxoList); - // - // expect(result, 2); - // - // verify(client?.getServerFeatures()).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // - // expect(secureStore?.interactions, 20); - // expect(secureStore?.writes, 10); - // expect(secureStore?.reads, 10); - // expect(secureStore?.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("insufficient funds option C coinSelection", () 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.?getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx9Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx10Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx11Raw); - // - // // recover to fill data - // await btc?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000); - // - // // modify addresses to properly mock data to build a tx - // final rcv44 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2PKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2PKH", - // value: rcv44?.replaceFirst("1RMSPixoLPuaXuhR2v4HsUMcRjLncKDaw", - // "16FuTPaeRSPVxxCnwQmdyx2PQWxX6HWzhQ")); - // final rcv49 = - // await secureStore?.read(key: testWalletId + "_receiveDerivationsP2SH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2SH", - // value: rcv49?.replaceFirst("3AV74rKfibWmvX34F99yEvUcG4LLQ9jZZk", - // "36NvZTcMsMowbt78wPzJaHHWaNiyR73Y4g")); - // final rcv84 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2WPKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2WPKH", - // value: rcv84?.replaceFirst( - // "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", - // "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - // - // final result = await btc?.coinSelection( - // 18900, 1000, "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc", - // utxos: utxoList); - // - // expect(result, 2); - // - // verify(client?.getServerFeatures()).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // - // expect(secureStore?.interactions, 26); - // expect(secureStore?.writes, 10); - // expect(secureStore?.reads, 16); - // expect(secureStore?.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("check for more outputs coinSelection", () 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?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx9Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx10Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx11Raw); - // - // // recover to fill data - // await btc?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000); - // - // // modify addresses to properly mock data to build a tx - // final rcv44 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2PKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2PKH", - // value: rcv44?.replaceFirst("1RMSPixoLPuaXuhR2v4HsUMcRjLncKDaw", - // "16FuTPaeRSPVxxCnwQmdyx2PQWxX6HWzhQ")); - // final rcv49 = - // await secureStore?.read(key: testWalletId + "_receiveDerivationsP2SH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2SH", - // value: rcv49?.replaceFirst("3AV74rKfibWmvX34F99yEvUcG4LLQ9jZZk", - // "36NvZTcMsMowbt78wPzJaHHWaNiyR73Y4g")); - // final rcv84 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2WPKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2WPKH", - // value: rcv84?.replaceFirst( - // "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", - // "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - // when(client?.getHistory(scripthash: anyNamed("scripthash"))) - // .thenAnswer((_) async => [ - // {"height": 1000, "tx_hash": "some tx hash"} - // ]); - // - // final result = await btc?.coinSelection( - // 11900, 1000, "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc", - // utxos: utxoList); - // - // expect(result, isA>()); - // expect(result.length > 0, true); - // - // verify(client?.getServerFeatures()).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(2); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(2); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // - // verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(1); - // - // expect(secureStore?.interactions, 33); - // expect(secureStore?.writes, 11); - // expect(secureStore?.reads, 22); - // expect(secureStore?.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - // - // test("prepareSend and confirmSend succeed", () 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(client?.getHistory(scripthash: anyNamed("scripthash"))) - // .thenAnswer((_) async => [ - // {"height": 1000, "tx_hash": "some tx hash"} - // ]); - // when(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx9Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx10Raw); - // when(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .thenAnswer((_) async => tx11Raw); - // - // // recover to fill data - // await btc?.recoverFromMnemonic( - // mnemonic: TEST_MNEMONIC, - // maxUnusedAddressGap: 2, - // maxNumberOfIndexesToCheck: 1000); - // - // // modify addresses to properly mock data to build a tx - // final rcv44 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2PKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2PKH", - // value: rcv44?.replaceFirst("1RMSPixoLPuaXuhR2v4HsUMcRjLncKDaw", - // "16FuTPaeRSPVxxCnwQmdyx2PQWxX6HWzhQ")); - // final rcv49 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2SH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2SH", - // value: rcv49?.replaceFirst("3AV74rKfibWmvX34F99yEvUcG4LLQ9jZZk", - // "36NvZTcMsMowbt78wPzJaHHWaNiyR73Y4g")); - // final rcv84 = await secureStore?.read( - // key: testWalletId + "_receiveDerivationsP2WPKH"); - // await secureStore?.write( - // key: testWalletId + "_receiveDerivationsP2WPKH", - // value: rcv84?.replaceFirst( - // "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", - // "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - // - // btc?.outputsList = utxoList; - // - // final result = await btc?.prepareSend( - // toAddress: "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc", - // amount: 15000); - // - // expect(result, isA>()); - // expect(result?.length! > 0, true); - // - // when(client?.broadcastTransaction( - // rawTx: result!["hex"], requestID: anyNamed("requestID"))) - // .thenAnswer((_) async => "some txHash"); - // - // final sentResult = await btc?.confirmSend(txData: result!); - // expect(sentResult, "some txHash"); - // - // verify(client?.getServerFeatures()).called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(cachedClient?.getTransaction( - // tx_hash: - // "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", - // coinName: "Bitcoin", - // callOutSideMainIsolate: false)) - // .called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); - // verify(client?.broadcastTransaction( - // rawTx: result!["hex"], requestID: anyNamed("requestID"))) - // .called(1); - // verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(1); - // - // expect(secureStore?.interactions, 29); - // expect(secureStore?.writes, 11); - // expect(secureStore?.reads, 18); - // expect(secureStore?.deletes, 0); - // - // verifyNoMoreInteractions(client); - // verifyNoMoreInteractions(cachedClient); - // verifyNoMoreInteractions(priceAPI); - // }); - test("prepareSend fails", () async { when(client?.getServerFeatures()).thenAnswer((_) async => { "hosts": {}, @@ -4049,22 +1218,22 @@ void main() { when(cachedClient?.getTransaction( txHash: - "2087ce09bc316877c9f10971526a2bffa3078d52ea31752639305cdcd8230703", + "dffa9543852197f9fb90f8adafaab8a0b9b4925e9ada8c6bdcaf00bf2e9f60d7", coin: Coin.namecoin)) - .thenAnswer((_) async => tx9Raw); + .thenAnswer((_) async => tx2Raw); when(cachedClient?.getTransaction( txHash: - "ed32c967a0e86d51669ac21c2bb9bc9c50f0f55fbacdd8db21d0a986fba93bd7", + "71b56532e9e7321bd8c30d0f8b14530743049d2f3edd5623065c46eee1dda04d", coin: Coin.namecoin)) - .thenAnswer((_) async => tx10Raw); + .thenAnswer((_) async => tx3Raw); when(cachedClient?.getTransaction( txHash: - "3f0032f89ac44b281b50314cff3874c969c922839dddab77ced54e86a21c3fd4", + "c7e700f7e23a85bbdd9de86d502322a933607ee7ea7e16adaf02e477cdd849b9", coin: Coin.namecoin, - )).thenAnswer((_) async => tx11Raw); + )).thenAnswer((_) async => tx4Raw); // recover to fill data - await btc?.recoverFromMnemonic( + await nmc?.recoverFromMnemonic( mnemonic: TEST_MNEMONIC, maxUnusedAddressGap: 2, maxNumberOfIndexesToCheck: 1000, @@ -4091,12 +1260,12 @@ void main() { "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - btc?.outputsList = utxoList; + nmc?.outputsList = utxoList; bool didThrow = false; try { - await btc?.prepareSend( - address: "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc", + await nmc?.prepareSend( + address: "nc1q6k4x8ye6865z3rc8zkt8gyu52na7njqt6hsk4v", satoshiAmount: 15000); } catch (_) { didThrow = true; @@ -4154,7 +1323,7 @@ void main() { test("confirmSend no hex", () async { bool didThrow = false; try { - await btc?.confirmSend(txData: {"some": "strange map"}); + await nmc?.confirmSend(txData: {"some": "strange map"}); } catch (_) { didThrow = true; } @@ -4170,7 +1339,7 @@ void main() { test("confirmSend hex is not string", () async { bool didThrow = false; try { - await btc?.confirmSend(txData: {"hex": true}); + await nmc?.confirmSend(txData: {"hex": true}); } catch (_) { didThrow = true; } @@ -4186,7 +1355,7 @@ void main() { test("confirmSend hex is string but missing other data", () async { bool didThrow = false; try { - await btc?.confirmSend(txData: {"hex": "a string"}); + await nmc?.confirmSend(txData: {"hex": "a string"}); } catch (_) { didThrow = true; } @@ -4206,7 +1375,7 @@ void main() { test("confirmSend fails due to vSize being greater than fee", () async { bool didThrow = false; try { - await btc + await nmc ?.confirmSend(txData: {"hex": "a string", "fee": 1, "vSize": 10}); } catch (_) { didThrow = true; @@ -4231,7 +1400,7 @@ void main() { bool didThrow = false; try { - await btc + await nmc ?.confirmSend(txData: {"hex": "a string", "fee": 10, "vSize": 10}); } catch (_) { didThrow = true; @@ -4254,7 +1423,7 @@ void main() { // // to the provided ipAddress below. This will throw a bunch of errors // // which what we want here as actually calling electrumx calls here is unwanted. // // test("listen to NodesChangedEvent", () async { - // // btc = NamecoinWallet( + // // nmc = NamecoinWallet( // // walletId: testWalletId, // // walletName: testWalletName, // // networkType: BasicNetworkType.test, @@ -4276,10 +1445,10 @@ void main() { // // }); // // await wallet.put("activeNodeID_Bitcoin", "default"); // // - // // final a = btc.cachedElectrumXClient; + // // final a = nmc.cachedElectrumXClient; // // // // // return when refresh is called on node changed trigger - // // btc.longMutex = true; + // // nmc.longMutex = true; // // // // GlobalEventBus.instance // // .fire(NodesChangedEvent(NodesChangedEventType.updatedCurrentNode)); @@ -4287,11 +1456,11 @@ void main() { // // // make sure event has processed before continuing // // await Future.delayed(Duration(seconds: 5)); // // - // // final b = btc.cachedElectrumXClient; + // // final b = nmc.cachedElectrumXClient; // // // // expect(identical(a, b), false); // // - // // await btc.exit(); + // // await nmc.exit(); // // // // expect(secureStore.interactions, 0); // // verifyNoMoreInteractions(client); @@ -4337,15 +1506,15 @@ void main() { await Hive.openBox(testWalletId); // recover to fill data - await btc?.recoverFromMnemonic( + await nmc?.recoverFromMnemonic( mnemonic: TEST_MNEMONIC, maxUnusedAddressGap: 2, maxNumberOfIndexesToCheck: 1000, height: 4000); - btc?.refreshMutex = true; + nmc?.refreshMutex = true; - await btc?.refresh(); + await nmc?.refresh(); verify(client?.getServerFeatures()).called(1); verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); @@ -4406,7 +1575,7 @@ void main() { await Hive.openBox(testWalletId); // recover to fill data - await btc?.recoverFromMnemonic( + await nmc?.recoverFromMnemonic( mnemonic: TEST_MNEMONIC, maxUnusedAddressGap: 2, maxNumberOfIndexesToCheck: 1000, @@ -4417,7 +1586,7 @@ void main() { when(client?.getBatchUTXOs(args: anyNamed("args"))) .thenAnswer((_) async => emptyHistoryBatchResponse); - await btc?.refresh(); + await nmc?.refresh(); verify(client?.getServerFeatures()).called(1); verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(4); From 1ca1332dea5528053f1a06e9a951505a001d59cc Mon Sep 17 00:00:00 2001 From: Likho Date: Mon, 19 Sep 2022 16:13:30 +0200 Subject: [PATCH 3/7] Add tbch explorer --- .../manage_nodes_views/add_edit_node_view.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart b/lib/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart index 3410befdd..def35b800 100644 --- a/lib/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart +++ b/lib/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart @@ -535,7 +535,6 @@ class _NodeFormState extends ConsumerState { case Coin.bitcoincashTestnet: case Coin.firoTestNet: case Coin.dogecoinTestNet: - case Coin.bitcoincashTestnet: return false; case Coin.epicCash: From 20e8d0c114b1e081a577a7fd75b37cbdd29e2c03 Mon Sep 17 00:00:00 2001 From: Likho Date: Mon, 19 Sep 2022 16:14:07 +0200 Subject: [PATCH 4/7] Add tbch explorer --- lib/utilities/block_explorers.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/utilities/block_explorers.dart b/lib/utilities/block_explorers.dart index 64478d872..bf619d88f 100644 --- a/lib/utilities/block_explorers.dart +++ b/lib/utilities/block_explorers.dart @@ -29,8 +29,5 @@ Uri getBlockExplorerTransactionUrlFor({ "https://blockexplorer.one/bitcoin-cash/testnet/tx/$txid"); case Coin.namecoin: return Uri.parse("https://chainz.cryptoid.info/nmc/tx.dws?$txid.htm"); - case Coin.bitcoincashTestnet: - throw UnimplementedError("missing block explorer for epic cash"); - break; } } From 8bb6ba6ab7d84890d74097b332bbca1eb9720c72 Mon Sep 17 00:00:00 2001 From: Likho Date: Mon, 19 Sep 2022 19:38:32 +0200 Subject: [PATCH 5/7] WIP: Update dust limit for nmc and bch, update nmc history data --- .../coins/bitcoincash/bitcoincash_wallet.dart | 2 +- .../coins/namecoin/namecoin_wallet.dart | 2 +- .../bitcoincash/bitcoincash_wallet_test.dart | 4 ++-- .../namecoin_history_sample_data.dart | 7 +++++-- .../coins/namecoin/namecoin_wallet_test.dart | 20 +++++++++---------- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index aa83ea4a9..8c3d474c5 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -44,7 +44,7 @@ import 'package:uuid/uuid.dart'; import 'package:bitbox/bitbox.dart' as Bitbox; const int MINIMUM_CONFIRMATIONS = 3; -const int DUST_LIMIT = 1000000; +const int DUST_LIMIT = 546; const String GENESIS_HASH_MAINNET = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"; diff --git a/lib/services/coins/namecoin/namecoin_wallet.dart b/lib/services/coins/namecoin/namecoin_wallet.dart index cf241d07a..9734a9b51 100644 --- a/lib/services/coins/namecoin/namecoin_wallet.dart +++ b/lib/services/coins/namecoin/namecoin_wallet.dart @@ -44,7 +44,7 @@ import 'package:uuid/uuid.dart'; const int MINIMUM_CONFIRMATIONS = 2; // Find real dust limit -const int DUST_LIMIT = 1000000; +const int DUST_LIMIT = 546; const String GENESIS_HASH_MAINNET = "000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770"; diff --git a/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart b/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart index 87d26cf43..fd2615b44 100644 --- a/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart +++ b/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart @@ -29,7 +29,7 @@ void main() { expect(MINIMUM_CONFIRMATIONS, 3); }); test("bitcoincash dust limit", () async { - expect(DUST_LIMIT, 1000000); + expect(DUST_LIMIT, 546); }); test("bitcoincash mainnet genesis block hash", () async { expect(GENESIS_HASH_MAINNET, @@ -1891,7 +1891,7 @@ void main() { bch = BitcoinCashWallet( walletId: testWalletId, walletName: testWalletName, - coin: Coin.bitcoincash, + coin: Coin.bitcoincashTestnet, client: client!, cachedClient: cachedClient!, tracker: tracker!, diff --git a/test/services/coins/namecoin/namecoin_history_sample_data.dart b/test/services/coins/namecoin/namecoin_history_sample_data.dart index a22764a9b..f657129f2 100644 --- a/test/services/coins/namecoin/namecoin_history_sample_data.dart +++ b/test/services/coins/namecoin/namecoin_history_sample_data.dart @@ -177,7 +177,10 @@ final Map>> emptyHistoryBatchResponse = { }; final List activeScriptHashes = [ - "83b744ccb88827d544081c1a03ea782a7d00d6224ff9fddb7d0fbad399e1cae7", + "dd63fc12f5e6c1ada2cf3c941d1648e6d561ce4024747bb2117d72112d83287c", + "587943864cefed4f1643a5ee2ce2b3c13a0c6ad7c435373f0ac328e144a15c1e", + "cd3dd4abe4f9efc7149ba334d2d6790020331805b0bd5c7ed89a3ac6a22f10b9", "86906979fc9107d06d560275d7de8305b69d7189c3206ac9070ad76e6abff874", - "5baba32b1899d5e740838559ef39b7d8e9ba302bd24b732eeedd4c0e6ec65b51", + "c068e7fa4aa0b8a63114f6d11c047ca4be6a8fa333eb0dac48506e8f150af73b", + "42d6e40636f4740f9c7f95ef0bbc2a4c17f54da2bc98a32a622e2bf73eb675c3" ]; diff --git a/test/services/coins/namecoin/namecoin_wallet_test.dart b/test/services/coins/namecoin/namecoin_wallet_test.dart index 0e6b50d52..d3bae2966 100644 --- a/test/services/coins/namecoin/namecoin_wallet_test.dart +++ b/test/services/coins/namecoin/namecoin_wallet_test.dart @@ -32,7 +32,7 @@ void main() { expect(MINIMUM_CONFIRMATIONS, 2); }); test("namecoin dust limit", () async { - expect(DUST_LIMIT, 1000000); + expect(DUST_LIMIT, 546); }); test("namecoin mainnet genesis block hash", () async { expect(GENESIS_HASH_MAINNET, @@ -761,14 +761,14 @@ 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(client?.getBatchHistory(args: historyBatchArgs4)) - // .thenAnswer((_) async => historyBatchResponse); - // when(client?.getBatchHistory(args: historyBatchArgs5)) - // .thenAnswer((_) async => historyBatchResponse); + when(client?.getBatchHistory(args: historyBatchArgs2)) + .thenAnswer((_) async => historyBatchResponse); + when(client?.getBatchHistory(args: historyBatchArgs3)) + .thenAnswer((_) async => historyBatchResponse); + when(client?.getBatchHistory(args: historyBatchArgs4)) + .thenAnswer((_) async => historyBatchResponse); + when(client?.getBatchHistory(args: historyBatchArgs5)) + .thenAnswer((_) async => historyBatchResponse); List dynamicArgValues = []; @@ -1000,7 +1000,7 @@ void main() { for (final arg in dynamicArgValues) { final map = Map>.from(arg as Map); - verify(client?.getBatchHistory(args: map)).called(1); + verify(client?.getBatchHistory(args: map)).called(2); expect(activeScriptHashes.contains(map.values.first.first as String), true); } From b5ad9ec0046022d89f476aa96ac233478f018575 Mon Sep 17 00:00:00 2001 From: Likho Date: Tue, 20 Sep 2022 15:09:46 +0200 Subject: [PATCH 6/7] Add new nodes from Rylee and fix bch tests --- lib/utilities/default_nodes.dart | 8 +-- .../bitcoincash/bitcoincash_wallet_test.dart | 59 ++++++++++++++----- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/lib/utilities/default_nodes.dart b/lib/utilities/default_nodes.dart index 666a16032..df32b1e46 100644 --- a/lib/utilities/default_nodes.dart +++ b/lib/utilities/default_nodes.dart @@ -34,8 +34,8 @@ abstract class DefaultNodes { ); static NodeModel get bitcoincash => NodeModel( - host: "electrum1.cipig.net", - port: 20055, + host: "bitcoincash.stackwallet.com", + port: 8332, name: defaultName, id: _nodeId(Coin.bitcoincash), useSSL: true, @@ -96,8 +96,8 @@ abstract class DefaultNodes { ); static NodeModel get namecoin => NodeModel( - host: "46.229.238.187", - port: 57002, + host: "namecoin.stackwallet.com", + port: 8336, name: defaultName, id: _nodeId(Coin.namecoin), useSSL: true, diff --git a/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart b/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart index fd2615b44..775071e72 100644 --- a/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart +++ b/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart @@ -2123,9 +2123,20 @@ void main() { when(client?.getBatchHistory(args: historyBatchArgs0)) .thenAnswer((_) async => historyBatchResponse); - // when(client?.getBatchHistory(args: historyBatchArgs1)) - // .thenAnswer((_) async => historyBatchResponse); - when(cachedClient?.clearSharedTransactionCache(coin: Coin.bitcoincash)) + when(client?.getBatchHistory(args: historyBatchArgs1)) + .thenAnswer((_) async => historyBatchResponse); + 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 {}); final wallet = await Hive.openBox(testWalletId); @@ -2184,18 +2195,13 @@ 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(1); verify(cachedClient?.clearSharedTransactionCache(coin: Coin.bitcoincash)) .called(1); expect(secureStore?.writes, 7); expect(secureStore?.reads, 12); expect(secureStore?.deletes, 4); - - verifyNoMoreInteractions(client); - verifyNoMoreInteractions(cachedClient); - verifyNoMoreInteractions(tracker); - verifyNoMoreInteractions(priceAPI); }); // // test("fetchBuildTxData succeeds", () async { @@ -2678,11 +2684,21 @@ 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(client?.getBatchHistory(args: { + "0": [ + "f0c86f888f2aca0efaf1705247dbd1ebc02347c183e197310c9062ea2c9d2e34" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "04818da846fe5e03ac993d2e0c1ccc3848ff6073c3aba6a572df4efc5432ae8b" + ] + })).thenAnswer((realInvocation) async => {"0": []}); final wallet = await Hive.openBox(testWalletId); - // recover to fill data await bch?.recoverFromMnemonic( mnemonic: TEST_MNEMONIC, @@ -2696,7 +2712,7 @@ 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: historyBatchArgs1)).called(1); expect(secureStore?.interactions, 6); expect(secureStore?.writes, 3); @@ -2723,8 +2739,19 @@ 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(client?.getBatchHistory(args: { + "0": [ + "f0c86f888f2aca0efaf1705247dbd1ebc02347c183e197310c9062ea2c9d2e34" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "04818da846fe5e03ac993d2e0c1ccc3848ff6073c3aba6a572df4efc5432ae8b" + ] + })).thenAnswer((realInvocation) async => {"0": []}); when(client?.getHistory(scripthash: anyNamed("scripthash"))) .thenThrow(Exception("some exception")); @@ -2741,7 +2768,7 @@ 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: historyBatchArgs1)).called(1); verify(client?.getBlockHeadTip()).called(1); verify(client?.getHistory(scripthash: anyNamed("scripthash"))).called(1); From 321b83d50ab69613a508aafdf23380a57afd92a6 Mon Sep 17 00:00:00 2001 From: Likho Date: Tue, 20 Sep 2022 19:23:51 +0200 Subject: [PATCH 7/7] Finalize nmc tests --- .../coins/namecoin/namecoin_wallet_test.dart | 195 +++++++++++++++--- 1 file changed, 162 insertions(+), 33 deletions(-) diff --git a/test/services/coins/namecoin/namecoin_wallet_test.dart b/test/services/coins/namecoin/namecoin_wallet_test.dart index d3bae2966..ab0f5fb4a 100644 --- a/test/services/coins/namecoin/namecoin_wallet_test.dart +++ b/test/services/coins/namecoin/namecoin_wallet_test.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:bitcoindart/bitcoindart.dart'; import 'package:decimal/decimal.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -38,6 +40,10 @@ void main() { expect(GENESIS_HASH_MAINNET, "000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770"); }); + test("namecoin testnet genesis block hash", () async { + expect(GENESIS_HASH_TESTNET, + "00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"); + }); }); test("namecoin DerivePathType enum", () { @@ -847,16 +853,39 @@ void main() { when(cachedClient?.clearSharedTransactionCache(coin: Coin.namecoin)) .thenAnswer((realInvocation) async {}); - List dynamicArgValues = []; + when(client?.getBatchHistory(args: { + "0": [ + "dd63fc12f5e6c1ada2cf3c941d1648e6d561ce4024747bb2117d72112d83287c" + ] + })).thenAnswer((realInvocation) async => {"0": []}); - when(client?.getBatchHistory(args: anyNamed("args"))) - .thenAnswer((realInvocation) async { - if (realInvocation.namedArguments.values.first.length == 1) { - dynamicArgValues.add(realInvocation.namedArguments.values.first); - } + when(client?.getBatchHistory(args: { + "0": [ + "86906979fc9107d06d560275d7de8305b69d7189c3206ac9070ad76e6abff874" + ] + })).thenAnswer((realInvocation) async => {"0": []}); - return historyBatchResponse; - }); + when(client?.getBatchHistory(args: { + "0": [ + "c068e7fa4aa0b8a63114f6d11c047ca4be6a8fa333eb0dac48506e8f150af73b" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "cd3dd4abe4f9efc7149ba334d2d6790020331805b0bd5c7ed89a3ac6a22f10b9" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + when(client?.getBatchHistory(args: { + "0": [ + "587943864cefed4f1643a5ee2ce2b3c13a0c6ad7c435373f0ac328e144a15c1e" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + when(client?.getBatchHistory(args: { + "0": [ + "42d6e40636f4740f9c7f95ef0bbc2a4c17f54da2bc98a32a622e2bf73eb675c3" + ] + })).thenAnswer((realInvocation) async => {"0": []}); final wallet = await Hive.openBox(testWalletId); @@ -994,16 +1023,67 @@ void main() { verify(client?.getBatchHistory(args: historyBatchArgs3)).called(2); verify(client?.getBatchHistory(args: historyBatchArgs4)).called(2); verify(client?.getBatchHistory(args: historyBatchArgs5)).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "dd63fc12f5e6c1ada2cf3c941d1648e6d561ce4024747bb2117d72112d83287c" + ] + })).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "86906979fc9107d06d560275d7de8305b69d7189c3206ac9070ad76e6abff874" + ] + })).called(2); + + verify(client?.getBatchHistory(args: { + "0": [ + "c068e7fa4aa0b8a63114f6d11c047ca4be6a8fa333eb0dac48506e8f150af73b" + ] + })).called(2); + + verify(client?.getBatchHistory(args: { + "0": [ + "cd3dd4abe4f9efc7149ba334d2d6790020331805b0bd5c7ed89a3ac6a22f10b9" + ] + })).called(2); + + verify(client?.getBatchHistory(args: { + "0": [ + "587943864cefed4f1643a5ee2ce2b3c13a0c6ad7c435373f0ac328e144a15c1e" + ] + })).called(2); + + verify(client?.getBatchHistory(args: { + "0": [ + "42d6e40636f4740f9c7f95ef0bbc2a4c17f54da2bc98a32a622e2bf73eb675c3" + ] + })).called(2); verify(cachedClient?.clearSharedTransactionCache(coin: Coin.namecoin)) .called(1); - for (final arg in dynamicArgValues) { - final map = Map>.from(arg as Map); + // for (final arg in dynamicArgValues) { + // final map = Map>.from(arg as Map); + // Map argCount = {}; + // + // // verify(client?.getBatchHistory(args: map)).called(1); + // // expect(activeScriptHashes.contains(map.values.first.first as String), + // // true); + // } - verify(client?.getBatchHistory(args: map)).called(2); - expect(activeScriptHashes.contains(map.values.first.first as String), - true); - } + // Map argCount = {}; + // + // for (final arg in dynamicArgValues) { + // final map = Map>.from(arg as Map); + // + // final str = jsonEncode(map); + // + // if (argCount[str] == null) { + // argCount[str] = 1; + // } else { + // argCount[str] = argCount[str]! + 1; + // } + // } + // + // argCount.forEach((key, value) => print("arg: $key\ncount: $value")); expect(secureStore?.writes, 25); expect(secureStore?.reads, 32); @@ -1038,20 +1118,46 @@ void main() { .thenAnswer((_) async => historyBatchResponse); when(client?.getBatchHistory(args: historyBatchArgs5)) .thenAnswer((_) async => historyBatchResponse); + + when(client?.getBatchHistory(args: { + "0": [ + "dd63fc12f5e6c1ada2cf3c941d1648e6d561ce4024747bb2117d72112d83287c" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "cd3dd4abe4f9efc7149ba334d2d6790020331805b0bd5c7ed89a3ac6a22f10b9" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "42d6e40636f4740f9c7f95ef0bbc2a4c17f54da2bc98a32a622e2bf73eb675c3" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "587943864cefed4f1643a5ee2ce2b3c13a0c6ad7c435373f0ac328e144a15c1e" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "86906979fc9107d06d560275d7de8305b69d7189c3206ac9070ad76e6abff874" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + + when(client?.getBatchHistory(args: { + "0": [ + "c068e7fa4aa0b8a63114f6d11c047ca4be6a8fa333eb0dac48506e8f150af73b" + ] + })).thenAnswer((realInvocation) async => {"0": []}); + when(cachedClient?.clearSharedTransactionCache(coin: Coin.namecoin)) .thenAnswer((realInvocation) async {}); - List dynamicArgValues = []; - - when(client?.getBatchHistory(args: anyNamed("args"))) - .thenAnswer((realInvocation) async { - if (realInvocation.namedArguments.values.first.length == 1) { - dynamicArgValues.add(realInvocation.namedArguments.values.first); - } - - return historyBatchResponse; - }); - final wallet = await Hive.openBox(testWalletId); // restore so we have something to rescan @@ -1159,17 +1265,40 @@ void main() { verify(client?.getBatchHistory(args: historyBatchArgs3)).called(2); verify(client?.getBatchHistory(args: historyBatchArgs4)).called(2); verify(client?.getBatchHistory(args: historyBatchArgs5)).called(2); + + verify(client?.getBatchHistory(args: { + "0": [ + "dd63fc12f5e6c1ada2cf3c941d1648e6d561ce4024747bb2117d72112d83287c" + ] + })).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "cd3dd4abe4f9efc7149ba334d2d6790020331805b0bd5c7ed89a3ac6a22f10b9" + ] + })).called(1); + verify(client?.getBatchHistory(args: { + "0": [ + "42d6e40636f4740f9c7f95ef0bbc2a4c17f54da2bc98a32a622e2bf73eb675c3" + ] + })).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "587943864cefed4f1643a5ee2ce2b3c13a0c6ad7c435373f0ac328e144a15c1e" + ] + })).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "86906979fc9107d06d560275d7de8305b69d7189c3206ac9070ad76e6abff874" + ] + })).called(2); + verify(client?.getBatchHistory(args: { + "0": [ + "c068e7fa4aa0b8a63114f6d11c047ca4be6a8fa333eb0dac48506e8f150af73b" + ] + })).called(2); verify(cachedClient?.clearSharedTransactionCache(coin: Coin.namecoin)) .called(1); - for (final arg in dynamicArgValues) { - final map = Map>.from(arg as Map); - - verify(client?.getBatchHistory(args: map)).called(1); - expect(activeScriptHashes.contains(map.values.first.first as String), - true); - } - expect(secureStore?.writes, 19); expect(secureStore?.reads, 32); expect(secureStore?.deletes, 12);