Skip to content

Commit

Permalink
tests: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabadesso committed Jan 27, 2025
1 parent 0b23f04 commit 1c4f0d6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
47 changes: 27 additions & 20 deletions packages/daemon/__tests__/services/services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,6 @@ import { FullNodeEventTypes } from '../../src/types';
import { Context } from '../../src/types';
import { generateFullNodeEvent } from '../utils';

jest.mock('../../src/config', () => {
return {
__esModule: true, // This property is needed for mocking a default export
default: jest.fn(() => ({
REORG_SIZE_INFO: 1,
REORG_SIZE_MINOR: 3,
REORG_SIZE_MAJOR: 5,
REORG_SIZE_CRITICAL: 10,
})),
getConfig: jest.fn(() => ({
REORG_SIZE_INFO: 1,
REORG_SIZE_MINOR: 3,
REORG_SIZE_MAJOR: 5,
REORG_SIZE_CRITICAL: 10,
})),
};
});

jest.mock('@hathor/wallet-lib');
jest.mock('../../src/logger', () => ({
debug: jest.fn(),
Expand Down Expand Up @@ -142,6 +124,24 @@ jest.mock('@wallet-service/common', () => {
};
});

jest.mock('../../src/config', () => {
return {
__esModule: true, // This property is needed for mocking a default export
default: jest.fn(() => ({
REORG_SIZE_INFO: 1,
REORG_SIZE_MINOR: 3,
REORG_SIZE_MAJOR: 5,
REORG_SIZE_CRITICAL: 10,
})),
getConfig: jest.fn(() => ({
REORG_SIZE_INFO: 1,
REORG_SIZE_MINOR: 3,
REORG_SIZE_MAJOR: 5,
REORG_SIZE_CRITICAL: 10,
})),
};
});

beforeEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -874,6 +874,15 @@ describe('metadataDiff', () => {

describe('handleReorgStarted', () => {
beforeEach(() => {
(getConfig as jest.Mock).mockReturnValue({
REORG_SIZE_INFO: 1,
REORG_SIZE_MINOR: 3,
REORG_SIZE_MAJOR: 5,
REORG_SIZE_CRITICAL: 10,
});
});

afterEach(() => {
jest.clearAllMocks();
});

Expand Down Expand Up @@ -919,8 +928,6 @@ describe('handleReorgStarted', () => {
// @ts-ignore
await handleReorgStarted({ event } as Context);

console.log('ADD ALERT:', addAlert);

expect(addAlert).toHaveBeenCalledWith(
'Minor Reorg Detected',
'A minor blockchain reorg of size 3 has occurred.',
Expand Down
13 changes: 3 additions & 10 deletions packages/daemon/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,30 +686,23 @@ export const handleReorgStarted = async (context: Context): Promise<void> => {
common_block,
};

console.log(reorg_size, {
REORG_SIZE_CRITICAL,
REORG_SIZE_INFO,
REORG_SIZE_MAJOR,
REORG_SIZE_MINOR,
});

if (reorg_size > REORG_SIZE_CRITICAL) {
if (reorg_size >= REORG_SIZE_CRITICAL) {
await addAlert(
'Critical Reorg Detected',
`A critical reorg of size ${reorg_size} has occurred.`,
Severity.CRITICAL,
metadata,
logger,
);
} else if (reorg_size > REORG_SIZE_MAJOR) {
} else if (reorg_size >= REORG_SIZE_MAJOR) {
await addAlert(
'Major Reorg Detected',
`A major reorg of size ${reorg_size} has occurred.`,
Severity.MAJOR,
metadata,
logger,
);
} else if (reorg_size > REORG_SIZE_MINOR) {
} else if (reorg_size >= REORG_SIZE_MINOR) {
await addAlert(
'Minor Reorg Detected',
`A minor reorg of size ${reorg_size} has occurred.`,
Expand Down

0 comments on commit 1c4f0d6

Please sign in to comment.