diff --git a/package.json b/package.json index e7c73712..89fc7a0d 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@aws-sdk/client-apigatewaymanagementapi": "3.540.0", "@aws-sdk/client-lambda": "3.540.0", "@aws-sdk/client-sqs": "3.540.0", - "@hathor/wallet-lib": "2.5.1", + "@hathor/wallet-lib": "2.8.3", "@wallet-service/common": "1.5.0", "bip32": "^4.0.0", "bitcoinjs-lib": "^6.1.5", diff --git a/packages/common/jest.config.js b/packages/common/jest.config.js index c80cb292..e11b9f1f 100644 --- a/packages/common/jest.config.js +++ b/packages/common/jest.config.js @@ -1,5 +1,6 @@ module.exports = { roots: ["/__tests__"], + setupFiles: ['./jestSetup.ts'], testRegex: ".*\\.test\\.ts$", moduleNameMapper: { '^@src/(.*)$': '/src/$1', diff --git a/packages/common/jestSetup.ts b/packages/common/jestSetup.ts new file mode 100644 index 00000000..bc3028f6 --- /dev/null +++ b/packages/common/jestSetup.ts @@ -0,0 +1,10 @@ +/** + * Copyright (c) Hathor Labs and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { stopGLLBackgroundTask } from '@hathor/wallet-lib'; +stopGLLBackgroundTask(); + diff --git a/packages/common/package.json b/packages/common/package.json index b3136a27..7d78d5c1 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -8,7 +8,7 @@ "test": "jest --runInBand --collectCoverage --detectOpenHandles --forceExit" }, "peerDependencies": { - "@hathor/wallet-lib": "2.5.1" + "@hathor/wallet-lib": "2.8.3" }, "dependencies": { "@aws-sdk/client-lambda": "3.540.0", diff --git a/packages/daemon/jest.config.js b/packages/daemon/jest.config.js index 8707fee2..3a1f11f5 100644 --- a/packages/daemon/jest.config.js +++ b/packages/daemon/jest.config.js @@ -1,5 +1,6 @@ module.exports = { roots: ["/__tests__"], + setupFiles: ['./jestSetup.ts'], testRegex: ".*\\.test\\.ts$", transform: { "^.+\\.ts$": ["ts-jest", { diff --git a/packages/daemon/jestSetup.ts b/packages/daemon/jestSetup.ts new file mode 100644 index 00000000..0e1420b6 --- /dev/null +++ b/packages/daemon/jestSetup.ts @@ -0,0 +1,13 @@ +/** + * Copyright (c) Hathor Labs and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { stopGLLBackgroundTask } from '@hathor/wallet-lib'; + +Object.defineProperty(global, '_bitcore', { get() { return undefined; }, set() {} }); + +stopGLLBackgroundTask(); + diff --git a/packages/daemon/jest_integration.config.js b/packages/daemon/jest_integration.config.js index 2e30f587..86722d5e 100644 --- a/packages/daemon/jest_integration.config.js +++ b/packages/daemon/jest_integration.config.js @@ -6,6 +6,7 @@ const mainTestMatch = process.env.SPECIFIC_INTEGRATION_TEST_FILE module.exports = { roots: ["/__tests__"], + setupFiles: ['./jestSetup.ts'], transform: { "^.+\\.ts$": ["ts-jest", { tsconfig: "./tsconfig.json", diff --git a/packages/daemon/package.json b/packages/daemon/package.json index 44da1f29..55ca89dd 100644 --- a/packages/daemon/package.json +++ b/packages/daemon/package.json @@ -46,7 +46,7 @@ "typescript": "4.9.5" }, "peerDependencies": { - "@hathor/wallet-lib": "2.5.1", + "@hathor/wallet-lib": "2.8.3", "@wallet-service/common": "1.5.0" }, "dependencies": { diff --git a/packages/wallet-service/package.json b/packages/wallet-service/package.json index eaca1b62..e226a934 100644 --- a/packages/wallet-service/package.json +++ b/packages/wallet-service/package.json @@ -44,7 +44,7 @@ "winston": "3.13.0" }, "peerDependencies": { - "@hathor/wallet-lib": "2.5.1", + "@hathor/wallet-lib": "2.8.3", "@wallet-service/common": "1.5.0" }, "devDependencies": { diff --git a/packages/wallet-service/tests/integration.test.ts b/packages/wallet-service/tests/integration.test.ts index 9f811322..527a4b3d 100644 --- a/packages/wallet-service/tests/integration.test.ts +++ b/packages/wallet-service/tests/integration.test.ts @@ -15,6 +15,7 @@ import { checkWalletTable, createOutput, createInput, + stopWalletLibOpenHandles, } from '@tests/utils'; import { SNSEvent } from 'aws-lambda'; @@ -130,6 +131,7 @@ beforeAll(async () => { process.env.BLOCK_REWARD_LOCK = '1'; const actualUtils = jest.requireActual('@src/utils'); + await stopWalletLibOpenHandles(); jest.mock('@src/utils', () => { return { ...actualUtils, diff --git a/packages/wallet-service/tests/jestSetup.ts b/packages/wallet-service/tests/jestSetup.ts index 7a477f44..a0aa3ecf 100644 --- a/packages/wallet-service/tests/jestSetup.ts +++ b/packages/wallet-service/tests/jestSetup.ts @@ -1,6 +1,8 @@ /* eslint-disable @typescript-eslint/no-empty-function */ import { config } from 'dotenv'; +import { stopGLLBackgroundTask } from '@hathor/wallet-lib'; Object.defineProperty(global, '_bitcore', { get() { return undefined; }, set() {} }); +stopGLLBackgroundTask(); config(); diff --git a/packages/wallet-service/tests/pushSendNotificationToDevice.test.ts b/packages/wallet-service/tests/pushSendNotificationToDevice.test.ts index 7848f429..afd9b946 100644 --- a/packages/wallet-service/tests/pushSendNotificationToDevice.test.ts +++ b/packages/wallet-service/tests/pushSendNotificationToDevice.test.ts @@ -19,6 +19,7 @@ import { makeGatewayEventWithAuthorizer, cleanDatabase, checkPushDevicesTable, + stopWalletLibOpenHandles, } from '@tests/utils'; import { APIGatewayProxyResult, Context } from 'aws-lambda'; import { Severity } from '@wallet-service/common/src/types'; @@ -253,6 +254,7 @@ describe('alert', () => { // allow android and desktop, while test for ios provider process.env.PUSH_ALLOWED_PROVIDERS = 'android,desktop'; await import('@src/api/pushSendNotificationToDevice'); + await stopWalletLibOpenHandles(); await addToWalletTable(mysql, [{ id: 'my-wallet', diff --git a/packages/wallet-service/tests/utils.ts b/packages/wallet-service/tests/utils.ts index 4eef5726..86b0a683 100644 --- a/packages/wallet-service/tests/utils.ts +++ b/packages/wallet-service/tests/utils.ts @@ -1145,3 +1145,8 @@ export const getXPrivKeyFromSeed = ( const code = new Mnemonic(seed); return code.toHDPrivateKey(passphrase, network.bitcoreNetwork); }; + +export const stopWalletLibOpenHandles = async () => { + const { stopGLLBackgroundTask } = await import('@hathor/wallet-lib'); + stopGLLBackgroundTask(); +}; diff --git a/packages/wallet-service/tests/utils/pushnotification.utils.test.ts b/packages/wallet-service/tests/utils/pushnotification.utils.test.ts index 16570e6b..0fde2b65 100644 --- a/packages/wallet-service/tests/utils/pushnotification.utils.test.ts +++ b/packages/wallet-service/tests/utils/pushnotification.utils.test.ts @@ -10,7 +10,7 @@ import { SendNotificationToDevice } from '@src/types'; import { Severity } from '@wallet-service/common/src/types'; import { sendMock, lambdaInvokeCommandMock } from '@tests/utils/aws-sdk.mock'; import { LambdaClient } from '@aws-sdk/client-lambda'; -import { buildWalletBalanceValueMap } from '@tests/utils'; +import { buildWalletBalanceValueMap, stopWalletLibOpenHandles } from '@tests/utils'; import { bigIntUtils } from '@hathor/wallet-lib'; const isFirebaseInitializedMock = jest.spyOn(pushnotificationUtils, 'isFirebaseInitialized'); @@ -61,6 +61,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); const resultMessageOfLastCallToLoggerError = logger.error.mock.calls[0][0]; expect(resultMessageOfLastCallToLoggerError).toMatchInlineSnapshot('"Error initializing Firebase Admin SDK. ErrorMessage: Failed to parse private key: Error: Invalid PEM formatted message."'); @@ -77,6 +78,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(mockedAddAlert).toHaveBeenLastCalledWith( 'Lambda missing env variables', @@ -97,6 +99,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(mockedAddAlert).toHaveBeenLastCalledWith( 'Lambda missing env variables', @@ -117,6 +120,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(mockedAddAlert).toHaveBeenLastCalledWith( 'Lambda missing env variables', @@ -137,6 +141,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(mockedAddAlert).toHaveBeenLastCalledWith( 'Lambda missing env variables', @@ -157,6 +162,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(mockedAddAlert).toHaveBeenLastCalledWith( 'Lambda missing env variables', @@ -177,6 +183,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(mockedAddAlert).toHaveBeenLastCalledWith( 'Lambda missing env variables', @@ -197,6 +204,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(mockedAddAlert).toHaveBeenLastCalledWith( 'Lambda missing env variables', @@ -217,6 +225,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(mockedAddAlert).toHaveBeenLastCalledWith( 'Lambda missing env variables', @@ -237,6 +246,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(mockedAddAlert).toHaveBeenLastCalledWith( 'Lambda missing env variables', @@ -257,6 +267,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(mockedAddAlert).toHaveBeenLastCalledWith( 'Lambda missing env variables', @@ -277,6 +288,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(mockedAddAlert).toHaveBeenLastCalledWith( 'Lambda missing env variables', @@ -300,6 +312,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); // No alert should be raised since push notifications are disabled expect(mockedAddAlert).not.toHaveBeenCalled(); @@ -315,6 +328,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(logger.error).toHaveBeenLastCalledWith('[ALERT] Error while parsing the env.FIREBASE_PRIVATE_KEY.'); }); @@ -328,6 +342,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); expect(logger.error).toHaveBeenLastCalledWith('[ALERT] env.PUSH_ALLOWED_PROVIDERS is empty.'); }); @@ -468,6 +483,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); const { PushNotificationUtils } = await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); const notification = { deviceId: 'device1', @@ -511,6 +527,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); const { PushNotificationUtils } = await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); const notification = { deviceId: 'device1', @@ -542,6 +559,7 @@ describe('PushNotificationUtils', () => { // reload module jest.resetModules(); const { PushNotificationUtils } = await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); const notification = { deviceId: 'device1', @@ -570,6 +588,7 @@ describe('PushNotificationUtils', () => { }); jest.resetModules(); const { PushNotificationUtils, buildFunctionName } = await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); const walletMap = buildWalletBalanceValueMap(); const result = await PushNotificationUtils.invokeOnTxPushNotificationRequestedLambda(walletMap); @@ -604,6 +623,7 @@ describe('PushNotificationUtils', () => { process.env.PUSH_NOTIFICATION_ENABLED = 'false'; jest.resetModules(); const { PushNotificationUtils } = await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); const walletMap = buildWalletBalanceValueMap(); const result = await PushNotificationUtils.invokeOnTxPushNotificationRequestedLambda(walletMap); @@ -634,6 +654,7 @@ describe('PushNotificationUtils', () => { process.env.PUSH_NOTIFICATION_ENABLED = 'true'; jest.resetModules(); const { PushNotificationUtils } = await import('@src/utils/pushnotification.utils'); + await stopWalletLibOpenHandles(); const walletMap = buildWalletBalanceValueMap(); await expect(PushNotificationUtils.invokeOnTxPushNotificationRequestedLambda(walletMap)).rejects.toMatchInlineSnapshot('[Error: hathor-wallet-service-stage-txPushRequested lambda invoke failed for wallets: wallet1]'); diff --git a/packages/wallet-service/tests/ws.utils.test.ts b/packages/wallet-service/tests/ws.utils.test.ts index 7c6e84bb..2d9cca59 100644 --- a/packages/wallet-service/tests/ws.utils.test.ts +++ b/packages/wallet-service/tests/ws.utils.test.ts @@ -42,6 +42,7 @@ jest.mock('redis', () => ({ })); import { endWsConnection } from '@src/redis'; +import { stopWalletLibOpenHandles } from './utils'; test('connectionInfoFromEvent', async () => { expect.hasAssertions(); @@ -60,6 +61,7 @@ test('connectionInfoFromEvent', async () => { try { const { connectionInfoFromEvent } = await import('@src/ws/utils'); + await stopWalletLibOpenHandles(); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const connInfo = connectionInfoFromEvent(event); @@ -90,6 +92,7 @@ test('missing WS_DOMAIN should throw', async () => { try { const { connectionInfoFromEvent } = await import('@src/ws/utils'); + await stopWalletLibOpenHandles(); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore expect(() => connectionInfoFromEvent(event)).toThrow('Domain not on env variables'); diff --git a/yarn.lock b/yarn.lock index a05d9d25..972274fa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3636,9 +3636,9 @@ __metadata: languageName: node linkType: hard -"@hathor/wallet-lib@npm:2.5.1": - version: 2.5.1 - resolution: "@hathor/wallet-lib@npm:2.5.1" +"@hathor/wallet-lib@npm:2.8.3": + version: 2.8.3 + resolution: "@hathor/wallet-lib@npm:2.8.3" dependencies: axios: "npm:1.7.7" bitcore-lib: "npm:8.25.10" @@ -3650,7 +3650,7 @@ __metadata: queue-microtask: "npm:1.2.3" ws: "npm:8.17.1" zod: "npm:3.23.8" - checksum: 10/6afb2123a29de80d09cfcbe14c69709a41cd36e1f4fdcbe5dcb74690057dbff482d434a904e734a0154ded4fb8e168eb443acba4d9b5815795d92f677f274b09 + checksum: 10/a52b8f8de761a7abdfb206ed536b0fae21c3904cb6b55730cc4dc5c293874ffd89c91babf47536d040c20dc3e2dd542016dfc6bdba282a662e86c3e638291c26 languageName: node linkType: hard @@ -7465,7 +7465,7 @@ __metadata: typescript: "npm:5.4.3" winston: "npm:3.13.0" peerDependencies: - "@hathor/wallet-lib": 2.5.1 + "@hathor/wallet-lib": 2.8.3 languageName: unknown linkType: soft @@ -12289,7 +12289,7 @@ __metadata: "@aws-sdk/client-apigatewaymanagementapi": "npm:3.540.0" "@aws-sdk/client-lambda": "npm:3.540.0" "@aws-sdk/client-sqs": "npm:3.540.0" - "@hathor/wallet-lib": "npm:2.5.1" + "@hathor/wallet-lib": "npm:2.8.3" "@types/jest": "npm:29.5.13" "@typescript-eslint/eslint-plugin": "npm:^7.4.0" "@typescript-eslint/parser": "npm:^7.4.0" @@ -17817,7 +17817,7 @@ __metadata: xstate: "npm:4.38.2" zod: "npm:3.23.8" peerDependencies: - "@hathor/wallet-lib": 2.5.1 + "@hathor/wallet-lib": 2.8.3 "@wallet-service/common": 1.5.0 languageName: unknown linkType: soft @@ -18938,7 +18938,7 @@ __metadata: webpack-node-externals: "npm:3.0.0" winston: "npm:3.13.0" peerDependencies: - "@hathor/wallet-lib": 2.5.1 + "@hathor/wallet-lib": 2.8.3 "@wallet-service/common": 1.5.0 languageName: unknown linkType: soft