Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: eslint on both projects #156

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dist
coverage/
packages/daemon/dist
packages/daemon/node_modules
packages/common/node_modules
packages/wallet-service/node_modules
packages/wallet-service/.serverless
packages/wallet-service/.webpack
Expand Down
32 changes: 25 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,40 @@
"version": "1.5.0",
"workspaces": [
"packages/daemon",
"packages/wallet-service"
"packages/wallet-service",
"packages/common"
],
"engines": {
"node": ">=18"
},
"nohoist": [
"**"
],
"repository": "[email protected]:HathorNetwork/hathor-wallet-service-sync_daemon.git",
"repository": "[email protected]:HathorNetwork/hathor-wallet-service.git",
"author": "André Abadesso <[email protected]>",
"private": true,
"devDependencies": {
"dotenv": "^16.3.1",
"mysql2": "^3.6.1",
"sequelize": "^6.33.0",
"sequelize-cli": "^6.6.1"
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"mysql2": "^3.9.3",
"sequelize": "^6.37.2",
"sequelize-cli": "^6.6.2"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"dependencies": {
"@aws-sdk/client-apigatewaymanagementapi": "3.540.0",
"@aws-sdk/client-lambda": "3.540.0",
"@aws-sdk/client-sqs": "3.540.0",
"@hathor/wallet-lib": "0.39.0",
"bip32": "^4.0.0",
"bitcoinjs-lib": "^6.1.5",
"bitcoinjs-message": "^2.2.0",
"tiny-secp256k1": "^2.2.3",
"winston": "^3.13.0"
}
}
1 change: 1 addition & 0 deletions packages/common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Common utils for the wallet-service
12 changes: 12 additions & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@wallet-service/common",
"packageManager": "[email protected]",
"peerDependencies": {
"@aws-sdk/client-lambda": "3.540.0",
"@hathor/wallet-lib": "0.39.0",
"winston": "^3.13.0"
},
"devDependencies": {
"@types/node": "^20.11.30"
}
}
61 changes: 61 additions & 0 deletions packages/common/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Alerts should follow the on-call guide for alerting, see
* https://github.com/HathorNetwork/ops-tools/blob/master/docs/on-call/guide.md#alert-severitypriority
*/
export enum Severity {
CRITICAL = 'critical',
MAJOR = 'major',
MEDIUM = 'medium',
MINOR = 'minor',
WARNING = 'warning',
INFO = 'info',
}

export interface Transaction {
// eslint-disable-next-line camelcase
tx_id: string;
nonce: number;
timestamp: number;
// eslint-disable-next-line camelcase
signal_bits: number;
version: number;
weight: number;
parents: string[];
inputs: TxInput[];
outputs: TxOutput[];
height?: number;
// eslint-disable-next-line camelcase
token_name?: string;
// eslint-disable-next-line camelcase
token_symbol?: string;
}

export interface TxInput {
// eslint-disable-next-line camelcase
tx_id: string;
index: number;
value: number;
// eslint-disable-next-line camelcase
token_data: number;
script: string;
token: string;
decoded: DecodedOutput;
}

export interface TxOutput {
value: number;
script: string;
token: string;
decoded: DecodedOutput;
// eslint-disable-next-line camelcase
spent_by: string | null;
// eslint-disable-next-line camelcase
token_data: number;
locked?: boolean;
}

export interface DecodedOutput {
type: string;
address: string;
timelock: number | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import { SendMessageCommand, SQSClient } from '@aws-sdk/client-sqs';
import { Severity } from '@src/types';
import { assertEnvVariablesExistence } from '@src/utils';
import createDefaultLogger from '@src/logger';
import { Severity } from '../types';
import { assertEnvVariablesExistence } from './index.utils';
import { Logger } from 'winston';

assertEnvVariablesExistence([
'NETWORK',
Expand All @@ -28,9 +28,9 @@ export const addAlert = async (
title: string,
message: string,
severity: Severity,
metadata?: unknown,
metadata: unknown = null,
logger: Logger,
): Promise<void> => {
const logger = createDefaultLogger();
const preparedMessage = {
title,
message,
Expand Down
25 changes: 25 additions & 0 deletions packages/common/src/utils/index.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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.
*/

/**
* Validates if a list of env variables are set in the environment. Throw if at least
* one of them is missing
*
* @param envVariables - A list of variables to check
*/
export const assertEnvVariablesExistence = (envVariables: string[]): void => {
const missingList = [];
for (const envVariable of envVariables) {
if (!(envVariable in process.env) || process.env[envVariable]?.length === 0) {
missingList.push(envVariable);
}
}

if (missingList.length > 0) {
throw new Error(`Env missing the following variables ${missingList.join(', ')}`);
}
};
20 changes: 20 additions & 0 deletions packages/common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"sourceMap": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist",
"types": ["node", "jest"]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"dist"
]
}
File renamed without changes.
3 changes: 2 additions & 1 deletion .eslintrc.yml → packages/daemon/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ parser: '@typescript-eslint/parser'
parserOptions:
ecmaVersion: 2022
sourceType: 'module'
project: './tsconfig.json'
project: './tsconfig.eslint.json'
env:
node: true
es6: true
Expand All @@ -22,6 +22,7 @@ overrides:
excludedFiles:
- 'dist/*'
- 'node_modules/*'
- '__tests__/**/*.ts'
- files:
- "*.js"
parser: "espree"
Expand Down
4 changes: 4 additions & 0 deletions packages/daemon/__tests__/guards/guards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jest.mock('../../src/config', () => {
};
});

jest.mock('@wallet-service/common/src/utils/index.utils', () => ({
assertEnvVariablesExistence: jest.fn(),
}));

import getConfig from '../../src/config';

const TxCache = {
Expand Down
4 changes: 4 additions & 0 deletions packages/daemon/__tests__/integration/balances.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jest.mock('../../src/config', () => {
};
});

jest.mock('@wallet-service/common/src/utils/index.utils', () => ({
assertEnvVariablesExistence: jest.fn(),
}));

import getConfig from '../../src/config';

// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const attemptConnection = async (maxAttempts: number, interval: number): Promise
}
}

