add mockable override option for testing purposes

This commit is contained in:
julian 2023-01-19 14:33:23 -06:00
parent 8921302ee0
commit 60e850f442
22 changed files with 75 additions and 88 deletions

View file

@ -10,6 +10,7 @@ import 'package:bs58check/bs58check.dart' as bs58check;
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:isar/isar.dart'; import 'package:isar/isar.dart';
import 'package:stackwallet/db/main_db.dart';
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
import 'package:stackwallet/electrumx_rpc/electrumx.dart'; import 'package:stackwallet/electrumx_rpc/electrumx.dart';
import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/balance.dart';
@ -659,8 +660,6 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
p2wpkhChangeAddressArray.add(address); p2wpkhChangeAddressArray.add(address);
} }
await isarInit();
await db.putAddresses([ await db.putAddresses([
...p2wpkhReceiveAddressArray, ...p2wpkhReceiveAddressArray,
...p2wpkhChangeAddressArray, ...p2wpkhChangeAddressArray,
@ -1164,7 +1163,6 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
} }
await _prefs.init(); await _prefs.init();
await isarInit();
} }
// hack to add tx to txData before refresh completes // hack to add tx to txData before refresh completes
@ -1249,6 +1247,7 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
required CachedElectrumX cachedClient, required CachedElectrumX cachedClient,
required TransactionNotificationTracker tracker, required TransactionNotificationTracker tracker,
required SecureStorageInterface secureStore, required SecureStorageInterface secureStore,
MainDB? mockableOverride,
}) { }) {
txTracker = tracker; txTracker = tracker;
_walletId = walletId; _walletId = walletId;
@ -1258,6 +1257,7 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
_cachedElectrumXClient = cachedClient; _cachedElectrumXClient = cachedClient;
_secureStore = secureStore; _secureStore = secureStore;
initCache(walletId, coin); initCache(walletId, coin);
isarInit(mockableOverride: mockableOverride);
} }
@override @override

View file

@ -11,6 +11,7 @@ import 'package:bs58check/bs58check.dart' as bs58check;
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:isar/isar.dart'; import 'package:isar/isar.dart';
import 'package:stackwallet/db/main_db.dart';
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
import 'package:stackwallet/electrumx_rpc/electrumx.dart'; import 'package:stackwallet/electrumx_rpc/electrumx.dart';
import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/balance.dart';
@ -604,8 +605,6 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
p2shChangeAddressArray.add(address); p2shChangeAddressArray.add(address);
} }
await isarInit();
await db.putAddresses([ await db.putAddresses([
...p2pkhReceiveAddressArray, ...p2pkhReceiveAddressArray,
...p2pkhChangeAddressArray, ...p2pkhChangeAddressArray,
@ -1094,7 +1093,6 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
} }
await _prefs.init(); await _prefs.init();
await isarInit();
} }
// hack to add tx to txData before refresh completes // hack to add tx to txData before refresh completes
@ -1206,6 +1204,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
required CachedElectrumX cachedClient, required CachedElectrumX cachedClient,
required TransactionNotificationTracker tracker, required TransactionNotificationTracker tracker,
required SecureStorageInterface secureStore, required SecureStorageInterface secureStore,
MainDB? mockableOverride,
}) { }) {
txTracker = tracker; txTracker = tracker;
_walletId = walletId; _walletId = walletId;
@ -1215,6 +1214,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
_cachedElectrumXClient = cachedClient; _cachedElectrumXClient = cachedClient;
_secureStore = secureStore; _secureStore = secureStore;
initCache(walletId, coin); initCache(walletId, coin);
isarInit(mockableOverride: mockableOverride);
} }
@override @override
@ -1372,8 +1372,6 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
_generateAddressForChain(1, 0, DerivePathType.bip49), _generateAddressForChain(1, 0, DerivePathType.bip49),
]); ]);
await isarInit();
await db.putAddresses(initialAddresses); await db.putAddresses(initialAddresses);
Logging.instance.log("_generateNewWalletFinished", level: LogLevel.Info); Logging.instance.log("_generateNewWalletFinished", level: LogLevel.Info);

View file

