Skip to content

Commit

Permalink
test(multi-srp): fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykLucka committed Feb 17, 2025
1 parent 4600df0 commit 1d1ade9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/scripts/lib/transaction/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export const createTransactionEventFragmentWithTxId = async (
* @param transactionMetricsRequest - Contains controller actions
* @param transactionMetricsRequest.getParticipateInMetrics - Returns whether the user has opted into metrics
* @param transactionMetricsRequest.trackEvent - MetaMetrics track event function
* @param transactionMetricsRequest.getHDSrpIndex - Returns the HD SRP index
* @param transactionMetricsRequest.getHDSrpIndex - Returns Index of the currently selected HD Keyring
* @param transactionEventPayload - The event payload
* @param transactionEventPayload.transactionMeta - The updated transaction meta
* @param transactionEventPayload.approvalTransactionMeta - The updated approval transaction meta
Expand Down
1 change: 1 addition & 0 deletions test/e2e/snaps/test-snap-metrics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ describe('Test Snap Metrics', function () {
locale: 'en',
chain_id: '0x539',
environment_type: 'background',
hd_srp_index: 0,
});
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type AssertSignatureMetricsOptions = {
decodingChangeTypes?: string[];
decodingResponse?: string;
decodingDescription?: string | null;
hdSrpIndex?: number;
};

type SignatureEventProperty = {
Expand Down Expand Up @@ -252,6 +251,7 @@ export async function assertAccountDetailsMetrics(
locale: 'en',
chain_id: '0x539',
environment_type: 'notification',
hd_srp_index: 0,
});
}

Expand Down
8 changes: 8 additions & 0 deletions test/e2e/tests/metrics/signature-approved.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ describe('Signature Approved Event', function () {
...expectedEventPropertiesBase,
signature_type: 'eth_signTypedData_v4',
eip712_primary_type: 'Mail',
hd_srp_index: 0,
});