throw new Error('Maximum connection attempts reached. Exiting.');;
throw new Error('Maximum connection attempts reached. Exiting.');
};

// Attempt to connect
Expand Down
3 changes: 3 additions & 0 deletions packages/daemon/__tests__/machines/SyncMachine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import getConfig from '../../src/config';
const { TX_CACHE_SIZE, FULLNODE_PEER_ID, STREAM_ID } = getConfig();
const { VERTEX_METADATA_CHANGED, NEW_VERTEX_ACCEPTED, REORG_STARTED } = EventFixtures;

jest.mock('@wallet-service/common/src/utils/index.utils', () => ({
assertEnvVariablesExistence: jest.fn(),
}));

const TxCache = new LRU(TX_CACHE_SIZE);

Expand Down
11 changes: 7 additions & 4 deletions packages/daemon/__tests__/services/services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ import {
handleVoidedTx,
handleVertexAccepted,
metadataDiff,
fetchMinRewardBlocks,
} from '../../src/services';
import logger from '../../src/logger';
import {
import {
getAddressBalanceMap,
prepareInputs,
prepareOutputs,
Expand Down Expand Up @@ -91,6 +90,10 @@ jest.mock('../../src/utils', () => ({
getFullnodeHttpUrl: jest.fn(),
}));

jest.mock('@wallet-service/common/src/utils/index.utils', () => ({
assertEnvVariablesExistence: jest.fn(),
}));

beforeEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -452,9 +455,9 @@ describe('handleVertexAccepted', () => {
maxGap: 10
},
});

await handleVertexAccepted(context as any, {} as any);

expect(getDbConnection).toHaveBeenCalled();
expect(mockDb.beginTransaction).toHaveBeenCalled();
expect(getTransactionById).toHaveBeenCalledWith(mockDb, 'hashValue');
Expand Down
21 changes: 13 additions & 8 deletions packages/daemon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,26 @@
"@types/mysql": "^2.15.21",
"@types/node": "^17.0.45",
"@types/ws": "^8.5.5",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-jest": "^27.4.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"jest": "^29.6.4",
"sequelize-cli": "^6.6.1",
"ts-jest": "^29.1.1",
"tslib": "^2.1.0",
"typescript": "^4.9.5"
"typescript": "^5.4.4"
},
"peerDependencies": {
"@aws-sdk/client-lambda": "3.540.0",
"@aws-sdk/client-sqs": "3.540.0",
"@hathor/wallet-lib": "0.39.0",
"winston": "^3.13.0"
},
"dependencies": {
"@aws-sdk/client-lambda": "^3.474.0",
"@aws-sdk/client-sqs": "^3.474.0",
"@hathor/wallet-lib": "^0.39.0",
"@wallet-service/common": "workspace:^",
"assert": "^2.1.0",
"aws-sdk": "^2.1454.0",
"axios": "^1.6.2",
Expand All @@ -54,7 +60,6 @@
"mysql2": "^3.5.2",
"sequelize": "^6.33.0",
"websocket": "^1.0.33",
"winston": "^3.3.3",
"ws": "^8.13.0",
"xstate": "^4.38.2"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/daemon/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const addUtxos = async (
* @param inputs - The transaction inputs
* @param txId - The transaction that spent these utxos
*/
export const updateTxOutputSpentBy = async (mysql: any, inputs: TxInput[], txId: string): Promise<void> => {
export const updateTxOutputSpentBy = async (mysql: any, inputs: TxInput[], txId: string): Promise<void> => {
const entries = inputs.map((input) => [input.tx_id, input.index]);
// entries might be empty if there are no inputs
if (entries.length) {
Expand Down Expand Up @@ -241,7 +241,7 @@ export const getTxOutputsFromTx = async (

* @returns A list of tx outputs
*/
export const getTxOutputs = async (
export const getTxOutputs = async (
mysql: any,
inputs: {txId: string, index: number}[],
): Promise<DbTxOutput[]> => {
Expand Down
Loading
Loading