@ -41,6 +41,8 @@ import 'package:stackwallet/utilities/prefs.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
import '../../../db/main_db.dart';
const int MINIMUM_CONFIRMATIONS = 1; const int MINIMUM_CONFIRMATIONS = 1;
const int DUST_LIMIT = 1000000; const int DUST_LIMIT = 1000000;
@ -519,8 +521,6 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
p2pkhChangeAddressArray.add(address); p2pkhChangeAddressArray.add(address);
} }
await isarInit();
await db.putAddresses([ await db.putAddresses([
...p2pkhReceiveAddressArray, ...p2pkhReceiveAddressArray,
...p2pkhChangeAddressArray, ...p2pkhChangeAddressArray,
@ -999,7 +999,6 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
} }
await _prefs.init(); await _prefs.init();
await isarInit();
} }
// hack to add tx to txData before refresh completes // hack to add tx to txData before refresh completes
@ -1084,6 +1083,7 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
required CachedElectrumX cachedClient, required CachedElectrumX cachedClient,
required TransactionNotificationTracker tracker, required TransactionNotificationTracker tracker,
required SecureStorageInterface secureStore, required SecureStorageInterface secureStore,
MainDB? mockableOverride,
}) { }) {
txTracker = tracker; txTracker = tracker;
_walletId = walletId; _walletId = walletId;
@ -1093,6 +1093,7 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
_cachedElectrumXClient = cachedClient; _cachedElectrumXClient = cachedClient;
_secureStore = secureStore; _secureStore = secureStore;
initCache(walletId, coin); initCache(walletId, coin);
isarInit(mockableOverride: mockableOverride);
} }
@override @override
@ -1234,8 +1235,6 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
final initialChangeAddressP2PKH = final initialChangeAddressP2PKH =
await _generateAddressForChain(1, 0, DerivePathType.bip44); await _generateAddressForChain(1, 0, DerivePathType.bip44);
await isarInit();
await db.putAddresses([ await db.putAddresses([
initialReceivingAddressP2PKH, initialReceivingAddressP2PKH,
initialChangeAddressP2PKH, initialChangeAddressP2PKH,

View file

@ -10,6 +10,7 @@ import 'package:http/http.dart';
import 'package:isar/isar.dart'; import 'package:isar/isar.dart';
import 'package:mutex/mutex.dart'; import 'package:mutex/mutex.dart';
import 'package:stack_wallet_backup/generate_password.dart'; import 'package:stack_wallet_backup/generate_password.dart';
import 'package:stackwallet/db/main_db.dart';
import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/balance.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models; import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models;
import 'package:stackwallet/models/node_model.dart'; import 'package:stackwallet/models/node_model.dart';
@ -528,17 +529,20 @@ class EpicCashWallet extends CoinServiceAPI
NodeModel? _epicNode; NodeModel? _epicNode;
EpicCashWallet( EpicCashWallet({
{required String walletId, required String walletId,
required String walletName, required String walletName,
required Coin coin, required Coin coin,
required SecureStorageInterface secureStore}) { required SecureStorageInterface secureStore,
MainDB? mockableOverride,
}) {
_walletId = walletId; _walletId = walletId;
_walletName = walletName; _walletName = walletName;
_coin = coin; _coin = coin;
_secureStore = secureStore; _secureStore = secureStore;
initCache(walletId, coin); initCache(walletId, coin);
initEpicCashHive(walletId); initEpicCashHive(walletId);
isarInit(mockableOverride: mockableOverride);
Logging.instance.log("$walletName isolate length: ${isolates.length}", Logging.instance.log("$walletName isolate length: ${isolates.length}",
level: LogLevel.Info); level: LogLevel.Info);
@ -969,7 +973,6 @@ class EpicCashWallet extends CoinServiceAPI
Logging.instance.log("Opening existing ${coin.prettyName} wallet", Logging.instance.log("Opening existing ${coin.prettyName} wallet",
level: LogLevel.Info); level: LogLevel.Info);
await isarInit();
final config = await getRealConfig(); final config = await getRealConfig();
final password = await _secureStore.read(key: '${_walletId}_password'); final password = await _secureStore.read(key: '${_walletId}_password');
@ -1039,8 +1042,6 @@ class EpicCashWallet extends CoinServiceAPI
String stringConfig = await getConfig(); String stringConfig = await getConfig();
String epicboxConfig = await getEpicBoxConfig(); String epicboxConfig = await getEpicBoxConfig();
await isarInit();
await _secureStore.write( await _secureStore.write(
key: '${_walletId}_mnemonic', value: mnemonicString); key: '${_walletId}_mnemonic', value: mnemonicString);
await _secureStore.write(key: '${_walletId}_config', value: stringConfig); await _secureStore.write(key: '${_walletId}_config', value: stringConfig);
@ -1081,7 +1082,6 @@ class EpicCashWallet extends CoinServiceAPI
epicUpdateChangeIndex(0), epicUpdateChangeIndex(0),
]); ]);
await isarInit();
final initialReceivingAddress = await _getReceivingAddressForIndex(0); final initialReceivingAddress = await _getReceivingAddressForIndex(0);
await db.putAddress(initialReceivingAddress); await db.putAddress(initialReceivingAddress);

View file

@ -11,6 +11,7 @@ import 'package:decimal/decimal.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:isar/isar.dart'; import 'package:isar/isar.dart';
import 'package:lelantus/lelantus.dart'; import 'package:lelantus/lelantus.dart';
import 'package:stackwallet/db/main_db.dart';
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
import 'package:stackwallet/electrumx_rpc/electrumx.dart'; import 'package:stackwallet/electrumx_rpc/electrumx.dart';
import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/balance.dart';
@ -1213,6 +1214,7 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
required CachedElectrumX cachedClient, required CachedElectrumX cachedClient,
required TransactionNotificationTracker tracker, required TransactionNotificationTracker tracker,
required SecureStorageInterface secureStore, required SecureStorageInterface secureStore,
MainDB? mockableOverride,
}) { }) {
txTracker = tracker; txTracker = tracker;
_walletId = walletId; _walletId = walletId;
@ -1223,6 +1225,7 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
_secureStore = secureStore; _secureStore = secureStore;
initCache(walletId, coin); initCache(walletId, coin);
initFiroHive(walletId); initFiroHive(walletId);
isarInit(mockableOverride: mockableOverride);
Logging.instance.log("$walletName isolates length: ${isolates.length}", Logging.instance.log("$walletName isolates length: ${isolates.length}",
level: LogLevel.Info); level: LogLevel.Info);
@ -1828,7 +1831,6 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
"Attempted to initialize an existing wallet using an unknown wallet ID!"); "Attempted to initialize an existing wallet using an unknown wallet ID!");
} }
await _prefs.init(); await _prefs.init();
await isarInit();
} }
Future<bool> refreshIfThereIsNewData() async { Future<bool> refreshIfThereIsNewData() async {
@ -2099,8 +2101,6 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
final initialReceivingAddress = await _generateAddressForChain(0, 0); final initialReceivingAddress = await _generateAddressForChain(0, 0);
final initialChangeAddress = await _generateAddressForChain(1, 0); final initialChangeAddress = await _generateAddressForChain(1, 0);
await isarInit();
await db.putAddresses([ await db.putAddresses([
initialReceivingAddress, initialReceivingAddress,
initialChangeAddress, initialChangeAddress,
@ -4292,8 +4292,6 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
Logging.instance Logging.instance
.log("PROCESSORS ${Platform.numberOfProcessors}", level: LogLevel.Info); .log("PROCESSORS ${Platform.numberOfProcessors}", level: LogLevel.Info);
try { try {
await isarInit();
final latestSetId = await getLatestSetId(); final latestSetId = await getLatestSetId();
final setDataMap = getSetDataMap(latestSetId); final setDataMap = getSetDataMap(latestSetId);
final usedSerialNumbers = getUsedCoinSerials(); final usedSerialNumbers = getUsedCoinSerials();

View file

@ -11,6 +11,7 @@ import 'package:crypto/crypto.dart';
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:isar/isar.dart'; import 'package:isar/isar.dart';
import 'package:stackwallet/db/main_db.dart';
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
import 'package:stackwallet/electrumx_rpc/electrumx.dart'; import 'package:stackwallet/electrumx_rpc/electrumx.dart';
import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/balance.dart';
@ -677,8 +678,6 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
p2wpkhChangeAddressArray.add(address); p2wpkhChangeAddressArray.add(address);
} }
await isarInit();
await db.putAddresses([ await db.putAddresses([
...p2wpkhReceiveAddressArray, ...p2wpkhReceiveAddressArray,
...p2wpkhChangeAddressArray, ...p2wpkhChangeAddressArray,
@ -1182,7 +1181,6 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
"Attempted to initialize an existing wallet using an unknown wallet ID!"); "Attempted to initialize an existing wallet using an unknown wallet ID!");
} }
await _prefs.init(); await _prefs.init();
await isarInit();
} }
// hack to add tx to txData before refresh completes // hack to add tx to txData before refresh completes
@ -1267,6 +1265,7 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
required CachedElectrumX cachedClient, required CachedElectrumX cachedClient,
required TransactionNotificationTracker tracker, required TransactionNotificationTracker tracker,
required SecureStorageInterface secureStore, required SecureStorageInterface secureStore,
MainDB? mockableOverride,
}) { }) {
txTracker = tracker; txTracker = tracker;
_walletId = walletId; _walletId = walletId;
@ -1276,6 +1275,7 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
_cachedElectrumXClient = cachedClient; _cachedElectrumXClient = cachedClient;
_secureStore = secureStore; _secureStore = secureStore;
initCache(walletId, coin); initCache(walletId, coin);
isarInit(mockableOverride: mockableOverride);
} }
@override @override
@ -1473,8 +1473,6 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
_generateAddressForChain(1, 0, DerivePathType.bip49), _generateAddressForChain(1, 0, DerivePathType.bip49),
]); ]);
await isarInit();
await db.putAddresses(initialAddresses); await db.putAddresses(initialAddresses);
Logging.instance.log("_generateNewWalletFinished", level: LogLevel.Info); Logging.instance.log("_generateNewWalletFinished", level: LogLevel.Info);

