From bdafa76635aa332d4c0fccddcb9fba71fd36d4b1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 27 Aug 2021 17:03:38 +0000 Subject: [PATCH 01/10] chore(deps): bump cypress from 8.3.0 to 8.3.1 Bumps [cypress](https://github.com/cypress-io/cypress) from 8.3.0 to 8.3.1. - [Release notes](https://github.com/cypress-io/cypress/releases) - [Changelog](https://github.com/cypress-io/cypress/blob/develop/.releaserc.base.js) - [Commits](https://github.com/cypress-io/cypress/compare/v8.3.0...v8.3.1) --- updated-dependencies: - dependency-name: cypress dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 81 ++++++++++++++++++++++++++++++----------------- package.json | 2 +- 2 files changed, 53 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index cdcd02c03..55a2b3a6a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "bytes32": "0.0.3", "commander": "8.1.0", "cross-zip": "4.0.0", - "cypress": "8.3.0", + "cypress": "8.3.1", "cypress-wait-until": "1.7.1", "eslint": "7.32.0", "eslint-config-prettier": "8.3.0", @@ -1363,9 +1363,9 @@ } }, "node_modules/@cypress/request": { - "version": "2.88.5", - "resolved": "https://registry.npmjs.org/@cypress/request/-/request-2.88.5.tgz", - "integrity": "sha512-TzEC1XMi1hJkywWpRfD2clreTa/Z+lOrXDCxxBTBPEcY5azdPi56A6Xw+O4tWJnaJH3iIE7G5aDXZC6JgRZLcA==", + "version": "2.88.6", + "resolved": "https://registry.npmjs.org/@cypress/request/-/request-2.88.6.tgz", + "integrity": "sha512-z0UxBE/+qaESAHY9p9sM2h8Y4XqtsbDCt0/DPOrqA/RZgKi4PkxdpXyK4wCCnSk1xHqWHZZAE+gV6aDAR6+caQ==", "dependencies": { "aws-sign2": "~0.7.0", "aws4": "^1.8.0", @@ -1380,18 +1380,25 @@ "isstream": "~0.1.2", "json-stringify-safe": "~5.0.1", "mime-types": "~2.1.19", - "oauth-sign": "~0.9.0", "performance-now": "^2.1.0", "qs": "~6.5.2", "safe-buffer": "^5.1.2", "tough-cookie": "~2.5.0", "tunnel-agent": "^0.6.0", - "uuid": "^3.3.2" + "uuid": "^8.3.2" }, "engines": { "node": ">= 6" } }, + "node_modules/@cypress/request/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@cypress/webpack-dev-server": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/@cypress/webpack-dev-server/-/webpack-dev-server-1.4.0.tgz", @@ -7682,12 +7689,12 @@ } }, "node_modules/cypress": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-8.3.0.tgz", - "integrity": "sha512-zA5Rcq8AZIfRfPXU0CCcauofF+YpaU9HYbfqkunFTmFV0Kdlo14tNjH2E3++MkjXKFnv3/pXq+HgxWtw8CSe8Q==", + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-8.3.1.tgz", + "integrity": "sha512-1v6pfx+/5cXhaT5T6QKOvnkawmEHWHLiVzm3MYMoQN1fkX2Ma1C32STd3jBStE9qT5qPSTILjGzypVRxCBi40g==", "hasInstallScript": true, "dependencies": { - "@cypress/request": "^2.88.5", + "@cypress/request": "^2.88.6", "@cypress/xvfb": "^1.2.4", "@types/node": "^14.14.31", "@types/sinonjs__fake-timers": "^6.0.2", @@ -23972,9 +23979,9 @@ } }, "@cypress/request": { - "version": "2.88.5", - "resolved": "https://registry.npmjs.org/@cypress/request/-/request-2.88.5.tgz", - "integrity": "sha512-TzEC1XMi1hJkywWpRfD2clreTa/Z+lOrXDCxxBTBPEcY5azdPi56A6Xw+O4tWJnaJH3iIE7G5aDXZC6JgRZLcA==", + "version": "2.88.6", + "resolved": "https://registry.npmjs.org/@cypress/request/-/request-2.88.6.tgz", + "integrity": "sha512-z0UxBE/+qaESAHY9p9sM2h8Y4XqtsbDCt0/DPOrqA/RZgKi4PkxdpXyK4wCCnSk1xHqWHZZAE+gV6aDAR6+caQ==", "requires": { "aws-sign2": "~0.7.0", "aws4": "^1.8.0", @@ -23989,13 +23996,19 @@ "isstream": "~0.1.2", "json-stringify-safe": "~5.0.1", "mime-types": "~2.1.19", - "oauth-sign": "~0.9.0", "performance-now": "^2.1.0", "qs": "~6.5.2", "safe-buffer": "^5.1.2", "tough-cookie": "~2.5.0", "tunnel-agent": "^0.6.0", - "uuid": "^3.3.2" + "uuid": "^8.3.2" + }, + "dependencies": { + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + } } }, "@cypress/webpack-dev-server": { @@ -24881,7 +24894,8 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-1.0.4.tgz", "integrity": "sha512-mLUsMkgP7K/cnFEw07kWqXGF5LKrOkD+lhCrKvPHXWDywAwuDUeDwWBpc69XK3pNX0uKiVt8g5z96PJ6z9xCFA==", - "dev": true + "dev": true, + "requires": {} }, "@octokit/plugin-rest-endpoint-methods": { "version": "5.7.0", @@ -26080,7 +26094,8 @@ "ws": { "version": "7.3.0", "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz", - "integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w==" + "integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w==", + "requires": {} } } }, @@ -26188,7 +26203,8 @@ "acorn-jsx": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", - "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==" + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "requires": {} }, "acorn-node": { "version": "1.8.2", @@ -27557,7 +27573,8 @@ "babelify": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/babelify/-/babelify-10.0.0.tgz", - "integrity": "sha512-X40FaxyH7t3X+JFAKvb1H9wooWKLRCi8pg3m8poqtdZaIng+bjzp9RvKQCvRjF9isHiPkXspbbXT/zwXLtwgwg==" + "integrity": "sha512-X40FaxyH7t3X+JFAKvb1H9wooWKLRCi8pg3m8poqtdZaIng+bjzp9RvKQCvRjF9isHiPkXspbbXT/zwXLtwgwg==", + "requires": {} }, "babylon": { "version": "6.18.0", @@ -29172,11 +29189,11 @@ "integrity": "sha512-FYDTSHb/7KXsWICVsxdmiExPjCfRC4qRFBdVwv7Ax9hMnvMmEjP9RfxTEZ3qPZGmADDn2vAKSo9UcN1jKVYscg==" }, "cypress": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-8.3.0.tgz", - "integrity": "sha512-zA5Rcq8AZIfRfPXU0CCcauofF+YpaU9HYbfqkunFTmFV0Kdlo14tNjH2E3++MkjXKFnv3/pXq+HgxWtw8CSe8Q==", + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-8.3.1.tgz", + "integrity": "sha512-1v6pfx+/5cXhaT5T6QKOvnkawmEHWHLiVzm3MYMoQN1fkX2Ma1C32STd3jBStE9qT5qPSTILjGzypVRxCBi40g==", "requires": { - "@cypress/request": "^2.88.5", + "@cypress/request": "^2.88.6", "@cypress/xvfb": "^1.2.4", "@types/node": "^14.14.31", "@types/sinonjs__fake-timers": "^6.0.2", @@ -29964,12 +29981,14 @@ "eslint-config-prettier": { "version": "8.3.0", "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz", - "integrity": "sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==" + "integrity": "sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==", + "requires": {} }, "eslint-config-standard": { "version": "16.0.3", "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-16.0.3.tgz", - "integrity": "sha512-x4fmJL5hGqNJKGHSjnLdgA6U6h1YW/G2dW9fA+cyVur4SK6lyue8+UgNKWlZtUDTXvgKDD/Oa3GQjmB5kjtVvg==" + "integrity": "sha512-x4fmJL5hGqNJKGHSjnLdgA6U6h1YW/G2dW9fA+cyVur4SK6lyue8+UgNKWlZtUDTXvgKDD/Oa3GQjmB5kjtVvg==", + "requires": {} }, "eslint-import-resolver-node": { "version": "0.3.6", @@ -30012,7 +30031,8 @@ "eslint-plugin-chai-friendly": { "version": "0.7.2", "resolved": "https://registry.npmjs.org/eslint-plugin-chai-friendly/-/eslint-plugin-chai-friendly-0.7.2.tgz", - "integrity": "sha512-LOIfGx5sZZ5FwM1shr2GlYAWV9Omdi+1/3byuVagvQNoGUuU0iHhp7AfjA1uR+4dJ4Isfb4+FwBJgQajIw9iAg==" + "integrity": "sha512-LOIfGx5sZZ5FwM1shr2GlYAWV9Omdi+1/3byuVagvQNoGUuU0iHhp7AfjA1uR+4dJ4Isfb4+FwBJgQajIw9iAg==", + "requires": {} }, "eslint-plugin-cypress": { "version": "2.11.3", @@ -30155,12 +30175,14 @@ "eslint-plugin-promise": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-5.1.0.tgz", - "integrity": "sha512-NGmI6BH5L12pl7ScQHbg7tvtk4wPxxj8yPHH47NvSmMtFneC077PSeY3huFj06ZWZvtbfxSPt3RuOQD5XcR4ng==" + "integrity": "sha512-NGmI6BH5L12pl7ScQHbg7tvtk4wPxxj8yPHH47NvSmMtFneC077PSeY3huFj06ZWZvtbfxSPt3RuOQD5XcR4ng==", + "requires": {} }, "eslint-plugin-standard": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/eslint-plugin-standard/-/eslint-plugin-standard-4.1.0.tgz", - "integrity": "sha512-ZL7+QRixjTR6/528YNGyDotyffm5OQst/sGxKDwGb9Uqs4In5Egi4+jbobhqJoyoCM6/7v/1A5fhQ7ScMtDjaQ==" + "integrity": "sha512-ZL7+QRixjTR6/528YNGyDotyffm5OQst/sGxKDwGb9Uqs4In5Egi4+jbobhqJoyoCM6/7v/1A5fhQ7ScMtDjaQ==", + "requires": {} }, "eslint-plugin-testing-library": { "version": "4.11.0", @@ -41326,7 +41348,8 @@ "ws": { "version": "7.4.6", "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", - "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==" + "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", + "requires": {} }, "xdg-basedir": { "version": "4.0.0", diff --git a/package.json b/package.json index 7c2d12874..1d97b59a7 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "bytes32": "0.0.3", "commander": "8.1.0", "cross-zip": "4.0.0", - "cypress": "8.3.0", + "cypress": "8.3.1", "cypress-wait-until": "1.7.1", "eslint": "7.32.0", "eslint-config-prettier": "8.3.0", From 307ecdf06e765235dddd01130073496053149751 Mon Sep 17 00:00:00 2001 From: Noah Litvin Date: Fri, 3 Sep 2021 09:04:56 -0400 Subject: [PATCH 02/10] Adds support for importing wallets using private keys --- README.md | 6 +-- commands/metamask.js | 65 ++++++++++++++++++++++++++ pages/metamask/first-time-flow-page.js | 12 +++++ pages/metamask/main-page.js | 7 +++ plugins/index.js | 13 ++++-- 5 files changed, 97 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ef18e715c..81f0cc9ff 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ There is a global [`before()`](https://github.com/synthetixio/synpress/blob/mast - changes network (defaults to `kovan`) or creates custom network and changes to it (depending on your setup) - switches back to Cypress window and starts testing -It requires environmental variable called `SECRET_WORDS` to be present in following format => `'word1, word2, etc..'`. +It requires environmental variable called `SECRET_WORDS` to be present in following format => `'word1, word2, etc..'` or a signer's private key in an environmental variable called `PRIVATE_KEY`. To change default network (`kovan`), you can use `NETWORK_NAME` environmental variable, for example: `NETWORK_NAME=rinkeby`. @@ -109,9 +109,9 @@ Metamask version is hardcoded and frequently updated under supervision to avoid If you don't want to use environmental variables, you can modify [`setupMetamask()`](https://github.com/synthetixio/synpress/blob/master/support/index.js#L26) to following: -`setupMetamask(secretWords, network, password)`, for example: `setupMetamask('word1, word2, etc..', 'mainnet', 'password')`. +`setupMetamask(secret, network, password)`, for example: `setupMetamask('word1, word2, etc..', 'mainnet', 'password')`. -You can also add and switch to custom network by passing an `object` instead of `string` inside `setupMetamask(secretWords, network, password)` function for `network` parameter. +You can also add and switch to custom network by passing an `object` instead of `string` inside `setupMetamask(secret, network, password)` function for `network` parameter. If you want to use Etherscan API helpers, you will have to provide Etherscan API key using `ETHERSCAN_KEY` enironmental variable. diff --git a/commands/metamask.js b/commands/metamask.js index da00a31d1..2ef58f436 100644 --- a/commands/metamask.js +++ b/commands/metamask.js @@ -86,6 +86,41 @@ module.exports = { } return true; }, + createWallet: async (password) => { + await puppeteer.waitAndClick(firstTimeFlowPageElements.createWalletButton); + await puppeteer.waitAndClick(metametricsPageElements.optOutAnalyticsButton); + await puppeteer.waitAndType( + firstTimeFlowFormPageElements.newPasswordInput, + password, + ); + await puppeteer.waitAndType( + firstTimeFlowFormPageElements.confirmPasswordInput, + password, + ); + await puppeteer.waitAndClick(firstTimeFlowFormPageElements.newSignupCheckbox); + await puppeteer.waitAndClick(firstTimeFlowFormPageElements.importButton); + + await puppeteer.waitFor(pageElements.loadingSpinner); + await puppeteer.waitAndClick(firstTimeFlowFormPageElements.nextButton); + await puppeteer.waitAndClick(firstTimeFlowFormPageElements.remindMeLaterButton); + await puppeteer.waitFor(mainPageElements.walletOverview); + + // close popup if present + if ( + (await puppeteer.metamaskWindow().$(mainPageElements.popup.container)) !== + null + ) { + await puppeteer.waitAndClick(mainPageElements.popup.closeButton); + } + return true; + }, + importFromPrivateKey: async (privateKey) => { + await puppeteer.waitAndClick(mainPageElements.accountMenu.button); + await puppeteer.waitAndClick(mainPageElements.accountMenu.importAccountButton); + + await puppeteer.waitAndType(mainPageElements.newAccountImport.input, privateKey); + await puppeteer.waitAndClick(mainPageElements.newAccountImport.button); + }, changeNetwork: async network => { setNetwork(network); await puppeteer.waitAndClick(mainPageElements.networkSwitcher.button); @@ -353,4 +388,34 @@ module.exports = { return true; } }, + initialSetupWithPrivateKey: async ({ privateKey, network, password }) => { + const isCustomNetwork = + process.env.NETWORK_NAME && process.env.RPC_URL && process.env.CHAIN_ID; + await puppeteer.init(); + await puppeteer.assignWindows(); + await puppeteer.metamaskWindow().waitForTimeout(1000); + if ( + (await puppeteer.metamaskWindow().$(unlockPageElements.unlockPage)) === + null + ) { + await module.exports.confirmWelcomePage(); + await module.exports.createWallet(password); + if (isCustomNetwork) { + await module.exports.addNetwork(network); + } else { + await module.exports.changeNetwork(network); + } + + await module.exports.importFromPrivateKey(privateKey); + + walletAddress = await module.exports.getWalletAddress(); + await puppeteer.switchToCypressWindow(); + return true; + } else { + await module.exports.unlock(password); + walletAddress = await module.exports.getWalletAddress(); + await puppeteer.switchToCypressWindow(); + return true; + } + }, }; diff --git a/pages/metamask/first-time-flow-page.js b/pages/metamask/first-time-flow-page.js index 30ba36e70..f087b1538 100644 --- a/pages/metamask/first-time-flow-page.js +++ b/pages/metamask/first-time-flow-page.js @@ -7,11 +7,14 @@ module.exports.welcomePageElements = { confirmButton, }; + const firstTimeFlowPage = '.first-time-flow'; const importWalletButton = `${firstTimeFlowPage} .first-time-flow__button`; +const createWalletButton = `${firstTimeFlowPage} .select-action__select-button:nth-child(2) .first-time-flow__button`; module.exports.firstTimeFlowPageElements = { firstTimeFlowPage, importWalletButton, + createWalletButton }; const metametricsPage = '.metametrics-opt-in'; @@ -27,6 +30,11 @@ const passwordInput = `${firstTimeFlowFormPage} #password`; const confirmPasswordInput = `${firstTimeFlowFormPage} #confirm-password`; const termsCheckbox = `${firstTimeFlowFormPage} .first-time-flow__terms`; const importButton = `${firstTimeFlowFormPage} .first-time-flow__button`; +const newPasswordInput = `${firstTimeFlowFormPage} #create-password`; +const newSignupCheckbox = `${firstTimeFlowFormPage} .first-time-flow__checkbox`; +const nextButton = `.seed-phrase-intro button.button.btn-primary`; +const remindMeLaterButton = `.button.btn-secondary.first-time-flow__button`; + module.exports.firstTimeFlowFormPageElements = { firstTimeFlowFormPage, secretWordsInput, @@ -34,6 +42,10 @@ module.exports.firstTimeFlowFormPageElements = { confirmPasswordInput, termsCheckbox, importButton, + newPasswordInput, + newSignupCheckbox, + nextButton, + remindMeLaterButton }; const endOfFlowPage = '.end-of-flow'; diff --git a/pages/metamask/main-page.js b/pages/metamask/main-page.js index 02ff387b6..ffb0690d5 100644 --- a/pages/metamask/main-page.js +++ b/pages/metamask/main-page.js @@ -14,6 +14,7 @@ const popup = { const accountMenu = { button: '.account-menu__icon', settingsButton: '.account-menu__item--clickable:nth-child(11)', + importAccountButton: '.account-menu__item--clickable:nth-child(7)', }; const optionsMenu = { @@ -36,6 +37,11 @@ const accountModal = { closeButton: '.account-modal__close', }; +const newAccountImport = { + input: "#private-key-box", + button: ".btn-secondary.button.new-account-create-form__button" +} + module.exports.mainPageElements = { networkSwitcher, walletOverview, @@ -44,4 +50,5 @@ module.exports.mainPageElements = { optionsMenu, connectedSites, accountModal, + newAccountImport }; diff --git a/plugins/index.js b/plugins/index.js index 135909eb4..316915bd5 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -150,14 +150,21 @@ module.exports = (on, config) => { fetchMetamaskWalletAddress: async () => { return metamask.walletAddress(); }, - setupMetamask: async ({ secretWords, network = 'kovan', password }) => { + setupMetamask: async ({ secret, network = 'kovan', password }) => { if (process.env.NETWORK_NAME) { network = process.env.NETWORK_NAME; } + if (process.env.PRIVATE_KEY) { + secret = process.env.PRIVATE_KEY; + } if (process.env.SECRET_WORDS) { - secretWords = process.env.SECRET_WORDS; + secret = process.env.SECRET_WORDS; + } + if (secret && secret.startsWith("0x")) { + await metamask.initialSetupWithPrivateKey({ privateKey: secret, network, password }); + } else { + await metamask.initialSetup({ secret, network, password }); } - await metamask.initialSetup({ secretWords, network, password }); return true; }, snxExchangerSettle: async ({ asset, walletAddress, privateKey }) => { From 098bd657e132abddb97fda7166782ada41db03e1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Sep 2021 17:04:13 +0000 Subject: [PATCH 03/10] chore(deps): bump github/codeql-action from 1.0.12 to 1.0.13 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 1.0.12 to 1.0.13. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/b0e70410b40f1a9af3bba1cecd95b4b57896af26...89d78ba4572c7854683ec144d212bf0b52cd2a2a) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/audit_and_lint.yml | 2 +- .github/workflows/codeql.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/audit_and_lint.yml b/.github/workflows/audit_and_lint.yml index 42733d8a5..e404ed230 100644 --- a/.github/workflows/audit_and_lint.yml +++ b/.github/workflows/audit_and_lint.yml @@ -68,7 +68,7 @@ jobs: - name: Upload lint results # run if lint failed and only on master/dev branch and pull requests if: always() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || github.event_name == 'pull_request') - uses: github/codeql-action/upload-sarif@b0e70410b40f1a9af3bba1cecd95b4b57896af26 # pin@codeql-bundle-20210517 + uses: github/codeql-action/upload-sarif@89d78ba4572c7854683ec144d212bf0b52cd2a2a # pin@codeql-bundle-20210517 with: sarif_file: lint-results.sarif continue-on-error: true diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 00936958e..44c0ac79a 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -17,10 +17,10 @@ jobs: uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # pin@v2 - name: Initialize CodeQL - uses: github/codeql-action/init@b0e70410b40f1a9af3bba1cecd95b4b57896af26 + uses: github/codeql-action/init@89d78ba4572c7854683ec144d212bf0b52cd2a2a with: queries: security-and-quality languages: javascript - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@b0e70410b40f1a9af3bba1cecd95b4b57896af26 + uses: github/codeql-action/analyze@89d78ba4572c7854683ec144d212bf0b52cd2a2a From a53036403c1d7459f495611d778fc82a04ac9014 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Wed, 8 Sep 2021 23:08:12 +0200 Subject: [PATCH 04/10] chore: fix linting Signed-off-by: Jakub Mucha --- commands/metamask.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/commands/metamask.js b/commands/metamask.js index 2ef58f436..8a3fa355d 100644 --- a/commands/metamask.js +++ b/commands/metamask.js @@ -86,7 +86,7 @@ module.exports = { } return true; }, - createWallet: async (password) => { + createWallet: async password => { await puppeteer.waitAndClick(firstTimeFlowPageElements.createWalletButton); await puppeteer.waitAndClick(metametricsPageElements.optOutAnalyticsButton); await puppeteer.waitAndType( @@ -97,12 +97,16 @@ module.exports = { firstTimeFlowFormPageElements.confirmPasswordInput, password, ); - await puppeteer.waitAndClick(firstTimeFlowFormPageElements.newSignupCheckbox); + await puppeteer.waitAndClick( + firstTimeFlowFormPageElements.newSignupCheckbox, + ); await puppeteer.waitAndClick(firstTimeFlowFormPageElements.importButton); await puppeteer.waitFor(pageElements.loadingSpinner); await puppeteer.waitAndClick(firstTimeFlowFormPageElements.nextButton); - await puppeteer.waitAndClick(firstTimeFlowFormPageElements.remindMeLaterButton); + await puppeteer.waitAndClick( + firstTimeFlowFormPageElements.remindMeLaterButton, + ); await puppeteer.waitFor(mainPageElements.walletOverview); // close popup if present @@ -114,11 +118,16 @@ module.exports = { } return true; }, - importFromPrivateKey: async (privateKey) => { + importFromPrivateKey: async privateKey => { await puppeteer.waitAndClick(mainPageElements.accountMenu.button); - await puppeteer.waitAndClick(mainPageElements.accountMenu.importAccountButton); + await puppeteer.waitAndClick( + mainPageElements.accountMenu.importAccountButton, + ); - await puppeteer.waitAndType(mainPageElements.newAccountImport.input, privateKey); + await puppeteer.waitAndType( + mainPageElements.newAccountImport.input, + privateKey, + ); await puppeteer.waitAndClick(mainPageElements.newAccountImport.button); }, changeNetwork: async network => { From 9c784c1dcae4a04a94a4678de1d0490ef13d528f Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Wed, 8 Sep 2021 23:08:33 +0200 Subject: [PATCH 05/10] po: refactor first time flow Signed-off-by: Jakub Mucha --- pages/metamask/first-time-flow-page.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pages/metamask/first-time-flow-page.js b/pages/metamask/first-time-flow-page.js index f087b1538..5b73391bd 100644 --- a/pages/metamask/first-time-flow-page.js +++ b/pages/metamask/first-time-flow-page.js @@ -7,14 +7,13 @@ module.exports.welcomePageElements = { confirmButton, }; - const firstTimeFlowPage = '.first-time-flow'; -const importWalletButton = `${firstTimeFlowPage} .first-time-flow__button`; +const importWalletButton = `${firstTimeFlowPage} .select-action__select-button:nth-child(1) .first-time-flow__button`; const createWalletButton = `${firstTimeFlowPage} .select-action__select-button:nth-child(2) .first-time-flow__button`; module.exports.firstTimeFlowPageElements = { firstTimeFlowPage, importWalletButton, - createWalletButton + createWalletButton, }; const metametricsPage = '.metametrics-opt-in'; @@ -32,8 +31,6 @@ const termsCheckbox = `${firstTimeFlowFormPage} .first-time-flow__terms`; const importButton = `${firstTimeFlowFormPage} .first-time-flow__button`; const newPasswordInput = `${firstTimeFlowFormPage} #create-password`; const newSignupCheckbox = `${firstTimeFlowFormPage} .first-time-flow__checkbox`; -const nextButton = `.seed-phrase-intro button.button.btn-primary`; -const remindMeLaterButton = `.button.btn-secondary.first-time-flow__button`; module.exports.firstTimeFlowFormPageElements = { firstTimeFlowFormPage, @@ -44,8 +41,13 @@ module.exports.firstTimeFlowFormPageElements = { importButton, newPasswordInput, newSignupCheckbox, +}; + +const secureYourWalletPage = '.first-time-flow__wrapper'; +const nextButton = `${secureYourWalletPage} button`; +module.exports.secureYourWalletPageElements = { + secureYourWalletPage, nextButton, - remindMeLaterButton }; const endOfFlowPage = '.end-of-flow'; From ba49b115a812b86d4dff198f1c1785cb7d57bcd9 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Wed, 8 Sep 2021 23:08:50 +0200 Subject: [PATCH 06/10] po: refactor main page Signed-off-by: Jakub Mucha --- pages/metamask/main-page.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pages/metamask/main-page.js b/pages/metamask/main-page.js index ffb0690d5..50bf31170 100644 --- a/pages/metamask/main-page.js +++ b/pages/metamask/main-page.js @@ -37,10 +37,13 @@ const accountModal = { closeButton: '.account-modal__close', }; -const newAccountImport = { - input: "#private-key-box", - button: ".btn-secondary.button.new-account-create-form__button" -} +const importAccountSelector = '.new-account'; +const importAccount = { + page: importAccountSelector, + input: `${importAccountSelector} #private-key-box`, + cancelButton: `${importAccountSelector} .btn-default`, + importButton: `${importAccountSelector} .btn-secondary`, +}; module.exports.mainPageElements = { networkSwitcher, @@ -50,5 +53,5 @@ module.exports.mainPageElements = { optionsMenu, connectedSites, accountModal, - newAccountImport + importAccount, }; From b1b231ef54b61cff50714f56756e342a01fafc68 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Wed, 8 Sep 2021 23:09:08 +0200 Subject: [PATCH 07/10] chore: adjust to recent po changes Signed-off-by: Jakub Mucha --- commands/metamask.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/commands/metamask.js b/commands/metamask.js index 8a3fa355d..4dde699a1 100644 --- a/commands/metamask.js +++ b/commands/metamask.js @@ -6,6 +6,8 @@ const { firstTimeFlowPageElements, metametricsPageElements, firstTimeFlowFormPageElements, + secureYourWalletPageElements, + revealSeedPageElements, endOfFlowPageElements, } = require('../pages/metamask/first-time-flow-page'); const { mainPageElements } = require('../pages/metamask/main-page'); @@ -103,10 +105,8 @@ module.exports = { await puppeteer.waitAndClick(firstTimeFlowFormPageElements.importButton); await puppeteer.waitFor(pageElements.loadingSpinner); - await puppeteer.waitAndClick(firstTimeFlowFormPageElements.nextButton); - await puppeteer.waitAndClick( - firstTimeFlowFormPageElements.remindMeLaterButton, - ); + await puppeteer.waitAndClick(secureYourWalletPageElements.nextButton); + await puppeteer.waitAndClick(revealSeedPageElements.remindLaterButton); await puppeteer.waitFor(mainPageElements.walletOverview); // close popup if present @@ -125,10 +125,11 @@ module.exports = { ); await puppeteer.waitAndType( - mainPageElements.newAccountImport.input, + mainPageElements.importAccount.input, privateKey, ); - await puppeteer.waitAndClick(mainPageElements.newAccountImport.button); + await puppeteer.waitAndClick(mainPageElements.importAccount.importButton); + return true; }, changeNetwork: async network => { setNetwork(network); From 2e39a5098a760288105c4b4b9418923bc47d5153 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Wed, 8 Sep 2021 23:09:45 +0200 Subject: [PATCH 08/10] minor: merge initialSetupWithPK with initialSetup Signed-off-by: Jakub Mucha --- commands/metamask.js | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/commands/metamask.js b/commands/metamask.js index 4dde699a1..d780afd01 100644 --- a/commands/metamask.js +++ b/commands/metamask.js @@ -370,7 +370,7 @@ module.exports = { await puppeteer.waitAndClick(mainPageElements.accountModal.closeButton); return walletAddress; }, - initialSetup: async ({ secretWords, network, password }) => { + initialSetup: async ({ secretWordsOrPrivateKey, network, password }) => { const isCustomNetwork = process.env.NETWORK_NAME && process.env.RPC_URL && process.env.CHAIN_ID; @@ -382,42 +382,17 @@ module.exports = { null ) { await module.exports.confirmWelcomePage(); - await module.exports.importWallet(secretWords, password); - if (isCustomNetwork) { - await module.exports.addNetwork(network); + if (secretWordsOrPrivateKey.includes(' ')) { + await module.exports.importWallet(secretWordsOrPrivateKey, password); } else { - await module.exports.changeNetwork(network); + await module.exports.createWallet(password); + await module.exports.importFromPrivateKey(secretWordsOrPrivateKey); } - walletAddress = await module.exports.getWalletAddress(); - await puppeteer.switchToCypressWindow(); - return true; - } else { - await module.exports.unlock(password); - walletAddress = await module.exports.getWalletAddress(); - await puppeteer.switchToCypressWindow(); - return true; - } - }, - initialSetupWithPrivateKey: async ({ privateKey, network, password }) => { - const isCustomNetwork = - process.env.NETWORK_NAME && process.env.RPC_URL && process.env.CHAIN_ID; - await puppeteer.init(); - await puppeteer.assignWindows(); - await puppeteer.metamaskWindow().waitForTimeout(1000); - if ( - (await puppeteer.metamaskWindow().$(unlockPageElements.unlockPage)) === - null - ) { - await module.exports.confirmWelcomePage(); - await module.exports.createWallet(password); if (isCustomNetwork) { await module.exports.addNetwork(network); } else { await module.exports.changeNetwork(network); } - - await module.exports.importFromPrivateKey(privateKey); - walletAddress = await module.exports.getWalletAddress(); await puppeteer.switchToCypressWindow(); return true; From 46c5e520f8fdb49d9afc07e665f2c622f916dfd7 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Wed, 8 Sep 2021 23:10:24 +0200 Subject: [PATCH 09/10] refactor: setupMetamask with new changes Signed-off-by: Jakub Mucha --- plugins/index.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/plugins/index.js b/plugins/index.js index 316915bd5..df477de9e 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -150,21 +150,25 @@ module.exports = (on, config) => { fetchMetamaskWalletAddress: async () => { return metamask.walletAddress(); }, - setupMetamask: async ({ secret, network = 'kovan', password }) => { + setupMetamask: async ({ + secretWordsOrPrivateKey, + network = 'kovan', + password, + }) => { if (process.env.NETWORK_NAME) { network = process.env.NETWORK_NAME; } if (process.env.PRIVATE_KEY) { - secret = process.env.PRIVATE_KEY; + secretWordsOrPrivateKey = process.env.PRIVATE_KEY; } if (process.env.SECRET_WORDS) { - secret = process.env.SECRET_WORDS; - } - if (secret && secret.startsWith("0x")) { - await metamask.initialSetupWithPrivateKey({ privateKey: secret, network, password }); - } else { - await metamask.initialSetup({ secret, network, password }); + secretWordsOrPrivateKey = process.env.SECRET_WORDS; } + await metamask.initialSetup({ + secretWordsOrPrivateKey, + network, + password, + }); return true; }, snxExchangerSettle: async ({ asset, walletAddress, privateKey }) => { From 2d3f74732135e213646bcaeb3daaa7c414bce9ee Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Wed, 8 Sep 2021 23:10:38 +0200 Subject: [PATCH 10/10] chore: readme update Signed-off-by: Jakub Mucha --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 81f0cc9ff..a34779548 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ There is a global [`before()`](https://github.com/synthetixio/synpress/blob/mast - changes network (defaults to `kovan`) or creates custom network and changes to it (depending on your setup) - switches back to Cypress window and starts testing -It requires environmental variable called `SECRET_WORDS` to be present in following format => `'word1, word2, etc..'` or a signer's private key in an environmental variable called `PRIVATE_KEY`. +It requires environmental variable called `SECRET_WORDS` to be present in following format => `'word1, word2, etc..'` or private key in an environmental variable called `PRIVATE_KEY`. To change default network (`kovan`), you can use `NETWORK_NAME` environmental variable, for example: `NETWORK_NAME=rinkeby`. @@ -109,9 +109,9 @@ Metamask version is hardcoded and frequently updated under supervision to avoid If you don't want to use environmental variables, you can modify [`setupMetamask()`](https://github.com/synthetixio/synpress/blob/master/support/index.js#L26) to following: -`setupMetamask(secret, network, password)`, for example: `setupMetamask('word1, word2, etc..', 'mainnet', 'password')`. +`setupMetamask(secretWordsOrPrivateKey, network, password)`, for example: `setupMetamask('word1, word2, etc..', 'mainnet', 'password')`. -You can also add and switch to custom network by passing an `object` instead of `string` inside `setupMetamask(secret, network, password)` function for `network` parameter. +You can also add and switch to custom network by passing an `object` instead of `string` inside `setupMetamask(secretWordsOrPrivateKey, network, password)` function for `network` parameter. If you want to use Etherscan API helpers, you will have to provide Etherscan API key using `ETHERSCAN_KEY` enironmental variable.