assert.deepStrictEqual(events[1].properties, {
...expectedEventPropertiesBase,
signature_type: 'eth_signTypedData_v4',
eip712_primary_type: 'Mail',
hd_srp_index: 0,
security_alert_response: 'Benign',
});
},
Expand Down Expand Up @@ -124,12 +126,14 @@ describe('Signature Approved Event', function () {
assert.deepStrictEqual(events[0].properties, {
...expectedEventPropertiesBase,
signature_type: 'eth_signTypedData_v3',
hd_srp_index: 0,
});

assert.deepStrictEqual(events[1].properties, {
...expectedEventPropertiesBase,
signature_type: 'eth_signTypedData_v3',
security_alert_response: 'Benign',
hd_srp_index: 0,
});
},
);
Expand Down Expand Up @@ -162,12 +166,14 @@ describe('Signature Approved Event', function () {
assert.deepStrictEqual(events[0].properties, {
...expectedEventPropertiesBase,
signature_type: 'eth_signTypedData',
hd_srp_index: 0,
});

assert.deepStrictEqual(events[1].properties, {
...expectedEventPropertiesBase,
signature_type: 'eth_signTypedData',
security_alert_response: 'Benign',
hd_srp_index: 0,
});
},
);
Expand Down Expand Up @@ -200,12 +206,14 @@ describe('Signature Approved Event', function () {
assert.deepStrictEqual(events[0].properties, {
...expectedEventPropertiesBase,
signature_type: 'personal_sign',
hd_srp_index: 0,
});

assert.deepStrictEqual(events[1].properties, {
...expectedEventPropertiesBase,
signature_type: 'personal_sign',
security_alert_response: 'Benign',
hd_srp_index: 0,
});
},
);
Expand Down
36 changes: 24 additions & 12 deletions test/e2e/tests/metrics/swaps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ async function assertPrepareSwapPageLoadedEvents(reqs) {
async function assertQuotesRequestedEvents(reqs) {
const assertionsReq3 = [
(req) => req.event === MetaMetricsEventName.QuotesRequested,
(req) => Object.keys(req.properties).length === 15,
(req) => Object.keys(req.properties).length === 16,

(req) => req.properties?.category === MetaMetricsEventCategory.Swaps,
(req) => req.properties?.chain_id === toHex(1337),
Expand All @@ -244,16 +244,18 @@ async function assertQuotesRequestedEvents(reqs) {
(req) => req.properties?.token_from === 'TESTETH',
(req) => req.properties?.token_from_amount === '2',
(req) => req.properties?.token_to === 'DAI',
(req) => req.properties?.hd_srp_index === 0,
];

const assertionsReq4 = [
(req) => req.event === MetaMetricsEventName.QuotesRequested,
(req) => Object.keys(req.properties).length === 4,
(req) => Object.keys(req.properties).length === 5,

(req) => req.properties?.category === MetaMetricsEventCategory.Swaps,
(req) => req.properties?.chain_id === toHex(1337),
(req) => req.properties?.environment_type === 'fullscreen',
(req) => req.properties?.locale === 'en',
(req) => req.properties?.hd_srp_index === 0,
];

assert.ok(
Expand All @@ -265,7 +267,7 @@ async function assertQuotesRequestedEvents(reqs) {
async function assertQuotesReceivedAndBestQuoteReviewedEvents(reqs) {
const assertionsReq5 = [
(req) => req.event === MetaMetricsEventName.QuotesReceived,
(req) => Object.keys(req.properties).length === 19,
(req) => Object.keys(req.properties).length === 20,

(req) => req.properties?.category === MetaMetricsEventCategory.Swaps,
(req) => req.properties?.chain_id === toHex(1337),
Expand All @@ -286,16 +288,18 @@ async function assertQuotesReceivedAndBestQuoteReviewedEvents(reqs) {
(req) => req.properties?.token_from_amount === '2',
(req) => req.properties?.token_to === 'DAI',
(req) => typeof req.properties?.token_to_amount === 'string',
(req) => req.properties?.hd_srp_index === 0,
];

const assertionsReq6 = [
(req) => req.event === MetaMetricsEventName.QuotesReceived,
(req) => Object.keys(req.properties).length === 4,
(req) => Object.keys(req.properties).length === 5,

(req) => req.properties?.category === MetaMetricsEventCategory.Swaps,
(req) => req.properties?.chain_id === toHex(1337),
(req) => req.properties?.environment_type === 'fullscreen',
(req) => req.properties?.locale === 'en',
(req) => req.properties?.hd_srp_index === 0,
];

const assertionsReq7 = [
Expand Down Expand Up @@ -390,7 +394,7 @@ async function assertAllAvailableQuotesOpenedEvents(reqs) {
async function assertSwapStartedEvents(reqs) {
const assertionsReq11 = [
(req) => req.event === MetaMetricsEventName.SwapStarted,
(req) => Object.keys(req.properties).length === 25,
(req) => Object.keys(req.properties).length === 26,

(req) => req.properties?.category === MetaMetricsEventCategory.Swaps,
(req) => req.properties?.chain_id === toHex(1337),
Expand All @@ -416,16 +420,18 @@ async function assertSwapStartedEvents(reqs) {
(req) => typeof req.properties?.reg_tx_max_fee_in_usd === 'number',
(req) => typeof req.properties?.reg_tx_max_fee_in_eth === 'number',
(req) => typeof req.properties?.other_quote_selected_source === 'string',
(req) => req.properties?.hd_srp_index === 0,
];

const assertionsReq12 = [
(req) => req.event === MetaMetricsEventName.SwapStarted,
(req) => Object.keys(req.properties).length === 4,
(req) => Object.keys(req.properties).length === 5,

(req) => req.properties?.category === MetaMetricsEventCategory.Swaps,
(req) => req.properties?.chain_id === toHex(1337),
(req) => req.properties?.environment_type === 'fullscreen',
(req) => req.properties?.locale === 'en',
(req) => req.properties?.hd_srp_index === 0,
];

assert.ok(
Expand All @@ -437,7 +443,7 @@ async function assertSwapStartedEvents(reqs) {
async function assertSwapCompletedEvents(reqs) {
const assertionsReq13 = [
(req) => req.event === MetaMetricsEventName.SwapCompleted,
(req) => Object.keys(req.properties).length === 31,
(req) => Object.keys(req.properties).length === 32,
(req) => req.properties?.category === MetaMetricsEventCategory.Swaps,
(req) => req.properties?.chain_id === toHex(1337),
(req) => req.properties?.environment_type === 'background',
Expand Down Expand Up @@ -469,15 +475,17 @@ async function assertSwapCompletedEvents(reqs) {
(req) => typeof req.properties?.trade_gas_cost_in_eth === 'number',
(req) =>
typeof req.properties?.trade_and_approval_gas_cost_in_eth === 'number',
(req) => req.properties?.hd_srp_index === 0,
];

const assertionsReq14 = [
(req) => req.event === MetaMetricsEventName.SwapCompleted,
(req) => Object.keys(req.properties).length === 4,
(req) => Object.keys(req.properties).length === 5,
(req) => req.properties?.category === MetaMetricsEventCategory.Swaps,
(req) => req.properties?.chain_id === toHex(1337),
(req) => req.properties?.environment_type === 'background',
(req) => req.properties?.locale === 'en',
(req) => req.properties?.hd_srp_index === 0,
];

assert.ok(
Expand All @@ -489,7 +497,7 @@ async function assertSwapCompletedEvents(reqs) {
async function assertExitedSwapsEvents(reqs) {
const assertionsReq15 = [
(req) => req.event === MetaMetricsEventName.ExitedSwaps,
(req) => Object.keys(req.properties).length === 13,
(req) => Object.keys(req.properties).length === 14,

(req) => req.properties?.category === MetaMetricsEventCategory.Swaps,
(req) => req.properties?.chain_id === toHex(1337),
Expand All @@ -504,16 +512,18 @@ async function assertExitedSwapsEvents(reqs) {
(req) => req.properties?.is_hardware_wallet === false,
(req) => req.properties?.stx_enabled === false,
(req) => req.properties?.current_stx_enabled === false,
(req) => req.properties?.hd_srp_index === 0,
];

const assertionsReq16 = [
(req) => req.event === MetaMetricsEventName.ExitedSwaps,
(req) => Object.keys(req.properties).length === 4,
(req) => Object.keys(req.properties).length === 5,

(req) => req.properties?.category === MetaMetricsEventCategory.Swaps,
(req) => req.properties?.chain_id === toHex(1337),
(req) => req.properties?.environment_type === 'fullscreen',
(req) => req.properties?.locale === 'en',
(req) => req.properties?.hd_srp_index === 0,
];

assert.ok(
Expand All @@ -523,7 +533,7 @@ async function assertExitedSwapsEvents(reqs) {

const assertionsReq17 = [
(req) => req.event === MetaMetricsEventName.ExitedSwaps,
(req) => Object.keys(req.properties).length === 10,
(req) => Object.keys(req.properties).length === 11,

(req) => req.properties?.category === MetaMetricsEventCategory.Swaps,
(req) => req.properties?.chain_id === toHex(1337),
Expand All @@ -535,16 +545,18 @@ async function assertExitedSwapsEvents(reqs) {
(req) => req.properties?.is_hardware_wallet === false,
(req) => req.properties?.stx_enabled === false,
(req) => req.properties?.current_stx_enabled === false,
(req) => req.properties?.hd_srp_index === 0,
];

const assertionsReq18 = [
(req) => req.event === MetaMetricsEventName.ExitedSwaps,
(req) => Object.keys(req.properties).length === 4,
(req) => Object.keys(req.properties).length === 5,

(req) => req.properties?.category === MetaMetricsEventCategory.Swaps,
(req) => req.properties?.chain_id === toHex(1337),
(req) => req.properties?.environment_type === 'fullscreen',
(req) => req.properties?.locale === 'en',
(req) => req.properties?.hd_srp_index === 0,
];

assert.ok(
Expand Down
1 change: 1 addition & 0 deletions test/e2e/tests/metrics/token-detection-metrics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe('Token detection event', function () {
chain_id: '0x539',
environment_type: 'fullscreen',
is_profile_syncing_enabled: true,
hd_srp_index: 0,
});
assert.deepStrictEqual(events[2].properties, {
token_detection_enabled: true,
Expand Down
1 change: 1 addition & 0 deletions test/e2e/tests/metrics/wallet-created.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe('Wallet Created Events', function () {
chain_id: '0x539',
environment_type: 'fullscreen',
is_profile_syncing_enabled: true,
hd_srp_index: 0,
});
},
);
Expand Down

0 comments on commit 1d1ade9

Please sign in to comment.