Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wallet Intereaction for Disconnecting al the DAPs #5

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions commands/keplr.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ const keplr = {
return true;
},

async disconnectWallet() {
await playwright.clickByText(
'Disconnect All',
playwright.keplrPermissionWindow(),
);
return true;
},

async initialSetup(
playwrightInstance,
{ secretWordsOrPrivateKey, password, newAccount },
Expand Down
19 changes: 18 additions & 1 deletion commands/playwright-keplr.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let mainWindow;
let keplrWindow;
let keplrNotificationWindow;
let keplrRegistrationWindow;
let keplrPermissionWindow;
let activeTabName;
let extensionsData = {};
let retries = 0;
Expand All @@ -21,6 +22,7 @@ module.exports = {
activeTabName = undefined;
keplrNotificationWindow = undefined;
keplrRegistrationWindow = undefined;
keplrPermissionWindow = undefined;
retries = 0;
extensionsData = {};
},
Expand All @@ -29,7 +31,7 @@ module.exports = {
const chromium = playwrightInstance
? playwrightInstance
: require('@playwright/test').chromium;
const debuggerDetails = await fetch('http://127.0.0.1:9222/json/version'); //DevSkim: ignore DS137138
const debuggerDetails = await fetch('http://127.0.0.1:9222/json/version');
const debuggerDetailsConfig = await debuggerDetails.json();
const webSocketDebuggerUrl = debuggerDetailsConfig.webSocketDebuggerUrl;
if (process.env.SLOW_MODE) {
Expand Down Expand Up @@ -362,6 +364,20 @@ module.exports = {
return extensionsData;
},

keplrPermissionWindow() {
return keplrPermissionWindow;
},

async switchToKeplrPermissionWindow() {
const keplrExtensionData = (await module.exports.getExtensionsData()).keplr;
const browserContext = await browser.contexts()[0];
keplrPermissionWindow = await browserContext.newPage();
await keplrPermissionWindow.goto(
`chrome-extension://${keplrExtensionData.id}/popup.html#/setting/security/permission`,
);
return true;
},

async switchToKeplrRegistrationWindow() {
const keplrExtensionData = (await module.exports.getExtensionsData()).keplr;
const browserContext = await browser.contexts()[0];
Expand All @@ -371,6 +387,7 @@ module.exports = {
);
return true;
},

async switchToKeplrNotification() {
const keplrExtensionData = (await module.exports.getExtensionsData()).keplr;

Expand Down
2 changes: 2 additions & 0 deletions plugins/keplr-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ module.exports = (on, config) => {
isCypressWindowActive: playwright.isCypressWindowActive,
switchToExtensionWindow: playwright.switchToKeplrWindow,
switchToExtensionRegistrationWindow: playwright.switchToKeplrRegistrationWindow,
switchToExtensionPermissionWindow: playwright.switchToKeplrPermissionWindow,

// keplr commands
importWallet: keplr.importWallet,
acceptAccess: keplr.acceptAccess,
confirmTransaction: keplr.confirmTransaction,
disconnectWallet: keplr.disconnectWallet,
setupWallet: async ({
secretWordsOrPrivateKey,
password,
Expand Down
8 changes: 8 additions & 0 deletions support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,14 @@ Cypress.Commands.add('switchToExtensionRegistrationWindow', () => {
return cy.task('switchToExtensionRegistrationWindow');
});

Cypress.Commands.add('switchToExtensionPermissionWindow', () => {
return cy.task('switchToExtensionPermissionWindow');
});

Cypress.Commands.add('disconnectWallet', () => {
return cy.task('disconnectWallet');
});

Cypress.Commands.add('makeOfferAndConfirmTransaction', () => {
cy.contains('agoric1p2aqakv3ulz4qfy2nut86j9gx0dx0yw09h96md');
cy.contains('Make an Offer').click();
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/specs/keplr/keplr-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ describe('Keplr', () => {
});
});

it(`should disconnect the wallet from all the connected DAPPs`, () => {
cy.switchToExtensionPermissionWindow().then(() => {
cy.disconnectWallet().then(taskCompleted => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to disconnectWalletFromDapp to be similar to metamask functions

expect(taskCompleted).to.be.true;
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is there anything more we can do to fully verify that the Dapp has disconnected?

});

it(`should complete Keplr setup by importing the wallet using private key`, () => {
cy.switchToExtensionRegistrationWindow().then(() => {
cy.setupWallet(
Expand Down
Loading