View file

@ -23,6 +23,7 @@ import 'package:flutter_libmonero/monero/monero.dart';
import 'package:flutter_libmonero/view_model/send/output.dart' as monero_output; import 'package:flutter_libmonero/view_model/send/output.dart' as monero_output;
import 'package:isar/isar.dart'; import 'package:isar/isar.dart';
import 'package:mutex/mutex.dart'; import 'package:mutex/mutex.dart';
import 'package:stackwallet/db/main_db.dart';
import 'package:stackwallet/hive/db.dart'; import 'package:stackwallet/hive/db.dart';
import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/balance.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models; import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models;
@ -83,6 +84,7 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
required Coin coin, required Coin coin,
required SecureStorageInterface secureStorage, required SecureStorageInterface secureStorage,
Prefs? prefs, Prefs? prefs,
MainDB? mockableOverride,
}) { }) {
_walletId = walletId; _walletId = walletId;
_walletName = walletName; _walletName = walletName;
@ -90,6 +92,7 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
_secureStorage = secureStorage; _secureStorage = secureStorage;
_prefs = prefs ?? Prefs.instance; _prefs = prefs ?? Prefs.instance;
initCache(walletId, coin); initCache(walletId, coin);
isarInit(mockableOverride: mockableOverride);
} }
@override @override
@ -269,7 +272,7 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
keysStorage = KeyService(_secureStorage); keysStorage = KeyService(_secureStorage);
await _prefs.init(); await _prefs.init();
await isarInit();
// final data = // final data =
// DB.instance.get<dynamic>(boxName: walletId, key: "latest_tx_model") // DB.instance.get<dynamic>(boxName: walletId, key: "latest_tx_model")
// as TransactionData?; // as TransactionData?;
@ -389,7 +392,6 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
// Generate and add addresses to relevant arrays // Generate and add addresses to relevant arrays
final initialReceivingAddress = await _generateAddressForChain(0, 0); final initialReceivingAddress = await _generateAddressForChain(0, 0);
// final initialChangeAddress = await _generateAddressForChain(1, 0); // final initialChangeAddress = await _generateAddressForChain(1, 0);
await isarInit();
await db.putAddress(initialReceivingAddress); await db.putAddress(initialReceivingAddress);

