From 722a884553b1af798e07356523c15908acaccb7c Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 19 Jan 2023 13:47:51 -0600 Subject: [PATCH] coin tests code error cleanup --- .gitignore | 1 + .../coins/bitcoin/bitcoin_wallet_test.dart | 102 ++++++++---------- .../bitcoincash/bitcoincash_wallet_test.dart | 31 ++---- .../coins/dogecoin/dogecoin_wallet_test.dart | 28 +---- .../services/coins/firo/firo_wallet_test.dart | 74 ++++++++----- .../coins/namecoin/namecoin_wallet_test.dart | 17 +-- .../coins/particl/particl_wallet_test.dart | 17 +-- 7 files changed, 106 insertions(+), 164 deletions(-) diff --git a/.gitignore b/.gitignore index e2b5c5a6a..ed66fa960 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,4 @@ libcw_monero.dll libcw_wownero.dll libepic_cash_wallet.dll libmobileliblelantus.dll +/libisar.so diff --git a/test/services/coins/bitcoin/bitcoin_wallet_test.dart b/test/services/coins/bitcoin/bitcoin_wallet_test.dart index 3b3b35e73..82c6e8f57 100644 --- a/test/services/coins/bitcoin/bitcoin_wallet_test.dart +++ b/test/services/coins/bitcoin/bitcoin_wallet_test.dart @@ -8,9 +8,9 @@ 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/isar/models/blockchain_data/utxo.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'; import 'package:stackwallet/services/coins/bitcoin/bitcoin_wallet.dart'; import 'package:stackwallet/services/price.dart'; import 'package:stackwallet/services/transaction_notification_tracker.dart'; @@ -612,18 +612,6 @@ void main() async { if (!hiveAdaptersRegistered) { hiveAdaptersRegistered = true; - // Registering Transaction Model Adapters - Hive.registerAdapter(TransactionDataAdapter()); - Hive.registerAdapter(TransactionChunkAdapter()); - Hive.registerAdapter(TransactionAdapter()); - Hive.registerAdapter(InputAdapter()); - Hive.registerAdapter(OutputAdapter()); - - // Registering Utxo Model Adapters - Hive.registerAdapter(UtxoDataAdapter()); - Hive.registerAdapter(UtxoObjectAdapter()); - Hive.registerAdapter(StatusAdapter()); - final wallets = await Hive.openBox('wallets'); await wallets.put('currentWalletName', testWalletName); } @@ -1295,50 +1283,48 @@ void main() async { // // }); // - // test("get utxos fails", () async { - // btc = BitcoinWallet( - // walletId: testWalletId, - // walletName: testWalletName, - // coin: Coin.bitcoinTestNet, - // client: client!, - // cachedClient: cachedClient!, - // tracker: tracker!, - // - // 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); - // - // }); + test("get utxos fails", () async { + btc = BitcoinWallet( + walletId: testWalletId, + walletName: testWalletName, + coin: Coin.bitcoinTestNet, + client: client!, + cachedClient: cachedClient!, + tracker: tracker!, + 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 Hive.openBox(testWalletId); + await Hive.openBox(DB.boxNamePrefs); + + when(client?.getBatchUTXOs(args: anyNamed("args"))) + .thenThrow(Exception("some exception")); + + await btc?.initializeNew(); + await btc?.initializeExisting(); + + final outputs = await btc!.utxos; + 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); + }); // // test("chain height fetch, update, and get", () async { // btc = BitcoinWallet( diff --git a/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart b/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart index 0a28b9d1f..7bf17df50 100644 --- a/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart +++ b/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart @@ -2,14 +2,14 @@ import 'package:decimal/decimal.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:hive/hive.dart'; import 'package:hive_test/hive_test.dart'; +import 'package:isar/isar.dart'; 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/isar/models/blockchain_data/utxo.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'; import 'package:stackwallet/services/coins/bitcoincash/bitcoincash_wallet.dart'; import 'package:stackwallet/services/price.dart'; import 'package:stackwallet/services/transaction_notification_tracker.dart'; @@ -22,7 +22,9 @@ import 'bitcoincash_wallet_test_parameters.dart'; @GenerateMocks( [ElectrumX, CachedElectrumX, PriceAPI, TransactionNotificationTracker]) -void main() { +void main() async { + await Isar.initializeIsarCore(download: true); + group("bitcoincash constants", () { test("bitcoincash minimum confirmations", () async { expect(MINIMUM_CONFIRMATIONS, 1); @@ -580,18 +582,6 @@ void main() { if (!hiveAdaptersRegistered) { hiveAdaptersRegistered = true; - // Registering Transaction Model Adapters - Hive.registerAdapter(TransactionDataAdapter()); - Hive.registerAdapter(TransactionChunkAdapter()); - Hive.registerAdapter(TransactionAdapter()); - Hive.registerAdapter(InputAdapter()); - Hive.registerAdapter(OutputAdapter()); - - // Registering Utxo Model Adapters - Hive.registerAdapter(UtxoDataAdapter()); - Hive.registerAdapter(UtxoObjectAdapter()); - Hive.registerAdapter(StatusAdapter()); - final wallets = await Hive.openBox('wallets'); await wallets.put('currentWalletName', testWalletName); } @@ -1162,14 +1152,9 @@ void main() { await bch?.initializeNew(); await bch?.initializeExisting(); - final utxoData = await bch?.utxoData; - expect(utxoData, isA()); - expect(utxoData.toString(), - r"{totalUserCurrency: 0.00, satoshiBalance: 0, bitcoinBalance: 0, unspentOutputArray: []}"); - - final outputs = await bch?.unspentOutputs; - expect(outputs, isA>()); - expect(outputs?.length, 0); + final outputs = await bch!.utxos; + expect(outputs, isA>()); + expect(outputs.length, 0); verifyNever(client?.ping()).called(0); verify(client?.getServerFeatures()).called(1); diff --git a/test/services/coins/dogecoin/dogecoin_wallet_test.dart b/test/services/coins/dogecoin/dogecoin_wallet_test.dart index bc59e7b98..8b2d83eb7 100644 --- a/test/services/coins/dogecoin/dogecoin_wallet_test.dart +++ b/test/services/coins/dogecoin/dogecoin_wallet_test.dart @@ -1,5 +1,3 @@ -// import 'dart:typed_data'; - import 'package:bitcoindart/bitcoindart.dart'; import 'package:decimal/decimal.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -10,9 +8,8 @@ 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/isar/models/blockchain_data/utxo.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'; import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart'; import 'package:stackwallet/services/price.dart'; import 'package:stackwallet/services/transaction_notification_tracker.dart'; @@ -473,18 +470,6 @@ void main() { if (!hiveAdaptersRegistered) { hiveAdaptersRegistered = true; - // Registering Transaction Model Adapters - Hive.registerAdapter(TransactionDataAdapter()); - Hive.registerAdapter(TransactionChunkAdapter()); - Hive.registerAdapter(TransactionAdapter()); - Hive.registerAdapter(InputAdapter()); - Hive.registerAdapter(OutputAdapter()); - - // Registering Utxo Model Adapters - Hive.registerAdapter(UtxoDataAdapter()); - Hive.registerAdapter(UtxoObjectAdapter()); - Hive.registerAdapter(StatusAdapter()); - final wallets = await Hive.openBox('wallets'); await wallets.put('currentWalletName', testWalletName); } @@ -1064,14 +1049,9 @@ void main() { await doge?.initializeNew(); await doge?.initializeExisting(); - final utxoData = await doge?.utxoData; - expect(utxoData, isA()); - expect(utxoData.toString(), - r"{totalUserCurrency: 0.00, satoshiBalance: 0, bitcoinBalance: 0, unspentOutputArray: []}"); - - final outputs = await doge?.unspentOutputs; - expect(outputs, isA>()); - expect(outputs?.length, 0); + final outputs = await doge!.utxos; + expect(outputs, isA>()); + expect(outputs.length, 0); verifyNever(client?.ping()).called(0); verify(client?.getServerFeatures()).called(1); diff --git a/test/services/coins/firo/firo_wallet_test.dart b/test/services/coins/firo/firo_wallet_test.dart index 2fc203a9b..110eab9c1 100644 --- a/test/services/coins/firo/firo_wallet_test.dart +++ b/test/services/coins/firo/firo_wallet_test.dart @@ -11,7 +11,11 @@ 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/models/models.dart'; +import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart'; +import 'package:stackwallet/models/isar/models/blockchain_data/utxo.dart'; +import 'package:stackwallet/models/lelantus_coin.dart'; +import 'package:stackwallet/models/lelantus_fee_data.dart'; +import 'package:stackwallet/models/paymint/transactions_model.dart' as old; import 'package:stackwallet/services/coins/firo/firo_wallet.dart'; import 'package:stackwallet/services/price.dart'; import 'package:stackwallet/services/transaction_notification_tracker.dart'; @@ -41,7 +45,7 @@ void main() { test("isolateRestore success", () async { final cachedClient = MockCachedElectrumX(); - final txData = TransactionData.fromJson(dateTimeChunksJson); + final txDataOLD = old.TransactionData.fromJson(dateTimeChunksJson); final Map setData = {}; setData[1] = GetAnonymitySetSampleData.data; final usedSerials = GetUsedSerialsSampleData.serials["serials"] as List; @@ -74,6 +78,34 @@ void main() { firoNetwork, ); const currentHeight = 100000000000; + + final txData = txDataOLD + .getAllTransactions() + .values + .map( + (t) => Transaction( + walletId: "walletId", + txid: t.txid, + timestamp: t.timestamp, + type: t.txType == "Sent" + ? TransactionType.outgoing + : TransactionType.incoming, + subType: t.subType == "mint" + ? TransactionSubType.mint + : t.subType == "join" + ? TransactionSubType.join + : TransactionSubType.none, + amount: t.amount, + fee: t.fees, + height: t.height, + isCancelled: t.isCancelled, + isLelantus: null, + slateId: t.slateId, + otherData: t.otherData, + ), + ) + .toList(); + final result = await staticProcessRestore(txData, message, currentHeight); expect(result, isA>()); @@ -512,18 +544,6 @@ void main() { if (!hiveAdaptersRegistered) { hiveAdaptersRegistered = true; - // Registering Transaction Model Adapters - Hive.registerAdapter(TransactionDataAdapter()); - Hive.registerAdapter(TransactionChunkAdapter()); - Hive.registerAdapter(TransactionAdapter()); - Hive.registerAdapter(InputAdapter()); - Hive.registerAdapter(OutputAdapter()); - - // Registering Utxo Model Adapters - Hive.registerAdapter(UtxoDataAdapter()); - Hive.registerAdapter(UtxoObjectAdapter()); - Hive.registerAdapter(StatusAdapter()); - // Registering Lelantus Model Adapters Hive.registerAdapter(LelantusCoinAdapter()); } @@ -1181,21 +1201,19 @@ void main() { const MethodChannel('uk.spiralarm.flutter/devicelocale') .setMockMethodCallHandler((methodCall) async => 'en_US'); - List utxos = [ - UtxoObject( + List utxos = [ + UTXO( txid: BuildMintTxTestParams.utxoInfo["txid"] as String, vout: BuildMintTxTestParams.utxoInfo["vout"] as int, value: BuildMintTxTestParams.utxoInfo["value"] as int, - txName: '', - status: Status( - confirmed: false, - blockHash: "", - blockHeight: -1, - blockTime: 42, - confirmations: 0), isCoinbase: false, - blocked: false, - fiatWorth: '', + walletId: '', + name: '', + isBlocked: false, + blockedReason: '', + blockHash: '', + blockHeight: -1, + blockTime: 42, ) ]; const sats = 9658; @@ -3023,7 +3041,7 @@ void main() { expect(firo.balance.getTotal(), Decimal.parse("0.00021594")); }); - test("get transactionData", () async { + test("get transactions", () async { final client = MockElectrumX(); final cachedClient = MockCachedElectrumX(); final secureStore = FakeSecureStorage(); @@ -3118,9 +3136,9 @@ void main() { 'receivingAddresses', RefreshTestParams.receivingAddresses); await wallet.put('changeAddresses', RefreshTestParams.changeAddresses); - final txData = await firo.transactionData; + final txData = await firo.transactions; - expect(txData, isA()); + expect(txData, isA>()); // kill timer and listener await firo.exit(); diff --git a/test/services/coins/namecoin/namecoin_wallet_test.dart b/test/services/coins/namecoin/namecoin_wallet_test.dart index 621f2d9a3..041882470 100644 --- a/test/services/coins/namecoin/namecoin_wallet_test.dart +++ b/test/services/coins/namecoin/namecoin_wallet_test.dart @@ -8,8 +8,6 @@ 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'; import 'package:stackwallet/services/coins/namecoin/namecoin_wallet.dart'; import 'package:stackwallet/services/price.dart'; import 'package:stackwallet/services/transaction_notification_tracker.dart'; @@ -18,7 +16,6 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'namecoin_history_sample_data.dart'; import 'namecoin_transaction_data_samples.dart'; -import 'namecoin_utxo_sample_data.dart'; import 'namecoin_wallet_test.mocks.dart'; import 'namecoin_wallet_test_parameters.dart'; @@ -442,18 +439,6 @@ void main() { if (!hiveAdaptersRegistered) { hiveAdaptersRegistered = true; - // Registering Transaction Model Adapters - Hive.registerAdapter(TransactionDataAdapter()); - Hive.registerAdapter(TransactionChunkAdapter()); - Hive.registerAdapter(TransactionAdapter()); - Hive.registerAdapter(InputAdapter()); - Hive.registerAdapter(OutputAdapter()); - - // Registering Utxo Model Adapters - Hive.registerAdapter(UtxoDataAdapter()); - Hive.registerAdapter(UtxoObjectAdapter()); - Hive.registerAdapter(StatusAdapter()); - final wallets = await Hive.openBox('wallets'); await wallets.put('currentWalletName', testWalletName); } @@ -1354,7 +1339,7 @@ void main() { "bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0", "bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc")); - nmc?.outputsList = utxoList; + // nmc?.outputsList = utxoList; bool didThrow = false; try { diff --git a/test/services/coins/particl/particl_wallet_test.dart b/test/services/coins/particl/particl_wallet_test.dart index 4cac06c9f..1ef429209 100644 --- a/test/services/coins/particl/particl_wallet_test.dart +++ b/test/services/coins/particl/particl_wallet_test.dart @@ -6,7 +6,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/models/models.dart'; +import 'package:stackwallet/models/paymint/fee_object_model.dart'; import 'package:stackwallet/services/coins/particl/particl_wallet.dart'; import 'package:stackwallet/services/price.dart'; import 'package:stackwallet/services/transaction_notification_tracker.dart'; @@ -15,7 +15,6 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'particl_history_sample_data.dart'; import 'particl_transaction_data_samples.dart'; -import 'particl_utxo_sample_data.dart'; import 'particl_wallet_test.mocks.dart'; import 'particl_wallet_test_parameters.dart'; @@ -489,18 +488,6 @@ void main() { if (!hiveAdaptersRegistered) { hiveAdaptersRegistered = true; - // Registering Transaction Model Adapters - Hive.registerAdapter(TransactionDataAdapter()); - Hive.registerAdapter(TransactionChunkAdapter()); - Hive.registerAdapter(TransactionAdapter()); - Hive.registerAdapter(InputAdapter()); - Hive.registerAdapter(OutputAdapter()); - - // Registering Utxo Model Adapters - Hive.registerAdapter(UtxoDataAdapter()); - Hive.registerAdapter(UtxoObjectAdapter()); - Hive.registerAdapter(StatusAdapter()); - final wallets = await Hive.openBox('wallets'); await wallets.put('currentWalletName', testWalletName); } @@ -1282,7 +1269,7 @@ void main() { "pw1qvr6ehcm44vvqe96mxy9zw9aa5sa5yezvr2r94s", "pw1q66xtkhqzcue808nlg8tp48uq7fshmaddljtkpy")); - part?.outputsList = utxoList; + // part?.outputsList = utxoList; bool didThrow = false; try {