Skip to content

Commit

Permalink
test: [POM] Migrate Send tx Revoke Permissions spec (#29273)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

- Migrates
`test/e2e/tests/request-queuing/sendTx-revokePermissions.spec.js` spec
to POM and ts
- Updates method classes to accommodate new functions needed in this
spec
- [A new
bug](#29272) has
been discovered thanks to this migration, and a new TODO has been added,
to add a new spec to cover that flow, once the bug is fixed

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29273?quickstart=1)

## **Related issues**

Fixes: #29276

## **Manual testing steps**

1. Check ci
2. Run test ` yarn test:e2e:single
test/e2e/tests/request-queuing/sendTx-revokePermissions.spec.ts
--browser=chrome --leave-running=true`

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
seaona authored Dec 17, 2024
1 parent 0ef0d54 commit a31d808
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 58 deletions.
20 changes: 20 additions & 0 deletions test/e2e/page-objects/pages/test-dapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,26 @@ class TestDapp {
});
}

/**
* Verifies the accounts connected to the test dapp.
*
* @param connectedAccounts - The expected connected accounts separated by a comma. If no accounts are connected we can omit the param.
*/
async check_connectedAccounts(connectedAccounts: string = '') {
console.log('Verify connected accounts');
if (connectedAccounts) {
await this.driver.waitForSelector({
css: this.connectedAccount,
text: connectedAccounts,
});
} else {
await this.driver.waitForSelector({
css: this.connectedAccount,
text: ' ',
});
}
}

/**
* Verify the failed personal sign signature.
*
Expand Down
58 changes: 0 additions & 58 deletions test/e2e/tests/request-queuing/sendTx-revokePermissions.spec.js

This file was deleted.

78 changes: 78 additions & 0 deletions test/e2e/tests/request-queuing/sendTx-revokePermissions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { loginWithBalanceValidation } from '../../page-objects/flows/login.flow';
import TestDapp from '../../page-objects/pages/test-dapp';
import TransactionConfirmation from '../../page-objects/pages/confirmations/redesign/transaction-confirmation';
import { Ganache } from '../../seeder/ganache';
import { Driver } from '../../webdriver/driver';
import { DEFAULT_FIXTURE_ACCOUNT } from '../../constants';
import FixtureBuilder from '../../fixture-builder';
import {
withFixtures,
defaultGanacheOptions,
WINDOW_TITLES,
} from '../../helpers';

describe('Request Queuing', function () {
// TODO: add a new spec which checks that after revoking and connecting again
// a pending tx is still closed when using revokePermissions.
// To be done once this bug is fixed: #29272
it('should clear tx confirmation when revokePermission is called from origin dapp', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withPreferencesControllerUseRequestQueueEnabled()
.withSelectedNetworkControllerPerDomain()
.build(),
ganacheOptions: {
...defaultGanacheOptions,
},
title: this.test?.fullTitle(),
},
async ({
driver,
ganacheServer,
}: {
driver: Driver;
ganacheServer?: Ganache;
}) => {
await loginWithBalanceValidation(driver, ganacheServer);

// Open test dapp
const testDapp = new TestDapp(driver);
await testDapp.openTestDappPage();
await testDapp.check_connectedAccounts(
DEFAULT_FIXTURE_ACCOUNT.toLowerCase(),
);

// Trigger a tx
await testDapp.clickSimpleSendButton();
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

const transactionConfirmation = new TransactionConfirmation(driver);
await transactionConfirmation.check_dappInitiatedHeadingTitle();

// wallet_revokePermissions request
const revokePermissionsRequest = JSON.stringify({
jsonrpc: '2.0',
method: 'wallet_revokePermissions',
params: [
{
eth_accounts: {},
},
],
});
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.executeScript(
`return window.ethereum.request(${revokePermissionsRequest})`,
);

// Should have cleared the tx confirmation
await driver.waitUntilXWindowHandles(2);

// Cleared eth_accounts account label
await testDapp.check_connectedAccounts();
},
);
});
});

0 comments on commit a31d808

Please sign in to comment.