From fa21859426a3759d2cadee5d04d8c1ebf0f797cb Mon Sep 17 00:00:00 2001 From: Rabi Siddique <60459172+rabi-siddique@users.noreply.github.com> Date: Tue, 5 Mar 2024 22:16:56 +0500 Subject: [PATCH] Getting Wallet Address (#17) * feat: initial working setup for retrieving wallet address * chore:code cleanup * feat: interaction to switch wallet * chore: simplifying switching screens in import wallet flow * chore format code with prettier * chore: moving get wallet address test case in the main context * chore: fixes for await async * chore: address PR comments --------- Co-authored-by: Fraz Arshad --- commands/keplr.js | 34 +++++++++++-- commands/playwright-keplr.js | 3 ++ package.json | 2 +- pages/keplr/notification-page.js | 4 ++ plugins/keplr-plugin.js | 1 + pnpm-lock.yaml | 76 +++++++++++++++++++++++++++++ support/commands.js | 5 ++ tests/e2e/specs/keplr/keplr-spec.js | 7 +++ 8 files changed, 126 insertions(+), 6 deletions(-) diff --git a/commands/keplr.js b/commands/keplr.js index 7ebbd9474..612024e07 100644 --- a/commands/keplr.js +++ b/commands/keplr.js @@ -4,13 +4,17 @@ const { onboardingElements } = require('../pages/keplr/first-time-flow-page'); const { notificationPageElements, } = require('../pages/keplr/notification-page'); +const clipboardy = require('clipboardy'); + let extensionId; let extensionVersion; let registrationUrl; let permissionsUrl; +let popupUrl; let walletsPageUrl; let switchBackToCypressWindow; +let walletAddress; const keplr = { async resetState() { @@ -19,8 +23,14 @@ const keplr = { extensionVersion = undefined; registrationUrl = undefined; permissionsUrl = undefined; + popupUrl = undefined; + walletAddress = undefined; walletsPageUrl = undefined; }, + walletAddress: () => { + return walletAddress; + + }, extensionId: () => { return extensionId; }, @@ -28,6 +38,7 @@ const keplr = { return { registrationUrl, permissionsUrl, + popupUrl, }; }, async goTo(url) { @@ -43,6 +54,9 @@ const keplr = { async goToPermissions() { await module.exports.goTo(permissionsUrl); }, + async goToHome() { + await module.exports.goTo(popupUrl); + }, async goToWalletsPage() { await module.exports.goTo(walletsPageUrl); }, @@ -60,6 +74,7 @@ const keplr = { extensionVersion = keplrExtensionData.version; registrationUrl = `chrome-extension://${extensionId}/register.html`; permissionsUrl = `chrome-extension://${extensionId}/popup.html#/setting/security/permission`; + popupUrl = `chrome-extension://${extensionId}/popup.html`; walletsPageUrl = `chrome-extension://${extensionId}/popup.html#/wallet/select`; return { @@ -67,6 +82,7 @@ const keplr = { extensionVersion, registrationUrl, permissionsUrl, + popupUrl, walletsPageUrl, }; }, @@ -153,7 +169,6 @@ const keplr = { await playwright.keplrWindow(), ); - await playwright.switchToCypressWindow(); return true; }, async importWalletWithPhrase(secretWords) { @@ -224,6 +239,17 @@ const keplr = { return true; }, + async getWalletAddress() { + await playwright.switchToKeplrWindow(); + await module.exports.goToHome(); + const page = playwright.keplrWindow(); + await playwright.waitAndClickByText(notificationPageElements.copyAddress); + await page.click(notificationPageElements.copyWalletAddressSelector); + walletAddress = clipboardy.readSync(); + await playwright.switchToCypressWindow(); + return walletAddress; + }, + async initialSetup( playwrightInstance, { secretWordsOrPrivateKey, password, newAccount, walletName }, @@ -235,10 +261,7 @@ const keplr = { } await playwright.assignWindows(); - if (!playwright.isKeplrWindowActive()) { - await playwright.switchToKeplrWindow(); - } - playwright.assignActiveTabName('keplr'); + await playwright.switchToKeplrWindow(); await module.exports.getExtensionDetails(); await module.exports.importWallet( secretWordsOrPrivateKey, @@ -246,6 +269,7 @@ const keplr = { newAccount, walletName, ); + await playwright.switchToCypressWindow(); }, async switchWallet({ walletName }) { diff --git a/commands/playwright-keplr.js b/commands/playwright-keplr.js index d5ff94d84..385ab7f55 100644 --- a/commands/playwright-keplr.js +++ b/commands/playwright-keplr.js @@ -44,6 +44,9 @@ module.exports = { isCypressWindowActive() { return activeTabName === 'cypress'; }, + activeTabName() { + return activeTabName; + }, async switchToKeplrWindow() { await keplrWindow.bringToFront(); module.exports.assignActiveTabName('keplr'); diff --git a/package.json b/package.json index 4d39cd6f3..886a46ea2 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "test:e2e:ci:cypress-action": "CYPRESS_USE_ANVIL=true pnpm synpress:run", "synpress:run:keplr": "EXTENSION=keplr SKIP_EXTENSION_SETUP=true SYNPRESS_LOCAL_TEST=true node synpress.js run --configFile=synpress.config.js", "test:e2e:keplr": "start-server-and-test 'pnpm start:ui' http-get://localhost:3000 'pnpm start:json-server' http-get://localhost:3004 'pnpm synpress:run:keplr'" - }, "dependencies": { "@cypress/code-coverage": "^3.11.0", @@ -73,6 +72,7 @@ "babel-plugin-transform-react-qa-classes": "^1.6.0", "babel-plugin-transform-react-styled-components-qa": "^2.1.0", "bytes32": "^0.0.3", + "clipboardy": "^2.3.0", "commander": "^11.0.0", "cypress": "12.17.3", "cypress-wait-until": "^2.0.1", diff --git a/pages/keplr/notification-page.js b/pages/keplr/notification-page.js index e5e59a883..e04726c24 100644 --- a/pages/keplr/notification-page.js +++ b/pages/keplr/notification-page.js @@ -1,5 +1,9 @@ const approveButton = `button`; +const copyAddress = 'Copy Address'; +const copyWalletAddressSelector = 'div.sc-dkzDqf div.sc-hKMtZM.sc-kDDrLX.cyoEAq.dkJSBQ' module.exports.notificationPageElements = { approveButton, + copyAddress, + copyWalletAddressSelector }; \ No newline at end of file diff --git a/plugins/keplr-plugin.js b/plugins/keplr-plugin.js index ae647e325..7da74b18b 100644 --- a/plugins/keplr-plugin.js +++ b/plugins/keplr-plugin.js @@ -68,6 +68,7 @@ module.exports = (on, config) => { importWallet: keplr.importWallet, acceptAccess: keplr.acceptAccess, rejectAccess: keplr.rejectAccess, + getWalletAddress: keplr.getWalletAddress, confirmTransaction: keplr.confirmTransaction, rejectTransaction: keplr.rejectTransaction, disconnectWalletFromDapp: keplr.disconnectWalletFromDapp, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index caa748429..e6c097911 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -68,6 +68,9 @@ importers: bytes32: specifier: ^0.0.3 version: 0.0.3 + clipboardy: + specifier: ^2.3.0 + version: 2.3.0 commander: specifier: ^11.0.0 version: 11.1.0 @@ -6322,6 +6325,15 @@ packages: engines: {node: '>= 12'} dev: true + /clipboardy@2.3.0: + resolution: {integrity: sha512-mKhiIL2DrQIsuXMgBgnfEHOZOryC7kY7YO//TN6c63wlEm3NG5tz+YgY5rVi29KCmq/QQjKYvM7a19+MDOTHOQ==} + engines: {node: '>=8'} + dependencies: + arch: 2.2.0 + execa: 1.0.0 + is-wsl: 2.2.0 + dev: false + /clipboardy@3.0.0: resolution: {integrity: sha512-Su+uU5sr1jkUy1sGRpLKjKrvEOVXgSgiSInwa/qeID6aJ07yh+5NWc3h2QfjHjBnfX4LhtFcuAWKUsJ3r+fjbg==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -6656,6 +6668,17 @@ packages: - encoding dev: true + /cross-spawn@6.0.5: + resolution: {integrity: sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==} + engines: {node: '>=4.8'} + dependencies: + nice-try: 1.0.5 + path-key: 2.0.1 + semver: 5.7.2 + shebang-command: 1.2.0 + which: 1.3.1 + dev: false + /cross-spawn@7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} @@ -8074,6 +8097,19 @@ packages: engines: {node: '>=0.8.x'} dev: false + /execa@1.0.0: + resolution: {integrity: sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==} + engines: {node: '>=6'} + dependencies: + cross-spawn: 6.0.5 + get-stream: 4.1.0 + is-stream: 1.1.0 + npm-run-path: 2.0.2 + p-finally: 1.0.0 + signal-exit: 3.0.7 + strip-eof: 1.0.0 + dev: false + /execa@4.1.0: resolution: {integrity: sha512-j5W0//W7f8UxAn8hXVnwG8tLwdiUy4FJLcSupCg6maBYZDpyBvTApK7KyuI4bKj8KOh1r2YH+6ucuYtJv1bTZA==} engines: {node: '>=10'} @@ -11030,6 +11066,10 @@ packages: type-fest: 2.19.0 dev: true + /nice-try@1.0.5: + resolution: {integrity: sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==} + dev: false + /no-case@3.0.4: resolution: {integrity: sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==} dependencies: @@ -11280,6 +11320,13 @@ packages: - supports-color dev: true + /npm-run-path@2.0.2: + resolution: {integrity: sha512-lJxZYlT4DW/bRUtFh1MQIWqmLwQfAxnqWG4HhEdjMlkrJYnJn0Jrr2u3mgxqaWsdiBc76TYkTG/mhrnYTuzfHw==} + engines: {node: '>=4'} + dependencies: + path-key: 2.0.1 + dev: false + /npm-run-path@4.0.1: resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} engines: {node: '>=8'} @@ -11819,6 +11866,11 @@ packages: resolution: {integrity: sha512-DUWJr3+ULp4zXmol/SZkFf3JGsS9/SIv+Y3Rt93/UjPpDpklB5f1er4O3POIbUuUJ3FXgqte2Q7SrU6zAqwk8w==} dev: true + /path-key@2.0.1: + resolution: {integrity: sha512-fEHGKCSmUSDPv4uoj8AlD+joPlq3peND+HRYyxFz4KPw4z926S/b8rIuFs2FYJg3BwsxJf6A9/3eIdLaYC+9Dw==} + engines: {node: '>=4'} + dev: false + /path-key@3.1.1: resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} engines: {node: '>=8'} @@ -13071,12 +13123,24 @@ packages: kind-of: 6.0.3 dev: false + /shebang-command@1.2.0: + resolution: {integrity: sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg==} + engines: {node: '>=0.10.0'} + dependencies: + shebang-regex: 1.0.0 + dev: false + /shebang-command@2.0.0: resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} engines: {node: '>=8'} dependencies: shebang-regex: 3.0.0 + /shebang-regex@1.0.0: + resolution: {integrity: sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ==} + engines: {node: '>=0.10.0'} + dev: false + /shebang-regex@3.0.0: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} @@ -13591,6 +13655,11 @@ packages: is-natural-number: 4.0.1 dev: false + /strip-eof@1.0.0: + resolution: {integrity: sha512-7FCwGGmx8mD5xQd3RPUvnSpUXHM3BWuzjtpD4TXsfcZ9EL4azvVVUscFYwD9nx8Kh+uCBC00XBtAykoMHwTh8Q==} + engines: {node: '>=0.10.0'} + dev: false + /strip-final-newline@2.0.0: resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==} engines: {node: '>=6'} @@ -14844,6 +14913,13 @@ packages: gopd: 1.0.1 has-tostringtag: 1.0.2 + /which@1.3.1: + resolution: {integrity: sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==} + hasBin: true + dependencies: + isexe: 2.0.0 + dev: false + /which@2.0.2: resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} engines: {node: '>= 8'} diff --git a/support/commands.js b/support/commands.js index af6c9494d..19c296bdd 100644 --- a/support/commands.js +++ b/support/commands.js @@ -455,6 +455,11 @@ Cypress.Commands.add('disconnectWalletFromDapp', () => { return cy.task('disconnectWalletFromDapp'); }); +Cypress.Commands.add('getWalletAddress', () => { + cy.task('getWalletAddress').then(address => { + return address; + }); +}); Cypress.Commands.add('switchWallet', walletName => { return cy.task('switchWallet', { walletName }); }); diff --git a/tests/e2e/specs/keplr/keplr-spec.js b/tests/e2e/specs/keplr/keplr-spec.js index ddab9eeb2..81a6af071 100644 --- a/tests/e2e/specs/keplr/keplr-spec.js +++ b/tests/e2e/specs/keplr/keplr-spec.js @@ -1,4 +1,5 @@ /* eslint-disable ui-testing/no-disabled-tests */ + describe('Keplr', () => { context('Test commands', () => { it(`should complete Keplr setup by importing an existing wallet using 24 word phrase`, () => { @@ -85,5 +86,11 @@ describe('Keplr', () => { expect(taskCompleted).to.be.true; }); }); + + it(`should get wallet address`, () => { + cy.getWalletAddress().then(walletAddress => { + expect(walletAddress.length).to.be.equal(45); + }); + }); }); });