From db9d7f371175899f898e17acd2f0a389ec94abf3 Mon Sep 17 00:00:00 2001 From: Derek Brans Date: Mon, 23 Sep 2024 14:46:20 -0400 Subject: [PATCH 1/9] initial e2e test for stx --- privacy-snapshot.json | 23 +- test/e2e/default-fixture.js | 2 + test/e2e/fixture-builder.js | 8 + test/e2e/mock-e2e.js | 64 ++-- ...rs-after-init-opt-in-background-state.json | 18 +- .../errors-after-init-opt-in-ui-state.json | 20 +- ...s-before-init-opt-in-background-state.json | 40 +- .../errors-before-init-opt-in-ui-state.json | 40 +- .../mock-requests-for-swap-test.ts | 349 ++++++++++++++++++ .../smart-transactions.spec.ts | 97 +++++ test/e2e/tests/swaps/{shared.js => shared.ts} | 102 +++-- .../{swap-eth.spec.js => swap-eth.spec.ts} | 28 +- ...ns.spec.js => swaps-notifications.spec.ts} | 23 +- test/e2e/webdriver/driver.js | 6 +- .../smart-transaction-status.js | 2 + 15 files changed, 656 insertions(+), 166 deletions(-) create mode 100644 test/e2e/tests/smart-transactions/mock-requests-for-swap-test.ts create mode 100644 test/e2e/tests/smart-transactions/smart-transactions.spec.ts rename test/e2e/tests/swaps/{shared.js => shared.ts} (70%) rename test/e2e/tests/swaps/{swap-eth.spec.js => swap-eth.spec.ts} (80%) rename test/e2e/tests/swaps/{swaps-notifications.spec.js => swaps-notifications.spec.ts} (92%) diff --git a/privacy-snapshot.json b/privacy-snapshot.json index 48c96582cab0..5ef0e33f82d0 100644 --- a/privacy-snapshot.json +++ b/privacy-snapshot.json @@ -6,6 +6,7 @@ "api.web3modal.com", "app.ens.domains", "arbitrum-mainnet.infura.io", + "authentication.api.cx.metamask.io", "bafkreifvhjdf6ve4jfv6qytqtux5nd4nwnelioeiqx5x2ez5yrgrzk7ypi.ipfs.dweb.link", "bafybeidxfmwycgzcp4v2togflpqh2gnibuexjy4m4qqwxp7nh3jx5zlh4y.ipfs.dweb.link", "bridge.api.cx.metamask.io", @@ -13,9 +14,11 @@ "cdn.segment.io", "cdnjs.cloudflare.com", "chainid.network", + "client-side-detection.api.cx.metamask.io", "configuration.dev.metamask-institutional.io", "configuration.metamask-institutional.io", "connect.trezor.io", + "crypto.com", "customnetwork.test", "doesntexist.test", "etherscan.io", @@ -24,6 +27,7 @@ "gas.api.cx.metamask.io", "github.com", "goerli.infura.io", + "lattice.gridplus.io", "localhost:8000", "localhost:8545", "mainnet.infura.io", @@ -31,11 +35,12 @@ "metamask.github.io", "min-api.cryptocompare.com", "nft.api.cx.metamask.io", + "oidc.api.cx.metamask.io", + "on-ramp-content.api.cx.metamask.io", + "on-ramp-content.uat-api.cx.metamask.io", "phishing-detection.api.cx.metamask.io", "portfolio.metamask.io", "price.api.cx.metamask.io", - "on-ramp-content.api.cx.metamask.io", - "on-ramp-content.uat-api.cx.metamask.io", "proxy.api.cx.metamask.io", "raw.githubusercontent.com", "registry.npmjs.org", @@ -49,15 +54,11 @@ "test.metamask-phishing.io", "token.api.cx.metamask.io", "tokens.api.cx.metamask.io", + "transaction.api.cx.metamask.io", "tx-sentinel-ethereum-mainnet.api.cx.metamask.io", - "unresponsive-rpc.url", - "www.4byte.directory", - "lattice.gridplus.io", "unresponsive-rpc.test", - "authentication.api.cx.metamask.io", - "oidc.api.cx.metamask.io", - "price.api.cx.metamask.io", - "token.api.cx.metamask.io", - "client-side-detection.api.cx.metamask.io", - "user-storage.api.cx.metamask.io" + "unresponsive-rpc.url", + "user-storage.api.cx.metamask.io", + "verify.walletconnect.com", + "www.4byte.directory" ] diff --git a/test/e2e/default-fixture.js b/test/e2e/default-fixture.js index 470e260ff959..495bef95b31d 100644 --- a/test/e2e/default-fixture.js +++ b/test/e2e/default-fixture.js @@ -232,7 +232,9 @@ function defaultFixture(inputChainId = CHAIN_IDS.LOCALHOST) { SmartTransactionsController: { smartTransactionsState: { fees: {}, + feesByChainId: {}, liveness: true, + livenessByChainId: {}, smartTransactions: { [CHAIN_IDS.MAINNET]: [], }, diff --git a/test/e2e/fixture-builder.js b/test/e2e/fixture-builder.js index cc30c261d22d..fb8e72efcdf3 100644 --- a/test/e2e/fixture-builder.js +++ b/test/e2e/fixture-builder.js @@ -600,6 +600,14 @@ class FixtureBuilder { }); } + withPreferencesControllerSmartTransactionsOptedIn() { + return this.withPreferencesController({ + preferences: { + smartTransactionsOptInStatus: true, + }, + }); + } + withPreferencesControllerAndFeatureFlag(flags) { merge(this.fixture.data.PreferencesController, flags); return this; diff --git a/test/e2e/mock-e2e.js b/test/e2e/mock-e2e.js index 929a424a36ef..07a8a9893d66 100644 --- a/test/e2e/mock-e2e.js +++ b/test/e2e/mock-e2e.js @@ -268,35 +268,38 @@ async function setupMocking( .thenCallback(() => { return { statusCode: 200, - json: [ - { - ethereum: { - fallbackToV1: false, - mobileActive: true, - extensionActive: true, - }, - bsc: { - fallbackToV1: false, - mobileActive: true, - extensionActive: true, - }, - polygon: { - fallbackToV1: false, - mobileActive: true, - extensionActive: true, - }, - avalanche: { - fallbackToV1: false, - mobileActive: true, - extensionActive: true, - }, - smartTransactions: { - mobileActive: false, - extensionActive: false, - }, - updated_at: '2022-03-17T15:54:00.360Z', + json: { + ethereum: { + fallbackToV1: false, + mobileActive: true, + extensionActive: true, }, - ], + bsc: { + fallbackToV1: false, + mobileActive: true, + extensionActive: true, + }, + polygon: { + fallbackToV1: false, + mobileActive: true, + extensionActive: true, + }, + avalanche: { + fallbackToV1: false, + mobileActive: true, + extensionActive: true, + }, + localhost: { + fallbackToV1: false, + mobileActive: true, + extensionActive: true, + }, + smartTransactions: { + mobileActive: false, + extensionActive: true, + }, + updated_at: '2022-03-17T15:54:00.360Z', + }, }; }); @@ -664,6 +667,11 @@ async function setupMocking( const portfolioRequestsMatcher = (request) => request.headers.referer === 'https://portfolio.metamask.io/'; + // Passthrough requests to ServerMochaToBackground's WebSocket server + // which is running on port 8111. + // TODO: forAnyWebSocket() is too broad, we should be able to more + // specifically target ServerMochaToBackground's WebSocket server + await server.forAnyWebSocket().thenPassThrough(); /** * Listen for requests and add the hostname to the privacy report if it did * not previously exist. This is used to track which hosts are requested diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json index c133de6128ca..8f07e2e062d5 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json @@ -62,16 +62,8 @@ "bridgeState": { "bridgeFeatureFlags": { "extensionSupport": "boolean", - "srcNetworkAllowlist": { - "0": "string", - "1": "string", - "2": "string" - }, - "destNetworkAllowlist": { - "0": "string", - "1": "string", - "2": "string" - } + "srcNetworkAllowlist": { "0": "string", "1": "string", "2": "string" }, + "destNetworkAllowlist": { "0": "string", "1": "string", "2": "string" } } } }, @@ -180,6 +172,7 @@ "permissionActivityLog": "object" }, "PreferencesController": { + "selectedAddress": "string", "useBlockie": false, "useNonceField": false, "usePhishDetect": true, @@ -228,8 +221,7 @@ "useExternalNameSources": "boolean", "useTransactionSimulations": true, "enableMV3TimestampSave": true, - "useExternalServices": "boolean", - "selectedAddress": "string" + "useExternalServices": "boolean" }, "QueuedRequestController": { "queuedRequestCount": 0 }, "SelectedNetworkController": { "domains": "object" }, @@ -242,7 +234,9 @@ "SmartTransactionsController": { "smartTransactionsState": { "fees": {}, + "feesByChainId": "object", "liveness": true, + "livenessByChainId": "object", "smartTransactions": "object" } }, diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json index dfee54fbd6cb..dff32fea5b34 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json @@ -96,6 +96,7 @@ } }, "keyrings": "object", + "selectedAddress": "string", "useNonceField": false, "usePhishDetect": true, "dismissSeedBackUpReminder": true, @@ -127,16 +128,15 @@ "useTransactionSimulations": true, "enableMV3TimestampSave": true, "useExternalServices": "boolean", - "selectedAddress": "string", "metaMetricsId": "fake-metrics-id", "marketingCampaignCookieId": null, - "metaMetricsDataDeletionId": null, - "metaMetricsDataDeletionTimestamp": 0, "eventsBeforeMetricsOptIn": "object", "traits": "object", "previousUserTraits": "object", "fragments": "object", "segmentApiCalls": "object", + "metaMetricsDataDeletionId": null, + "metaMetricsDataDeletionTimestamp": 0, "currentCurrency": "usd", "alertEnabledness": { "unconnectedAccount": true, "web3ShimUsage": true }, "unconnectedAccountAlertShownOrigins": "object", @@ -167,7 +167,9 @@ "allDetectedTokens": {}, "smartTransactionsState": { "fees": {}, + "feesByChainId": "object", "liveness": true, + "livenessByChainId": "object", "smartTransactions": "object" }, "allNftContracts": "object", @@ -248,16 +250,8 @@ "bridgeState": { "bridgeFeatureFlags": { "extensionSupport": "boolean", - "srcNetworkAllowlist": { - "0": "string", - "1": "string", - "2": "string" - }, - "destNetworkAllowlist": { - "0": "string", - "1": "string", - "2": "string" - } + "srcNetworkAllowlist": { "0": "string", "1": "string", "2": "string" }, + "destNetworkAllowlist": { "0": "string", "1": "string", "2": "string" } } }, "ensEntries": "object", diff --git a/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-background-state.json b/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-background-state.json index b6354922add0..2ccfa6ce44a4 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-background-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-background-state.json @@ -50,6 +50,23 @@ }, "snapsInstallPrivacyWarningShown": true }, + "BridgeController": { + "bridgeState": { + "bridgeFeatureFlags": { + "extensionSupport": "boolean", + "srcNetworkAllowlist": { + "0": "string", + "1": "string", + "2": "string" + }, + "destNetworkAllowlist": { + "0": "string", + "1": "string", + "2": "string" + } + } + } + }, "CurrencyController": { "currentCurrency": "usd", "currencyRates": { @@ -80,11 +97,11 @@ }, "NetworkController": { "selectedNetworkClientId": "string", + "networkConfigurations": "object", "networksMetadata": { "networkConfigurationId": { "EIPS": {}, "status": "available" } }, - "providerConfig": "object", - "networkConfigurations": "object" + "providerConfig": "object" }, "OnboardingController": { "completedOnboarding": true, @@ -134,27 +151,12 @@ "SmartTransactionsController": { "smartTransactionsState": { "fees": {}, + "feesByChainId": "object", "liveness": true, + "livenessByChainId": "object", "smartTransactions": "object" } }, - "BridgeController": { - "bridgeState": { - "bridgeFeatureFlags": { - "extensionSupport": "boolean", - "srcNetworkAllowlist": { - "0": "string", - "1": "string", - "2": "string" - }, - "destNetworkAllowlist": { - "0": "string", - "1": "string", - "2": "string" - } - } - } - }, "SubjectMetadataController": { "subjectMetadata": "object" }, "TokensController": { "allDetectedTokens": {}, diff --git a/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-ui-state.json b/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-ui-state.json index 51910b2057a7..2aa4f3e4f5c6 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-ui-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-ui-state.json @@ -50,6 +50,23 @@ }, "snapsInstallPrivacyWarningShown": true }, + "BridgeController": { + "bridgeState": { + "bridgeFeatureFlags": { + "extensionSupport": "boolean", + "srcNetworkAllowlist": { + "0": "string", + "1": "string", + "2": "string" + }, + "destNetworkAllowlist": { + "0": "string", + "1": "string", + "2": "string" + } + } + } + }, "CurrencyController": { "currentCurrency": "usd", "currencyRates": { @@ -80,11 +97,11 @@ }, "NetworkController": { "selectedNetworkClientId": "string", + "networkConfigurations": "object", "networksMetadata": { "networkConfigurationId": { "EIPS": {}, "status": "available" } }, - "providerConfig": "object", - "networkConfigurations": "object" + "providerConfig": "object" }, "OnboardingController": { "completedOnboarding": true, @@ -134,7 +151,9 @@ "SmartTransactionsController": { "smartTransactionsState": { "fees": {}, + "feesByChainId": "object", "liveness": true, + "livenessByChainId": "object", "smartTransactions": "object" } }, @@ -147,23 +166,6 @@ "ignoredTokens": "object", "tokens": "object" }, - "BridgeController": { - "bridgeState": { - "bridgeFeatureFlags": { - "extensionSupport": "boolean", - "srcNetworkAllowlist": { - "0": "string", - "1": "string", - "2": "string" - }, - "destNetworkAllowlist": { - "0": "string", - "1": "string", - "2": "string" - } - } - } - }, "TransactionController": { "transactions": "object" }, "config": "object", "firstTimeInfo": "object" diff --git a/test/e2e/tests/smart-transactions/mock-requests-for-swap-test.ts b/test/e2e/tests/smart-transactions/mock-requests-for-swap-test.ts new file mode 100644 index 000000000000..69b482aee671 --- /dev/null +++ b/test/e2e/tests/smart-transactions/mock-requests-for-swap-test.ts @@ -0,0 +1,349 @@ +import { MockttpServer } from 'mockttp'; +import { mockEthDaiTrade } from '../swaps/shared'; + +const STX_UUID = '0d506aaa-5e38-4cab-ad09-2039cb7a0f33'; + +const GET_FEES_REQUEST_INCLUDES = { + txs: [ + { + from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', + to: '0x881D40237659C251811CEC9c364ef91dC08D300C', + value: '0x1bc16d674ec80000', + gas: '0xf4240', + nonce: '0x0', + }, + ], +}; + +const GET_FEES_RESPONSE = { + blockNumber: 20728974, + id: '19d4eea3-8a49-463e-9e9c-099f9d9571ca', + txs: [ + { + cancelFees: [], + return: '0x', + status: 1, + gasUsed: 190780, + gasLimit: 239420, + fees: [ + { + maxFeePerGas: 4667609171, + maxPriorityFeePerGas: 1000000004, + gas: 239420, + balanceNeeded: 1217518987960240, + currentBalance: 751982303082919400, + error: '', + }, + ], + feeEstimate: 627603309182220, + baseFeePerGas: 2289670348, + maxFeeEstimate: 1117518987720820, + }, + ], +}; + +const SUBMIT_TRANSACTIONS_REQUEST_EXACTLY = { + rawTxs: [ + '0x02f91a3b0180843b9aca048501163610538303a73c94881d40237659c251811cec9c364ef91dc08d300c881bc16d674ec80000b919c65f575529000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001bc16d674ec8000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000136b796265725377617046656544796e616d69630000000000000000000000000000000000000000000000000000000000000000000000000000000000000018e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000001b83413f0b3640000000000000000000000000000000000000000000000000f7a8daea356aa92bfe0000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000003e2c284391c000000000000000000000000000f326e4de8f66a0bdc0970b79e0924e33c79f1915000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017a4e21fd0e90000000000000000000000000000000000000000000000000000000000000020000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd67000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000132000000000000000000000000000000000000000000000000000000000000015200000000000000000000000000000000000000000000000000000000000001260000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000074de5d4fcbf63e00296fd95d33236b97940166310000000000000000000000000000000000000000000000000000000066e029cc00000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000008200000000000000000000000000000000000000000000000000000000000000ac00000000000000000000000000000000000000000000000000000000000000e80000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000068000000000000000000000000000000000000000000000000000000000000000400e00deaa000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080000000000000000000000000c697051d1c6296c24ae3bcef39aca743861d9a81000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae900000000000000000000000000000000000000000000000006e0d04fc2cd90000000000000000000000000000000000000000000000000000000000000000040003c5f890000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000004e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000ead050515e10fdb3540ccd6f8236c46790508a7600000000000000000000000000000000000000000000000074b3f935bb79d45400000000000000000000000000000000000000000000000000000000000000e00000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd670000000000000000000000000000000000000000000000c4000000000000000000000000000000000000000000000000000000000000000000000000000003a4e525b10b000000000000000000000000000000000000000000000000000000000000002000000000000000000000000028cacd5e26a719f139e2105ca1efc3d9dc892826000000000000000000000000ff8ba4d1fc3762f6154cc942ccf30049a2a0cec6000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd670000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000074b3f935bb79d45400000000000000000000000000000000000000000000000074b3f935bb79d4540000000000000000000000000000000000000000000000000000000045aff3b30000000000000000000000000000000000000000000000000000000066e025760000000000000000000000000000000000000000000000000016649acb241b017da53b79cbf14cc2a737cd6469098549000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000026000000000000000000000000067297ee4eb097e072b4ab6f1620268061ae80464000000000000000000000000ae4fdcc420f1409c8b9b2af04db150dd986f66a5000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000002e0000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000444b27250000000000000000000000000000000000000000000000000000000000000041031bc9026b766621ebb870691407a8f5b5d222977566d0bb38bbd633459fc9671e24b5c970373555d66f0a46e830ee1605152bd519fed1a9684a097364f8b41f1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000413e4923699eff11cb0252c3f8b42793eeac8793bea92843fa4028b80ff3391bbf1df4ddef51732ceeb6f65a8c9dc2651e4b952568d350b4029d4b8b5cae5c1f991c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000408cc7a56b0000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c879c58f70905f734641735bc61e45c19dd9ad60bc0000000000000000000004e7000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000045921fcd000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000004063407a490000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd6700000000000000000000000011b815efb8f581194ae79006d24e0d814b7697f6000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000000000000000000000000000000840f9f95029e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000408cc7a56b0000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c879c58f70905f734641735bc61e45c19dd9ad60bc0000000000000000000004e7000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000000005354532a0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000004063407a490000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd6700000000000000000000000011b815efb8f581194ae79006d24e0d814b7697f6000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000000000000000000000000000000840f9f95029e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040301a40330000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000005b6a0771c752e35b2ca2aff4f22a66b1598a2bc50000000000000000000000000000000000000000000000000000000053516d7f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd6700000000000000000000000000000000000000000000000000000000000000408cc7a56b0000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c879c58f70905f734641735bc61e45c19dd9ad60bc0000000000000000000004e7000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000000005351dd8d000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000004063407a490000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd6700000000000000000000000011b815efb8f581194ae79006d24e0d814b7697f6000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000004207cfca814f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000408cc7a56b0000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c806df3b2bbb68adc8b0e302443692037ed9f91b42000000000000000000000063000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000029a7a0aa0000000000000000000000000000000000000000000000000000000000000020000000000000000000108fd5cc11eaa000000000000000fcb6c0091c62637b42000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000074de5d4fcbf63e00296fd95d33236b97940166310000000000000000000000000000000000000000000000001b83413f0b3640000000000000000000000000000000000000000000000000f7a8daea356aa92bfe000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002337b22536f75726365223a226d6574616d61736b222c22416d6f756e74496e555344223a22343635382e373832393833313733303632222c22416d6f756e744f7574555344223a22343637362e393836303733303034303236222c22526566657272616c223a22222c22466c616773223a302c22416d6f756e744f7574223a2234363631373438303431393032373532373538353934222c2254696d657374616d70223a313732353936353539362c22496e74656772697479496e666f223a7b224b65794944223a2231222c225369676e6174757265223a22546363534e7837537235376b367242794f5a74344b714472344d544637356b7651527658644230724266386e395864513869634a3830385963355155595a34675a52527645337777433237352f59586a722f34625065662b4a58514b4969556b6334356a4e73556c366e6141387141774d5a48324f4a3234657932647253386c52625551444f67784b4d6979334d413164467472575241306f6d6e664873365044624b6d6f4e494c58674b45416e497a6b6d687a675043346e396d39715043337a457459737875457042772b386356426b684e7761684f56625850635854646977334870437356365555635375522f4a495342386d6a737a494b6d664b46595a716333516c5a714e6e507a50576a3648366e73587050512b6145725338334c3544554b5868364e6a70584855764748314d7a557074584169615634737354795849582f435645685a396e76564845746b2f776b6a42673d3d227d7d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000ac001a0e067d3acdb151721e7fdb3834cf2563d667aad9b4c18a5afb81390d6288ac2fe9fa0e74a9e40e017bcd926f3c5da4355e0926ae7e45b3b9e1bc474507220cb43', + ], + rawCancelTxs: '', +}; + +const GET_BATCH_STATUS_RESPONSE_PENDING = { + '0d506aaa-5e38-4cab-ad09-2039cb7a0f33': { + cancellationFeeWei: 0, + cancellationReason: 'not_cancelled', + deadlineRatio: 0, + isSettled: false, + minedTx: 'not_mined', + wouldRevertMessage: null, + minedHash: '', + duplicated: false, + timedOut: false, + proxied: false, + type: 'sentinel', + }, +}; + +const GET_BATCH_STATUS_RESPONSE_SUCCESS = { + '0d506aaa-5e38-4cab-ad09-2039cb7a0f33': { + cancellationFeeWei: 0, + cancellationReason: 'not_cancelled', + deadlineRatio: 0, + isSettled: true, + minedTx: 'success', + wouldRevertMessage: null, + minedHash: + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + duplicated: true, + timedOut: true, + proxied: false, + type: 'sentinel', + }, +}; + +const GET_TRANSACTION_RECEIPT_RESPONSE = { + id: 2901696354742565, + jsonrpc: '2.0', + result: { + blockHash: + '0xe90b92d004a9c22c32c50c628bbd93f22e3468ec4ffc62422d68cf6370f59f1d', + blockNumber: '0x2', + contractAddress: null, + cumulativeGasUsed: '0xc138b1', + effectiveGasPrice: '0x1053fcd93', + from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', + gasUsed: '0x2e93c', + logs: [ + { + address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', + blockHash: + '0xe90b92d004a9c22c32c50c628bbd93f22e3468ec4ffc62422d68cf6370f59f1d', + blockNumber: '0x13c80ce', + data: '0x00000000000000000000000000000000000000000000000000005af3107a4000', + logIndex: '0xde', + removed: false, + topics: [ + '0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c', + '0x00000000000000000000000074de5d4fcbf63e00296fd95d33236b9794016631', + ], + transactionHash: + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + transactionIndex: '0x2f', + }, + { + address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', + blockHash: + '0xe90b92d004a9c22c32c50c628bbd93f22e3468ec4ffc62422d68cf6370f59f1d', + blockNumber: '0x13c80ce', + data: '0x00000000000000000000000000000000000000000000000000005a275669d200', + logIndex: '0xdf', + removed: false, + topics: [ + '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', + '0x00000000000000000000000074de5d4fcbf63e00296fd95d33236b9794016631', + '0x00000000000000000000000051c72848c68a965f66fa7a88855f9f7784502a7f', + ], + transactionHash: + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + transactionIndex: '0x2f', + }, + { + address: '0x6b175474e89094c44da98b954eedeac495271d0f', + blockHash: + '0xe90b92d004a9c22c32c50c628bbd93f22e3468ec4ffc62422d68cf6370f59f1d', + blockNumber: '0x13c80ce', + data: '0x000000000000000000000000000000000000000000000000033dd7a160e2a300', + logIndex: '0xe0', + removed: false, + topics: [ + '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', + '0x00000000000000000000000051c72848c68a965f66fa7a88855f9f7784502a7f', + '0x00000000000000000000000074de5d4fcbf63e00296fd95d33236b9794016631', + ], + transactionHash: + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + transactionIndex: '0x2f', + }, + { + address: '0x6b175474e89094c44da98b954eedeac495271d0f', + blockHash: + '0xe90b92d004a9c22c32c50c628bbd93f22e3468ec4ffc62422d68cf6370f59f1d', + blockNumber: '0x13c80ce', + data: '0x00000000000000000000000000000000000000000000000000006a3845cef618', + logIndex: '0xe1', + removed: false, + topics: [ + '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', + '0x00000000000000000000000051c72848c68a965f66fa7a88855f9f7784502a7f', + '0x000000000000000000000000ad30f7eebd9bd5150a256f47da41d4403033cdf0', + ], + transactionHash: + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + transactionIndex: '0x2f', + }, + { + address: '0xd82fa167727a4dc6d6f55830a2c47abbb4b3a0f8', + blockHash: + '0xe90b92d004a9c22c32c50c628bbd93f22e3468ec4ffc62422d68cf6370f59f1d', + blockNumber: '0x13c80ce', + data: '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000033dd7a160e2a3000000000000000000000000000000000000000000000000000000000000000005000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000005a275669d200', + logIndex: '0xe2', + removed: false, + topics: [ + '0xb651f2787ff61b5ab14f3936f2daebdad3d84aeb74438e82870cc3b7aee71e90', + '0x00000000000000000000000000000000000000000000000000000191e0cc96ac', + '0x00000000000000000000000051c72848c68a965f66fa7a88855f9f7784502a7f', + '0x00000000000000000000000074de5d4fcbf63e00296fd95d33236b9794016631', + ], + transactionHash: + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + transactionIndex: '0x2f', + }, + { + address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', + blockHash: + '0xe90b92d004a9c22c32c50c628bbd93f22e3468ec4ffc62422d68cf6370f59f1d', + blockNumber: '0x13c80ce', + data: '0x000000000000000000000000000000000000000000000000000000cbba106e00', + logIndex: '0xe3', + removed: false, + topics: [ + '0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65', + '0x00000000000000000000000074de5d4fcbf63e00296fd95d33236b9794016631', + ], + transactionHash: + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + transactionIndex: '0x2f', + }, + { + address: '0xf326e4de8f66a0bdc0970b79e0924e33c79f1915', + blockHash: + '0xe90b92d004a9c22c32c50c628bbd93f22e3468ec4ffc62422d68cf6370f59f1d', + blockNumber: '0x13c80ce', + data: '0x000000000000000000000000000000000000000000000000000000cbba106e00', + logIndex: '0xe4', + removed: false, + topics: [ + '0x3d0ce9bfc3ed7d6862dbb28b2dea94561fe714a1b4d019aa8af39730d1ad7c3d', + '0x00000000000000000000000074de5d4fcbf63e00296fd95d33236b9794016631', + ], + transactionHash: + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + transactionIndex: '0x2f', + }, + { + address: '0x6b175474e89094c44da98b954eedeac495271d0f', + blockHash: + '0xe90b92d004a9c22c32c50c628bbd93f22e3468ec4ffc62422d68cf6370f59f1d', + blockNumber: '0x13c80ce', + data: '0x000000000000000000000000000000000000000000000000033dd7a160e2a300', + logIndex: '0xe5', + removed: false, + topics: [ + '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', + '0x00000000000000000000000074de5d4fcbf63e00296fd95d33236b9794016631', + '0x0000000000000000000000005cfe73b6021e818b776b421b1c4db2474086a7e1', + ], + transactionHash: + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + transactionIndex: '0x2f', + }, + { + address: '0x881d40237659c251811cec9c364ef91dc08d300c', + blockHash: + '0xe90b92d004a9c22c32c50c628bbd93f22e3468ec4ffc62422d68cf6370f59f1d', + blockNumber: '0x13c80ce', + data: '0x', + logIndex: '0xe6', + removed: false, + topics: [ + '0xbeee1e6e7fe307ddcf84b0a16137a4430ad5e2480fc4f4a8e250ab56ccd7630d', + '0x015123c6e2552626efe611b6c48de60d080a6650860a38f237bc2b6f651f79d1', + '0x0000000000000000000000005cfe73b6021e818b776b421b1c4db2474086a7e1', + ], + transactionHash: + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + transactionIndex: '0x2f', + }, + ], + logsBloom: + '0x00000000000000001000000000000000000000000000000000000001000000000000010000000000000010000000000002000000080008000000040000000000a00000000000000000020008000000000000000000540000000004008020000010000000000000000000000000000801000000000000040000000010004010000000021000000000000000000000000000020041000100004020000000000000000000000200000000000040000000000000000000000000000000000000000000000002000400000000000000000000001002000400000000000002000000000020200000000400000000800000000000000000020200400000000000001000', + status: '0x1', + to: '0x881d40237659c251811cec9c364ef91dc08d300c', + transactionHash: + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + transactionIndex: '0x2f', + type: '0x2', + }, +}; + +const GET_TRANSACTION_BY_HASH_RESPONSE = { + id: 2901696354742565, + jsonrpc: '2.0', + result: { + accessList: [], + blockHash: + '0xe90b92d004a9c22c32c50c628bbd93f22e3468ec4ffc62422d68cf6370f59f1d', + blockNumber: '0x2', + chainId: '0x539', + from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', + gas: '0x3a73c', + gasPrice: '0x1053fcd93', + hash: '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + input: + '0x5f5755290000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000001c616972737761704c696768743446656544796e616d696346697865640000000000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000191e0cc96ac0000000000000000000000000000000000000000000000000000000066e44f2c00000000000000000000000051c72848c68a965f66fa7a88855f9f7784502a7f0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000033dd7a160e2a300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005a275669d200000000000000000000000000000000000000000000000000000000000000001bc1acb8a206598705baeb494a479a8af9dc3a9f9b7bd1ce9818360fd6f603cf0766e7bdc77f9f72e90dcd9157e007291adc6d3947e9b6d89ff412c5b54f9a17f1000000000000000000000000000000000000000000000000000000cbba106e00000000000000000000000000f326e4de8f66a0bdc0970b79e0924e33c79f1915000000000000000000000000000000000000000000000000000000000000000000d7', + maxFeePerGas: '0x14bdcd619', + maxPriorityFeePerGas: '0x3b9aca04', + nonce: '0x127', + r: '0x5a5463bfe8e587ee1211be74580c74fa759f8292f37f970033df4b782f5e097d', + s: '0x50e403a70000b106e9f598b1b3f55b6ea9d2ec21d9fc67de63eb1d07df2767dd', + to: '0x881d40237659c251811cec9c364ef91dc08d300c', + transactionIndex: '0x2f', + type: '0x2', + v: '0x0', + value: '0x5af3107a4000', + yParity: '0x0', + }, +}; + +export const mockSwapRequests = async (mockServer: MockttpServer) => { + await mockEthDaiTrade(mockServer); + + await mockServer + .forPost('https://transaction.api.cx.metamask.io/networks/1/getFees') + .withJsonBodyIncluding(GET_FEES_REQUEST_INCLUDES) + .thenJson(200, GET_FEES_RESPONSE); + + await mockServer + .forPost( + 'https://transaction.api.cx.metamask.io/networks/1/submitTransactions', + ) + .once() + .withJsonBody(SUBMIT_TRANSACTIONS_REQUEST_EXACTLY) + .thenJson(200, { uuid: STX_UUID }); + + await mockServer + .forGet('https://transaction.api.cx.metamask.io/networks/1/batchStatus') + .withQuery({ uuids: STX_UUID }) + .once() + .thenJson(200, GET_BATCH_STATUS_RESPONSE_PENDING); + + await mockServer + .forGet('https://transaction.api.cx.metamask.io/networks/1/batchStatus') + .withQuery({ uuids: STX_UUID }) + .once() + .thenJson(200, GET_BATCH_STATUS_RESPONSE_SUCCESS); + + await mockServer + .forJsonRpcRequest({ + method: 'eth_getBalance', + params: ['0x5cfe73b6021e818b776b421b1c4db2474086a7e1'], + }) + // .once() + .thenJson(200, { + id: 3806592044086814, + jsonrpc: '2.0', + result: '0x1bc16d674ec80000', // 2 ETH + }); + + await mockServer + .forJsonRpcRequest({ + method: 'eth_getTransactionReceipt', + params: [ + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + ], + }) + // .once() + .thenJson(200, GET_TRANSACTION_RECEIPT_RESPONSE); + + await mockServer + .forJsonRpcRequest({ + method: 'eth_getTransactionByHash', + params: [ + '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', + ], + }) + // .once() + .thenJson(200, GET_TRANSACTION_BY_HASH_RESPONSE); +}; diff --git a/test/e2e/tests/smart-transactions/smart-transactions.spec.ts b/test/e2e/tests/smart-transactions/smart-transactions.spec.ts new file mode 100644 index 000000000000..210d5abdb034 --- /dev/null +++ b/test/e2e/tests/smart-transactions/smart-transactions.spec.ts @@ -0,0 +1,97 @@ +import { MockttpServer } from 'mockttp'; +import { + buildQuote, + reviewQuote, + checkActivityTransaction, +} from '../swaps/shared'; +import FixtureBuilder from '../../fixture-builder'; +import { unlockWallet, withFixtures } from '../../helpers'; +import { Driver } from '../../webdriver/driver'; +import { CHAIN_IDS } from '../../../../shared/constants/network'; +import { mockSwapRequests } from './mock-requests-for-swap-test'; + +export async function withFixturesForSmartTransactions( + { + title, + testSpecificMock, + }: { + title?: string; + testSpecificMock: (mockServer: MockttpServer) => Promise; + }, + test: (args: { driver: Driver }) => Promise, +) { + const inputChainId = CHAIN_IDS.MAINNET; + await withFixtures( + { + fixtures: new FixtureBuilder({ inputChainId }) + .withPermissionControllerConnectedToTestDapp() + .withPreferencesControllerSmartTransactionsOptedIn() + .withNetworkControllerOnMainnet() + .build(), + title, + testSpecificMock, + dapp: true, + }, + async ({ driver }) => { + await unlockWallet(driver); + await test({ driver }); + }, + ); +} + +export const waitForTransactionToComplete = async ( + driver: Driver, + options: { tokenName: string }, +) => { + await driver.waitForSelector({ + css: '[data-testid="swap-smart-transaction-status-header"]', + text: 'Privately submitting your Swap', + }); + + await driver.waitForSelector( + { + css: '[data-testid="swap-smart-transaction-status-header"]', + text: 'Swap complete!', + }, + { timeout: 30000 }, + ); + + await driver.findElement({ + css: '[data-testid="swap-smart-transaction-status-description"]', + text: `${options.tokenName}`, + }); + + await driver.clickElement({ text: 'Close', tag: 'button' }); + await driver.waitForSelector('[data-testid="account-overview__asset-tab"]'); +}; + +describe('smart transactions @no-mmi', function () { + it('Completes a Swap', async function () { + await withFixturesForSmartTransactions( + { + title: this.test?.fullTitle(), + testSpecificMock: mockSwapRequests, + }, + async ({ driver }) => { + await buildQuote(driver, { + amount: 2, + swapTo: 'DAI', + }); + await reviewQuote(driver, { + amount: 2, + swapFrom: 'ETH', + swapTo: 'DAI', + }); + + await driver.clickElement({ text: 'Swap', tag: 'button' }); + await waitForTransactionToComplete(driver, { tokenName: 'DAI' }); + await checkActivityTransaction(driver, { + index: 0, + amount: '2', + swapFrom: 'ETH', + swapTo: 'DAI', + }); + }, + ); + }); +}); diff --git a/test/e2e/tests/swaps/shared.js b/test/e2e/tests/swaps/shared.ts similarity index 70% rename from test/e2e/tests/swaps/shared.js rename to test/e2e/tests/swaps/shared.ts index 3bfdefcf71d7..c960395b58ec 100644 --- a/test/e2e/tests/swaps/shared.js +++ b/test/e2e/tests/swaps/shared.ts @@ -1,27 +1,54 @@ -const { strict: assert } = require('assert'); -const FixtureBuilder = require('../../fixture-builder'); -const { regularDelayMs, veryLargeDelayMs } = require('../../helpers'); - -const ganacheOptions = { - accounts: [ - { - secretKey: - '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', - balance: 25000000000000000000, +import { strict as assert } from 'assert'; +import { ServerOptions } from 'ganache'; +import { MockttpServer } from 'mockttp'; +import { Driver } from '../../webdriver/driver'; +import FixtureBuilder from '../../fixture-builder'; +import { regularDelayMs, veryLargeDelayMs } from '../../helpers'; +import { SWAP_TEST_ETH_DAI_TRADES_MOCK } from '../../../data/mock-data'; + +export async function mockEthDaiTrade(mockServer: MockttpServer) { + return [ + await mockServer + .forGet('https://swap.api.cx.metamask.io/networks/1/trades') + .thenCallback(() => { + return { + statusCode: 200, + json: SWAP_TEST_ETH_DAI_TRADES_MOCK, + }; + }), + ]; +} + +export const ganacheOptions: ServerOptions & { miner: { blockTime?: number } } = + { + wallet: { + accounts: [ + { + secretKey: + '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', + balance: 25000000000000000000n, + }, + ], }, - ], -}; + miner: {}, + }; -const withFixturesOptions = { +export const withFixturesOptions = { fixtures: new FixtureBuilder().build(), ganacheOptions, }; -const buildQuote = async (driver, options) => { +type SwapOptions = { + amount: number; + swapTo?: string; + swapToContractAddress?: string; +}; + +export const buildQuote = async (driver: Driver, options: SwapOptions) => { await driver.clickElement('[data-testid="token-overview-button-swap"]'); await driver.fill( 'input[data-testid="prepare-swap-page-from-token-amount"]', - options.amount, + options.amount.toString(), ); await driver.delay(veryLargeDelayMs); // Need an extra delay after typing an amount. await driver.clickElement('[data-testid="prepare-swap-page-swap-to"]'); @@ -29,7 +56,7 @@ const buildQuote = async (driver, options) => { await driver.fill( 'input[id="list-with-search__text-search"]', - options.swapTo || options.swapToContractAddress, + options.swapTo || options.swapToContractAddress || '', ); await driver.delay(veryLargeDelayMs); // Need an extra delay after typing an amount. @@ -55,11 +82,23 @@ const buildQuote = async (driver, options) => { ); }; -const reviewQuote = async (driver, options) => { +export const reviewQuote = async ( + driver: Driver, + options: { + swapFrom: string; + swapTo: string; + amount: number; + skipCounter?: boolean; + }, +) => { const summary = await driver.waitForSelector( '[data-testid="exchange-rate-display-quote-rate"]', ); const summaryText = await summary.getText(); + console.log('============\nsummaryText\n============', { + summaryText, + options, + }); assert.equal(summaryText.includes(options.swapFrom), true); assert.equal(summaryText.includes(options.swapTo), true); const quote = summaryText.split(`\n`); @@ -68,7 +107,7 @@ const reviewQuote = async (driver, options) => { '[data-testid="prepare-swap-page-receive-amount"]', ); const swapToAmount = await elementSwapToAmount.getText(); - const expectedAmount = parseFloat(quote[3]) * options.amount; + const expectedAmount = Number(quote[3]) * options.amount; const dotIndex = swapToAmount.indexOf('.'); const decimals = dotIndex === -1 ? 0 : swapToAmount.length - dotIndex - 1; assert.equal( @@ -91,7 +130,10 @@ const reviewQuote = async (driver, options) => { } }; -const waitForTransactionToComplete = async (driver, options) => { +export const waitForTransactionToComplete = async ( + driver: Driver, + options: { tokenName: string }, +) => { await driver.waitForSelector({ css: '[data-testid="awaiting-swap-header"]', text: 'Processing', @@ -114,7 +156,10 @@ const waitForTransactionToComplete = async (driver, options) => { await driver.waitForSelector('[data-testid="account-overview__asset-tab"]'); }; -const checkActivityTransaction = async (driver, options) => { +export const checkActivityTransaction = async ( + driver: Driver, + options: { index: number; swapFrom: string; swapTo: string; amount: string }, +) => { await driver.clickElement('[data-testid="account-overview__activity-tab"]'); await driver.waitForSelector('.activity-list-item'); @@ -149,7 +194,10 @@ const checkActivityTransaction = async (driver, options) => { await driver.clickElement('[data-testid="popover-close"]'); }; -const checkNotification = async (driver, options) => { +export const checkNotification = async ( + driver: Driver, + options: { title: string; text: string }, +) => { const isExpectedBoxTitlePresentAndVisible = await driver.isElementPresentAndVisible({ css: '[data-testid="swaps-banner-title"]', @@ -171,7 +219,7 @@ const checkNotification = async (driver, options) => { ); }; -const changeExchangeRate = async (driver) => { +export const changeExchangeRate = async (driver: Driver) => { await driver.clickElement('[data-testid="review-quote-view-all-quotes"]'); await driver.waitForSelector({ text: 'Quote details', tag: 'h2' }); @@ -182,13 +230,3 @@ const changeExchangeRate = async (driver) => { await networkFees[random].click(); await driver.clickElement({ text: 'Select', tag: 'button' }); }; - -module.exports = { - withFixturesOptions, - buildQuote, - reviewQuote, - waitForTransactionToComplete, - checkActivityTransaction, - checkNotification, - changeExchangeRate, -}; diff --git a/test/e2e/tests/swaps/swap-eth.spec.js b/test/e2e/tests/swaps/swap-eth.spec.ts similarity index 80% rename from test/e2e/tests/swaps/swap-eth.spec.js rename to test/e2e/tests/swaps/swap-eth.spec.ts index 35847b0ae33a..18d049e5de16 100644 --- a/test/e2e/tests/swaps/swap-eth.spec.js +++ b/test/e2e/tests/swaps/swap-eth.spec.ts @@ -1,35 +1,22 @@ -const { withFixtures, unlockWallet } = require('../../helpers'); -const { SWAP_TEST_ETH_DAI_TRADES_MOCK } = require('../../../data/mock-data'); -const { +import { unlockWallet, withFixtures } from '../../helpers'; +import { withFixturesOptions, buildQuote, reviewQuote, waitForTransactionToComplete, checkActivityTransaction, changeExchangeRate, -} = require('./shared'); - -async function mockEthDaiTrade(mockServer) { - return [ - await mockServer - .forGet('https://swap.api.cx.metamask.io/networks/1/trades') - .thenCallback(() => { - return { - statusCode: 200, - json: SWAP_TEST_ETH_DAI_TRADES_MOCK, - }; - }), - ]; -} + mockEthDaiTrade, +} from './shared'; describe('Swap Eth for another Token @no-mmi', function () { it('Completes second Swaps while first swap is processing', async function () { - withFixturesOptions.ganacheOptions.blockTime = 10; + withFixturesOptions.ganacheOptions.miner.blockTime = 10; await withFixtures( { ...withFixturesOptions, - title: this.test.fullTitle(), + title: this.test?.fullTitle(), }, async ({ driver }) => { await unlockWallet(driver); @@ -70,12 +57,13 @@ describe('Swap Eth for another Token @no-mmi', function () { }, ); }); + it('Completes a Swap between ETH and DAI after changing initial rate', async function () { await withFixtures( { ...withFixturesOptions, testSpecificMock: mockEthDaiTrade, - title: this.test.fullTitle(), + title: this.test?.fullTitle(), }, async ({ driver }) => { await unlockWallet(driver); diff --git a/test/e2e/tests/swaps/swaps-notifications.spec.js b/test/e2e/tests/swaps/swaps-notifications.spec.ts similarity index 92% rename from test/e2e/tests/swaps/swaps-notifications.spec.js rename to test/e2e/tests/swaps/swaps-notifications.spec.ts index c6dbbd469959..134741d3683c 100644 --- a/test/e2e/tests/swaps/swaps-notifications.spec.js +++ b/test/e2e/tests/swaps/swaps-notifications.spec.ts @@ -1,13 +1,14 @@ -const { withFixtures, unlockWallet } = require('../../helpers'); -const { SWAP_TEST_ETH_USDC_TRADES_MOCK } = require('../../../data/mock-data'); -const { +import { Mockttp } from 'mockttp'; +import { withFixtures, unlockWallet } from '../../helpers'; +import { SWAP_TEST_ETH_USDC_TRADES_MOCK } from '../../../data/mock-data'; +import { withFixturesOptions, buildQuote, reviewQuote, checkNotification, -} = require('./shared'); +} from './shared'; -async function mockSwapsTransactionQuote(mockServer) { +async function mockSwapsTransactionQuote(mockServer: Mockttp) { return [ await mockServer .forGet('https://swap.api.cx.metamask.io/networks/1/trades') @@ -19,7 +20,7 @@ async function mockSwapsTransactionQuote(mockServer) { } describe('Swaps - notifications @no-mmi', function () { - async function mockTradesApiPriceSlippageError(mockServer) { + async function mockTradesApiPriceSlippageError(mockServer: Mockttp) { await mockServer .forGet('https://swap.api.cx.metamask.io/networks/1/trades') .thenCallback(() => { @@ -71,7 +72,7 @@ describe('Swaps - notifications @no-mmi', function () { { ...withFixturesOptions, testSpecificMock: mockTradesApiPriceSlippageError, - title: this.test.fullTitle(), + title: this.test?.fullTitle(), }, async ({ driver }) => { await unlockWallet(driver); @@ -122,7 +123,7 @@ describe('Swaps - notifications @no-mmi', function () { ...withFixturesOptions, ganacheOptions: lowBalanceGanacheOptions, testSpecificMock: mockSwapsTransactionQuote, - title: this.test.fullTitle(), + title: this.test?.fullTitle(), }, async ({ driver }) => { await unlockWallet(driver); @@ -152,7 +153,7 @@ describe('Swaps - notifications @no-mmi', function () { await withFixtures( { ...withFixturesOptions, - title: this.test.fullTitle(), + title: this.test?.fullTitle(), }, async ({ driver }) => { await unlockWallet(driver); @@ -174,12 +175,12 @@ describe('Swaps - notifications @no-mmi', function () { await withFixtures( { ...withFixturesOptions, - title: this.test.fullTitle(), + title: this.test?.fullTitle(), }, async ({ driver }) => { await unlockWallet(driver); await buildQuote(driver, { - amount: '.0001', + amount: 0.0001, swapTo: 'DAI', }); await driver.clickElement('[title="Transaction settings"]'); diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index 6c386042b88e..e50ba69347ec 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -317,10 +317,14 @@ class Driver { * Waits for an element that matches the given locator to reach the specified state within the timeout period. * * @param {string | object} rawLocator - Element locator - * @param {number} timeout - optional parameter that specifies the maximum amount of time (in milliseconds) + * @param {object} [options] - parameter object + * @param {number} [options.timeout] - specifies the maximum amount of time (in milliseconds) * to wait for the condition to be met and desired state of the element to wait for. * It defaults to 'visible', indicating that the method will wait until the element is visible on the page. * The other supported state is 'detached', which means waiting until the element is removed from the DOM. + * @param {string} [options.state] - specifies the state of the element to wait for. + * It defaults to 'visible', indicating that the method will wait until the element is visible on the page. + * The other supported state is 'detached', which means waiting until the element is removed from the DOM. * @returns {Promise} promise resolving when the element meets the state or timeout occurs. * @throws {Error} Will throw an error if the element does not reach the specified state within the timeout period. */ diff --git a/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js b/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js index 157190687f31..9cd04d494c22 100644 --- a/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js +++ b/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js @@ -404,6 +404,7 @@ export default function SmartTransactionStatusPage() { )} Date: Tue, 24 Sep 2024 06:51:49 -0400 Subject: [PATCH 2/9] addressing review comments --- test/e2e/mock-e2e.js | 5 ---- .../mock-requests-for-swap-test.ts | 25 ++++++++----------- test/e2e/tests/swaps/shared.ts | 4 --- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/test/e2e/mock-e2e.js b/test/e2e/mock-e2e.js index 07a8a9893d66..f0a62f5f9c77 100644 --- a/test/e2e/mock-e2e.js +++ b/test/e2e/mock-e2e.js @@ -289,11 +289,6 @@ async function setupMocking( mobileActive: true, extensionActive: true, }, - localhost: { - fallbackToV1: false, - mobileActive: true, - extensionActive: true, - }, smartTransactions: { mobileActive: false, extensionActive: true, diff --git a/test/e2e/tests/smart-transactions/mock-requests-for-swap-test.ts b/test/e2e/tests/smart-transactions/mock-requests-for-swap-test.ts index 69b482aee671..80b4be8dba58 100644 --- a/test/e2e/tests/smart-transactions/mock-requests-for-swap-test.ts +++ b/test/e2e/tests/smart-transactions/mock-requests-for-swap-test.ts @@ -290,6 +290,17 @@ const GET_TRANSACTION_BY_HASH_RESPONSE = { export const mockSwapRequests = async (mockServer: MockttpServer) => { await mockEthDaiTrade(mockServer); + await mockServer + .forJsonRpcRequest({ + method: 'eth_getBalance', + params: ['0x5cfe73b6021e818b776b421b1c4db2474086a7e1'], + }) + .thenJson(200, { + id: 3806592044086814, + jsonrpc: '2.0', + result: '0x1bc16d674ec80000', // 2 ETH + }); + await mockServer .forPost('https://transaction.api.cx.metamask.io/networks/1/getFees') .withJsonBodyIncluding(GET_FEES_REQUEST_INCLUDES) @@ -315,18 +326,6 @@ export const mockSwapRequests = async (mockServer: MockttpServer) => { .once() .thenJson(200, GET_BATCH_STATUS_RESPONSE_SUCCESS); - await mockServer - .forJsonRpcRequest({ - method: 'eth_getBalance', - params: ['0x5cfe73b6021e818b776b421b1c4db2474086a7e1'], - }) - // .once() - .thenJson(200, { - id: 3806592044086814, - jsonrpc: '2.0', - result: '0x1bc16d674ec80000', // 2 ETH - }); - await mockServer .forJsonRpcRequest({ method: 'eth_getTransactionReceipt', @@ -334,7 +333,6 @@ export const mockSwapRequests = async (mockServer: MockttpServer) => { '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', ], }) - // .once() .thenJson(200, GET_TRANSACTION_RECEIPT_RESPONSE); await mockServer @@ -344,6 +342,5 @@ export const mockSwapRequests = async (mockServer: MockttpServer) => { '0xec9d6214684d6dc191133ae4a7ec97db3e521fff9cfe5c4f48a84cb6c93a5fa5', ], }) - // .once() .thenJson(200, GET_TRANSACTION_BY_HASH_RESPONSE); }; diff --git a/test/e2e/tests/swaps/shared.ts b/test/e2e/tests/swaps/shared.ts index c960395b58ec..3f3aff4447e5 100644 --- a/test/e2e/tests/swaps/shared.ts +++ b/test/e2e/tests/swaps/shared.ts @@ -95,10 +95,6 @@ export const reviewQuote = async ( '[data-testid="exchange-rate-display-quote-rate"]', ); const summaryText = await summary.getText(); - console.log('============\nsummaryText\n============', { - summaryText, - options, - }); assert.equal(summaryText.includes(options.swapFrom), true); assert.equal(summaryText.includes(options.swapTo), true); const quote = summaryText.split(`\n`); From 4c6472f290ff33c5b214aea21e647e14ca793cbb Mon Sep 17 00:00:00 2001 From: Derek Brans Date: Mon, 7 Oct 2024 10:35:39 -0400 Subject: [PATCH 3/9] yarn lint:fix --- privacy-snapshot.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/privacy-snapshot.json b/privacy-snapshot.json index 4326ebfa17f1..7f4a1db6d0a5 100644 --- a/privacy-snapshot.json +++ b/privacy-snapshot.json @@ -62,4 +62,4 @@ "user-storage.api.cx.metamask.io", "verify.walletconnect.com", "www.4byte.directory" -] \ No newline at end of file +] From 06d4b9754891c9e5e4e71fcf2e57332baae10e97 Mon Sep 17 00:00:00 2001 From: Derek Brans Date: Mon, 7 Oct 2024 11:49:36 -0400 Subject: [PATCH 4/9] fix e2e test --- .../e2e/tests/smart-transactions/mock-requests-for-swap-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/tests/smart-transactions/mock-requests-for-swap-test.ts b/test/e2e/tests/smart-transactions/mock-requests-for-swap-test.ts index 80b4be8dba58..457d1ea6c0a1 100644 --- a/test/e2e/tests/smart-transactions/mock-requests-for-swap-test.ts +++ b/test/e2e/tests/smart-transactions/mock-requests-for-swap-test.ts @@ -46,7 +46,7 @@ const SUBMIT_TRANSACTIONS_REQUEST_EXACTLY = { rawTxs: [ '0x02f91a3b0180843b9aca048501163610538303a73c94881d40237659c251811cec9c364ef91dc08d300c881bc16d674ec80000b919c65f575529000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001bc16d674ec8000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000136b796265725377617046656544796e616d69630000000000000000000000000000000000000000000000000000000000000000000000000000000000000018e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000001b83413f0b3640000000000000000000000000000000000000000000000000f7a8daea356aa92bfe0000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000003e2c284391c000000000000000000000000000f326e4de8f66a0bdc0970b79e0924e33c79f1915000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017a4e21fd0e90000000000000000000000000000000000000000000000000000000000000020000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd67000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000132000000000000000000000000000000000000000000000000000000000000015200000000000000000000000000000000000000000000000000000000000001260000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000074de5d4fcbf63e00296fd95d33236b97940166310000000000000000000000000000000000000000000000000000000066e029cc00000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000008200000000000000000000000000000000000000000000000000000000000000ac00000000000000000000000000000000000000000000000000000000000000e80000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000068000000000000000000000000000000000000000000000000000000000000000400e00deaa000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080000000000000000000000000c697051d1c6296c24ae3bcef39aca743861d9a81000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae900000000000000000000000000000000000000000000000006e0d04fc2cd90000000000000000000000000000000000000000000000000000000000000000040003c5f890000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000004e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000ead050515e10fdb3540ccd6f8236c46790508a7600000000000000000000000000000000000000000000000074b3f935bb79d45400000000000000000000000000000000000000000000000000000000000000e00000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd670000000000000000000000000000000000000000000000c4000000000000000000000000000000000000000000000000000000000000000000000000000003a4e525b10b000000000000000000000000000000000000000000000000000000000000002000000000000000000000000028cacd5e26a719f139e2105ca1efc3d9dc892826000000000000000000000000ff8ba4d1fc3762f6154cc942ccf30049a2a0cec6000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd670000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000074b3f935bb79d45400000000000000000000000000000000000000000000000074b3f935bb79d4540000000000000000000000000000000000000000000000000000000045aff3b30000000000000000000000000000000000000000000000000000000066e025760000000000000000000000000000000000000000000000000016649acb241b017da53b79cbf14cc2a737cd6469098549000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000026000000000000000000000000067297ee4eb097e072b4ab6f1620268061ae80464000000000000000000000000ae4fdcc420f1409c8b9b2af04db150dd986f66a5000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000002e0000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000444b27250000000000000000000000000000000000000000000000000000000000000041031bc9026b766621ebb870691407a8f5b5d222977566d0bb38bbd633459fc9671e24b5c970373555d66f0a46e830ee1605152bd519fed1a9684a097364f8b41f1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000413e4923699eff11cb0252c3f8b42793eeac8793bea92843fa4028b80ff3391bbf1df4ddef51732ceeb6f65a8c9dc2651e4b952568d350b4029d4b8b5cae5c1f991c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000408cc7a56b0000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c879c58f70905f734641735bc61e45c19dd9ad60bc0000000000000000000004e7000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000045921fcd000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000004063407a490000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd6700000000000000000000000011b815efb8f581194ae79006d24e0d814b7697f6000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000000000000000000000000000000840f9f95029e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000408cc7a56b0000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c879c58f70905f734641735bc61e45c19dd9ad60bc0000000000000000000004e7000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000000005354532a0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000004063407a490000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd6700000000000000000000000011b815efb8f581194ae79006d24e0d814b7697f6000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000000000000000000000000000000840f9f95029e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040301a40330000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000005b6a0771c752e35b2ca2aff4f22a66b1598a2bc50000000000000000000000000000000000000000000000000000000053516d7f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd6700000000000000000000000000000000000000000000000000000000000000408cc7a56b0000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c879c58f70905f734641735bc61e45c19dd9ad60bc0000000000000000000004e7000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000000005351dd8d000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000004063407a490000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000f081470f5c6fbccf48cc4e5b82dd926409dcdd6700000000000000000000000011b815efb8f581194ae79006d24e0d814b7697f6000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000004207cfca814f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000408cc7a56b0000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c806df3b2bbb68adc8b0e302443692037ed9f91b42000000000000000000000063000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000029a7a0aa0000000000000000000000000000000000000000000000000000000000000020000000000000000000108fd5cc11eaa000000000000000fcb6c0091c62637b42000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000074de5d4fcbf63e00296fd95d33236b97940166310000000000000000000000000000000000000000000000001b83413f0b3640000000000000000000000000000000000000000000000000f7a8daea356aa92bfe000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002337b22536f75726365223a226d6574616d61736b222c22416d6f756e74496e555344223a22343635382e373832393833313733303632222c22416d6f756e744f7574555344223a22343637362e393836303733303034303236222c22526566657272616c223a22222c22466c616773223a302c22416d6f756e744f7574223a2234363631373438303431393032373532373538353934222c2254696d657374616d70223a313732353936353539362c22496e74656772697479496e666f223a7b224b65794944223a2231222c225369676e6174757265223a22546363534e7837537235376b367242794f5a74344b714472344d544637356b7651527658644230724266386e395864513869634a3830385963355155595a34675a52527645337777433237352f59586a722f34625065662b4a58514b4969556b6334356a4e73556c366e6141387141774d5a48324f4a3234657932647253386c52625551444f67784b4d6979334d413164467472575241306f6d6e664873365044624b6d6f4e494c58674b45416e497a6b6d687a675043346e396d39715043337a457459737875457042772b386356426b684e7761684f56625850635854646977334870437356365555635375522f4a495342386d6a737a494b6d664b46595a716333516c5a714e6e507a50576a3648366e73587050512b6145725338334c3544554b5868364e6a70584855764748314d7a557074584169615634737354795849582f435645685a396e76564845746b2f776b6a42673d3d227d7d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000ac001a0e067d3acdb151721e7fdb3834cf2563d667aad9b4c18a5afb81390d6288ac2fe9fa0e74a9e40e017bcd926f3c5da4355e0926ae7e45b3b9e1bc474507220cb43', ], - rawCancelTxs: '', + rawCancelTxs: [], }; const GET_BATCH_STATUS_RESPONSE_PENDING = { From d731f2635fe887648dd58e9350460787df8f3664 Mon Sep 17 00:00:00 2001 From: Derek Brans Date: Thu, 10 Oct 2024 12:43:56 -0400 Subject: [PATCH 5/9] remove unknown urls from privacy snapshot --- privacy-snapshot.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/privacy-snapshot.json b/privacy-snapshot.json index 4f381b0f6237..37a05025382d 100644 --- a/privacy-snapshot.json +++ b/privacy-snapshot.json @@ -19,7 +19,6 @@ "configuration.dev.metamask-institutional.io", "configuration.metamask-institutional.io", "connect.trezor.io", - "crypto.com", "customnetwork.test", "doesntexist.test", "etherscan.io", @@ -62,6 +61,5 @@ "unresponsive-rpc.test", "unresponsive-rpc.url", "user-storage.api.cx.metamask.io", - "verify.walletconnect.com", "www.4byte.directory" ] From 2ae2da2cf3bf9e3ecc262e58ef2dd9be0e12209c Mon Sep 17 00:00:00 2001 From: Derek Brans Date: Fri, 11 Oct 2024 12:59:04 -0400 Subject: [PATCH 6/9] re-add urls to privacy snapshot --- privacy-snapshot.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/privacy-snapshot.json b/privacy-snapshot.json index 37a05025382d..4f381b0f6237 100644 --- a/privacy-snapshot.json +++ b/privacy-snapshot.json @@ -19,6 +19,7 @@ "configuration.dev.metamask-institutional.io", "configuration.metamask-institutional.io", "connect.trezor.io", + "crypto.com", "customnetwork.test", "doesntexist.test", "etherscan.io", @@ -61,5 +62,6 @@ "unresponsive-rpc.test", "unresponsive-rpc.url", "user-storage.api.cx.metamask.io", + "verify.walletconnect.com", "www.4byte.directory" ] From bdd7c1dcc1c6bc8dafa5e8a565e363285242d789 Mon Sep 17 00:00:00 2001 From: Derek Brans Date: Fri, 11 Oct 2024 13:25:26 -0400 Subject: [PATCH 7/9] remove verify.walletconnect from privacy snapshot --- privacy-snapshot.json | 1 - 1 file changed, 1 deletion(-) diff --git a/privacy-snapshot.json b/privacy-snapshot.json index 4f381b0f6237..cee552d7d7fb 100644 --- a/privacy-snapshot.json +++ b/privacy-snapshot.json @@ -62,6 +62,5 @@ "unresponsive-rpc.test", "unresponsive-rpc.url", "user-storage.api.cx.metamask.io", - "verify.walletconnect.com", "www.4byte.directory" ] From aa5321eb0f7b54ebc860ae6c190dc32dbbfab05a Mon Sep 17 00:00:00 2001 From: Derek Brans Date: Fri, 11 Oct 2024 14:16:44 -0400 Subject: [PATCH 8/9] =?UTF-8?q?remove=20crypto.com=20again=20=E2=80=93?= =?UTF-8?q?=C2=A0we'll=20get=20rid=20of=20this=20requirement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- privacy-snapshot.json | 1 - 1 file changed, 1 deletion(-) diff --git a/privacy-snapshot.json b/privacy-snapshot.json index cee552d7d7fb..37a05025382d 100644 --- a/privacy-snapshot.json +++ b/privacy-snapshot.json @@ -19,7 +19,6 @@ "configuration.dev.metamask-institutional.io", "configuration.metamask-institutional.io", "connect.trezor.io", - "crypto.com", "customnetwork.test", "doesntexist.test", "etherscan.io", From b8aa01123ba93b885f28b7198bb167683ed54807 Mon Sep 17 00:00:00 2001 From: Derek Brans Date: Fri, 11 Oct 2024 14:20:52 -0400 Subject: [PATCH 9/9] remove source of crypto.com and verify.walletconnect.com calls --- test/e2e/mock-e2e.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/test/e2e/mock-e2e.js b/test/e2e/mock-e2e.js index d66a92d37f5c..209777f32bd7 100644 --- a/test/e2e/mock-e2e.js +++ b/test/e2e/mock-e2e.js @@ -468,7 +468,7 @@ async function setupMocking( decimals: 18, name: 'Dai Stablecoin', iconUrl: - 'https://crypto.com/price/coin-data/icon/DAI/color_icon.png', + 'https://static.cx.metamask.io/api/v1/tokenIcons/1/0x6b175474e89094c44da98b954eedeac495271d0f.png', type: 'erc20', aggregators: [ 'aave', @@ -495,7 +495,7 @@ async function setupMocking( decimals: 6, name: 'USD Coin', iconUrl: - 'https://crypto.com/price/coin-data/icon/USDC/color_icon.png', + 'https://static.cx.metamask.io/api/v1/tokenIcons/1/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png', type: 'erc20', aggregators: [ 'aave', @@ -712,11 +712,6 @@ async function setupMocking( const portfolioRequestsMatcher = (request) => request.headers.referer === 'https://portfolio.metamask.io/'; - // Passthrough requests to ServerMochaToBackground's WebSocket server - // which is running on port 8111. - // TODO: forAnyWebSocket() is too broad, we should be able to more - // specifically target ServerMochaToBackground's WebSocket server - await server.forAnyWebSocket().thenPassThrough(); /** * Listen for requests and add the hostname to the privacy report if it did * not previously exist. This is used to track which hosts are requested