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
19 changes: 5 additions & 14 deletions oxlint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4767,23 +4767,9 @@
"count": 2
}
},
"packages/phishing-controller/jest.config.cjs": {
"import/unambiguous": {
"count": 1
}
},
"packages/phishing-controller/src/BulkTokenScan.test.ts": {
"typescript/explicit-function-return-type": {
"count": 2
},
"typescript/no-unsafe-call": {
"count": 1
},
"typescript/no-unsafe-member-access": {
"count": 1
},
"typescript/no-unsafe-return": {
"count": 2
}
},
"packages/phishing-controller/src/CacheManager.test.ts": {
Expand Down Expand Up @@ -4850,6 +4836,11 @@
"count": 1
}
},
"packages/phishing-controller/src/signature-address-extraction.test.ts": {
"vitest/no-conditional-in-test": {
"count": 1
}
},
"packages/phishing-controller/src/tests/utils.ts": {
"typescript/explicit-function-return-type": {
"count": 2
Expand Down
26 changes: 0 additions & 26 deletions packages/phishing-controller/jest.config.cjs

This file was deleted.

15 changes: 6 additions & 9 deletions packages/phishing-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
"messenger-action-types:check": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check",
"messenger-action-types:generate": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
"test": "vitest",
"test:clean": "vitest --clearCache",
"test:verbose": "vitest --reporter=verbose",
"test:watch": "vitest --watch"
},
"dependencies": {
"@metamask/address-book-controller": "^8.0.0",
Expand All @@ -64,16 +64,13 @@
"devDependencies": {
"@metamask/auto-changelog": "^6.2.1",
"@metamask/eth-sig-util": "^9.0.0",
"@types/jest": "^30.0.0",
"@typescript/native": "npm:typescript@^7.0.2",
"deepmerge": "^4.3.1",
"jest": "^30.5.2",
"nock": "^13.5.6",
"rimraf": "^6.1.3",
"ts-jest": "^29.4.14",
"typedoc": "^0.28.20",
"typedoc-plugin-missing-exports": "^4.1.4",
"typescript": "npm:@typescript/typescript6@^6.0.2"
"typescript": "npm:@typescript/typescript6@^6.0.2",
"vitest": "^5.0.0"
},
"engines": {
"node": "^22.14.0 || ^24"
Expand Down
39 changes: 24 additions & 15 deletions packages/phishing-controller/src/BulkTokenScan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type {
MockAnyNamespace,
} from '@metamask/messenger';
import nock, { cleanAll } from 'nock';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type { MockInstance, MockedFunction } from 'vitest';

import {
PhishingController,
Expand All @@ -19,15 +21,16 @@ import type {
import { TokenScanResultType } from './types.js';
import type { BulkTokenScanRequest, TokenScanApiResponse } from './types.js';

jest.mock('@metamask/controller-utils', () => ({
...jest.requireActual('@metamask/controller-utils'),
safelyExecuteWithTimeout: jest.fn(),
vi.mock('@metamask/controller-utils', async () => ({
...(await vi.importActual<typeof import('@metamask/controller-utils')>(
'@metamask/controller-utils',
)),
safelyExecuteWithTimeout: vi.fn(),
}));

const mockSafelyExecuteWithTimeout =
safelyExecuteWithTimeout as jest.MockedFunction<
typeof safelyExecuteWithTimeout
>;
const mockSafelyExecuteWithTimeout = safelyExecuteWithTimeout as MockedFunction<
typeof safelyExecuteWithTimeout
>;

const controllerName = 'PhishingController';

Expand Down Expand Up @@ -98,20 +101,26 @@ function getPhishingController(options?: Partial<PhishingControllerOptions>) {

describe('PhishingController - Bulk Token Scanning', () => {
let controller: PhishingController;
let consoleErrorSpy: jest.SpyInstance;
let consoleWarnSpy: jest.SpyInstance;
let consoleErrorSpy: MockInstance;
let consoleWarnSpy: MockInstance;

beforeEach(() => {
controller = getPhishingController();
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
consoleErrorSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined);
consoleWarnSpy = vi
.spyOn(console, 'warn')
.mockImplementation(() => undefined);

// Reset the mock to its default behavior (pass through to real implementation)
mockSafelyExecuteWithTimeout.mockImplementation(
(fn, throwOnTimeout, timeout) => {
return jest
.requireActual('@metamask/controller-utils')
.safelyExecuteWithTimeout(fn, throwOnTimeout, timeout);
async (fn, throwOnTimeout, timeout) => {
return (
await vi.importActual<typeof import('@metamask/controller-utils')>(
'@metamask/controller-utils',
)
).safelyExecuteWithTimeout(fn, throwOnTimeout, timeout);
},
);
});
Expand Down
21 changes: 12 additions & 9 deletions packages/phishing-controller/src/CacheManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import type { Mock } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { CacheManager } from './CacheManager.js';
import * as utils from './utils.js';

describe('CacheManager', () => {
let updateStateSpy: jest.Mock;
let updateStateSpy: Mock;
let cache: CacheManager<{ value: string }>;

beforeEach(() => {
jest.useFakeTimers({ doNotFake: ['nextTick', 'queueMicrotask'], now: 0 });
jest
.spyOn(utils, 'fetchTimeNow')
.mockImplementation(() => Math.floor(Date.now() / 1000));
updateStateSpy = jest.fn();
vi.useFakeTimers({ now: 0 });
vi.spyOn(utils, 'fetchTimeNow').mockImplementation(() =>
Math.floor(Date.now() / 1000),
);
updateStateSpy = vi.fn();
cache = new CacheManager<{ value: string }>({
cacheTTL: 300, // 5 minutes
maxCacheSize: 3,
Expand All @@ -19,8 +22,8 @@ describe('CacheManager', () => {
});

afterEach(() => {
jest.useRealTimers();
jest.restoreAllMocks();
vi.useRealTimers();
vi.restoreAllMocks();
});

describe('constructor', () => {
Expand Down Expand Up @@ -67,7 +70,7 @@ describe('CacheManager', () => {
cache.set('key1', { value: 'value1' });

// Fast forward time past TTL
jest.advanceTimersByTime(301 * 1000);
vi.advanceTimersByTime(301 * 1000);

expect(cache.get('key1')).toBeUndefined();
});
Expand Down
2 changes: 2 additions & 0 deletions packages/phishing-controller/src/PathTrie.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { beforeEach, describe, expect, it } from 'vitest';

import {
convertListToTrie,
deepCopyPathTrie,
Expand Down
Loading
Loading