From d1b80a23bca95d27a234538378ba969866b20640 Mon Sep 17 00:00:00 2001 From: Vinicius Stevam Date: Mon, 27 Jan 2025 13:51:52 +0000 Subject: [PATCH] fix: unit tests --- app/scripts/lib/ppom/ppom-middleware.test.ts | 4 +--- app/scripts/lib/ppom/ppom-middleware.ts | 10 +++++----- app/scripts/lib/ppom/ppom-util.test.ts | 18 ------------------ app/scripts/lib/transaction/util.ts | 8 ++++---- shared/constants/security-provider.ts | 13 ------------- 5 files changed, 10 insertions(+), 43 deletions(-) diff --git a/app/scripts/lib/ppom/ppom-middleware.test.ts b/app/scripts/lib/ppom/ppom-middleware.test.ts index ea9cc7c78cc9..23acca61b639 100644 --- a/app/scripts/lib/ppom/ppom-middleware.test.ts +++ b/app/scripts/lib/ppom/ppom-middleware.test.ts @@ -142,9 +142,7 @@ describe('PPOMMiddleware', () => { () => undefined, ); - expect(req.securityAlertResponse?.reason).toBe( - BlockaidReason.checkingChain, - ); + expect(req.securityAlertResponse?.reason).toBe(BlockaidReason.inProgress); expect(req.securityAlertResponse?.result_type).toBe( BlockaidResultType.Loading, ); diff --git a/app/scripts/lib/ppom/ppom-middleware.ts b/app/scripts/lib/ppom/ppom-middleware.ts index f99cf675f534..21013cc2dd1b 100644 --- a/app/scripts/lib/ppom/ppom-middleware.ts +++ b/app/scripts/lib/ppom/ppom-middleware.ts @@ -13,9 +13,9 @@ import { MESSAGE_TYPE } from '../../../../shared/constants/app'; import { SIGNING_METHODS } from '../../../../shared/constants/transaction'; import { PreferencesController } from '../../controllers/preferences-controller'; import { AppStateController } from '../../controllers/app-state-controller'; -import { SECURITY_ALERT_RESPONSE_CHECKING_CHAIN } from '../../../../shared/constants/security-provider'; import { getProviderConfig } from '../../../../shared/modules/selectors/networks'; import { trace, TraceContext, TraceName } from '../../../../shared/lib/trace'; +import { LOADING_SECURITY_ALERT_RESPONSE } from '../../../../shared/constants/security-provider'; import { generateSecurityAlertId, handlePPOMError, @@ -118,18 +118,18 @@ export function createPPOMMiddleware< }), ); - const securityAlertResponseCheckingChain: SecurityAlertResponse = { - ...SECURITY_ALERT_RESPONSE_CHECKING_CHAIN, + const securityAlertResponseLoading: SecurityAlertResponse = { + ...LOADING_SECURITY_ALERT_RESPONSE, securityAlertId, }; if (SIGNING_METHODS.includes(req.method)) { appStateController.addSignatureSecurityAlertResponse( - securityAlertResponseCheckingChain, + securityAlertResponseLoading, ); } - req.securityAlertResponse = securityAlertResponseCheckingChain; + req.securityAlertResponse = securityAlertResponseLoading; } catch (error) { req.securityAlertResponse = handlePPOMError( error, diff --git a/app/scripts/lib/ppom/ppom-util.test.ts b/app/scripts/lib/ppom/ppom-util.test.ts index 2d4f13982886..0bb1deb72c86 100644 --- a/app/scripts/lib/ppom/ppom-util.test.ts +++ b/app/scripts/lib/ppom/ppom-util.test.ts @@ -15,7 +15,6 @@ import { BlockaidReason, BlockaidResultType, LOADING_SECURITY_ALERT_RESPONSE, - SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED, SecurityAlertSource, } from '../../../../shared/constants/security-provider'; import { AppStateController } from '../../controllers/app-state-controller'; @@ -303,23 +302,6 @@ describe('PPOM Utils', () => { }); }, ); - - it('updates response indicating chain is not supported', async () => { - const ppomController = {} as PPOMController; - const CHAIN_ID_UNSUPPORTED_MOCK = '0x2'; - - await validateRequestWithPPOM({ - ...validateRequestWithPPOMOptionsBase, - ppomController, - chainId: CHAIN_ID_UNSUPPORTED_MOCK, - }); - - expect(updateSecurityAlertResponseMock).toHaveBeenCalledWith( - validateRequestWithPPOMOptionsBase.request.method, - SECURITY_ALERT_ID_MOCK, - SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED, - ); - }); }); describe('generateSecurityAlertId', () => { diff --git a/app/scripts/lib/transaction/util.ts b/app/scripts/lib/transaction/util.ts index a3d0b929aff8..419def19be6e 100644 --- a/app/scripts/lib/transaction/util.ts +++ b/app/scripts/lib/transaction/util.ts @@ -24,7 +24,7 @@ import { UpdateSecurityAlertResponse, } from '../ppom/types'; import { - SECURITY_ALERT_RESPONSE_CHECKING_CHAIN, + LOADING_SECURITY_ALERT_RESPONSE, SECURITY_PROVIDER_EXCLUDED_TRANSACTION_TYPES, } from '../../../../shared/constants/security-provider'; import { endTrace, TraceName } from '../../../../shared/lib/trace'; @@ -287,13 +287,13 @@ async function validateSecurity(request: AddTransactionRequest) { updateSecurityAlertResponse, }); - const securityAlertResponseCheckingChain: SecurityAlertResponse = { - ...SECURITY_ALERT_RESPONSE_CHECKING_CHAIN, + const securityAlertResponseLoading: SecurityAlertResponse = { + ...LOADING_SECURITY_ALERT_RESPONSE, securityAlertId, }; request.transactionOptions.securityAlertResponse = - securityAlertResponseCheckingChain; + securityAlertResponseLoading; } catch (error) { handlePPOMError(error, 'Error validating JSON RPC using PPOM: '); } diff --git a/shared/constants/security-provider.ts b/shared/constants/security-provider.ts index beb7ee75aa3a..b9853bb53991 100644 --- a/shared/constants/security-provider.ts +++ b/shared/constants/security-provider.ts @@ -55,8 +55,6 @@ export enum BlockaidReason { errored = 'Error', notApplicable = 'NotApplicable', inProgress = 'validation_in_progress', - checkingChain = 'CheckingChain', - chainNotSupported = 'ChainNotSupported', } export enum BlockaidResultType { @@ -102,17 +100,6 @@ export const LOADING_SECURITY_ALERT_RESPONSE: SecurityAlertResponse = { reason: BlockaidReason.inProgress, }; -export const SECURITY_ALERT_RESPONSE_CHECKING_CHAIN: SecurityAlertResponse = { - result_type: BlockaidResultType.Loading, - reason: BlockaidReason.checkingChain, -}; - -export const SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED: SecurityAlertResponse = - { - result_type: BlockaidResultType.Benign, - reason: BlockaidReason.chainNotSupported, - }; - export enum SecurityAlertSource { /** Validation performed remotely using the Security Alerts API. */ API = 'api',