Skip to content
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

test(3615): E2E to test the scenario when the dapp requests to switch the active network, and grant permission on the fly #12829

Merged
merged 1 commit into from
Jan 9, 2025
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
11 changes: 11 additions & 0 deletions e2e/pages/Browser/TestDApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
12 changes: 11 additions & 1 deletion e2e/resources/networks.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions e2e/selectors/Browser/TestDapp.selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Original file line number Diff line number Diff line change
@@ -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,
);
},
);
});
});
});
Loading