Skip to content

Commit

Permalink
chore: rebas eme
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabadesso committed Jun 6, 2024
1 parent 3e80498 commit fe2078e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 19 deletions.
11 changes: 8 additions & 3 deletions packages/common/__tests__/utils/alerting.utils.mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export const mockedAddAlert = jest.fn();
export default jest.mock('@src/utils/alerting.utils', () => ({
addAlert: mockedAddAlert.mockReturnValue(Promise.resolve()),
}));
export default jest.mock('@src/utils/alerting.utils', () => {
const originalModule = jest.requireActual('@src/utils/alerting.utils');

return {
...originalModule,
addAlert: mockedAddAlert.mockReturnValue(Promise.resolve()),
};
});
11 changes: 10 additions & 1 deletion packages/common/__tests__/utils/nft.utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @ts-ignore: Using old wallet-lib version, no types exported
import hathorLib from '@hathor/wallet-lib';
import { mockedAddAlert } from './alerting.utils.mock';
import { Severity } from '@src/types';
import { NftUtils } from '@src/utils/nft.utils';
import { Severity } from '@src/types';
import { getHandlerContext, getTransaction } from '../events/nftCreationTx';
import {
LambdaClient as LambdaClientMock,
Expand Down Expand Up @@ -37,6 +37,15 @@ jest.mock('@aws-sdk/client-lambda', () => {
};
});

jest.mock('@src/utils/index.utils', () => {
const originalModule = jest.requireActual('@src/utils/index.utils');

return {
...originalModule,
assertEnvVariablesExistence: jest.fn(),
};
});

const network = new hathorLib.Network('testnet');
const logger = new Logger();

Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/utils/alerting.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import { SendMessageCommand, SQSClient } from '@aws-sdk/client-sqs';
import { Severity } from '../types';
import { Logger } from 'winston';
import * as indexUtils from './index.utils';
import { assertEnvVariablesExistence } from './index.utils';

console.log('index utils: ', indexUtils);

assertEnvVariablesExistence([
'NETWORK',
'APPLICATION_NAME',
Expand Down
6 changes: 3 additions & 3 deletions packages/common/src/utils/index.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

export * as alertUtils from './alerting.utils';
export * as nftUtils from './nft.utils';
export * as walletUtils from './wallet.utils';
export * from './alerting.utils';
export * from './nft.utils';
export * from './wallet.utils';

/**
* Validates if a list of env variables are set in the environment. Throw if at least
Expand Down
6 changes: 3 additions & 3 deletions packages/daemon/__tests__/db/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import {
createOutput,
XPUBKEY,
} from '../utils';
import { walletUtils } from '@wallet-service/common';
import { isAuthority } from '@wallet-service/common';
import { DbTxOutput, StringMap, TokenInfo, WalletStatus } from '../../src/types';
import { Authorities, TokenBalanceMap } from '@wallet-service/common';

Expand Down Expand Up @@ -160,7 +160,7 @@ describe('tx output methods', () => {
let { value } = output;
const { token, decoded } = output;
let authorities = 0;
if (walletUtils.isAuthority(output.token_data)) {
if (isAuthority(output.token_data)) {
authorities = value;
value = 0;
}
Expand Down Expand Up @@ -233,7 +233,7 @@ describe('tx output methods', () => {
let { value } = output;
const { token, decoded } = output;
let authorities = 0;
if (walletUtils.isAuthority(output.token_data)) {
if (isAuthority(output.token_data)) {
authorities = value;
value = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/daemon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test_images_wait_for_db": "yarn dlx ts-node ./__tests__/integration/scripts/wait-for-db-up.ts",
"test_images_wait_for_ws": "yarn dlx ts-node ./__tests__/integration/scripts/wait-for-ws-up.ts",
"test_images_setup_database": "yarn dlx ts-node ./__tests__/integration/scripts/setup-database.ts",
"test": "jest --coverage",
"test": "jest --coverage --verbose",
"test_integration": "yarn run test_images_up && yarn run test_images_wait_for_db && yarn run test_images_wait_for_ws && yarn run test_images_setup_database && yarn run test_images_migrate && yarn run test_images_integration && yarn run test_images_down"
},
"name": "sync-daemon",
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 @@ -25,7 +25,7 @@ import {
TokenBalanceMap,
TxOutputWithIndex,
} from '@wallet-service/common';
import { walletUtils as walletServiceUtils } from '@wallet-service/common';
import { isAuthority } from '@wallet-service/common';
import {
AddressBalanceRow,
AddressTxHistorySumRow,
Expand Down Expand Up @@ -126,7 +126,7 @@ export const addUtxos = async (
let authorities = 0;
let value = output.value;

if (walletServiceUtils.isAuthority(output.token_data)) {
if (isAuthority(output.token_data)) {
authorities = value;
value = 0;
}
Expand Down
9 changes: 3 additions & 6 deletions packages/daemon/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import hathorLib from '@hathor/wallet-lib';
import axios from 'axios';
import { get } from 'lodash';
import { nftUtils } from '@wallet-service/common';
import { NftUtils } from '@wallet-service/common';
import {
StringMap,
Wallet,
Expand Down Expand Up @@ -67,9 +67,6 @@ import getConfig from '../config';
import logger from '../logger';
import { invokeOnTxPushNotificationRequestedLambda, sendMessageSQS } from '../utils/aws';

console.log('\n\n\n NFT UTILS', nftUtils);
console.log('\n\n\n');

export const METADATA_DIFF_EVENT_TYPES = {
IGNORE: 'IGNORE',
TX_VOIDED: 'TX_VOIDED',
Expand Down Expand Up @@ -359,10 +356,10 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => {
const network = new hathorLib.Network(NETWORK);

// Validating for NFTs only after the tx is successfully added
if (nftUtils.NftUtils.shouldInvokeNftHandlerForTx(tx, network, logger)) {
if (NftUtils.shouldInvokeNftHandlerForTx(tx, network, logger)) {
// This process is not critical, so we run it in a fire-and-forget manner, not waiting for the promise.
// In case of errors, just log the asynchronous exception and take no action on it.
nftUtils.NftUtils.invokeNftHandlerLambda(tx.tx_id, STAGE, logger)
NftUtils.invokeNftHandlerLambda(tx.tx_id, STAGE, logger)
.catch((err: unknown) => logger.error('[ALERT] Error on nftHandlerLambda invocation', err));
}
}
Expand Down

0 comments on commit fe2078e

Please sign in to comment.