Skip to content

Commit

Permalink
test: add fixture permission controller test dapp two accounts (#29671)
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**

Cleanup the fixture for the `eth_accounts` and `Increase Token
Allowance` e2e specs

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

## **Related issues**

See:
#27847 (comment)

## **Manual testing steps**

1. Go to this page...
2.
3.

## **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
jiexi authored Jan 14, 2025
1 parent df4458a commit c5e39f4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
28 changes: 28 additions & 0 deletions test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,34 @@ class FixtureBuilder {
});
}

withPermissionControllerConnectedToTestDappWithTwoAccounts() {
const subjects = {
[DAPP_URL]: {
origin: DAPP_URL,
permissions: {
eth_accounts: {
id: 'ZaqPEWxyhNCJYACFw93jE',
parentCapability: 'eth_accounts',
invoker: DAPP_URL,
caveats: [
{
type: 'restrictReturnedAccounts',
value: [
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
'0x09781764c08de8ca82e156bbf156a3ca217c7950',
],
},
],
date: 1664388714636,
},
},
},
};
return this.withPermissionController({
subjects,
});
}

withPermissionControllerSnapAccountConnectedToTestDapp(
restrictReturnedAccounts = true,
) {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/json-rpc/eth_accounts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('eth_accounts', function () {
.withKeyringControllerAdditionalAccountVault()
.withPreferencesControllerAdditionalAccountIdentities()
.withAccountsControllerAdditionalAccountIdentities()
.withPermissionControllerConnectedToTestDapp()
.withPermissionControllerConnectedToTestDappWithTwoAccounts()
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
Expand Down
27 changes: 7 additions & 20 deletions test/e2e/tests/tokens/increase-token-allowance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ describe('Increase Token Allowance', function () {
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withKeyringControllerAdditionalAccountVault()
.withPreferencesControllerAdditionalAccountIdentities()
.withAccountsControllerAdditionalAccountIdentities()
.withPermissionControllerConnectedToTestDappWithTwoAccounts()
.build(),
ganacheOptions: defaultGanacheOptions,
smartContract,
title: this.test.fullTitle(),
},
async ({ driver, contractRegistry }) => {
const ACCOUNT_1_NAME = 'Account 1';
const ACCOUNT_2_NAME = '2nd Account';
const ACCOUNT_2_NAME = 'Account 2';

const initialSpendingCap = '1';
const additionalSpendingCap = '1';
Expand All @@ -41,6 +44,8 @@ describe('Increase Token Allowance', function () {

await tempToggleSettingRedesignedTransactionConfirmations(driver);

await switchToAccountWithName(driver, ACCOUNT_1_NAME);

const contractAddress = await contractRegistry.getContractAddress(
smartContract,
);
Expand All @@ -50,7 +55,6 @@ describe('Increase Token Allowance', function () {
await approveTokenSpendingCapTo(driver, ACCOUNT_2, initialSpendingCap);

await sendTransaction(driver, ACCOUNT_2, '1');
await addAccount(driver, ACCOUNT_2_NAME);

await triggerTransferFromTokens(driver, ACCOUNT_1, ACCOUNT_2);
// 'Transfer From Tokens' on the test dApp attempts to transfer 1.5 TST.
Expand Down Expand Up @@ -126,23 +130,6 @@ describe('Increase Token Allowance', function () {
});
}

async function addAccount(driver, newAccountName) {
await driver.clickElement('[data-testid="account-menu-icon"]');
await driver.clickElement(
'[data-testid="multichain-account-menu-popover-action-button"]',
);
await driver.clickElement(
'[data-testid="multichain-account-menu-popover-add-account"]',
);

await driver.fill('[placeholder="Account 2"]', newAccountName);
await driver.clickElement({ text: 'Add account', tag: 'button' });
await driver.findElement({
css: '[data-testid="account-menu-icon"]',
text: newAccountName,
});
}

async function triggerTransferFromTokens(
driver,
senderAccount,
Expand Down

0 comments on commit c5e39f4

Please sign in to comment.