diff --git a/cypress.config.js b/cypress.config.js index 8d621707..759bf51a 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,5 +1,5 @@ import { defineConfig } from 'cypress'; -import { existsSync, readFileSync } from 'fs'; +import { existsSync } from 'fs'; import cypressPlayback from '@oreillymedia/cypress-playback/addTasks.js'; export default defineConfig({ e2e: { diff --git a/scripts/chain_params.js b/scripts/chain_params.js index 329c4c07..c0722bb0 100644 --- a/scripts/chain_params.js +++ b/scripts/chain_params.js @@ -12,9 +12,6 @@ export const COIN = 10 ** 8; /** The maximum gap (absence of transactions within a range of derived addresses) before an account search ends */ export const MAX_ACCOUNT_GAP = 20; -/** The batch size of Shield block synchronisation */ -export const SHIELD_BATCH_SYNC_SIZE = 32; - /** Transaction Sapling Version */ export const SAPLING_TX_VERSION = 3; diff --git a/scripts/database.js b/scripts/database.js index 39358313..8ff6ace9 100644 --- a/scripts/database.js +++ b/scripts/database.js @@ -2,10 +2,9 @@ import { openDB } from 'idb'; import Masternode from './masternode.js'; import { Settings } from './settings.js'; import { cChainParams } from './chain_params.js'; -import { confirmPopup, sanitizeHTML, isSameType, isEmpty } from './misc.js'; +import { isSameType, isEmpty } from './misc.js'; import { createAlert } from './alerts/alert.js'; import { PromoWallet } from './promos.js'; -import { ALERTS, translation } from './i18n.js'; import { Account } from './accounts.js'; import { COutpoint, CTxIn, CTxOut, Transaction } from './transaction.js'; import { debugError, debugLog, DebugTopics } from './debug.js'; diff --git a/scripts/global.js b/scripts/global.js index 451faa2a..1c296ccf 100644 --- a/scripts/global.js +++ b/scripts/global.js @@ -28,7 +28,6 @@ import Stake from './stake/Stake.vue'; import { createPinia } from 'pinia'; import { cOracle } from './prices.js'; -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'; diff --git a/scripts/network/__mocks__/network_manager.js b/scripts/network/__mocks__/network_manager.js index 5e99a278..f5c7f6d9 100644 --- a/scripts/network/__mocks__/network_manager.js +++ b/scripts/network/__mocks__/network_manager.js @@ -39,7 +39,7 @@ class TestNetwork { return 1; }); - getTxPage = vi.fn((nStartHeight, addr, n) => { + getTxPage = vi.fn((nStartHeight, addr, _n) => { if (addr === 'DTSTGkncpC86sbEUZ2rCBLEe2aXSeZPLnC') { // 1) Legacy mainnet wallet // tx_1 provides a spendable balance of 0.1 * 10^8 satoshi diff --git a/scripts/network/network.js b/scripts/network/network.js index 2ccf72ac..a0767dfb 100644 --- a/scripts/network/network.js +++ b/scripts/network/network.js @@ -121,13 +121,13 @@ export class Network { } async submitProposal({ - name, - url, - nPayments, - start, - address, - monthlyPayment, - txid, + _name, + _url, + _nPayments, + _start, + _address, + _monthlyPayment, + _txid, }) { throw new Error('submitProposal must be implemented'); } diff --git a/scripts/network/network_manager.js b/scripts/network/network_manager.js index 5425861b..57ee11a3 100644 --- a/scripts/network/network_manager.js +++ b/scripts/network/network_manager.js @@ -1,4 +1,4 @@ -import { ExplorerNetwork, Network, RPCNodeNetwork } from './network.js'; +import { ExplorerNetwork, RPCNodeNetwork } from './network.js'; import { cChainParams } from '../chain_params.js'; import { fAutoSwitch } from '../settings.js'; import { debugLog, DebugTopics, debugWarn } from '../debug.js'; @@ -7,17 +7,17 @@ import { getEventEmitter } from '../event_bus.js'; class NetworkManager { /** - * @type {Network} - Current selected Explorer + * @type {import('./network.js').Network} - Current selected Explorer */ #currentExplorer; /** - * @type {Network} - Current selected RPC node + * @type {import('./network.js').Network} - Current selected RPC node */ #currentNode; /** - * @type {Array} - List of all available Networks + * @type {Array} - List of all available Networks */ #networks = []; diff --git a/scripts/utils.js b/scripts/utils.js index bcd78d6f..2a34c1dc 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -75,56 +75,6 @@ export function arrayToCSV(data) { .join('\r\n'); // rows starting on new lines } -/** - * Start a batch of promises, processing them concurrently up to `batchSize`. - * This does *not* run them in parallel. Only 1 CPU core is used - * @template T - * @param {(number)=>Promise} promiseFactory - Function that spawns promises based - * on a number. 0 is the first, length-1 is the last one. - * @param {number} length - How many promises to spawn - * @param {number} batchSize - How many promises to spawn at a time - * @returns {Promise} array of the return value of the promise. - * It's guaranteed to be sorted, i.e. it will contain - * [ await promsieFactory(0), await promisefactory(1), ... ] - * If the promises depend on each other, then behavior is undefined - */ -export async function startBatch( - promiseFactory, - length, - batchSize, - retryTime = 10000 -) { - if (length === 0) { - return; - } - return new Promise((res) => { - const running = []; - let i = 0; - const startNext = async (current) => { - let result; - try { - result = await promiseFactory(current); - } catch (e) { - // Try again later - await sleep(retryTime); - return await startNext(current); - } - i++; - if (i < length) { - running.push(startNext(i)); - } else { - (async () => res(await Promise.all(running)))(); - } - return result; - }; - // Start fisrt batchsize promises - for (i = 0; i < batchSize && i < length; i++) { - running.push(startNext(i)); - } - --i; - }); -} - /** * An artificial sleep function to pause code execution * diff --git a/scripts/wallet.js b/scripts/wallet.js index d5aa0443..1fd5ef56 100644 --- a/scripts/wallet.js +++ b/scripts/wallet.js @@ -1,9 +1,9 @@ import { validateMnemonic } from 'bip39'; import { decrypt } from './aes-gcm.js'; -import { bytesToNum, mergeUint8Arrays, parseWIF } from './encoding.js'; +import { bytesToNum, parseWIF } from './encoding.js'; import { beforeUnloadListener, blockCount } from './global.js'; import { getNetwork } from './network/network_manager.js'; -import { MAX_ACCOUNT_GAP, SHIELD_BATCH_SYNC_SIZE } from './chain_params.js'; +import { MAX_ACCOUNT_GAP } from './chain_params.js'; import { HistoricalTx, HistoricalTxType } from './historical_tx.js'; import { COutpoint, Transaction } from './transaction.js'; import { confirmPopup, isShieldAddress } from './misc.js'; @@ -15,7 +15,7 @@ import { Database } from './database.js'; import { RECEIVE_TYPES } from './contacts-book.js'; import { Account } from './accounts.js'; import { fAdvancedMode } from './settings.js'; -import { bytesToHex, hexToBytes, sleep, startBatch } from './utils.js'; +import { bytesToHex, hexToBytes, sleep } from './utils.js'; import { strHardwareName } from './ledger.js'; import { OutpointState, Mempool } from './mempool.js'; import { getEventEmitter } from './event_bus.js'; diff --git a/tests/unit/start_batch.test.js b/tests/unit/start_batch.test.js deleted file mode 100644 index ca723dab..00000000 --- a/tests/unit/start_batch.test.js +++ /dev/null @@ -1,39 +0,0 @@ -import { startBatch } from '../../scripts/utils.js'; -import { describe, it, test } from 'vitest'; - -describe('Start batch tests', () => { - const basicFunc = async (arrSize, batchSize) => { - const arr = new Array(arrSize).fill(0).map((_, i) => i * 2); - const promiseFactory = async (i) => { - return arr[i] * 2; - }; - const res = await startBatch(promiseFactory, arr.length, batchSize); - for (let i = 0; i < arr.length; i++) { - expect(res[i]).toBe(arr[i] * 2); - } - }; - test('basic functionality', async () => await basicFunc(100, 8)); - it('works with batchSize > length', async () => basicFunc(4, 500)); - it('works with batchSize = length', async () => basicFunc(500, 500)); - - it('correctly handles errors', async () => { - const arr = new Array(100).fill(0).map((_, i) => i * 2); - // Simulated fail calls with a ~80% success rate - const failCalls = [ - 5, 13, 16, 18, 20, 28, 29, 34, 40, 41, 51, 58, 65, 67, 70, 71, 73, - 81, 88, 91, 94, 97, 100, 105, 112, 115, 117, 119, 127, 128, 130, - ]; - let counter = 0; - const promiseFactory = async (i) => { - counter++; - if (failCalls.includes(counter)) { - throw new Error(':('); - } - return arr[i] * 2; - }; - const res = await startBatch(promiseFactory, arr.length, 8, 50); - for (let i = 0; i < arr.length; i++) { - expect(res[i]).toBe(arr[i] * 2); - } - }); -});