-
Notifications
You must be signed in to change notification settings - Fork 5.4k
test: adds blockaid multiple network support test #22691
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
151 changes: 151 additions & 0 deletions
151
test/e2e/tests/ppom-blockaid-alert-networks-support.spec.js
This file contains hidden or 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,151 @@ | ||
| const { strict: assert } = require('assert'); | ||
| const FixtureBuilder = require('../fixture-builder'); | ||
| const { mockServerJsonRpc } = require('../mock-server-json-rpc'); | ||
| const { | ||
| WINDOW_TITLES, | ||
| defaultGanacheOptions, | ||
| openDapp, | ||
| unlockWallet, | ||
| withFixtures, | ||
| } = require('../helpers'); | ||
|
|
||
| async function mockInfura(mockServer) { | ||
| await mockServerJsonRpc(mockServer, [ | ||
| ['eth_blockNumber'], | ||
| ['eth_call'], | ||
| ['eth_estimateGas'], | ||
| ['eth_feeHistory'], | ||
| ['eth_gasPrice'], | ||
| ['eth_getBalance'], | ||
| ['eth_getBlockByNumber'], | ||
| ['eth_getCode'], | ||
| ['eth_getTransactionCount'], | ||
| ]); | ||
| } | ||
|
|
||
| async function mockInfuraWithMaliciousResponses(mockServer) { | ||
| await mockInfura(mockServer); | ||
| await mockServer | ||
| .forPost() | ||
| .withJsonBodyIncluding({ | ||
| method: 'debug_traceCall', | ||
| params: [{ accessList: [], data: '0x00000000' }], | ||
| }) | ||
| .thenCallback(async (req) => { | ||
| return { | ||
| statusCode: 200, | ||
| json: { | ||
| jsonrpc: '2.0', | ||
| id: (await req.body.getJson()).id, | ||
| error: { | ||
| message: | ||
| 'The method debug_traceCall does not exist/is not available', | ||
| }, | ||
| }, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| describe('PPOM Blockaid Alert - Multiple Networks Support @no-mmi', function () { | ||
| it('should show banner alert after switchinig to another supported network', async function () { | ||
| await withFixtures( | ||
| { | ||
| dapp: true, | ||
| fixtures: new FixtureBuilder() | ||
| .withNetworkControllerOnMainnet() | ||
| .withPermissionControllerConnectedToTestDapp() | ||
| .withPreferencesController({ | ||
| securityAlertsEnabled: true, | ||
| }) | ||
| .build(), | ||
| defaultGanacheOptions, | ||
| testSpecificMock: mockInfuraWithMaliciousResponses, | ||
| title: this.test.fullTitle(), | ||
| }, | ||
|
|
||
| async ({ driver }) => { | ||
| const expectedTitle = 'This is a deceptive request'; | ||
| const expectedDescriptionMainnet = | ||
| 'If you approve this request, you might lose your assets.'; | ||
|
|
||
| const expectedDescriptionArbitrum = | ||
| 'If you approve this request, a third party known for scams will take all your assets.'; | ||
|
|
||
| await unlockWallet(driver); | ||
| await openDapp(driver); | ||
|
|
||
| // Click TestDapp button to send JSON-RPC request | ||
| await driver.clickElement('#maliciousTradeOrder'); | ||
|
|
||
| // Wait for confirmation pop-up | ||
| await driver.waitUntilXWindowHandles(3); | ||
| await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); | ||
|
|
||
| const bannerAlertSelector = | ||
| '[data-testid="security-provider-banner-alert"]'; | ||
|
|
||
| let bannerAlertFoundByTitle = await driver.findElement({ | ||
| css: bannerAlertSelector, | ||
| text: expectedTitle, | ||
| }); | ||
| let bannerAlertText = await bannerAlertFoundByTitle.getText(); | ||
|
|
||
| assert( | ||
| bannerAlertFoundByTitle, | ||
| `Banner alert not found. Expected Title: ${expectedTitle} \nExpected reason: approval_farming\n`, | ||
| ); | ||
| assert( | ||
| bannerAlertText.includes(expectedDescriptionMainnet), | ||
| `Unexpected banner alert description. Expected: ${expectedDescriptionMainnet} \nExpected reason: approval_farming\n`, | ||
| ); | ||
|
|
||
| await driver.clickElement({ text: 'Reject', tag: 'button' }); | ||
| await driver.waitUntilXWindowHandles(2); | ||
| await driver.switchToWindowWithTitle( | ||
| WINDOW_TITLES.ExtensionInFullScreenView, | ||
| ); | ||
|
|
||
| // switch network to arbitrum | ||
| await driver.clickElement('[data-testid="network-display"]'); | ||
|
|
||
| await driver.clickElement({ tag: 'button', text: 'Add network' }); | ||
| await driver.clickElement({ | ||
| tag: 'button', | ||
| text: 'Add', | ||
| }); | ||
|
|
||
| await driver.clickElement({ tag: 'a', text: 'View all details' }); | ||
|
|
||
| await driver.clickElement({ tag: 'button', text: 'Close' }); | ||
| await driver.clickElement({ tag: 'button', text: 'Approve' }); | ||
| await driver.clickElement({ | ||
| tag: 'h6', | ||
| text: 'Switch to Arbitrum One', | ||
| }); | ||
|
|
||
| await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); | ||
| // Click TestDapp button to send JSON-RPC request | ||
| await driver.clickElement('#maliciousRawEthButton'); | ||
|
|
||
| // Wait for confirmation pop-up | ||
| await driver.waitUntilXWindowHandles(3); | ||
| await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); | ||
|
|
||
| bannerAlertFoundByTitle = await driver.findElement({ | ||
| css: bannerAlertSelector, | ||
| text: expectedTitle, | ||
| }); | ||
| bannerAlertText = await bannerAlertFoundByTitle.getText(); | ||
|
|
||
| assert( | ||
| bannerAlertFoundByTitle, | ||
| `Banner alert not found. Expected Title: ${expectedTitle} \nExpected reason: raw_native_token_transfer\n`, | ||
| ); | ||
| assert( | ||
| bannerAlertText.includes(expectedDescriptionArbitrum), | ||
| `Unexpected banner alert description. Expected: ${expectedDescriptionArbitrum} \nExpected reason: raw_native_token_transfer\n`, | ||
| ); | ||
| }, | ||
| ); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there was a default mock for Arbitrum that another test is using, that returns the chain id to any request made to Arbitrum RPC. We don't want this mock to be applied to all requests, since now we need to mock different requests, so this mock is now only applied when the chainId method is called - preserving the other test functionality, as well as making it work with new Arbitrum mocks added in this PR