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): add new e2e test for initial dapp connection and non permitted flow #12488

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
16 changes: 14 additions & 2 deletions app/components/UI/PermissionsSummary/PermissionsSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { selectProviderConfig } from '../../../selectors/networkController';
import { useNetworkInfo } from '../../../selectors/selectedNetworkController';
import { ConnectedAccountsSelectorsIDs } from '../../../../e2e/selectors/Browser/ConnectedAccountModal.selectors';
import { PermissionSummaryBottomSheetSelectorsIDs } from '../../../../e2e/selectors/Browser/PermissionSummaryBottomSheet.selectors';
import { NetworkNonPemittedBottomSheetSelectorsIDs } from '../../../../e2e/selectors/Network/NetworkNonPemittedBottomSheet.selectors';

const PermissionsSummary = ({
currentPageInformation,
Expand Down Expand Up @@ -272,7 +273,10 @@ const PermissionsSummary = ({
function renderAccountPermissionsRequestInfoCard() {
return (
<TouchableOpacity onPress={handleEditAccountsButtonPress}>
<View style={styles.accountPermissionRequestInfoCard} testID={PermissionSummaryBottomSheetSelectorsIDs.CONTAINER}>
<View
style={styles.accountPermissionRequestInfoCard}
testID={PermissionSummaryBottomSheetSelectorsIDs.CONTAINER}
>
<Avatar
variant={AvatarVariant.Icon}
style={styles.walletIcon}
Expand Down Expand Up @@ -408,7 +412,12 @@ const PermissionsSummary = ({
<View style={styles.mainContainer}>
<View>
{renderHeader()}
<View style={styles.title} testID={PermissionSummaryBottomSheetSelectorsIDs.NETWORK_PERMISSIONS_CONTAINER}>
<View
style={styles.title}
testID={
PermissionSummaryBottomSheetSelectorsIDs.NETWORK_PERMISSIONS_CONTAINER
}
>
<TextComponent variant={TextVariant.HeadingSM}>
{isNonDappNetworkSwitch
? strings('permissions.title_add_network_permission')
Expand Down Expand Up @@ -482,6 +491,9 @@ const PermissionsSummary = ({
<Button
variant={ButtonVariants.Primary}
label={strings('permissions.add_this_network')}
testID={
NetworkNonPemittedBottomSheetSelectorsIDs.ADD_THIS_NETWORK_BUTTON
}
onPress={onAddNetwork}
size={ButtonSize.Lg}
style={{
Expand Down
23 changes: 23 additions & 0 deletions e2e/pages/Browser/NetworkConnectMultiSelector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { NetworkConnectMultiSelectorSelectorsIDs } from '../../selectors/Browser/NetworkConnectMultiSelector.selectors';
import Matchers from '../../utils/Matchers';
import Gestures from '../../utils/Gestures';

class NetworkConnectMultiSelector {
get container() {
return Matchers.getElementByID(
NetworkConnectMultiSelectorSelectorsIDs.CONTAINER,
);
}

get backButton() {
return Matchers.getElementByID(
NetworkConnectMultiSelectorSelectorsIDs.BACK_BUTTON,
);
}

async tapBackButton() {
await Gestures.waitAndTap(this.backButton);
}
}

export default new NetworkConnectMultiSelector();
50 changes: 50 additions & 0 deletions e2e/pages/Network/NetworkNonPemittedBottomSheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
NetworkListModalSelectorsIDs,
NetworkListModalSelectorsText,
} from '../../selectors/Network/NetworkListModal.selectors';
import Matchers from '../../utils/Matchers';
import Gestures from '../../utils/Gestures';
import {
NetworkNonPemittedBottomSheetSelectorsIDs,
NetworkNonPemittedBottomSheetSelectorsText,
} from '../../selectors/Network/NetworkNonPemittedBottomSheet.selectors';

class NetworkNonPemittedBottomSheet {
get addThisNetworkTitle() {
return Matchers.getElementByText(
NetworkNonPemittedBottomSheetSelectorsText.ADD_THIS_NETWORK_TITLE,
);
}

get sepoliaNetworkName() {
return Matchers.getElementByText(
NetworkNonPemittedBottomSheetSelectorsText.SEPOLIA_NETWORK_NAME,
);
}

get ethereumMainNetNetworkName() {
return Matchers.getElementByText(
NetworkNonPemittedBottomSheetSelectorsText.ETHEREUM_MAIN_NET_NETWORK_NAME,
);
}

get addThisNetworkButton() {
return Matchers.getElementByID(
NetworkNonPemittedBottomSheetSelectorsIDs.ADD_THIS_NETWORK_BUTTON,
);
}

async tapAddThisNetworkButton() {
await Gestures.waitAndTap(this.addThisNetworkButton);
}

async tapSepoliaNetworkName() {
await Gestures.waitAndTap(this.sepoliaNetworkName);
}

async tapEthereumMainNetNetworkName() {
await Gestures.waitAndTap(this.ethereumMainNetNetworkName);
}
}

export default new NetworkNonPemittedBottomSheet();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const NetworkConnectMultiSelectorSelectorsIDs = {
BACK_BUTTON: 'sheet-header-back-button',
CONTAINER: 'network-connect-multi-selector-container',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import enContent from '../../../locales/languages/en.json';

export const NetworkNonPemittedBottomSheetSelectorsText = {
ADD_THIS_NETWORK_TITLE: enContent.permissions.title_add_network_permission,
SEPOLIA_NETWORK_NAME: 'Sepolia',
ETHEREUM_MAIN_NET_NETWORK_NAME: 'Ethereum Main Network',
};

export const NetworkNonPemittedBottomSheetSelectorsIDs = {
ADD_THIS_NETWORK_BUTTON: 'add-this-network-button',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { SmokeCore } from '../../tags';
import { loginToApp } from '../../viewHelper';
import WalletView from '../../pages/wallet/WalletView';
import NetworkListModal from '../../pages/Network/NetworkListModal';
import NetworkEducationModal from '../../pages/Network/NetworkEducationModal';
import Assertions from '../../utils/Assertions';
import TestHelpers from '../../helpers';
import FixtureBuilder from '../../fixtures/fixture-builder';
import { stopFixtureServer, withFixtures } from '../../fixtures/fixture-helper';
import FixtureServer from '../../fixtures/fixture-server';
import { CustomNetworks } from '../../resources/networks.e2e';
import Browser from '../../pages/Browser/BrowserView';
import TabBarComponent from '../../pages/TabBarComponent';
import NetworkNonPemittedBottomSheet from '../../pages/Network/NetworkNonPemittedBottomSheet';
import ConnectedAccountsModal from '../../pages/Browser/ConnectedAccountsModal';

const fixtureServer = new FixtureServer();
const SEPOLIA = CustomNetworks.Sepolia.providerConfig.nickname;

describe(SmokeCore('Network Permission System, non-permitted chain'), () => {
beforeAll(async () => {
await TestHelpers.reverseServerPort();
});

beforeEach(() => {
jest.setTimeout(150000);
});

afterAll(async () => {
await stopFixtureServer(fixtureServer);
});

it('should show bottom sheet when switching to non-permitted network', async () => {
await withFixtures(
{
dapp: true,
fixture: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withChainPermission()
.build(),
restartDevice: true,
},
async () => {
await loginToApp();
await TabBarComponent.tapBrowser();
await Browser.navigateToTestDApp();

// Switch to non-permitted network
await TabBarComponent.tapWallet();
await WalletView.tapNetworksButtonOnNavBar();
await NetworkListModal.scrollToBottomOfNetworkList();
await NetworkListModal.changeNetworkTo(SEPOLIA);
await NetworkEducationModal.tapGotItButton();

// Verify bottom sheet appears
await TabBarComponent.tapBrowser();
await Assertions.checkIfVisible(
NetworkNonPemittedBottomSheet.addThisNetworkTitle,
);
},
);
});

it('should NOT show bottom sheet when permission was already granted', async () => {
await withFixtures(
{
dapp: true,
fixture: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withChainPermission(['0x1', '0xaa36a7'])
.build(),
restartDevice: true,
},
async () => {
await loginToApp();
await TabBarComponent.tapBrowser();
await Browser.navigateToTestDApp();

// Switch to already permitted network
await TabBarComponent.tapWallet();
await WalletView.tapNetworksButtonOnNavBar();
await NetworkListModal.scrollToBottomOfNetworkList();
await NetworkListModal.changeNetworkTo(SEPOLIA);
await NetworkEducationModal.tapGotItButton();

// Verify no bottom sheet appears
await TabBarComponent.tapBrowser();
await Assertions.checkIfNotVisible(
NetworkNonPemittedBottomSheet.addThisNetworkTitle,
);
},
);
});

it('should add network permission when requested', async () => {
await withFixtures(
{
dapp: true,
fixture: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withChainPermission()
.build(),
restartDevice: true,
},
async () => {
await loginToApp();
await TabBarComponent.tapBrowser();
await Browser.navigateToTestDApp();

// Switch to non-permitted network
await TabBarComponent.tapWallet();
await WalletView.tapNetworksButtonOnNavBar();
await NetworkListModal.scrollToBottomOfNetworkList();
await NetworkListModal.changeNetworkTo(SEPOLIA);
await NetworkEducationModal.tapGotItButton();

// Add network permission
await TabBarComponent.tapBrowser();
await NetworkNonPemittedBottomSheet.tapAddThisNetworkButton();

// Verify permission was added by checking that disconnecting both networks shows disconnect all button
await Browser.tapNetworkAvatarButtonOnBrowser();
await ConnectedAccountsModal.tapManagePermissionsButton();
await ConnectedAccountsModal.tapNavigateToEditNetworksPermissionsButton();
await NetworkNonPemittedBottomSheet.tapSepoliaNetworkName();
await NetworkNonPemittedBottomSheet.tapEthereumMainNetNetworkName();
await Assertions.checkIfVisible(
ConnectedAccountsModal.disconnectNetworksButton,
);
},
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';
import TestHelpers from '../../helpers';
import { SmokeCore } from '../../tags';
import Browser from '../../pages/Browser/BrowserView';
import TabBarComponent from '../../pages/TabBarComponent';
import ConnectedAccountsModal from '../../pages/Browser/ConnectedAccountsModal';
import FixtureBuilder from '../../fixtures/fixture-builder';
import { withFixtures } from '../../fixtures/fixture-helper';
import { loginToApp } from '../../viewHelper';
import Assertions from '../../utils/Assertions';
import NetworkConnectMultiSelector from '../../pages/Browser/NetworkConnectMultiSelector';
import NetworkNonPemittedBottomSheet from '../../pages/Network/NetworkNonPemittedBottomSheet';

describe(SmokeCore('MultiChain Permissions System:'), () => {
beforeAll(async () => {
jest.setTimeout(150000);
await TestHelpers.reverseServerPort();
});

it('should discard chain permission changes when navigating back without confirming', async () => {
await withFixtures(
{
dapp: true,
fixture: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withChainPermission()
.build(),
restartDevice: true,
},
async () => {
await loginToApp();
await TabBarComponent.tapBrowser();
await Assertions.checkIfVisible(Browser.browserScreenID);

await Browser.navigateToTestDApp();
await Browser.tapNetworkAvatarButtonOnBrowser();

// Navigate to chain permissions and add Sepolia
await ConnectedAccountsModal.tapManagePermissionsButton();
await ConnectedAccountsModal.tapNavigateToEditNetworksPermissionsButton();
await NetworkNonPemittedBottomSheet.tapSepoliaNetworkName();

// Navigate back without confirming changes
await NetworkConnectMultiSelector.tapBackButton();

// Verify changes were discarded by checking chain permissions again
await ConnectedAccountsModal.tapNavigateToEditNetworksPermissionsButton();

// Deselect Ethereum mainnet (should be the only chain selected)
await NetworkNonPemittedBottomSheet.tapEthereumMainNetNetworkName();

// Verify the disconnect all button appears (indicating no chain are selected)
await Assertions.checkIfVisible(
ConnectedAccountsModal.disconnectNetworksButton,
);
},
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';
import TestHelpers from '../../helpers';
import { SmokeCore } from '../../tags';
import Browser from '../../pages/Browser/BrowserView';
import TabBarComponent from '../../pages/TabBarComponent';
import NetworkListModal from '../../pages/Network/NetworkListModal';
import TestDApp from '../../pages/Browser/TestDApp';
import ConnectedAccountsModal from '../../pages/Browser/ConnectedAccountsModal';
import FixtureBuilder from '../../fixtures/fixture-builder';
import { withFixtures } from '../../fixtures/fixture-helper';
import { loginToApp } from '../../viewHelper';
import Assertions from '../../utils/Assertions';
import ConnectBottomSheet from '../../pages/Browser/ConnectBottomSheet';

describe(SmokeCore('MultiChain Permissions System:'), () => {
beforeAll(async () => {
jest.setTimeout(150000);
await TestHelpers.reverseServerPort();
});

it('should grant initial permissions for one account and one chain', async () => {
await withFixtures(
{
dapp: true,
fixture: new FixtureBuilder().withPermissionController().build(),
restartDevice: true,
},
async () => {
await loginToApp();
await TabBarComponent.tapBrowser();
await Assertions.checkIfVisible(Browser.browserScreenID);

await Browser.navigateToTestDApp();
await TestDApp.connect();
await ConnectBottomSheet.tapConnectButton();

await Browser.tapNetworkAvatarButtonOnBrowser();
await Assertions.checkIfVisible(ConnectedAccountsModal.title);
},
);
});
});
Loading