Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/e2e/mock-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ async function setupMocking(server, testSpecificMock, { chainId }) {
.forPost(
'https://arbitrum-mainnet.infura.io/v3/00000000000000000000000000000000',
)
.withJsonBodyIncluding({
method: 'eth_chainId',
})
Copy link
Member Author

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

.thenCallback(() => {
return {
statusCode: 200,
Expand Down
151 changes: 151 additions & 0 deletions test/e2e/tests/ppom-blockaid-alert-networks-support.spec.js
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`,
);
},
);
});
});