From b653fe4656092940f0e748e4ba169de61cb0382e Mon Sep 17 00:00:00 2001 From: Vinicius Stevam Date: Fri, 17 Jan 2025 08:48:00 +0000 Subject: [PATCH 1/4] fix: remove supported chains check --- app/scripts/lib/ppom/ppom-middleware.test.ts | 3 -- app/scripts/lib/ppom/ppom-util.test.ts | 37 ------------------- app/scripts/lib/ppom/ppom-util.ts | 28 -------------- .../lib/ppom/security-alerts-api.test.ts | 28 -------------- app/scripts/lib/ppom/security-alerts-api.ts | 7 +--- app/scripts/lib/transaction/util.test.ts | 3 -- shared/constants/security-provider.ts | 19 ---------- test/e2e/mock-e2e.js | 12 ------ 8 files changed, 1 insertion(+), 136 deletions(-) diff --git a/app/scripts/lib/ppom/ppom-middleware.test.ts b/app/scripts/lib/ppom/ppom-middleware.test.ts index 16317fef0380..ea9cc7c78cc9 100644 --- a/app/scripts/lib/ppom/ppom-middleware.test.ts +++ b/app/scripts/lib/ppom/ppom-middleware.test.ts @@ -12,7 +12,6 @@ import { createPPOMMiddleware, PPOMMiddlewareRequest } from './ppom-middleware'; import { generateSecurityAlertId, handlePPOMError, - isChainSupported, validateRequestWithPPOM, } from './ppom-util'; import { SecurityAlertResponse } from './types'; @@ -106,7 +105,6 @@ const createMiddleware = ( describe('PPOMMiddleware', () => { const generateSecurityAlertIdMock = jest.mocked(generateSecurityAlertId); const handlePPOMErrorMock = jest.mocked(handlePPOMError); - const isChainSupportedMock = jest.mocked(isChainSupported); const detectSIWEMock = jest.mocked(detectSIWE); beforeEach(() => { @@ -114,7 +112,6 @@ describe('PPOMMiddleware', () => { generateSecurityAlertIdMock.mockReturnValue(SECURITY_ALERT_ID_MOCK); handlePPOMErrorMock.mockReturnValue(SECURITY_ALERT_RESPONSE_MOCK); - isChainSupportedMock.mockResolvedValue(true); detectSIWEMock.mockReturnValue({ isSIWEMessage: false } as SIWEMessage); globalThis.sentry = { diff --git a/app/scripts/lib/ppom/ppom-util.test.ts b/app/scripts/lib/ppom/ppom-util.test.ts index c143f3dfe11b..2d4f13982886 100644 --- a/app/scripts/lib/ppom/ppom-util.test.ts +++ b/app/scripts/lib/ppom/ppom-util.test.ts @@ -21,7 +21,6 @@ import { import { AppStateController } from '../../controllers/app-state-controller'; import { generateSecurityAlertId, - isChainSupported, METHOD_SIGN_TYPED_DATA_V3, METHOD_SIGN_TYPED_DATA_V4, updateSecurityAlertResponse, @@ -114,10 +113,6 @@ describe('PPOM Utils', () => { const normalizeTransactionParamsMock = jest.mocked( normalizeTransactionParams, ); - const getSupportedChainIdsMock = jest.spyOn( - securityAlertAPI, - 'getSecurityAlertsAPISupportedChainIds', - ); let isSecurityAlertsEnabledMock: jest.SpyInstance; const updateSecurityAlertResponseMock = jest.fn(); @@ -457,36 +452,4 @@ describe('PPOM Utils', () => { ); }); }); - - describe('isChainSupported', () => { - describe('when security alerts API is enabled', () => { - beforeEach(async () => { - isSecurityAlertsEnabledMock.mockReturnValue(true); - getSupportedChainIdsMock.mockResolvedValue([CHAIN_ID_MOCK]); - }); - - it('returns true if chain is supported', async () => { - expect(await isChainSupported(CHAIN_ID_MOCK)).toStrictEqual(true); - }); - - it('returns false if chain is not supported', async () => { - expect(await isChainSupported('0x2')).toStrictEqual(false); - }); - - it('returns correctly if security alerts API throws', async () => { - getSupportedChainIdsMock.mockRejectedValue(new Error('Test Error')); - expect(await isChainSupported(CHAIN_ID_MOCK)).toStrictEqual(true); - }); - }); - - describe('when security alerts API is disabled', () => { - it('returns true if chain is supported', async () => { - expect(await isChainSupported(CHAIN_ID_MOCK)).toStrictEqual(true); - }); - - it('returns false if chain is not supported', async () => { - expect(await isChainSupported('0x2')).toStrictEqual(false); - }); - }); - }); }); diff --git a/app/scripts/lib/ppom/ppom-util.ts b/app/scripts/lib/ppom/ppom-util.ts index 0407c0604a69..29a1d594c7a2 100644 --- a/app/scripts/lib/ppom/ppom-util.ts +++ b/app/scripts/lib/ppom/ppom-util.ts @@ -12,15 +12,12 @@ import { BlockaidReason, BlockaidResultType, LOADING_SECURITY_ALERT_RESPONSE, - SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED, - SECURITY_PROVIDER_SUPPORTED_CHAIN_IDS_FALLBACK_LIST, SecurityAlertSource, } from '../../../../shared/constants/security-provider'; import { SIGNING_METHODS } from '../../../../shared/constants/transaction'; import { AppStateController } from '../../controllers/app-state-controller'; import { SecurityAlertResponse, UpdateSecurityAlertResponse } from './types'; import { - getSecurityAlertsAPISupportedChainIds, isSecurityAlertsAPIEnabled, SecurityAlertsAPIRequest, validateWithSecurityAlertsAPI, @@ -56,15 +53,6 @@ export async function validateRequestWithPPOM({ updateSecurityAlertResponse: UpdateSecurityAlertResponse; }) { try { - if (!(await isChainSupported(chainId))) { - await updateSecurityResponse( - request.method, - securityAlertId, - SECURITY_ALERT_RESPONSE_CHAIN_NOT_SUPPORTED, - ); - return; - } - await updateSecurityResponse( request.method, securityAlertId, @@ -149,22 +137,6 @@ export function handlePPOMError( }; } -export async function isChainSupported(chainId: Hex): Promise { - let supportedChainIds = SECURITY_PROVIDER_SUPPORTED_CHAIN_IDS_FALLBACK_LIST; - - try { - if (isSecurityAlertsAPIEnabled()) { - supportedChainIds = await getSecurityAlertsAPISupportedChainIds(); - } - } catch (error: unknown) { - handlePPOMError( - error, - `Error fetching supported chains from security alerts API`, - ); - } - return supportedChainIds.includes(chainId as Hex); -} - function normalizePPOMRequest( request: PPOMRequest | JsonRpcRequest, ): PPOMRequest | JsonRpcRequest { diff --git a/app/scripts/lib/ppom/security-alerts-api.test.ts b/app/scripts/lib/ppom/security-alerts-api.test.ts index 460139c1d359..6bb4b045b735 100644 --- a/app/scripts/lib/ppom/security-alerts-api.test.ts +++ b/app/scripts/lib/ppom/security-alerts-api.test.ts @@ -3,7 +3,6 @@ import { BlockaidResultType, } from '../../../../shared/constants/security-provider'; import { - getSecurityAlertsAPISupportedChainIds, isSecurityAlertsAPIEnabled, validateWithSecurityAlertsAPI, } from './security-alerts-api'; @@ -95,31 +94,4 @@ describe('Security Alerts API', () => { expect(isEnabled).toBe(false); }); }); - - describe('getSecurityAlertsAPISupportedChainIds', () => { - it('sends GET request', async () => { - const SUPPORTED_CHAIN_IDS_MOCK = ['0x1', '0x2']; - fetchMock.mockResolvedValue({ - ok: true, - json: async () => SUPPORTED_CHAIN_IDS_MOCK, - }); - const response = await getSecurityAlertsAPISupportedChainIds(); - - expect(response).toEqual(SUPPORTED_CHAIN_IDS_MOCK); - - expect(fetchMock).toHaveBeenCalledTimes(1); - expect(fetchMock).toHaveBeenCalledWith( - `${BASE_URL}/supportedChains`, - undefined, - ); - }); - - it('throws an error if response is not ok', async () => { - fetchMock.mockResolvedValue({ ok: false, status: 404 }); - - await expect(getSecurityAlertsAPISupportedChainIds()).rejects.toThrow( - 'Security alerts API request failed with status: 404', - ); - }); - }); }); diff --git a/app/scripts/lib/ppom/security-alerts-api.ts b/app/scripts/lib/ppom/security-alerts-api.ts index d0b6bc812b1a..9b9de32800e4 100644 --- a/app/scripts/lib/ppom/security-alerts-api.ts +++ b/app/scripts/lib/ppom/security-alerts-api.ts @@ -1,8 +1,7 @@ -import { Hex, JsonRpcRequest } from '@metamask/utils'; +import { JsonRpcRequest } from '@metamask/utils'; import { SecurityAlertResponse } from './types'; const ENDPOINT_VALIDATE = 'validate'; -const ENDPOINT_SUPPORTED_CHAINS = 'supportedChains'; type SecurityAlertsAPIRequestBody = { method: string; @@ -36,10 +35,6 @@ export async function validateWithSecurityAlertsAPI( }); } -export async function getSecurityAlertsAPISupportedChainIds(): Promise { - return request(ENDPOINT_SUPPORTED_CHAINS); -} - async function request(endpoint: string, options?: RequestInit) { const url = getUrl(endpoint); diff --git a/app/scripts/lib/transaction/util.test.ts b/app/scripts/lib/transaction/util.test.ts index 0a941968d802..e41b2a6280f6 100644 --- a/app/scripts/lib/transaction/util.test.ts +++ b/app/scripts/lib/transaction/util.test.ts @@ -9,7 +9,6 @@ import { UserOperationController } from '@metamask/user-operation-controller'; import { cloneDeep } from 'lodash'; import { generateSecurityAlertId, - isChainSupported, validateRequestWithPPOM, } from '../ppom/ppom-util'; import { @@ -100,7 +99,6 @@ describe('Transaction Utils', () => { let userOperationController: jest.Mocked; const validateRequestWithPPOMMock = jest.mocked(validateRequestWithPPOM); const generateSecurityAlertIdMock = jest.mocked(generateSecurityAlertId); - const isChainSupportedMock = jest.mocked(isChainSupported); beforeEach(() => { jest.resetAllMocks(); @@ -125,7 +123,6 @@ describe('Transaction Utils', () => { }); generateSecurityAlertIdMock.mockReturnValue(SECURITY_ALERT_ID_MOCK); - isChainSupportedMock.mockResolvedValue(true); request.transactionController = transactionController; request.userOperationController = userOperationController; diff --git a/shared/constants/security-provider.ts b/shared/constants/security-provider.ts index 82f8814da9da..beb7ee75aa3a 100644 --- a/shared/constants/security-provider.ts +++ b/shared/constants/security-provider.ts @@ -1,9 +1,7 @@ -import { Hex } from '@metamask/utils'; import { SecurityAlertResponse, TransactionType, } from '@metamask/transaction-controller'; -import { CHAIN_IDS } from './network'; export enum SecurityProvider { Blockaid = 'blockaid', @@ -91,23 +89,6 @@ export const FALSE_POSITIVE_REPORT_BASE_URL = export const SECURITY_PROVIDER_UTM_SOURCE = 'metamask-ppom'; -export const SECURITY_PROVIDER_SUPPORTED_CHAIN_IDS_FALLBACK_LIST: Hex[] = [ - CHAIN_IDS.ARBITRUM, - CHAIN_IDS.AVALANCHE, - CHAIN_IDS.BASE, - CHAIN_IDS.BSC, - CHAIN_IDS.LINEA_MAINNET, - CHAIN_IDS.MAINNET, - CHAIN_IDS.OPBNB, - CHAIN_IDS.OPTIMISM, - CHAIN_IDS.POLYGON, - CHAIN_IDS.SEPOLIA, - CHAIN_IDS.ZKSYNC_ERA, - CHAIN_IDS.SCROLL, - CHAIN_IDS.BERACHAIN, - CHAIN_IDS.METACHAIN_ONE, -]; - export const SECURITY_PROVIDER_EXCLUDED_TRANSACTION_TYPES = [ TransactionType.swap, TransactionType.swapApproval, diff --git a/test/e2e/mock-e2e.js b/test/e2e/mock-e2e.js index 72809ea62e48..7d25ee54f0d3 100644 --- a/test/e2e/mock-e2e.js +++ b/test/e2e/mock-e2e.js @@ -1,8 +1,5 @@ const fs = require('fs'); -const { - SECURITY_PROVIDER_SUPPORTED_CHAIN_IDS_FALLBACK_LIST, -} = require('../../shared/constants/security-provider'); const { BRIDGE_DEV_API_BASE_URL, BRIDGE_PROD_API_BASE_URL, @@ -157,15 +154,6 @@ async function setupMocking( }; }); - await server - .forGet(`${SECURITY_ALERTS_PROD_API_BASE_URL}/supportedChains`) - .thenCallback(() => { - return { - statusCode: 200, - json: SECURITY_PROVIDER_SUPPORTED_CHAIN_IDS_FALLBACK_LIST, - }; - }); - await server .forPost(`${SECURITY_ALERTS_PROD_API_BASE_URL}/validate/${chainId}`) .thenCallback(() => { From 770c98d655e757821cd028625a8150b03e3e7cd5 Mon Sep 17 00:00:00 2001 From: Vinicius Stevam Date: Mon, 27 Jan 2025 14:05:15 +0000 Subject: [PATCH 2/4] 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.test.ts | 2 +- app/scripts/lib/transaction/util.ts | 8 ++++---- shared/constants/security-provider.ts | 13 ------------- 6 files changed, 11 insertions(+), 44 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.test.ts b/app/scripts/lib/transaction/util.test.ts index e41b2a6280f6..f9b0a50fae1b 100644 --- a/app/scripts/lib/transaction/util.test.ts +++ b/app/scripts/lib/transaction/util.test.ts @@ -396,7 +396,7 @@ describe('Transaction Utils', () => { ).toHaveBeenCalledWith(TRANSACTION_PARAMS_MOCK, { ...TRANSACTION_OPTIONS_MOCK, securityAlertResponse: { - reason: BlockaidReason.checkingChain, + reason: BlockaidReason.inProgress, result_type: BlockaidResultType.Loading, securityAlertId: SECURITY_ALERT_ID_MOCK, }, 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', From 6c0d03bfee343678b18d5d8b20d06a018b23f08d Mon Sep 17 00:00:00 2001 From: Vinicius Stevam Date: Mon, 27 Jan 2025 14:29:17 +0000 Subject: [PATCH 3/4] fix: lint unit test --- test/e2e/tests/confirmations/signatures/signature-helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/tests/confirmations/signatures/signature-helpers.ts b/test/e2e/tests/confirmations/signatures/signature-helpers.ts index a4c9dd31b2ca..d5aff8e42532 100644 --- a/test/e2e/tests/confirmations/signatures/signature-helpers.ts +++ b/test/e2e/tests/confirmations/signatures/signature-helpers.ts @@ -91,7 +91,7 @@ function getSignatureEventProperty( signatureType: string, primaryType: string, uiCustomizations: string[], - securityAlertReason: string = BlockaidReason.checkingChain, + securityAlertReason: string = BlockaidReason.inProgress, securityAlertResponse: string = BlockaidResultType.Loading, decodingChangeTypes?: string[], decodingResponse?: string, From 748ed7cf1dbaf44299e1951f7b5d434f67c02e2e Mon Sep 17 00:00:00 2001 From: Vinicius Stevam Date: Tue, 28 Jan 2025 10:28:59 +0000 Subject: [PATCH 4/4] fix: e2e tests --- test/data/confirmations/typed_sign.ts | 2 +- .../signatures/signature-helpers.ts | 27 +++++++++++++++++-- .../tests/metrics/signature-approved.spec.js | 6 ++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/test/data/confirmations/typed_sign.ts b/test/data/confirmations/typed_sign.ts index b0984684f12d..efa65a05937d 100644 --- a/test/data/confirmations/typed_sign.ts +++ b/test/data/confirmations/typed_sign.ts @@ -203,7 +203,7 @@ export const seaportSignatureMsg = { networkClientId: 'mainnet', securityAlertResponse: { result_type: 'loading', - reason: 'CheckingChain', + reason: 'validation_in_progress', securityAlertId: 'def3b0ef-c96b-4c87-b1b1-c69cc02a0f78', }, status: 'unapproved', diff --git a/test/e2e/tests/confirmations/signatures/signature-helpers.ts b/test/e2e/tests/confirmations/signatures/signature-helpers.ts index d5aff8e42532..07cdc08e8c1a 100644 --- a/test/e2e/tests/confirmations/signatures/signature-helpers.ts +++ b/test/e2e/tests/confirmations/signatures/signature-helpers.ts @@ -39,6 +39,7 @@ type AssertSignatureMetricsOptions = { withAnonEvents?: boolean; securityAlertReason?: string; securityAlertResponse?: string; + securityAlertSource?: string; decodingChangeTypes?: string[]; decodingResponse?: string; decodingDescription?: string | null; @@ -52,6 +53,7 @@ type SignatureEventProperty = { locale: 'en'; security_alert_reason: string; security_alert_response: string; + security_alert_source?: string; signature_type: string; eip712_primary_type?: string; decoding_change_types?: string[]; @@ -83,6 +85,7 @@ export async function initializePages(driver: Driver) { * @param uiCustomizations * @param securityAlertReason * @param securityAlertResponse + * @param securityAlertSource * @param decodingChangeTypes * @param decodingResponse * @param decodingDescription @@ -93,6 +96,7 @@ function getSignatureEventProperty( uiCustomizations: string[], securityAlertReason: string = BlockaidReason.inProgress, securityAlertResponse: string = BlockaidResultType.Loading, + securityAlertSource: string = 'api', decodingChangeTypes?: string[], decodingResponse?: string, decodingDescription?: string | null, @@ -106,6 +110,7 @@ function getSignatureEventProperty( locale: 'en', security_alert_reason: securityAlertReason, security_alert_response: securityAlertResponse, + security_alert_source: securityAlertSource, ui_customizations: uiCustomizations, }; @@ -118,6 +123,7 @@ function getSignatureEventProperty( signatureEventProperty.decoding_response = decodingResponse; signatureEventProperty.decoding_description = decodingDescription; } + return signatureEventProperty; } @@ -150,6 +156,7 @@ export async function assertSignatureConfirmedMetrics({ withAnonEvents = false, securityAlertReason, securityAlertResponse, + securityAlertSource, decodingChangeTypes, decodingResponse, decodingDescription, @@ -161,6 +168,7 @@ export async function assertSignatureConfirmedMetrics({ uiCustomizations, securityAlertReason, securityAlertResponse, + securityAlertSource, decodingChangeTypes, decodingResponse, decodingDescription, @@ -197,6 +205,7 @@ export async function assertSignatureRejectedMetrics({ withAnonEvents = false, securityAlertReason, securityAlertResponse, + securityAlertSource, decodingChangeTypes, decodingResponse, decodingDescription, @@ -208,6 +217,7 @@ export async function assertSignatureRejectedMetrics({ uiCustomizations, securityAlertReason, securityAlertResponse, + securityAlertSource, decodingChangeTypes, decodingResponse, decodingDescription, @@ -264,7 +274,7 @@ function assertEventPropertiesMatch( compareDecodingAPIResponse(actualProperties, expectedProps, eventName); - compareSecurityAlertResponse(actualProperties, expectedProps, eventName); + compareSecurityAlertProperties(actualProperties, expectedProps, eventName); assert(event, `${eventName} event not found`); assert.deepStrictEqual( @@ -274,7 +284,7 @@ function assertEventPropertiesMatch( ); } -function compareSecurityAlertResponse( +function compareSecurityAlertProperties( actualProperties: Record, expectedProperties: Record, eventName: string, @@ -296,6 +306,19 @@ function compareSecurityAlertResponse( delete actualProperties.security_alert_response; delete expectedProperties.security_alert_response; } + + if (expectedProperties.security_alert_source) { + if ( + actualProperties.security_alert_source !== 'api' && + expectedProperties.security_alert_source !== 'api' + ) { + assert.fail( + `${eventName} event properties do not match: security_alert_source is ${actualProperties.security_alert_source}`, + ); + } + delete actualProperties.security_alert_source; + delete expectedProperties.security_alert_source; + } } function compareDecodingAPIResponse( diff --git a/test/e2e/tests/metrics/signature-approved.spec.js b/test/e2e/tests/metrics/signature-approved.spec.js index 4a14d3c36648..c57f95156ab4 100644 --- a/test/e2e/tests/metrics/signature-approved.spec.js +++ b/test/e2e/tests/metrics/signature-approved.spec.js @@ -52,7 +52,7 @@ const expectedEventPropertiesBase = { locale: 'en', chain_id: '0x539', environment_type: 'background', - security_alert_reason: 'CheckingChain', + security_alert_reason: 'validation_in_progress', security_alert_response: 'loading', ui_customizations: ['redesigned_confirmation'], }; @@ -94,6 +94,7 @@ describe('Signature Approved Event', function () { signature_type: 'eth_signTypedData_v4', eip712_primary_type: 'Mail', security_alert_response: 'Benign', + security_alert_source: 'api', }); }, ); @@ -133,6 +134,7 @@ describe('Signature Approved Event', function () { ...expectedEventPropertiesBase, signature_type: 'eth_signTypedData_v3', security_alert_response: 'Benign', + security_alert_source: 'api', }); }, ); @@ -172,6 +174,7 @@ describe('Signature Approved Event', function () { ...expectedEventPropertiesBase, signature_type: 'eth_signTypedData', security_alert_response: 'Benign', + security_alert_source: 'api', }); }, ); @@ -211,6 +214,7 @@ describe('Signature Approved Event', function () { ...expectedEventPropertiesBase, signature_type: 'personal_sign', security_alert_response: 'Benign', + security_alert_source: 'api', }); }, );