From a4e5832d3c9cfae9506bc58f4c5d931b538767c3 Mon Sep 17 00:00:00 2001 From: Tomas Martykan Date: Thu, 7 Nov 2024 15:17:05 +0100 Subject: [PATCH] feat(connect): make transportReconnect implicitly true --- packages/connect/e2e/common.setup.ts | 1 + .../connect/src/core/__tests__/Core.test.ts | 6 ++++- packages/connect/src/data/connectSettings.ts | 1 + .../src/device/__tests__/DeviceList.test.ts | 24 +++++++++++-------- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/connect/e2e/common.setup.ts b/packages/connect/e2e/common.setup.ts index ef055bb644e..397af5403bf 100644 --- a/packages/connect/e2e/common.setup.ts +++ b/packages/connect/e2e/common.setup.ts @@ -127,6 +127,7 @@ export const initTrezorConnect = async ( debug: false, popup: false, pendingTransportEvent: true, + transportReconnect: false, connectSrc: process.env.TREZOR_CONNECT_SRC, // custom source for karma tests ...options, }); diff --git a/packages/connect/src/core/__tests__/Core.test.ts b/packages/connect/src/core/__tests__/Core.test.ts index 68b80aaa1b4..bcd9e4dbcd8 100644 --- a/packages/connect/src/core/__tests__/Core.test.ts +++ b/packages/connect/src/core/__tests__/Core.test.ts @@ -7,7 +7,11 @@ import { initCoreState } from '../index'; const { createTestTransport } = global.JestMocks; const getSettings = (partial: Partial = {}) => - parseConnectSettings({ transports: [createTestTransport()], ...partial }); + parseConnectSettings({ + transports: [createTestTransport()], + transportReconnect: false, + ...partial, + }); describe('Core', () => { beforeAll(async () => {}); diff --git a/packages/connect/src/data/connectSettings.ts b/packages/connect/src/data/connectSettings.ts index e4e0b021a89..1886127aa15 100644 --- a/packages/connect/src/data/connectSettings.ts +++ b/packages/connect/src/data/connectSettings.ts @@ -29,6 +29,7 @@ const initialSettings: ConnectSettings = { interactionTimeout: 600, // 5 minutes sharedLogger: true, deeplinkUrl: `${DEFAULT_DOMAIN}deeplink/${DEEPLINK_VERSION}/`, + transportReconnect: true, }; const parseManifest = (manifest?: Manifest) => { diff --git a/packages/connect/src/device/__tests__/DeviceList.test.ts b/packages/connect/src/device/__tests__/DeviceList.test.ts index 9c90023a4d0..9feca0ce57b 100644 --- a/packages/connect/src/device/__tests__/DeviceList.test.ts +++ b/packages/connect/src/device/__tests__/DeviceList.test.ts @@ -27,7 +27,9 @@ describe('DeviceList', () => { beforeAll(async () => { // todo: I don't get it. If we pass empty messages: {} (see getDeviceListParams), tests behave differently. await DataManager.load({ - ...parseConnectSettings({}), + ...parseConnectSettings({ + transportReconnect: false, + }), }); // Todo: This is a hack, it should not be here at all. Transport shall return valid device (with valid features) @@ -42,7 +44,9 @@ describe('DeviceList', () => { beforeEach(() => { list = new DeviceList({ - ...parseConnectSettings({}), + ...parseConnectSettings({ + transportReconnect: false, + }), messages: DataManager.getProtobufMessages(), }); eventsSpy = jest.fn(); @@ -99,7 +103,7 @@ describe('DeviceList', () => { ); list.setTransports([transport]); - list.init({ pendingTransportEvent: true }); + list.init({ pendingTransportEvent: true, transportReconnect: false }); // transport-error is not emitted yet because list.init is not awaited expect(eventsSpy).toHaveBeenCalledTimes(0); await list.pendingConnection(); @@ -117,7 +121,7 @@ describe('DeviceList', () => { ); list.setTransports([transport]); - list.init({ pendingTransportEvent: true }); + list.init({ pendingTransportEvent: true, transportReconnect: false }); // transport-error is not emitted yet because list.init is not awaited expect(eventsSpy).toHaveBeenCalledTimes(0); await list.pendingConnection(); @@ -131,7 +135,7 @@ describe('DeviceList', () => { }); list.setTransports([transport]); - list.init({ pendingTransportEvent: true }); + list.init({ pendingTransportEvent: true, transportReconnect: false }); await list.pendingConnection(); const events = eventsSpy.mock.calls.map(call => call[0]); @@ -144,7 +148,7 @@ describe('DeviceList', () => { }); list.setTransports([transport]); - list.init({ pendingTransportEvent: true }); + list.init({ pendingTransportEvent: true, transportReconnect: false }); const transportFirstEvent = list.pendingConnection(); // NOTE: this behavior is wrong, if device creation fails DeviceList shouldn't wait 10 secs. @@ -174,7 +178,7 @@ describe('DeviceList', () => { }); list.setTransports([transport]); - list.init({ pendingTransportEvent: true }); + list.init({ pendingTransportEvent: true, transportReconnect: false }); await list.pendingConnection(); const events = eventsSpy.mock.calls.map(call => call[0]); @@ -189,7 +193,7 @@ describe('DeviceList', () => { }); list.setTransports([transport]); - list.init({ pendingTransportEvent: true }); + list.init({ pendingTransportEvent: true, transportReconnect: false }); await list.pendingConnection(); const events = eventsSpy.mock.calls.map(([event, { path }]) => [event, path]); @@ -221,7 +225,7 @@ describe('DeviceList', () => { // NOTE: this behavior is wrong jest.useFakeTimers(); list.setTransports([transport]); - list.init({ pendingTransportEvent: true }); + list.init({ pendingTransportEvent: true, transportReconnect: false }); const transportFirstEvent = list.pendingConnection(); await jest.advanceTimersByTimeAsync(6 * 1000); // TODO: this is wrong await transportFirstEvent; @@ -267,7 +271,7 @@ describe('DeviceList', () => { }); list.setTransports([transport]); - list.init({ pendingTransportEvent: true }); + list.init({ pendingTransportEvent: true, transportReconnect: false }); await list.pendingConnection(); // emit TRANSPORT.CHANGE 3 times