From 9bd8b73a0cbdd89dd26f70114319bcc5613b36b8 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 5 May 2022 15:15:00 +1000 Subject: [PATCH] fix testnet --- preload.js | 12 +- ts/models/conversation.ts | 6 +- ts/node/sql.ts | 157 +++++++++--------- ts/session/apis/seed_node_api/SeedNodeAPI.ts | 20 +-- ts/session/apis/snode_api/SNodeAPI.ts | 6 +- ts/session/apis/snode_api/snodePool.ts | 4 +- ts/session/apis/snode_api/swarmPolling.ts | 18 +- ts/session/onions/onionPath.ts | 4 +- ts/session/sending/MessageSender.ts | 27 +-- ts/session/types/PubKey.ts | 5 +- ts/test/session/unit/onion/GuardNodes_test.ts | 6 +- .../session/unit/onion/SeedNodeAPI_test.ts | 4 +- .../unit/swarm_polling/SwarmPolling_test.ts | 2 +- ts/util/crypto/attachmentsEncrypter.ts | 6 +- ts/window.d.ts | 2 +- 15 files changed, 138 insertions(+), 141 deletions(-) diff --git a/preload.js b/preload.js index 817e9c627..fef258d1c 100644 --- a/preload.js +++ b/preload.js @@ -212,15 +212,9 @@ window.ReactDOM = require('react-dom'); window.clipboard = clipboard; window.getSeedNodeList = () => [ - { - url: 'https://storage.seed1.loki.network:4433/', - }, - { - url: 'https://storage.seed3.loki.network:4433/', - }, - { - url: 'https://public.loki.foundation:4433/', - }, + 'https://storage.seed1.loki.network:4433/', + 'https://storage.seed3.loki.network:4433/', + 'https://public.loki.foundation:4433/', ]; const { locale: localFromEnv } = config; diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index d50597ca8..7e0cf307c 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -1250,7 +1250,7 @@ export class ConversationModel extends Backbone.Model { public async setIsApproved(value: boolean, shouldCommit: boolean = true) { if (value !== this.isApproved()) { - window?.log?.info(`Setting ${this.attributes.profileName} isApproved to:: ${value}`); + window?.log?.info(`Setting ${ed25519Str(this.attributes.id)} isApproved to: ${value}`); this.set({ isApproved: value, }); @@ -1263,7 +1263,7 @@ export class ConversationModel extends Backbone.Model { public async setDidApproveMe(value: boolean, shouldCommit: boolean = true) { if (value !== this.didApproveMe()) { - window?.log?.info(`Setting ${this.attributes.profileName} didApproveMe to:: ${value}`); + window?.log?.info(`Setting ${ed25519Str(this.attributes.id)} didApproveMe to: ${value}`); this.set({ didApproveMe: value, }); @@ -1751,7 +1751,7 @@ const trotthledAllConversationsDispatch = _.debounce( updatesToDispatch.clear(); }, 2000, - { maxWait: 5000, trailing: true } + { maxWait: 2000, trailing: true, leading: true } ); const updatesToDispatch: Map = new Map(); diff --git a/ts/node/sql.ts b/ts/node/sql.ts index 8b35fd747..5e9c0572c 100644 --- a/ts/node/sql.ts +++ b/ts/node/sql.ts @@ -1181,6 +1181,7 @@ function updateToLokiSchemaVersion17(currentVersion: number, db: BetterSqlite3.D } function dropFtsAndTriggers(db: BetterSqlite3.Database) { + console.info('dropping fts5 table'); db.exec(` DROP TRIGGER IF EXISTS messages_on_insert; DROP TRIGGER IF EXISTS messages_on_delete; @@ -1190,6 +1191,7 @@ function dropFtsAndTriggers(db: BetterSqlite3.Database) { } function rebuildFtsTable(db: BetterSqlite3.Database) { + console.info('rebuildFtsTable'); db.exec(` -- Then we create our full-text search table and populate it CREATE VIRTUAL TABLE ${MESSAGES_FTS_TABLE} @@ -1220,6 +1222,7 @@ function rebuildFtsTable(db: BetterSqlite3.Database) { ); END; `); + console.info('rebuildFtsTable built'); } function updateToLokiSchemaVersion18(currentVersion: number, db: BetterSqlite3.Database) { @@ -1380,10 +1383,7 @@ function updateToLokiSchemaVersion23(currentVersion: number, db: BetterSqlite3.D expiresAt INTEGER, namespace INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (id, snode, namespace) - ); - - - ` + );` ); db.exec( @@ -2891,7 +2891,6 @@ function removeAllAttachmentDownloadJobs() { function removeAll() { assertGlobalInstance().exec(` DELETE FROM ${IDENTITY_KEYS_TABLE}; - DELETE FROM ${ITEMS_TABLE}; DELETE FROM unprocessed; DELETE FROM ${LAST_HASHES_TABLE}; @@ -3417,89 +3416,93 @@ function cleanUpOldOpengroups() { // first remove very old messages for each opengroups - dropFtsAndTriggers(assertGlobalInstance()); - v2Convos.forEach(convo => { - const convoId = convo.id; - const messagesInConvoBefore = getMessagesCountByConversation(convoId); - - if (messagesInConvoBefore >= maxMessagePerOpengroupConvo) { - const minute = 1000 * 60; - const sixMonths = minute * 60 * 24 * 30 * 6; - const messagesTimestampToRemove = Date.now() - sixMonths; - const countToRemove = assertGlobalInstance() - .prepare( - `SELECT count(*) from ${MESSAGES_TABLE} WHERE serverTimestamp <= $serverTimestamp AND conversationId = $conversationId;` - ) - .get({ conversationId: convoId, serverTimestamp: Date.now() - sixMonths })['count(*)']; - const start = Date.now(); - - assertGlobalInstance() - .prepare( - ` + assertGlobalInstance().transaction(() => { + dropFtsAndTriggers(assertGlobalInstance()); + v2Convos.forEach(convo => { + const convoId = convo.id; + const messagesInConvoBefore = getMessagesCountByConversation(convoId); + + if (messagesInConvoBefore >= maxMessagePerOpengroupConvo) { + const minute = 1000 * 60; + const sixMonths = minute * 60 * 24 * 30 * 6; + const messagesTimestampToRemove = Date.now() - sixMonths; + const countToRemove = assertGlobalInstance() + .prepare( + `SELECT count(*) from ${MESSAGES_TABLE} WHERE serverTimestamp <= $serverTimestamp AND conversationId = $conversationId;` + ) + .get({ conversationId: convoId, serverTimestamp: Date.now() - sixMonths })['count(*)']; + const start = Date.now(); + + assertGlobalInstance() + .prepare( + ` DELETE FROM ${MESSAGES_TABLE} WHERE serverTimestamp <= $serverTimestamp AND conversationId = $conversationId` - ) - .run({ conversationId: convoId, serverTimestamp: messagesTimestampToRemove }); // delete messages older than sixMonths - const messagesInConvoAfter = getMessagesCountByConversation(convoId); + ) + .run({ conversationId: convoId, serverTimestamp: messagesTimestampToRemove }); // delete messages older than sixMonths + const messagesInConvoAfter = getMessagesCountByConversation(convoId); - console.info( - `Cleaning ${countToRemove} messages older than 6 months in public convo: ${convoId} took ${Date.now() - - start}ms. Old message count: ${messagesInConvoBefore}, new message count: ${messagesInConvoAfter}` - ); + console.info( + `Cleaning ${countToRemove} messages older than 6 months in public convo: ${convoId} took ${Date.now() - + start}ms. Old message count: ${messagesInConvoBefore}, new message count: ${messagesInConvoAfter}` + ); - const unreadCount = getUnreadCountByConversation(convoId); - const convoProps = getConversationById(convoId); - if (convoProps) { - convoProps.unreadCount = unreadCount; - updateConversation(convoProps); + const unreadCount = getUnreadCountByConversation(convoId); + const convoProps = getConversationById(convoId); + if (convoProps) { + convoProps.unreadCount = unreadCount; + updateConversation(convoProps); + } } - } - }); + }); - // now, we might have a bunch of private conversation, without any interaction and no messages - // those are the conversation of the old members in the opengroups we just cleaned. - const allInactiveConvos = assertGlobalInstance() - .prepare( - ` + // now, we might have a bunch of private conversation, without any interaction and no messages + // those are the conversation of the old members in the opengroups we just cleaned. + const allInactiveConvos = assertGlobalInstance() + .prepare( + ` SELECT id FROM ${CONVERSATIONS_TABLE} WHERE type = 'private' AND (active_at IS NULL OR active_at = 0)` - ) - .all(); - - const ourNumber = getItemById('number_id'); - if (!ourNumber || !ourNumber.value) { - return; - } - const ourPubkey = ourNumber.value.split('.')[0]; + ) + .all(); - const allInactiveAndWithoutMessagesConvo = allInactiveConvos - .map(c => c.id as string) - .filter(convoId => { - return convoId !== ourPubkey && getMessagesCountBySender({ source: convoId }) === 0 - ? true - : false; - }); - if (allInactiveAndWithoutMessagesConvo.length) { - console.info( - `Removing ${allInactiveAndWithoutMessagesConvo.length} completely inactive convos` - ); - const start = Date.now(); + const ourNumber = getItemById('number_id'); + if (!ourNumber || !ourNumber.value) { + return; + } + const ourPubkey = ourNumber.value.split('.')[0]; + + const allInactiveAndWithoutMessagesConvo = allInactiveConvos + .map(c => c.id as string) + .filter(convoId => { + return convoId !== ourPubkey && getMessagesCountBySender({ source: convoId }) === 0 + ? true + : false; + }); + if (allInactiveAndWithoutMessagesConvo.length) { + console.info( + `Removing ${allInactiveAndWithoutMessagesConvo.length} completely inactive convos` + ); + const start = Date.now(); - const chunks = chunk(allInactiveAndWithoutMessagesConvo, 500); - chunks.forEach(ch => { - assertGlobalInstance() - .prepare(`DELETE FROM ${CONVERSATIONS_TABLE} WHERE id IN (${ch.map(() => '?').join(',')});`) - .run(ch); - }); + const chunks = chunk(allInactiveAndWithoutMessagesConvo, 500); + chunks.forEach(ch => { + assertGlobalInstance() + .prepare( + `DELETE FROM ${CONVERSATIONS_TABLE} WHERE id IN (${ch.map(() => '?').join(',')});` + ) + .run(ch); + }); - console.info( - `Removing of ${ - allInactiveAndWithoutMessagesConvo.length - } completely inactive convos done in ${Date.now() - start}ms` - ); - } + console.info( + `Removing of ${ + allInactiveAndWithoutMessagesConvo.length + } completely inactive convos done in ${Date.now() - start}ms` + ); + } - cleanUpMessagesJson(); + cleanUpMessagesJson(); - rebuildFtsTable(assertGlobalInstance()); + rebuildFtsTable(assertGlobalInstance()); + }); } // tslint:disable: binary-expression-operand-order insecure-random diff --git a/ts/session/apis/seed_node_api/SeedNodeAPI.ts b/ts/session/apis/seed_node_api/SeedNodeAPI.ts index e1d39473b..171e517e5 100644 --- a/ts/session/apis/seed_node_api/SeedNodeAPI.ts +++ b/ts/session/apis/seed_node_api/SeedNodeAPI.ts @@ -14,17 +14,13 @@ import { ipcRenderer } from 'electron'; // tslint:disable: function-name -export type SeedNode = { - url: string; -}; - /** * Fetch all snodes from seed nodes. * Exported only for tests. This is not to be used by the app directly * @param seedNodes the seednodes to use to fetch snodes details */ export async function fetchSnodePoolFromSeedNodeWithRetries( - seedNodes: Array + seedNodes: Array ): Promise> { try { window?.log?.info(`fetchSnodePoolFromSeedNode with seedNodes.length ${seedNodes.length}`); @@ -148,7 +144,7 @@ export interface SnodeFromSeed { * If all attempts fails, this function will throw the last error. * The returned list is not shuffled when returned. */ -async function getSnodeListFromSeednode(seedNodes: Array): Promise> { +async function getSnodeListFromSeednode(seedNodes: Array): Promise> { const SEED_NODE_RETRIES = 4; return pRetry( @@ -185,7 +181,7 @@ export function getMinTimeout() { * This function is to be used with a pRetry caller */ export async function TEST_fetchSnodePoolFromSeedNodeRetryable( - seedNodes: Array + seedNodes: Array ): Promise> { window?.log?.info('fetchSnodePoolFromSeedNodeRetryable starting...'); @@ -194,8 +190,8 @@ export async function TEST_fetchSnodePoolFromSeedNodeRetryable( throw new Error('fetchSnodePoolFromSeedNodeRetryable: Seed nodes are empty'); } - const seedNode = _.sample(seedNodes); - if (!seedNode) { + const seedNodeUrl = _.sample(seedNodes); + if (!seedNodeUrl) { window?.log?.warn( 'loki_snode_api::fetchSnodePoolFromSeedNodeRetryable - Could not select random snodes from', seedNodes @@ -203,14 +199,14 @@ export async function TEST_fetchSnodePoolFromSeedNodeRetryable( throw new Error('fetchSnodePoolFromSeedNodeRetryable: Seed nodes are empty #2'); } - const tryUrl = new URL(seedNode.url); + const tryUrl = new URL(seedNodeUrl); const snodes = await getSnodesFromSeedUrl(tryUrl); if (snodes.length === 0) { window?.log?.warn( - `loki_snode_api::fetchSnodePoolFromSeedNodeRetryable - ${seedNode.url} did not return any snodes` + `loki_snode_api::fetchSnodePoolFromSeedNodeRetryable - ${seedNodeUrl} did not return any snodes` ); - throw new Error(`Failed to contact seed node: ${seedNode.url}`); + throw new Error(`Failed to contact seed node: ${seedNodeUrl}`); } return snodes; diff --git a/ts/session/apis/snode_api/SNodeAPI.ts b/ts/session/apis/snode_api/SNodeAPI.ts index 0ee5f9604..f0919e537 100644 --- a/ts/session/apis/snode_api/SNodeAPI.ts +++ b/ts/session/apis/snode_api/SNodeAPI.ts @@ -66,6 +66,7 @@ export type SendParams = { data: string; isSyncMessage?: boolean; messageId?: string; + namespace: number; }; /** @@ -438,6 +439,7 @@ export async function storeOnNode( try { const parsed = JSON.parse(result.body); handleTimestampOffset('store', parsed.t); + await handleHardforkResult(parsed); const messageHash = parsed.hash; if (messageHash) { @@ -505,12 +507,12 @@ export async function retrieveNextMessages( targetNode: Snode, lastHash: string, associatedWith: string, - namespace: number + namespace?: number ): Promise> { const params: RetrieveRequestParams = { pubKey: associatedWith, lastHash: lastHash || '', - namespace: namespace || 0, + namespace, }; const signatureParams = (await getRetrieveSignatureParams(params)) || {}; diff --git a/ts/session/apis/snode_api/snodePool.ts b/ts/session/apis/snode_api/snodePool.ts index 588493934..fe72ca71e 100644 --- a/ts/session/apis/snode_api/snodePool.ts +++ b/ts/session/apis/snode_api/snodePool.ts @@ -9,6 +9,7 @@ import { ed25519Str } from '../../onions/onionPath'; import { OnionPaths } from '../../onions'; import { Onions, SnodePool } from '.'; import { SeedNodeAPI } from '../seed_node_api'; +import { useTestNet } from '../../types'; /** * If we get less than this snode in a swarm, we fetch new snodes for this pubkey */ @@ -179,7 +180,8 @@ export async function getRandomSnodePool(): Promise> { */ // tslint:disable: function-name export async function TEST_fetchFromSeedWithRetriesAndWriteToDb() { - const seedNodes = window.getSeedNodeList(); + // tslint:disable-next-line: no-http-string + const seedNodes = useTestNet ? ['http://public.loki.foundation:38157'] : window.getSeedNodeList(); if (!seedNodes || !seedNodes.length) { window?.log?.error( diff --git a/ts/session/apis/snode_api/swarmPolling.ts b/ts/session/apis/snode_api/swarmPolling.ts index 31b4697bf..5debba79d 100644 --- a/ts/session/apis/snode_api/swarmPolling.ts +++ b/ts/session/apis/snode_api/swarmPolling.ts @@ -163,17 +163,16 @@ export class SwarmPolling { ?.idForLogging() || group.pubkey.key; if (diff >= convoPollingTimeout) { - window?.log?.info( - `Polling for ${loggingId}; timeout: ${convoPollingTimeout} ; diff: ${diff}` - ); - const hardfork190Happened = await getHasSeenHF190(); const hardfork191Happened = await getHasSeenHF191(); + window?.log?.info( + `Polling for ${loggingId}; timeout: ${convoPollingTimeout}; diff: ${diff} ; hardfork190Happened: ${hardfork190Happened}; hardfork191Happened: ${hardfork191Happened} ` + ); if (hardfork190Happened && !hardfork191Happened) { // during the transition period, we poll from both namespaces (0 and -10) for groups return Promise.all([ - this.pollOnceForKey(group.pubkey, true, 0), + this.pollOnceForKey(group.pubkey, true, undefined), this.pollOnceForKey(group.pubkey, true, -10), ]).then(() => undefined); } @@ -184,7 +183,6 @@ export class SwarmPolling { } // before any of those hardforks, we just poll from the default namespace being 0 - console.warn('before any of those hardforks'); return this.pollOnceForKey(group.pubkey, true, 0); } window?.log?.info( @@ -206,7 +204,7 @@ export class SwarmPolling { /** * Only exposed as public for testing */ - public async pollOnceForKey(pubkey: PubKey, isGroup: boolean, namespace: number) { + public async pollOnceForKey(pubkey: PubKey, isGroup: boolean, namespace?: number) { const pkStr = pubkey.key; const swarmSnodes = await snodePool.getSwarmFor(pkStr); @@ -290,7 +288,7 @@ export class SwarmPolling { private async pollNodeForKey( node: Snode, pubkey: PubKey, - namespace: number + namespace?: number ): Promise | null> { const edkey = node.pubkey_ed25519; @@ -299,7 +297,7 @@ export class SwarmPolling { try { return await pRetry( async () => { - const prevHash = await this.getLastHash(edkey, pkStr, namespace); + const prevHash = await this.getLastHash(edkey, pkStr, namespace || 0); const messages = await retrieveNextMessages(node, prevHash, pkStr, namespace); if (!messages.length) { return []; @@ -310,7 +308,7 @@ export class SwarmPolling { await this.updateLastHash({ edkey: edkey, pubkey, - namespace, + namespace: namespace || 0, hash: lastMessage.hash, expiration: lastMessage.expiration, }); diff --git a/ts/session/onions/onionPath.ts b/ts/session/onions/onionPath.ts index 3fc3d7c0c..2015064bf 100644 --- a/ts/session/onions/onionPath.ts +++ b/ts/session/onions/onionPath.ts @@ -276,7 +276,7 @@ async function internalUpdateGuardNodes(updatedGuardNodes: Array) { await Data.updateGuardNodes(edKeys); } -export async function TEST_testGuardNode(snode: Data.Snode) { +export async function testGuardNode(snode: Data.Snode) { window?.log?.info(`Testing a candidate guard node ${ed25519Str(snode.pubkey_ed25519)}`); // Send a post request and make sure it is OK @@ -381,7 +381,7 @@ export async function selectGuardNodes(): Promise> { // Test all three nodes at once, wait for all to resolve or reject // eslint-disable-next-line no-await-in-loop const idxOk = ( - await Promise.allSettled(candidateNodes.map(OnionPaths.TEST_testGuardNode)) + await Promise.allSettled(candidateNodes.map(OnionPaths.testGuardNode)) ).flatMap(p => (p.status === 'fulfilled' ? p.value : null)); const goodNodes = _.zip(idxOk, candidateNodes) diff --git a/ts/session/sending/MessageSender.ts b/ts/session/sending/MessageSender.ts index 7b0099354..6ededfe7e 100644 --- a/ts/session/sending/MessageSender.ts +++ b/ts/session/sending/MessageSender.ts @@ -22,6 +22,7 @@ import { getConversationController } from '../conversations'; import { ed25519Str } from '../onions/onionPath'; import { EmptySwarmError } from '../utils/errors'; import ByteBuffer from 'bytebuffer'; +import { getHasSeenHF190, getHasSeenHF191 } from '../apis/snode_api/hfHandling'; const DEFAULT_CONNECTIONS = 1; @@ -137,29 +138,34 @@ export async function sendMessageToSnode( const data64 = ByteBuffer.wrap(data).toString('base64'); const swarm = await getSwarmFor(pubKey); + const conversation = getConversationController().get(pubKey); + const isClosedGroup = conversation?.isClosedGroup(); + + const hardfork190Happened = await getHasSeenHF190(); + const hardfork191Happened = await getHasSeenHF191(); + const namespace = isClosedGroup ? -10 : 0; + window?.log?.debug( - 'Sending envelope with timestamp: ', - timestamp, - ' to ', - ed25519Str(pubKey), - ' size base64:', - data64.length + `Sending envelope with timestamp: ${timestamp} to ${ed25519Str(pubKey)} size base64: ${ + data64.length + }; hardfork190Happened:${hardfork190Happened}; hardfork191Happened:${hardfork191Happened} to namespace:${namespace}` ); + // send parameters const params = { pubKey, ttl: `${ttl}`, timestamp: `${timestamp}`, data: data64, - isSyncMessage, - messageId, + isSyncMessage, // I don't think that's of any use + messageId, // I don't think that's of any use + namespace, }; const usedNodes = _.slice(swarm, 0, DEFAULT_CONNECTIONS); let successfulSendHash: any; const promises = usedNodes.map(async usedNode => { - // TODO: Revert back to using snode address instead of IP // No pRetry here as if this is a bad path it will be handled and retried in lokiOnionFetch. // the only case we could care about a retry would be when the usedNode is not correct, // but considering we trigger this request with a few snode in //, this should be fine. @@ -189,9 +195,6 @@ export async function sendMessageToSnode( throw new EmptySwarmError(pubKey, 'Ran out of swarm nodes to query'); } - const conversation = getConversationController().get(pubKey); - const isClosedGroup = conversation?.isClosedGroup(); - // If message also has a sync message, save that hash. Otherwise save the hash from the regular message send i.e. only closed groups in this case. if (messageId && (isSyncMessage || isClosedGroup)) { const message = await getMessageById(messageId); diff --git a/ts/session/types/PubKey.ts b/ts/session/types/PubKey.ts index 2076f2e33..f1d0fa4dc 100644 --- a/ts/session/types/PubKey.ts +++ b/ts/session/types/PubKey.ts @@ -1,7 +1,8 @@ import { fromHexToArray } from '../utils/String'; -export const getStoragePubKey = (key: string) => - window.isDev?.() || false ? key.substring(2) : key; +export const useTestNet = process.env.NODE_APP_INSTANCE?.includes('testnet'); + +export const getStoragePubKey = (key: string) => (useTestNet ? key.substring(2) : key); export class PubKey { public static readonly PUBKEY_LEN = 66; diff --git a/ts/test/session/unit/onion/GuardNodes_test.ts b/ts/test/session/unit/onion/GuardNodes_test.ts index e4afd8d21..2dc475bf9 100644 --- a/ts/test/session/unit/onion/GuardNodes_test.ts +++ b/ts/test/session/unit/onion/GuardNodes_test.ts @@ -63,7 +63,7 @@ describe('GuardNodes', () => { SnodePool, 'TEST_fetchFromSeedWithRetriesAndWriteToDb' ).resolves(); - const testGuardNode = Sinon.stub(OnionPaths, 'TEST_testGuardNode').resolves(true); + const testGuardNode = Sinon.stub(OnionPaths, 'testGuardNode').resolves(true); Sinon.stub(Data, 'updateGuardNodes').resolves(); // run the command @@ -98,7 +98,7 @@ describe('GuardNodes', () => { SnodePool, 'TEST_fetchFromSeedWithRetriesAndWriteToDb' ).resolves(); - const testGuardNode = Sinon.stub(OnionPaths, 'TEST_testGuardNode').resolves(false); + const testGuardNode = Sinon.stub(OnionPaths, 'testGuardNode').resolves(false); Sinon.stub(Data, 'updateGuardNodes').resolves(); // run the command @@ -154,7 +154,7 @@ describe('GuardNodes', () => { const invalidSndodePool = fakeSnodePool.slice(0, 11); Sinon.stub(Data, 'getSnodePoolFromDb').resolves(invalidSndodePool); TestUtils.stubWindow('getSeedNodeList', () => [{ url: 'whatever' }]); - const testGuardNode = Sinon.stub(OnionPaths, 'TEST_testGuardNode').resolves(true); + const testGuardNode = Sinon.stub(OnionPaths, 'testGuardNode').resolves(true); getSnodePoolFromDBOrFetchFromSeed = Sinon.stub( SnodePool, diff --git a/ts/test/session/unit/onion/SeedNodeAPI_test.ts b/ts/test/session/unit/onion/SeedNodeAPI_test.ts index 528cb30c7..51fdbd2b0 100644 --- a/ts/test/session/unit/onion/SeedNodeAPI_test.ts +++ b/ts/test/session/unit/onion/SeedNodeAPI_test.ts @@ -74,9 +74,7 @@ describe('SeedNodeAPI', () => { Sinon.stub(SeedNodeAPI, 'getMinTimeout').returns(20); // run the command - const fetched = await SeedNodeAPI.fetchSnodePoolFromSeedNodeWithRetries([ - { url: 'seednode1' }, - ]); + const fetched = await SeedNodeAPI.fetchSnodePoolFromSeedNodeWithRetries(['seednode1']); const sortedFetch = fetched.sort((a, b) => (a.pubkey_ed25519 > b.pubkey_ed25519 ? -1 : 1)); const sortedFakeSnodePool = fakeSnodePool.sort((a, b) => diff --git a/ts/test/session/unit/swarm_polling/SwarmPolling_test.ts b/ts/test/session/unit/swarm_polling/SwarmPolling_test.ts index a539393cf..75ad14834 100644 --- a/ts/test/session/unit/swarm_polling/SwarmPolling_test.ts +++ b/ts/test/session/unit/swarm_polling/SwarmPolling_test.ts @@ -231,7 +231,7 @@ describe('SwarmPolling', () => { // our pubkey will be polled for, hence the 2 expect(pollOnceForKeySpy.callCount).to.eq(3); expect(pollOnceForKeySpy.firstCall.args).to.deep.eq([ourPubkey, false, 0]); - expect(pollOnceForKeySpy.secondCall.args).to.deep.eq([groupConvoPubkey, true, 0]); + expect(pollOnceForKeySpy.secondCall.args).to.deep.eq([groupConvoPubkey, true, undefined]); expect(pollOnceForKeySpy.thirdCall.args).to.deep.eq([groupConvoPubkey, true, -10]); getItemByIdStub.restore(); getItemByIdStub = TestUtils.stubDataItem('getItemById'); diff --git a/ts/util/crypto/attachmentsEncrypter.ts b/ts/util/crypto/attachmentsEncrypter.ts index 521955b06..3258bf539 100644 --- a/ts/util/crypto/attachmentsEncrypter.ts +++ b/ts/util/crypto/attachmentsEncrypter.ts @@ -5,7 +5,7 @@ async function sign(key: any, data: any) { return crypto.subtle .importKey('raw', key, { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']) - .then(async function(secondKey: any) { + .then(async function(secondKey) { return crypto.subtle.sign({ name: 'HMAC', hash: 'SHA-256' }, secondKey, data); }); } @@ -13,14 +13,14 @@ async function sign(key: any, data: any) { async function encrypt(key: any, data: any, iv: any) { return crypto.subtle .importKey('raw', key, { name: 'AES-CBC' }, false, ['encrypt']) - .then(async function(secondKey: any) { + .then(async function(secondKey) { return crypto.subtle.encrypt({ name: 'AES-CBC', iv: new Uint8Array(iv) }, secondKey, data); }); } async function decrypt(key: any, data: any, iv: any) { return crypto.subtle .importKey('raw', key, { name: 'AES-CBC' }, false, ['decrypt']) - .then(async function(secondKey: any) { + .then(async function(secondKey) { return crypto.subtle.decrypt({ name: 'AES-CBC', iv: new Uint8Array(iv) }, secondKey, data); }); } diff --git a/ts/window.d.ts b/ts/window.d.ts index 0b0c2b994..d9064755a 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -42,7 +42,7 @@ declare global { onLogin: any; persistStore?: Persistor; restart: any; - getSeedNodeList: () => Array | undefined; + getSeedNodeList: () => Array | undefined; setPassword: any; storage: any; isOnline: boolean;