Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/common/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
roots: ["<rootDir>/__tests__"],
setupFiles: ['./jestSetup.ts'],
testRegex: ".*\\.test\\.ts$",
moduleNameMapper: {
'^@src/(.*)$': '<rootDir>/src/$1',
Expand Down
10 changes: 10 additions & 0 deletions packages/common/jestSetup.ts
Original file line number Diff line number Diff line change
@@ -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';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing hathor header

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

stopGLLBackgroundTask();

2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/daemon/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
roots: ["<rootDir>/__tests__"],
setupFiles: ['./jestSetup.ts'],
testRegex: ".*\\.test\\.ts$",
transform: {
"^.+\\.ts$": ["ts-jest", {
Expand Down
13 changes: 13 additions & 0 deletions packages/daemon/jestSetup.ts
Original file line number Diff line number Diff line change
@@ -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';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing hathor header

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


Object.defineProperty(global, '_bitcore', { get() { return undefined; }, set() {} });

stopGLLBackgroundTask();

1 change: 1 addition & 0 deletions packages/daemon/jest_integration.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const mainTestMatch = process.env.SPECIFIC_INTEGRATION_TEST_FILE

module.exports = {
roots: ["<rootDir>/__tests__"],
setupFiles: ['./jestSetup.ts'],
transform: {
"^.+\\.ts$": ["ts-jest", {
tsconfig: "./tsconfig.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/daemon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions packages/wallet-service/tests/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
checkWalletTable,
createOutput,
createInput,
stopWalletLibOpenHandles,
} from '@tests/utils';
import { SNSEvent } from 'aws-lambda';

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/wallet-service/tests/jestSetup.ts
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Comment thread
pedroferreira1 marked this conversation as resolved.

await addToWalletTable(mysql, [{
id: 'my-wallet',
Expand Down
5 changes: 5 additions & 0 deletions packages/wallet-service/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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."');
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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();
Expand All @@ -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.');
});
Expand All @@ -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.');
});
Expand Down Expand Up @@ -468,6 +483,7 @@ describe('PushNotificationUtils', () => {
// reload module
jest.resetModules();
const { PushNotificationUtils } = await import('@src/utils/pushnotification.utils');
await stopWalletLibOpenHandles();

const notification = {
deviceId: 'device1',
Expand Down Expand Up @@ -511,6 +527,7 @@ describe('PushNotificationUtils', () => {
// reload module
jest.resetModules();
const { PushNotificationUtils } = await import('@src/utils/pushnotification.utils');
await stopWalletLibOpenHandles();

const notification = {
deviceId: 'device1',
Expand Down Expand Up @@ -542,6 +559,7 @@ describe('PushNotificationUtils', () => {
// reload module
jest.resetModules();
const { PushNotificationUtils } = await import('@src/utils/pushnotification.utils');
await stopWalletLibOpenHandles();

const notification = {
deviceId: 'device1',
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]');
Expand Down
3 changes: 3 additions & 0 deletions packages/wallet-service/tests/ws.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jest.mock('redis', () => ({
}));

import { endWsConnection } from '@src/redis';
import { stopWalletLibOpenHandles } from './utils';

test('connectionInfoFromEvent', async () => {
expect.hasAssertions();
Expand All @@ -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);
Expand Down Expand Up @@ -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');
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down