Skip to content

Commit

Permalink
Getting Wallet Address (#17)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
rabi-siddique and frazarshad authored Mar 5, 2024
1 parent d333345 commit fa21859
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 6 deletions.
34 changes: 29 additions & 5 deletions commands/keplr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -19,15 +23,22 @@ const keplr = {
extensionVersion = undefined;
registrationUrl = undefined;
permissionsUrl = undefined;
popupUrl = undefined;
walletAddress = undefined;
walletsPageUrl = undefined;
},
walletAddress: () => {
return walletAddress;

},
extensionId: () => {
return extensionId;
},
extensionUrls: () => {
return {
registrationUrl,
permissionsUrl,
popupUrl,
};
},
async goTo(url) {
Expand All @@ -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);
},
Expand All @@ -60,13 +74,15 @@ 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 {
extensionId,
extensionVersion,
registrationUrl,
permissionsUrl,
popupUrl,
walletsPageUrl,
};
},
Expand Down Expand Up @@ -153,7 +169,6 @@ const keplr = {
await playwright.keplrWindow(),
);

await playwright.switchToCypressWindow();
return true;
},
async importWalletWithPhrase(secretWords) {
Expand Down Expand Up @@ -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 },
Expand All @@ -235,17 +261,15 @@ 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,
password,
newAccount,
walletName,
);
await playwright.switchToCypressWindow();
},

async switchWallet({ walletName }) {
Expand Down
3 changes: 3 additions & 0 deletions commands/playwright-keplr.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ module.exports = {
isCypressWindowActive() {
return activeTabName === 'cypress';
},
activeTabName() {
return activeTabName;
},
async switchToKeplrWindow() {
await keplrWindow.bringToFront();
module.exports.assignActiveTabName('keplr');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions pages/keplr/notification-page.js
Original file line number Diff line number Diff line change
@@ -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
};
1 change: 1 addition & 0 deletions plugins/keplr-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
76 changes: 76 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
7 changes: 7 additions & 0 deletions tests/e2e/specs/keplr/keplr-spec.js
Original file line number Diff line number Diff line change
@@ -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`, () => {
Expand Down Expand Up @@ -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);
});
});
});
});

0 comments on commit fa21859

Please sign in to comment.