View file

@ -11,6 +11,7 @@ import 'package:crypto/crypto.dart';
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:isar/isar.dart'; import 'package:isar/isar.dart';
import 'package:stackwallet/db/main_db.dart';
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
import 'package:stackwallet/electrumx_rpc/electrumx.dart'; import 'package:stackwallet/electrumx_rpc/electrumx.dart';
import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/balance.dart';
@ -667,8 +668,6 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
p2wpkhChangeAddressArray.add(address); p2wpkhChangeAddressArray.add(address);
} }
await isarInit();
await db.putAddresses([ await db.putAddresses([
...p2wpkhReceiveAddressArray, ...p2wpkhReceiveAddressArray,
...p2wpkhChangeAddressArray, ...p2wpkhChangeAddressArray,
@ -1171,7 +1170,6 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
"Attempted to initialize an existing wallet using an unknown wallet ID!"); "Attempted to initialize an existing wallet using an unknown wallet ID!");
} }
await _prefs.init(); await _prefs.init();
await isarInit();
} }
// hack to add tx to txData before refresh completes // hack to add tx to txData before refresh completes
@ -1256,6 +1254,7 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
required CachedElectrumX cachedClient, required CachedElectrumX cachedClient,
required TransactionNotificationTracker tracker, required TransactionNotificationTracker tracker,
required SecureStorageInterface secureStore, required SecureStorageInterface secureStore,
MainDB? mockableOverride,
}) { }) {
txTracker = tracker; txTracker = tracker;
_walletId = walletId; _walletId = walletId;
@ -1265,6 +1264,7 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
_cachedElectrumXClient = cachedClient; _cachedElectrumXClient = cachedClient;
_secureStore = secureStore; _secureStore = secureStore;
initCache(walletId, coin); initCache(walletId, coin);
isarInit(mockableOverride: mockableOverride);
} }
@override @override
@ -1450,8 +1450,6 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
_generateAddressForChain(1, 0, DerivePathType.bip49), _generateAddressForChain(1, 0, DerivePathType.bip49),
]); ]);
await isarInit();
await db.putAddresses(initialAddresses); await db.putAddresses(initialAddresses);
Logging.instance.log("_generateNewWalletFinished", level: LogLevel.Info); Logging.instance.log("_generateNewWalletFinished", level: LogLevel.Info);

