-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ERC20 Revoke Allowance (#26906)
<!-- 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** Includes e2e test. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26906?quickstart=1) ## **Related issues** Fixes: MetaMask/MetaMask-planning#3004 ## **Manual testing steps** 1. Go to https://etherscan.io/token/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599#writeContract 2. Connect your wallet 3. Go to approve 4. Input an address under spender 5. Input 0 under value 6. Click write 7. Notice MM confirmation ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> <img width="472" alt="Screenshot 2024-09-04 at 17 00 32" src="https://github.com/user-attachments/assets/6520ca14-068b-4fff-a4e3-7783c5fac60b"> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.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. --------- Co-authored-by: Priya Narayanaswamy <[email protected]>
- Loading branch information
1 parent
406346f
commit 0e82276
Showing
19 changed files
with
414 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
test/e2e/tests/confirmations/transactions/revoke-allowance-redesign.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ | ||
import { MockttpServer } from 'mockttp'; | ||
import { WINDOW_TITLES } from '../../../helpers'; | ||
import { Driver } from '../../../webdriver/driver'; | ||
import { scrollAndConfirmAndAssertConfirm } from '../helpers'; | ||
import { mocked4BytesApprove } from './erc20-approve-redesign.spec'; | ||
import { | ||
assertChangedSpendingCap, | ||
editSpendingCap, | ||
} from './increase-token-allowance-redesign.spec'; | ||
import { openDAppWithContract, TestSuiteArguments } from './shared'; | ||
|
||
const { | ||
defaultGanacheOptions, | ||
defaultGanacheOptionsForType2Transactions, | ||
withFixtures, | ||
} = require('../../../helpers'); | ||
const FixtureBuilder = require('../../../fixture-builder'); | ||
const { SMART_CONTRACTS } = require('../../../seeder/smart-contracts'); | ||
|
||
describe('Confirmation Redesign ERC20 Revoke Allowance', function () { | ||
const smartContract = SMART_CONTRACTS.HST; | ||
|
||
describe('Submit an revoke transaction @no-mmi', function () { | ||
it('Sends a type 0 transaction (Legacy)', async function () { | ||
await withFixtures( | ||
{ | ||
dapp: true, | ||
fixtures: new FixtureBuilder() | ||
.withPermissionControllerConnectedToTestDapp() | ||
.withPreferencesController({ | ||
preferences: { | ||
redesignedConfirmationsEnabled: true, | ||
isRedesignedConfirmationsDeveloperEnabled: true, | ||
}, | ||
}) | ||
.build(), | ||
ganacheOptions: defaultGanacheOptions, | ||
smartContract, | ||
testSpecificMock: mocks, | ||
title: this.test?.fullTitle(), | ||
}, | ||
async ({ driver, contractRegistry }: TestSuiteArguments) => { | ||
await openDAppWithContract(driver, contractRegistry, smartContract); | ||
|
||
await createERC20ApproveTransaction(driver); | ||
|
||
const NEW_SPENDING_CAP = '0'; | ||
await editSpendingCap(driver, NEW_SPENDING_CAP); | ||
|
||
await driver.waitForSelector({ | ||
css: 'h2', | ||
text: 'Remove permission', | ||
}); | ||
|
||
await scrollAndConfirmAndAssertConfirm(driver); | ||
|
||
await assertChangedSpendingCap(driver, NEW_SPENDING_CAP); | ||
}, | ||
); | ||
}); | ||
|
||
it('Sends a type 2 transaction (EIP1559)', async function () { | ||
await withFixtures( | ||
{ | ||
dapp: true, | ||
fixtures: new FixtureBuilder() | ||
.withPermissionControllerConnectedToTestDapp() | ||
.withPreferencesController({ | ||
preferences: { | ||
redesignedConfirmationsEnabled: true, | ||
isRedesignedConfirmationsDeveloperEnabled: true, | ||
}, | ||
}) | ||
.build(), | ||
ganacheOptions: defaultGanacheOptionsForType2Transactions, | ||
smartContract, | ||
testSpecificMock: mocks, | ||
title: this.test?.fullTitle(), | ||
}, | ||
async ({ driver, contractRegistry }: TestSuiteArguments) => { | ||
await openDAppWithContract(driver, contractRegistry, smartContract); | ||
|
||
await createERC20ApproveTransaction(driver); | ||
|
||
const NEW_SPENDING_CAP = '0'; | ||
await editSpendingCap(driver, NEW_SPENDING_CAP); | ||
|
||
await driver.waitForSelector({ | ||
css: 'h2', | ||
text: 'Remove permission', | ||
}); | ||
|
||
await scrollAndConfirmAndAssertConfirm(driver); | ||
|
||
await assertChangedSpendingCap(driver, NEW_SPENDING_CAP); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
async function mocks(server: MockttpServer) { | ||
return [await mocked4BytesApprove(server)]; | ||
} | ||
|
||
async function createERC20ApproveTransaction(driver: Driver) { | ||
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); | ||
await driver.clickElement('#approveTokens'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.