From a37c3830a476a0ca8acbae501656bd1e92ddeb62 Mon Sep 17 00:00:00 2001 From: EtherWizard33 Date: Mon, 23 Dec 2024 18:13:57 +0300 Subject: [PATCH] test(3615): E2E to test the scenario when the dapp requests to switch the active network, and grant permission on the fly --- e2e/pages/Browser/TestDApp.js | 11 ++++ e2e/resources/networks.e2e.js | 12 +++- e2e/selectors/Browser/TestDapp.selectors.js | 1 + ...ion-system-dapp-chain-switch-grant.spec.js | 64 +++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 e2e/specs/multichain/permissions/chains/permission-system-dapp-chain-switch-grant.spec.js diff --git a/e2e/pages/Browser/TestDApp.js b/e2e/pages/Browser/TestDApp.js index ec451f5dbe5..8810cda9ea0 100644 --- a/e2e/pages/Browser/TestDApp.js +++ b/e2e/pages/Browser/TestDApp.js @@ -139,6 +139,13 @@ class TestDApp { ); } + get switchChainFromTestDappButton() { + return Matchers.getElementByWebID( + BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID, + TestDappSelectorsWebIDs.SWITCH_ETHEREUM_CHAIN, + ); + } + async connect() { await this.tapButton(this.DappConnectButton); } @@ -223,6 +230,10 @@ class TestDApp { ); await TestHelpers.delay(3000); // should have a better assertion that waits until the webpage loads } + + async switchChainFromTestDapp() { + await this.tapButton(this.switchChainFromTestDappButton); + } } export default new TestDApp(); diff --git a/e2e/resources/networks.e2e.js b/e2e/resources/networks.e2e.js index 8480ea55e74..be8c299175a 100644 --- a/e2e/resources/networks.e2e.js +++ b/e2e/resources/networks.e2e.js @@ -91,7 +91,17 @@ const CustomNetworks = { ticker: 'SepoliaETH', }, }, - + ElysiumTestnet: { + providerConfig: { + type: 'rpc', + chainId: '0x53a', + rpcUrlInvalid: 'https://rpc.atlantischain.network', + rpcUrl: 'https://rpc.atlantischain.network', + rpcUrlAlt: 'https://rpc.atlantischain.network', + nickname: 'Elysium Testnet', + ticker: 'LAVA', + }, + }, Tenderly: { isCustomNetwork: true, providerConfig: { diff --git a/e2e/selectors/Browser/TestDapp.selectors.js b/e2e/selectors/Browser/TestDapp.selectors.js index f2449607808..e2204c9cfa4 100644 --- a/e2e/selectors/Browser/TestDapp.selectors.js +++ b/e2e/selectors/Browser/TestDapp.selectors.js @@ -15,4 +15,5 @@ export const TestDappSelectorsWebIDs = { ADD_TOKENS_TO_WALLET_BUTTON: 'watchAssets', SEND_FAILING_TRANSACTION_BUTTON_ID: 'sendFailingButton', BATCH_TRANSFER_ERC1155_BUTTON_ID: 'batchTransferFromButton', + SWITCH_ETHEREUM_CHAIN: 'switchEthereumChain', }; diff --git a/e2e/specs/multichain/permissions/chains/permission-system-dapp-chain-switch-grant.spec.js b/e2e/specs/multichain/permissions/chains/permission-system-dapp-chain-switch-grant.spec.js new file mode 100644 index 00000000000..f0b8c0f4dc6 --- /dev/null +++ b/e2e/specs/multichain/permissions/chains/permission-system-dapp-chain-switch-grant.spec.js @@ -0,0 +1,64 @@ +'use strict'; +import FixtureBuilder from '../../../../fixtures/fixture-builder'; +import { withFixtures } from '../../../../fixtures/fixture-helper'; +import TestHelpers from '../../../../helpers'; +import Browser from '../../../../pages/Browser/BrowserView'; +import ConnectBottomSheet from '../../../../pages/Browser/ConnectBottomSheet'; +import TestDApp from '../../../../pages/Browser/TestDApp'; +import NetworkEducationModal from '../../../../pages/Network/NetworkEducationModal'; +import TabBarComponent from '../../../../pages/wallet/TabBarComponent'; +import WalletView from '../../../../pages/wallet/WalletView'; +import { CustomNetworks } from '../../../../resources/networks.e2e'; +import { SmokeMultiChainPermissions } from '../../../../tags'; +import Assertions from '../../../../utils/Assertions'; +import { loginToApp } from '../../../../viewHelper'; +import ConnectedAccountsModal from '../../../../pages/Browser/ConnectedAccountsModal'; +import NetworkConnectMultiSelector from '../../../../pages/Browser/NetworkConnectMultiSelector'; + +describe(SmokeMultiChainPermissions('Chain Permission System'), () => { + beforeAll(async () => { + jest.setTimeout(150000); + await TestHelpers.reverseServerPort(); + }); + + describe('When a dApp requests to switch to a new chain', () => { + it('should grant permission to the new chain and switch to it when approved', async () => { + await withFixtures( + { + dapp: true, + fixture: new FixtureBuilder() + .withNetworkController(CustomNetworks.ElysiumTestnet) + .withNetworkController(CustomNetworks.EthereumMainCustom) + .withPermissionController() + .build(), + restartDevice: true, + }, + async () => { + // Setup: Login and navigate to browser + await loginToApp(); + await TabBarComponent.tapBrowser(); + await Assertions.checkIfVisible(Browser.browserScreenID); + + // Connect to test dApp + await Browser.navigateToTestDApp(); + await TestDApp.connect(); + await ConnectBottomSheet.tapConnectButton(); + + // Grant permission and switch to new chain + await TestDApp.switchChainFromTestDapp(); + await ConnectBottomSheet.tapConnectButton(); + await NetworkEducationModal.tapGotItButton(); + + // Verify network switch was successful + await TabBarComponent.tapWallet(); + await Assertions.checkIfVisible(WalletView.container); + const networkPicker = await WalletView.getNavbarNetworkPicker(); + await Assertions.checkIfElementHasLabel( + networkPicker, + CustomNetworks.ElysiumTestnet.providerConfig.nickname, + ); + }, + ); + }); + }); +});