View file

@ -11,6 +11,7 @@ import 'package:crypto/crypto.dart';
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:isar/isar.dart'; import 'package:isar/isar.dart';
import 'package:stackwallet/db/main_db.dart';
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
import 'package:stackwallet/electrumx_rpc/electrumx.dart'; import 'package:stackwallet/electrumx_rpc/electrumx.dart';
import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/balance.dart';
@ -602,8 +603,6 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
p2wpkhChangeAddressArray.add(address); p2wpkhChangeAddressArray.add(address);
} }
await isarInit();
await db.putAddresses([ await db.putAddresses([
...p2wpkhReceiveAddressArray, ...p2wpkhReceiveAddressArray,
...p2wpkhChangeAddressArray, ...p2wpkhChangeAddressArray,
@ -1101,7 +1100,6 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
"Attempted to initialize an existing wallet using an unknown wallet ID!"); "Attempted to initialize an existing wallet using an unknown wallet ID!");
} }
await _prefs.init(); await _prefs.init();
await isarInit();
} }
// TODO make sure this copied implementation from bitcoin_wallet.dart applies for particl just as well--or import it // TODO make sure this copied implementation from bitcoin_wallet.dart applies for particl just as well--or import it
@ -1187,6 +1185,7 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
required CachedElectrumX cachedClient, required CachedElectrumX cachedClient,
required TransactionNotificationTracker tracker, required TransactionNotificationTracker tracker,
required SecureStorageInterface secureStore, required SecureStorageInterface secureStore,
MainDB? mockableOverride,
}) { }) {
txTracker = tracker; txTracker = tracker;
_walletId = walletId; _walletId = walletId;
@ -1196,6 +1195,7 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
_cachedElectrumXClient = cachedClient; _cachedElectrumXClient = cachedClient;
_secureStore = secureStore; _secureStore = secureStore;
initCache(walletId, coin); initCache(walletId, coin);
isarInit(mockableOverride: mockableOverride);
} }
@override @override
@ -1364,8 +1364,6 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
_generateAddressForChain(1, 0, DerivePathType.bip44), _generateAddressForChain(1, 0, DerivePathType.bip44),
]); ]);
await isarInit();
await db.putAddresses(initialAddresses); await db.putAddresses(initialAddresses);
Logging.instance.log("_generateNewWalletFinished", level: LogLevel.Info); Logging.instance.log("_generateNewWalletFinished", level: LogLevel.Info);

