diff --git a/scripts/__mocks__/network.js b/scripts/__mocks__/network_manager.js similarity index 100% rename from scripts/__mocks__/network.js rename to scripts/__mocks__/network_manager.js diff --git a/scripts/dashboard/CreateWallet.vue b/scripts/dashboard/CreateWallet.vue index 77ebe1384..f6ea4ae17 100644 --- a/scripts/dashboard/CreateWallet.vue +++ b/scripts/dashboard/CreateWallet.vue @@ -7,7 +7,7 @@ import { ref, watch, toRefs } from 'vue'; import { useWallet } from '../composables/use_wallet.js'; import newWalletIcon from '../../assets/icons/icon-new-wallet.svg'; import Password from '../Password.vue'; -import { getNetwork } from '../network.js'; +import { getNetwork } from '../network_manager.js'; const emit = defineEmits(['importWallet']); const showModal = ref(false); diff --git a/scripts/dashboard/Dashboard.vue b/scripts/dashboard/Dashboard.vue index e5ea8c230..3c79c86f3 100644 --- a/scripts/dashboard/Dashboard.vue +++ b/scripts/dashboard/Dashboard.vue @@ -28,7 +28,7 @@ import { isColdAddress, isStandardAddress, } from '../misc.js'; -import { getNetwork } from '../network.js'; +import { getNetwork } from '../network_manager.js'; import { strHardwareName } from '../ledger'; import { guiAddContactPrompt } from '../contacts-book'; import { scanQRCode } from '../scanner'; diff --git a/scripts/global.js b/scripts/global.js index e1d86567a..ef3a75097 100644 --- a/scripts/global.js +++ b/scripts/global.js @@ -3,7 +3,7 @@ import { TransactionBuilder } from './transaction_builder.js'; import Masternode from './masternode.js'; import { ALERTS, tr, start as i18nStart, translation } from './i18n.js'; import { wallet, hasEncryptedWallet, Wallet } from './wallet.js'; -import { getNetwork } from './network.js'; +import { getNetwork } from './network_manager.js'; import { start as settingsStart, strCurrency, @@ -32,6 +32,7 @@ import pIconCopy from '../assets/icons/icon-copy.svg'; import pIconCheck from '../assets/icons/icon-check.svg'; import SideNavbar from './SideNavbar.vue'; import { AsyncInterval } from './async_interval.js'; +import { networkManager } from './network_manager.js'; /** A flag showing if base MPW is fully loaded or not */ export let fIsLoaded = false; @@ -259,7 +260,6 @@ export async function start() { // Register native app service registerWorker(); await settingsStart(); - subscribeToNetworkEvents(); // Make sure we know the correct number of blocks await refreshChainData(); diff --git a/scripts/index.js b/scripts/index.js index 5bacec1b5..118c2e38e 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -67,6 +67,6 @@ import Masternode from './masternode.js'; export { renderChangelog } from './changelog.js'; export { Masternode }; -export { getNetwork } from './network.js'; +export { getNetwork } from './network_manager.js'; export { FlipDown } from './flipdown.js'; diff --git a/scripts/ledger.js b/scripts/ledger.js index 717487b6f..be661cddd 100644 --- a/scripts/ledger.js +++ b/scripts/ledger.js @@ -1,7 +1,7 @@ import createXpub from 'create-xpub'; import { ALERTS, tr } from './i18n.js'; import { confirmPopup } from './misc.js'; -import { getNetwork } from './network.js'; +import { getNetwork } from './network_manager.js'; import { Transaction } from './transaction.js'; import { COIN, cChainParams } from './chain_params.js'; import { hexToBytes, bytesToHex } from './utils.js'; diff --git a/scripts/legacy.js b/scripts/legacy.js index a27983e19..80a8ce420 100644 --- a/scripts/legacy.js +++ b/scripts/legacy.js @@ -7,7 +7,7 @@ import { wallet, getNewAddress } from './wallet.js'; import { cChainParams, COIN, COIN_DECIMALS } from './chain_params.js'; import { generateMasternodePrivkey, confirmPopup } from './misc.js'; import { Database } from './database.js'; -import { getNetwork } from './network.js'; +import { getNetwork } from './network_manager.js'; import { ledgerSignTransaction } from './ledger.js'; import { createAlert } from './alerts/alert.js'; diff --git a/scripts/masternode.js b/scripts/masternode.js index 8bb93f561..b2a7b40e0 100644 --- a/scripts/masternode.js +++ b/scripts/masternode.js @@ -10,7 +10,7 @@ import { OP } from './script.js'; import bs58 from 'bs58'; import base32 from 'base32'; import { isStandardAddress } from './misc.js'; -import { getNetwork } from './network.js'; +import { getNetwork } from './network_manager.js'; import { debugError, DebugTopics } from './debug.js'; /** diff --git a/scripts/network.js b/scripts/network.js index f9e8fecd1..edfe36bcd 100644 --- a/scripts/network.js +++ b/scripts/network.js @@ -1,9 +1,4 @@ -import { cChainParams } from './chain_params.js'; -import { debugError, debugLog, DebugTopics } from './debug.js'; import { isStandardAddress, isXPub } from './misc.js'; -import { sleep } from './utils.js'; -import { getEventEmitter } from './event_bus.js'; -import { setExplorer, fAutoSwitch, setNode } from './settings.js'; import { cNode } from './settings.js'; import { Transaction } from './transaction.js'; @@ -47,36 +42,49 @@ export class Network { } } - getBlockCount() { + async getBlock(blockHeight, skipCoinstake) { throw new Error('getBlockCount must be implemented'); } - getBestBlockHash() { + async getTxPage(nStartHeight, addr, n) { + throw new Error('getTxPage must be implemented'); + } + + async getNumPages(nStartHeight, addr) { + throw new Error('getNumPages must be implemented'); + } + + async getUTXOs(strAddress) { + throw new Error('getUTXOs must be implemented'); + } + + async getXPubInfo(strXPUB) { + throw new Error('getXPubInfo must be implemented'); + } + + async getShieldBlockList() { + throw new Error('getShieldBlockList must be implemented'); + } + + async getBlockCount() { + throw new Error('getBlockCount must be implemented'); + } + + async getBestBlockHash() { throw new Error('getBestBlockHash must be implemented'); } - sendTransaction() { + async sendTransaction(hex) { throw new Error('sendTransaction must be implemented'); } async getTxInfo(_txHash) { throw new Error('getTxInfo must be implemented'); } - - /** - * A safety-wrapped RPC interface for calling Node RPCs with automatic correction handling - * @param {string} api - The API endpoint to call - * @param {boolean} isText - Optionally parse the result as Text rather than JSON - * @returns {Promise} - The RPC response; JSON by default, text if `isText` is true. - */ - async callRPC(api, isText = false) { - const cRes = await retryWrapper(fetchNode, false, api); - return isText ? await cRes.text() : await cRes.json(); - } } /** - * + * Network realization with a blockbook Explorer */ export class ExplorerNetwork extends Network { /** @@ -98,9 +106,8 @@ export class ExplorerNetwork extends Network { * @returns {Promise} the block fetched from explorer */ async getBlock(blockHeight, skipCoinstake = false) { - const block = await this.safeFetchFromExplorer( - `/api/v2/block/${blockHeight}` - ); + const req = await this.fetchBlockbook(`/api/v2/block/${blockHeight}`); + const block = await req.json(); const newTxs = []; // This is bad. We're making so many requests // This is a quick fix to try to be compliant with the blockbook @@ -127,10 +134,8 @@ export class ExplorerNetwork extends Network { * @returns {Promise} - Block height */ async getBlockCount() { - const { backend } = await ( - await retryWrapper(fetchBlockbook, true, `/api/v2/api`) - ).json(); - + const req = await this.fetchBlockbook(`/api/v2/api`); + const { backend } = await req.json(); return backend.blocks; } @@ -139,46 +144,11 @@ export class ExplorerNetwork extends Network { * @returns {Promise} - Block hash */ async getBestBlockHash() { - const { backend } = await ( - await retryWrapper(fetchBlockbook, true, `/api/v2/api`) - ).json(); - + const req = await this.fetchBlockbook(`/api/v2/api`); + const { backend } = await req.json(); return backend.bestBlockHash; } - /** - * Sometimes blockbook might return internal error, in this case this function will sleep for some times and retry - * @param {string} strCommand - The specific Blockbook api to call - * @param {number} sleepTime - How many milliseconds sleep between two calls. Default value is 20000ms - * @returns {Promise} Explorer result in json - */ - async safeFetchFromExplorer(strCommand, sleepTime = 20000) { - let trials = 0; - const maxTrials = 6; - let error; - while (trials < maxTrials) { - trials += 1; - const res = await retryWrapper(fetchBlockbook, true, strCommand); - if (!res.ok) { - try { - error = (await res.json()).error; - } catch (e) { - error = 'Cannot safe fetch from explorer!'; - } - debugLog( - DebugTopics.NET, - 'Blockbook internal error! sleeping for ' + - sleepTime + - ' seconds' - ); - await sleep(sleepTime); - continue; - } - return await res.json(); - } - throw new Error(error); - } - /** * Returns the n-th page of transactions belonging to addr * @param {number} nStartHeight - The minimum transaction block height @@ -193,7 +163,8 @@ export class ExplorerNetwork extends Network { } const strRoot = `/api/v2/${isXPub(addr) ? 'xpub/' : 'address/'}${addr}`; const strCoreParams = `?details=txs&from=${nStartHeight}&pageSize=${pageSize}&page=${n}`; - return await this.safeFetchFromExplorer(strRoot + strCoreParams); + const req = await this.fetchBlockbook(strRoot + strCoreParams); + return await req.json(); } /** @@ -243,20 +214,10 @@ export class ExplorerNetwork extends Network { * @returns {Promise>} Resolves when it has finished fetching UTXOs */ async getUTXOs(strAddress) { - try { - let publicKey = strAddress; - // Fetch UTXOs for the key - const arrUTXOs = await ( - await retryWrapper( - fetchBlockbook, - true, - `/api/v2/utxo/${publicKey}` - ) - ).json(); - return arrUTXOs; - } catch (e) { - debugError(DebugTopics.NET, e); - } + let publicKey = strAddress; + // Fetch UTXOs for the key + const req = await this.fetchBlockbook(`/api/v2/utxo/${publicKey}`); + return await req.json(); } /** @@ -265,145 +226,61 @@ export class ExplorerNetwork extends Network { * @returns {Promise} - A JSON class of aggregated XPUB info */ async getXPubInfo(strXPUB) { - return await ( - await retryWrapper(fetchBlockbook, true, `/api/v2/xpub/${strXPUB}`) - ).json(); + const req = await this.fetchBlockbook(`/api/v2/xpub/${strXPUB}`); + return await req.json(); } async sendTransaction(hex) { - try { - const data = await ( - await retryWrapper(fetchBlockbook, true, '/api/v2/sendtx/', { - method: 'post', - body: hex, - }) - ).json(); - - // Throw and catch if the data is not a TXID - if (!data.result || data.result.length !== 64) throw data; - - debugLog(DebugTopics.NET, 'Transaction sent! ' + data.result); - getEventEmitter().emit('transaction-sent', true, data.result); - return data.result; - } catch (e) { - getEventEmitter().emit('transaction-sent', false, e); - return false; - } + const req = await this.fetchBlockbook('/api/v2/sendtx/', { + method: 'post', + body: hex, + }); + return await req.json(); } async getTxInfo(txHash) { - const req = await retryWrapper( - fetchBlockbook, - true, - `/api/v2/tx/${txHash}` - ); + const req = await this.fetchBlockbook(`/api/v2/tx/${txHash}`); return await req.json(); } + /** + * A Fetch wrapper which uses the current Blockbook Network's base URL + * @param {string} api - The specific Blockbook api to call + * @param {RequestInit?} options - The Fetch options + * @returns {Promise} - The unresolved Fetch promise + */ + fetchBlockbook(api, options) { + return fetch(this.strUrl + api, options); + } + + ///////////////////////////////////////////////////////////////////// + // TODO: REMOVE ALL FUNCTIONS BELOW THIS COMMENT ONCE #427 IS MERGED + ///////////////////////////////////////////////////////////////////// + /** * @return {Promise} The list of blocks which have at least one shield transaction */ async getShieldBlockList() { return await this.callRPC('/getshieldblocks'); } -} - -let _network = null; - -/** - * Sets the network in use by MPW. - * @param {ExplorerNetwork} network - network to use - */ -export function setNetwork(network) { - _network = network; -} - -/** - * Gets the network in use by MPW. - * @returns {ExplorerNetwork?} Returns the network in use, may be null if MPW hasn't properly loaded yet. - */ -export function getNetwork() { - return _network; -} - -/** - * A Fetch wrapper which uses the current Blockbook Network's base URL - * @param {string} api - The specific Blockbook api to call - * @param {RequestInit} options - The Fetch options - * @returns {Promise} - The unresolved Fetch promise - */ -export function fetchBlockbook(api, options) { - return fetch(_network.strUrl + api, options); -} - -/** - * A Fetch wrapper which uses the current Node's base URL - * @param {string} api - The specific Node api to call - * @param {RequestInit} options - The Fetch options - * @returns {Promise} - The unresolved Fetch promise - */ -export function fetchNode(api, options) { - return fetch(cNode.url + api, options); -} - -/** - * A wrapper for Blockbook and Node calls which can, in the event of an unresponsive instance, - * seamlessly attempt the same call on multiple other instances until success. - * @param {Function} func - The function to re-attempt with - * @param {boolean} isExplorer - Whether this is an Explorer or Node call - * @param {...any} args - The arguments to pass to the function - */ -export async function retryWrapper(func, isExplorer, ...args) { - // Track internal errors from the wrapper - let err; - - // Select the instances list to use - Explorers or Nodes - const arrInstances = isExplorer - ? cChainParams.current.Explorers - : cChainParams.current.Nodes; - - // If allowed by the user, Max Tries is ALL MPW-supported instances, otherwise, restrict to only the current one. - let nMaxTries = arrInstances.length + 1; - let retries = 0; - - // The instance index we started at - let nIndex = arrInstances.findIndex((a) => - a.url === isExplorer ? getNetwork().strUrl : cNode.url - ); - - // Run the call until successful, or all attempts exhausted - while (retries < nMaxTries) { - try { - // Call the passed function with the arguments - const res = await func(...args); - // If the endpoint is non-OK, assume it's an error - if (!res.ok) throw new Error(res.statusText); - - // Return the result if successful - return res; - } catch (error) { - err = error; - - // If allowed, switch instances - if (!fAutoSwitch) throw err; - nIndex = (nIndex + 1) % arrInstances.length; - const cNewInstance = arrInstances[nIndex]; - - if (isExplorer) { - // Set the explorer at Network-class level, then as a hacky workaround for the current callback; we - // ... adjust the internal URL to the new explorer. - await setExplorer(cNewInstance, true); - } else { - // For the Node, we change the setting directly - setNode(cNewInstance, true); - } - - // Bump the attempts, and re-try next loop - retries++; - } + /** + * A Fetch wrapper which uses the current Node's base URL + * @param {string} api - The specific Node api to call + * @param {RequestInit?} options - The Fetch options + * @returns {Promise} - The unresolved Fetch promise + */ + fetchNode(api, options) { + return fetch(cNode.url + api, options); + } + /** + * A safety-wrapped RPC interface for calling Node RPCs with automatic correction handling + * @param {string} api - The API endpoint to call + * @param {boolean} isText - Optionally parse the result as Text rather than JSON + * @returns {Promise} - The RPC response; JSON by default, text if `isText` is true. + */ + async callRPC(api, isText = false) { + const cRes = await this.fetchNode(api); + return isText ? await cRes.text() : await cRes.json(); } - - // Throw an error so the calling code knows the operation failed - throw err; } diff --git a/scripts/network_manager.js b/scripts/network_manager.js new file mode 100644 index 000000000..e9aeff945 --- /dev/null +++ b/scripts/network_manager.js @@ -0,0 +1,181 @@ +import { ExplorerNetwork, Network } from './network.js'; +import { cChainParams } from './chain_params.js'; +import { fAutoSwitch } from './settings.js'; +import { debugLog, DebugTopics } from './debug.js'; +import { sleep } from './utils.js'; +import { getEventEmitter } from './event_bus.js'; + +class NetWorkManager { + /** + * @type {Network} - Current selected network + */ + currentNetwork; + + /** + * @type {Array} - List of all available Networks + */ + networks = []; + + start() { + this.networks = []; + for (let network of cChainParams.current.Explorers) { + this.networks.push(new ExplorerNetwork(network.url)); + } + } + + /** + * Sets the network in use by MPW. + * @param {ExplorerNetwork} network - network to use + */ + setNetwork(strUrl) { + if (this.networks.length === 0) { + this.start(); + } + this.currentNetwork = this.networks.find( + (network) => network.strUrl === strUrl + ); + } + + /** + * Call all networks until one is succesful + * seamlessly attempt the same call on multiple other instances until success. + * @param {Function} func - The function to re-attempt with + * @param {...any} args - The arguments to pass to the function + */ + async retryWrapper(func, ...args) { + const startingUrl = this.currentNetwork.strUrl; + let nMaxTries = this.networks.length; + let i = this.networks.findIndex((net) => net === this.currentNetwork); + + // Run the call until successful, or all attempts exhausted + try { + for (let attempts = 0; attempts < nMaxTries; attempts++) { + try { + const res = await func.call(this.currentNetwork, ...args); + return res; + } catch (error) { + // If allowed, switch instances + if (!fAutoSwitch || attempts == nMaxTries) { + throw error; + } + this.currentNetwork = + this.networks[(i + attempts) % nMaxTries]; + } + } + } finally { + // TODO: Change once there are more types of explorers + this.currentNetwork = new ExplorerNetwork(startingUrl); + } + } + + /** + * Sometimes blockbook might return internal error, in this case this function will sleep for some times and retry + * @param {string} strCommand - The specific Blockbook api to call + * @param {number} sleepTime - How many milliseconds sleep between two calls. Default value is 20000ms + * @returns {Promise} Explorer result in json + */ + async safeFetch(func, ...args) { + let trials = 0; + const sleepTime = 20000; + const maxTrials = 6; + while (trials < maxTrials) { + trials += 1; + try { + return await func.call(this.currentNetwork, ...args); + } catch (e) { + debugLog( + DebugTopics.NET, + 'Blockbook internal error! sleeping for ' + + sleepTime + + ' seconds' + ); + await sleep(sleepTime); + } + } + throw new Error('Cannot safe fetch'); + } + + async getBlock(blockHeight, skipCoinstake) { + return await this.safeFetch( + this.currentNetwork.getBlock, + blockHeight, + skipCoinstake + ); + } + + async getTxPage(nStartHeight, addr, n) { + return await this.safeFetch( + this.currentNetwork.getTxPage, + nStartHeight, + addr, + n + ); + } + + async getNumPages(nStartHeight, addr) { + return await this.safeFetch( + this.currentNetwork.getNumPages, + nStartHeight, + addr + ); + } + + async getUTXOs(strAddress) { + return await this.retryWrapper( + this.currentNetwork.getUTXOs, + strAddress + ); + } + + async getXPubInfo(strXPUB) { + return await this.retryWrapper( + this.currentNetwork.getXPubInfo, + strXPUB + ); + } + + async getShieldBlockList() { + return await this.retryWrapper(this.currentNetwork.getShieldBlockList); + } + + async getBlockCount() { + return await this.retryWrapper(this.currentNetwork.getBlockCount); + } + + async getBestBlockHash() { + return await this.retryWrapper(this.currentNetwork.getBestBlockHash); + } + + async sendTransaction(hex) { + try { + const data = await this.retryWrapper( + this.currentNetwork.sendTransaction, + hex + ); + + // Throw and catch if the data is not a TXID + if (!data.result || data.result.length !== 64) throw data; + + debugLog(DebugTopics.NET, 'Transaction sent! ' + data.result); + getEventEmitter().emit('transaction-sent', true, data.result); + return data.result; + } catch (e) { + getEventEmitter().emit('transaction-sent', false, e); + return false; + } + } + + async getTxInfo(_txHash) { + return await this.retryWrapper(this.currentNetwork.getTxInfo, _txHash); + } +} + +export const networkManager = new NetWorkManager(); + +/** + * Gets the network in use by MPW. + * @returns {ExplorerNetwork?} Returns the network in use, may be null if MPW hasn't properly loaded yet. + */ +export function getNetwork() { + return networkManager; +} diff --git a/scripts/promos.js b/scripts/promos.js index 95d98dfd6..131e819ce 100644 --- a/scripts/promos.js +++ b/scripts/promos.js @@ -4,7 +4,7 @@ import { doms, restoreWallet, sweepAddress } from './global.js'; import { downloadBlob } from './misc.js'; import { getAlphaNumericRand, arrayToCSV } from './utils.js'; import { ALERTS, translation, tr } from './i18n.js'; -import { getNetwork } from './network.js'; +import { getNetwork } from './network_manager.js'; import { scanQRCode } from './scanner.js'; import { createAndSendTransaction } from './legacy.js'; import { UTXO, COutpoint } from './transaction.js'; diff --git a/scripts/settings.js b/scripts/settings.js index 7b92e037a..1d4112aac 100644 --- a/scripts/settings.js +++ b/scripts/settings.js @@ -7,7 +7,6 @@ import { } from './global.js'; import { wallet, hasEncryptedWallet } from './wallet.js'; import { cChainParams } from './chain_params.js'; -import { setNetwork, ExplorerNetwork, getNetwork } from './network.js'; import { confirmPopup } from './misc.js'; import { switchTranslation, @@ -20,6 +19,7 @@ import { createAlert } from './alerts/alert.js'; import { Database } from './database.js'; import { getEventEmitter } from './event_bus.js'; import countries from 'country-locale-map/countries.json'; +import { networkManager } from './network_manager.js'; // --- Default Settings /** A mode that emits verbose console info for internal MPW operations */ @@ -216,28 +216,20 @@ function subscribeToNetworkEvents() { } // --- Settings Functions -export async function setExplorer(explorer, fSilent = false) { +export async function setExplorer(explorer) { const database = await Database.getInstance(); await database.setSettings({ explorer: explorer.url }); cExplorer = explorer; - - // Enable networking + notify if allowed - if (getNetwork()) { - getNetwork().strUrl = cExplorer.url; - } else { - const network = new ExplorerNetwork(cExplorer.url); - setNetwork(network); - } + networkManager.setNetwork(cExplorer.url); // Update the selector UI doms.domExplorerSelect.value = cExplorer.url; - if (!fSilent) - createAlert( - 'success', - tr(ALERTS.SWITCHED_EXPLORERS, [{ explorerName: cExplorer.name }]), - 2250 - ); + createAlert( + 'success', + tr(ALERTS.SWITCHED_EXPLORERS, [{ explorerName: cExplorer.name }]), + 2250 + ); getEventEmitter().emit('explorer_changed', cExplorer.url); } diff --git a/scripts/stake/Stake.vue b/scripts/stake/Stake.vue index 7b4c21de7..1c05bfb7d 100644 --- a/scripts/stake/Stake.vue +++ b/scripts/stake/Stake.vue @@ -6,7 +6,7 @@ import Activity from '../dashboard/Activity.vue'; import RestoreWallet from '../dashboard/RestoreWallet.vue'; import { Database } from '../database'; import { getEventEmitter } from '../event_bus'; -import { getNetwork } from '../network'; +import { getNetwork } from '../network_manager'; import StakeBalance from './StakeBalance.vue'; import StakeInput from './StakeInput.vue'; import { onMounted, ref, watch, nextTick } from 'vue'; diff --git a/scripts/wallet.js b/scripts/wallet.js index 66fe675ee..5aa0f3f74 100644 --- a/scripts/wallet.js +++ b/scripts/wallet.js @@ -2,7 +2,7 @@ import { validateMnemonic } from 'bip39'; import { decrypt } from './aes-gcm.js'; import { parseWIF } from './encoding.js'; import { beforeUnloadListener, blockCount } from './global.js'; -import { getNetwork } from './network.js'; +import { getNetwork } from './network_manager.js'; import { MAX_ACCOUNT_GAP, SHIELD_BATCH_SYNC_SIZE } from './chain_params.js'; import { HistoricalTx, HistoricalTxType } from './historical_tx.js'; import { COutpoint, Transaction } from './transaction.js'; diff --git a/tests/components/CreateWallet.test.js b/tests/components/CreateWallet.test.js index 2a77e6750..26d99a66c 100644 --- a/tests/components/CreateWallet.test.js +++ b/tests/components/CreateWallet.test.js @@ -5,7 +5,7 @@ import Modal from '../../scripts/Modal.vue'; import { vi, it, describe } from 'vitest'; import 'fake-indexeddb/auto'; -vi.mock('../../scripts/network.js'); +vi.mock('../../scripts/network_manager.js'); vi.stubGlobal('indexedDB', new IDBFactory()); describe('create wallet tests', () => { diff --git a/tests/integration/wallet/sync.spec.js b/tests/integration/wallet/sync.spec.js index be86ce6c4..de881fd11 100644 --- a/tests/integration/wallet/sync.spec.js +++ b/tests/integration/wallet/sync.spec.js @@ -9,12 +9,12 @@ import { describe, it, vi, expect, afterAll } from 'vitest'; import { getNetwork, resetNetwork, -} from '../../../scripts/__mocks__/network.js'; +} from '../../../scripts/__mocks__/network_manager.js'; import { refreshChainData } from '../../../scripts/global.js'; import { sleep } from '../../../scripts/utils.js'; import { COIN } from '../../../scripts/chain_params.js'; -vi.mock('../../../scripts/network.js'); +vi.mock('../../../scripts/network_manager.js'); /** * @param{import('scripts/wallet').Wallet} wallet - wallet that will generate the transaction diff --git a/tests/unit/use_wallet.spec.js b/tests/unit/use_wallet.spec.js index 57fd63701..5d6647dba 100644 --- a/tests/unit/use_wallet.spec.js +++ b/tests/unit/use_wallet.spec.js @@ -4,11 +4,11 @@ import { describe, it, beforeEach, vi } from 'vitest'; import { useWallet } from '../../scripts/composables/use_wallet.js'; import { hasEncryptedWallet, wallet } from '../../scripts/wallet.js'; import { LegacyMasterKey } from '../../scripts/masterkey.js'; -import { getNetwork } from '../../scripts/network.js'; +import { getNetwork } from '../../scripts/network_manager.js'; import { strCurrency } from '../../scripts/settings.js'; import { setUpLegacyMainnetWallet } from '../utils/test_utils'; -vi.mock('../../scripts/network.js'); +vi.mock('../../scripts/network_manager.js'); describe('useWallet tests', () => { let walletComposable; diff --git a/tests/unit/wallet/signature.spec.js b/tests/unit/wallet/signature.spec.js index 8e70935b2..ecc79cde2 100644 --- a/tests/unit/wallet/signature.spec.js +++ b/tests/unit/wallet/signature.spec.js @@ -13,7 +13,7 @@ import { } from '../../../scripts/transaction.js'; import { hexToBytes } from '../../../scripts/utils'; -vi.mock('../../../scripts/network.js'); +vi.mock('../../../scripts/network_manager.js'); vi.mock('../../../scripts/global.js'); describe('Wallet signature tests', () => { diff --git a/tests/unit/wallet/transactions.spec.js b/tests/unit/wallet/transactions.spec.js index b682ef28e..4755ff7fe 100644 --- a/tests/unit/wallet/transactions.spec.js +++ b/tests/unit/wallet/transactions.spec.js @@ -14,7 +14,7 @@ import { TransactionBuilder } from '../../../scripts/transaction_builder.js'; vi.stubGlobal('localStorage', { length: 0 }); vi.mock('../../../scripts/global.js'); -vi.mock('../../../scripts/network.js'); +vi.mock('../../../scripts/network_manager.js'); /** * @param {Wallet} wallet