Skip to content

Commit

Permalink
Added Interaction to handle rejection of wallet connection (#8)
Browse files Browse the repository at this point in the history
* feat: added code to handle reject wallet access

* feat: added test case for reject wallet access + modified test structure
  • Loading branch information
frazarshad authored Mar 4, 2024
1 parent afdc0a4 commit dbc5fe0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 24 deletions.
8 changes: 7 additions & 1 deletion commands/keplr.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const keplr = {
async disconnectWalletFromDapp() {
await playwright.waitAndClickByText(
'Disconnect All',
playwright.keplrPermissionWindow()
playwright.keplrPermissionWindow(),
);
return true;
},
Expand Down Expand Up @@ -166,6 +166,12 @@ const keplr = {
return true;
},

async rejectAccess() {
const notificationPage = await playwright.switchToKeplrNotification();
await notificationPage.close();
return true;
},

async confirmTransaction() {
const notificationPage = await playwright.switchToKeplrNotification();
await playwright.waitAndClick(
Expand Down
17 changes: 8 additions & 9 deletions plugins/keplr-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module.exports = (on, config) => {
if (!process.env.SKIP_KEPLR_INSTALL) {
// NOTE: extensions cannot be loaded in headless Chrome
const keplrPath = await helpers.prepareExtension(
process.env.KEPLR_VERSION || '0.12.68', process.env.EXTENSION
process.env.KEPLR_VERSION || '0.12.68',
process.env.EXTENSION,
);
arguments_.extensions.push(keplrPath);
}
Expand All @@ -59,27 +60,25 @@ module.exports = (on, config) => {
clearWindows: playwright.clearWindows,
isCypressWindowActive: playwright.isCypressWindowActive,
switchToExtensionWindow: playwright.switchToKeplrWindow,
switchToExtensionRegistrationWindow: playwright.switchToKeplrRegistrationWindow,
switchToExtensionRegistrationWindow:
playwright.switchToKeplrRegistrationWindow,
switchToExtensionPermissionWindow: playwright.switchToKeplrPermissionWindow,

// keplr commands
importWallet: keplr.importWallet,
acceptAccess: keplr.acceptAccess,
rejectAccess: keplr.rejectAccess,
confirmTransaction: keplr.confirmTransaction,
disconnectWalletFromDapp: keplr.disconnectWalletFromDapp,
setupWallet: async ({
secretWordsOrPrivateKey,
password,
newAccount,
}) => {
setupWallet: async ({ secretWordsOrPrivateKey, password, newAccount }) => {
await keplr.initialSetup(null, {
secretWordsOrPrivateKey,
password,
newAccount
newAccount,
});
return true;
},
});

return config;
};
};
10 changes: 7 additions & 3 deletions support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,12 @@ Cypress.Commands.add(
(
secretWordsOrPrivateKey = 'orbit bench unit task food shock brand bracket domain regular warfare company announce wheel grape trust sphere boy doctor half guard ritual three ecology',
password = 'Test1234',
newAccount = false
newAccount = false,
) => {
return cy.task('setupWallet', {
secretWordsOrPrivateKey,
password,
newAccount
newAccount,
});
},
);
Expand All @@ -429,6 +429,10 @@ Cypress.Commands.add('acceptAccess', () => {
return cy.task('acceptAccess');
});

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

Cypress.Commands.add('confirmTransaction', () => {
return cy.task('confirmTransaction');
});
Expand All @@ -451,4 +455,4 @@ Cypress.Commands.add('switchToExtensionPermissionWindow', () => {

Cypress.Commands.add('disconnectWalletFromDapp', () => {
return cy.task('disconnectWalletFromDapp');
});
});
44 changes: 33 additions & 11 deletions tests/e2e/specs/keplr/keplr-spec.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
/* eslint-disable ui-testing/no-disabled-tests */
describe('Keplr', () => {
context('Test commands', () => {
it(`should complete Keplr connect with wallet, and confirm transaction after importing an existing wallet using 24 word phrase`, () => {
it(`should complete Keplr setup by importing an existing wallet using 24 word phrase`, () => {
cy.setupWallet().then(setupFinished => {
expect(setupFinished).to.be.true;
});
cy.visit('/');
});
it(`should reject connect with wallet`, () => {
const alertShown = cy.stub().as('alertShown');
cy.on('window:alert', alertShown);

cy.visit('/');
cy.contains('Connect Wallet').click();
cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;

cy.contains('Make an Offer').click();
cy.confirmTransaction().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});
});
cy.contains('Connect Wallet').click();
cy.rejectAccess().then(rejected => {
expect(rejected).to.be.true;
});
cy.get('@alertShown').should(
'have.been.calledOnceWith',
'Request rejected',
);
});
it(`should accept connection with wallet`, () => {
cy.contains('Connect Wallet').click();
cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});
});
it(`should confirm make an offer transaction`, () => {
const alertShown = cy.stub().as('alertShown');
cy.on('window:alert', alertShown);

cy.contains('Make an Offer').click();
cy.confirmTransaction().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});

cy.get('@alertShown').should(
'have.been.calledOnceWith',
'Offer accepted',
);
});
it(`should complete Keplr connect with wallet, and confirm transaction after creating a new wallet using 24 word phrase`, () => {
cy.switchToExtensionRegistrationWindow().then(() => {
cy.setupWallet(
Expand Down

0 comments on commit dbc5fe0

Please sign in to comment.