View file

@ -25,6 +25,7 @@ import 'package:flutter_libmonero/view_model/send/output.dart'
import 'package:flutter_libmonero/wownero/wownero.dart'; import 'package:flutter_libmonero/wownero/wownero.dart';
import 'package:isar/isar.dart'; import 'package:isar/isar.dart';
import 'package:mutex/mutex.dart'; import 'package:mutex/mutex.dart';
import 'package:stackwallet/db/main_db.dart';
import 'package:stackwallet/hive/db.dart'; import 'package:stackwallet/hive/db.dart';
import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/balance.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models; import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models;
@ -85,6 +86,7 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
required Coin coin, required Coin coin,
required SecureStorageInterface secureStorage, required SecureStorageInterface secureStorage,
Prefs? prefs, Prefs? prefs,
MainDB? mockableOverride,
}) { }) {
_walletId = walletId; _walletId = walletId;
_walletName = walletName; _walletName = walletName;
@ -92,6 +94,7 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
_secureStorage = secureStorage; _secureStorage = secureStorage;
_prefs = prefs ?? Prefs.instance; _prefs = prefs ?? Prefs.instance;
initCache(walletId, coin); initCache(walletId, coin);
isarInit(mockableOverride: mockableOverride);
} }
@override @override
@ -293,7 +296,6 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
keysStorage = KeyService(_secureStorage); keysStorage = KeyService(_secureStorage);
await _prefs.init(); await _prefs.init();
await isarInit();
String? password; String? password;
try { try {
@ -397,7 +399,6 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
// Generate and add addresses to relevant arrays // Generate and add addresses to relevant arrays
final initialReceivingAddress = await _generateAddressForChain(0, 0); final initialReceivingAddress = await _generateAddressForChain(0, 0);
// final initialChangeAddress = await _generateAddressForChain(1, 0); // final initialChangeAddress = await _generateAddressForChain(1, 0);
await isarInit();
await db.putAddress(initialReceivingAddress); await db.putAddress(initialReceivingAddress);

View file

@ -4,10 +4,11 @@ import 'package:stackwallet/models/isar/models/isar_models.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
mixin WalletDB { mixin WalletDB {
MainDB get db => MainDB.instance; MainDB? _db;
MainDB get db => _db!;
Future<void> isarInit() async { void isarInit({MainDB? mockableOverride}) async {
await db.isarInit(); _db = mockableOverride ?? MainDB.instance;
} }
Future<void> addNewTransactionData( Future<void> addNewTransactionData(

View file

@ -403,7 +403,7 @@ class DbVersionMigrator with WalletDB {
_parseTransactions(txnsLelantus, walletId, true, newAddresses)); _parseTransactions(txnsLelantus, walletId, true, newAddresses));
// store newly parsed data in isar // store newly parsed data in isar
await isarInit(); isarInit();
await db.isar.writeTxn(() async { await db.isar.writeTxn(() async {
await db.isar.addresses.putAll(newAddresses); await db.isar.addresses.putAll(newAddresses);
}); });

View file

@ -1558,14 +1558,14 @@ class MockBitcoinWallet extends _i1.Mock implements _i21.BitcoinWallet {
returnValueForMissingStub: _i17.Future<void>.value(), returnValueForMissingStub: _i17.Future<void>.value(),
) as _i17.Future<void>); ) as _i17.Future<void>);
@override @override
_i17.Future<void> isarInit() => (super.noSuchMethod( void isarInit({_i13.MainDB? mockableOverride}) => super.noSuchMethod(
Invocation.method( Invocation.method(
#isarInit, #isarInit,
[], [],
{#mockableOverride: mockableOverride},
), ),
returnValue: _i17.Future<void>.value(), returnValueForMissingStub: null,
returnValueForMissingStub: _i17.Future<void>.value(), );
) as _i17.Future<void>);
@override @override
_i17.Future<void> addNewTransactionData( _i17.Future<void> addNewTransactionData(
List< List<

View file

@ -3,7 +3,6 @@ import 'package:decimal/decimal.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:hive_test/hive_test.dart'; import 'package:hive_test/hive_test.dart';
import 'package:isar/isar.dart';
import 'package:mockito/annotations.dart'; import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
@ -23,8 +22,6 @@ import 'bitcoin_wallet_test_parameters.dart';
@GenerateMocks([ElectrumX, CachedElectrumX, TransactionNotificationTracker]) @GenerateMocks([ElectrumX, CachedElectrumX, TransactionNotificationTracker])
void main() async { void main() async {
await Isar.initializeIsarCore(download: true);
group("bitcoin constants", () { group("bitcoin constants", () {
test("bitcoin minimum confirmations", () async { test("bitcoin minimum confirmations", () async {
expect(MINIMUM_CONFIRMATIONS, 1); expect(MINIMUM_CONFIRMATIONS, 1);

View file

@ -2,7 +2,6 @@ import 'package:decimal/decimal.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:hive_test/hive_test.dart'; import 'package:hive_test/hive_test.dart';
import 'package:isar/isar.dart';
import 'package:mockito/annotations.dart'; import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
@ -21,8 +20,6 @@ import 'bitcoincash_wallet_test_parameters.dart';
@GenerateMocks([ElectrumX, CachedElectrumX, TransactionNotificationTracker]) @GenerateMocks([ElectrumX, CachedElectrumX, TransactionNotificationTracker])
void main() async { void main() async {
await Isar.initializeIsarCore(download: true);
group("bitcoincash constants", () { group("bitcoincash constants", () {
test("bitcoincash minimum confirmations", () async { test("bitcoincash minimum confirmations", () async {
expect(MINIMUM_CONFIRMATIONS, 1); expect(MINIMUM_CONFIRMATIONS, 1);

View file

@ -978,14 +978,14 @@ class MockFiroWallet extends _i1.Mock implements _i9.FiroWallet {
returnValueForMissingStub: _i10.Future<void>.value(), returnValueForMissingStub: _i10.Future<void>.value(),
) as _i10.Future<void>); ) as _i10.Future<void>);
@override @override
_i10.Future<void> isarInit() => (super.noSuchMethod( void isarInit({_i7.MainDB? mockableOverride}) => super.noSuchMethod(
Invocation.method( Invocation.method(
#isarInit, #isarInit,
[], [],
{#mockableOverride: mockableOverride},
), ),
returnValue: _i10.Future<void>.value(), returnValueForMissingStub: null,
returnValueForMissingStub: _i10.Future<void>.value(), );
) as _i10.Future<void>);
@override @override
_i10.Future<void> addNewTransactionData( _i10.Future<void> addNewTransactionData(
List< List<

View file

@ -1348,14 +1348,14 @@ class MockBitcoinWallet extends _i1.Mock implements _i20.BitcoinWallet {
returnValueForMissingStub: _i17.Future<void>.value(), returnValueForMissingStub: _i17.Future<void>.value(),
) as _i17.Future<void>); ) as _i17.Future<void>);
@override @override
_i17.Future<void> isarInit() => (super.noSuchMethod( void isarInit({_i12.MainDB? mockableOverride}) => super.noSuchMethod(
Invocation.method( Invocation.method(
#isarInit, #isarInit,
[], [],
{#mockableOverride: mockableOverride},
), ),
returnValue: _i17.Future<void>.value(), returnValueForMissingStub: null,
returnValueForMissingStub: _i17.Future<void>.value(), );
) as _i17.Future<void>);
@override @override
_i17.Future<void> addNewTransactionData( _i17.Future<void> addNewTransactionData(
List< List<

View file

@ -1333,14 +1333,14 @@ class MockBitcoinWallet extends _i1.Mock implements _i19.BitcoinWallet {
returnValueForMissingStub: _i16.Future<void>.value(), returnValueForMissingStub: _i16.Future<void>.value(),
) as _i16.Future<void>); ) as _i16.Future<void>);
@override @override
_i16.Future<void> isarInit() => (super.noSuchMethod( void isarInit({_i12.MainDB? mockableOverride}) => super.noSuchMethod(
Invocation.method( Invocation.method(
#isarInit, #isarInit,
[], [],
{#mockableOverride: mockableOverride},
), ),
returnValue: _i16.Future<void>.value(), returnValueForMissingStub: null,
returnValueForMissingStub: _i16.Future<void>.value(), );
) as _i16.Future<void>);
@override @override
_i16.Future<void> addNewTransactionData( _i16.Future<void> addNewTransactionData(
List< List<

View file

@ -1891,14 +1891,14 @@ class MockFiroWallet extends _i1.Mock implements _i22.FiroWallet {
returnValueForMissingStub: _i18.Future<void>.value(), returnValueForMissingStub: _i18.Future<void>.value(),
) as _i18.Future<void>); ) as _i18.Future<void>);
@override @override
_i18.Future<void> isarInit() => (super.noSuchMethod( void isarInit({_i13.MainDB? mockableOverride}) => super.noSuchMethod(
Invocation.method( Invocation.method(
#isarInit, #isarInit,
[], [],
{#mockableOverride: mockableOverride},
), ),
returnValue: _i18.Future<void>.value(), returnValueForMissingStub: null,
returnValueForMissingStub: _i18.Future<void>.value(), );
) as _i18.Future<void>);
@override @override
_i18.Future<void> addNewTransactionData( _i18.Future<void> addNewTransactionData(
List< List<

View file

@ -1096,14 +1096,14 @@ class MockBitcoinWallet extends _i1.Mock implements _i18.BitcoinWallet {
returnValueForMissingStub: _i15.Future<void>.value(), returnValueForMissingStub: _i15.Future<void>.value(),
) as _i15.Future<void>); ) as _i15.Future<void>);
@override @override
_i15.Future<void> isarInit() => (super.noSuchMethod( void isarInit({_i12.MainDB? mockableOverride}) => super.noSuchMethod(
Invocation.method( Invocation.method(
#isarInit, #isarInit,
[], [],
{#mockableOverride: mockableOverride},
), ),
returnValue: _i15.Future<void>.value(), returnValueForMissingStub: null,
returnValueForMissingStub: _i15.Future<void>.value(), );
) as _i15.Future<void>);
@override @override
_i15.Future<void> addNewTransactionData( _i15.Future<void> addNewTransactionData(
List< List<

View file

@ -1347,14 +1347,14 @@ class MockBitcoinWallet extends _i1.Mock implements _i20.BitcoinWallet {
returnValueForMissingStub: _i17.Future<void>.value(), returnValueForMissingStub: _i17.Future<void>.value(),
) as _i17.Future<void>); ) as _i17.Future<void>);
@override @override
_i17.Future<void> isarInit() => (super.noSuchMethod( void isarInit({_i12.MainDB? mockableOverride}) => super.noSuchMethod(
Invocation.method( Invocation.method(
#isarInit, #isarInit,
[], [],
{#mockableOverride: mockableOverride},
), ),
returnValue: _i17.Future<void>.value(), returnValueForMissingStub: null,
returnValueForMissingStub: _i17.Future<void>.value(), );
) as _i17.Future<void>);
@override @override
_i17.Future<void> addNewTransactionData( _i17.Future<void> addNewTransactionData(
List< List<

View file

@ -1347,14 +1347,14 @@ class MockBitcoinWallet extends _i1.Mock implements _i20.BitcoinWallet {
returnValueForMissingStub: _i17.Future<void>.value(), returnValueForMissingStub: _i17.Future<void>.value(),
) as _i17.Future<void>); ) as _i17.Future<void>);
@override @override
_i17.Future<void> isarInit() => (super.noSuchMethod( void isarInit({_i12.MainDB? mockableOverride}) => super.noSuchMethod(
Invocation.method( Invocation.method(
#isarInit, #isarInit,
[], [],
{#mockableOverride: mockableOverride},
), ),
returnValue: _i17.Future<void>.value(), returnValueForMissingStub: null,
returnValueForMissingStub: _i17.Future<void>.value(), );
) as _i17.Future<void>);
@override @override
_i17.Future<void> addNewTransactionData( _i17.Future<void> addNewTransactionData(
List< List<