Skip to content

Commit

Permalink
fix: e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistevam committed Jan 28, 2025
1 parent 6c0d03b commit 4c3fcf1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/data/confirmations/typed_sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
27 changes: 25 additions & 2 deletions test/e2e/tests/confirmations/signatures/signature-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type AssertSignatureMetricsOptions = {
withAnonEvents?: boolean;
securityAlertReason?: string;
securityAlertResponse?: string;
securityAlertSource?: string;
decodingChangeTypes?: string[];
decodingResponse?: string;
decodingDescription?: string | null;
Expand All @@ -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[];
Expand Down Expand Up @@ -83,6 +85,7 @@ export async function initializePages(driver: Driver) {
* @param uiCustomizations
* @param securityAlertReason
* @param securityAlertResponse
* @param securityAlertSource
* @param decodingChangeTypes
* @param decodingResponse
* @param decodingDescription
Expand All @@ -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,
Expand All @@ -106,6 +110,7 @@ function getSignatureEventProperty(
locale: 'en',
security_alert_reason: securityAlertReason,
security_alert_response: securityAlertResponse,
security_alert_source: securityAlertSource,
ui_customizations: uiCustomizations,
};

Expand All @@ -118,6 +123,7 @@ function getSignatureEventProperty(
signatureEventProperty.decoding_response = decodingResponse;
signatureEventProperty.decoding_description = decodingDescription;
}

return signatureEventProperty;
}

Expand Down Expand Up @@ -150,6 +156,7 @@ export async function assertSignatureConfirmedMetrics({
withAnonEvents = false,
securityAlertReason,
securityAlertResponse,
securityAlertSource,
decodingChangeTypes,
decodingResponse,
decodingDescription,
Expand All @@ -161,6 +168,7 @@ export async function assertSignatureConfirmedMetrics({
uiCustomizations,
securityAlertReason,
securityAlertResponse,
securityAlertSource,
decodingChangeTypes,
decodingResponse,
decodingDescription,
Expand Down Expand Up @@ -197,6 +205,7 @@ export async function assertSignatureRejectedMetrics({
withAnonEvents = false,
securityAlertReason,
securityAlertResponse,
securityAlertSource,
decodingChangeTypes,
decodingResponse,
decodingDescription,
Expand All @@ -208,6 +217,7 @@ export async function assertSignatureRejectedMetrics({
uiCustomizations,
securityAlertReason,
securityAlertResponse,
securityAlertSource,
decodingChangeTypes,
decodingResponse,
decodingDescription,
Expand Down Expand Up @@ -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(
Expand All @@ -274,7 +284,7 @@ function assertEventPropertiesMatch(
);
}

function compareSecurityAlertResponse(
function compareSecurityAlertProperties(
actualProperties: Record<string, unknown>,
expectedProperties: Record<string, unknown>,
eventName: string,
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/metrics/signature-approved.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
};
Expand Down

0 comments on commit 4c3fcf1

Please sign in to comment.