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: approve erc721 token e2e #12767

Merged
merged 2 commits into from
Dec 19, 2024
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
28 changes: 24 additions & 4 deletions e2e/pages/Browser/TestDApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Matchers from '../../utils/Matchers';

export const TEST_DAPP_LOCAL_URL = `http://localhost:${getLocalTestDappPort()}`;
const CONFIRM_BUTTON_TEXT = enContent.confirmation_modal.confirm_cta;
const APPROVE_BUTTON_TEXT = enContent.transactions.tx_review_approve;

class TestDApp {
get androidContainer() {
Expand All @@ -22,17 +23,28 @@ class TestDApp {
return Matchers.getElementByText(CONFIRM_BUTTON_TEXT);
}

get approveButtonText() {
C-Ivan marked this conversation as resolved.
Show resolved Hide resolved
return Matchers.getElementByText(APPROVE_BUTTON_TEXT);
}

get DappConnectButton() {
return Matchers.getElementByWebID(
BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID,
TestDappSelectorsWebIDs.CONNECT_BUTTON,
);
}

get ApproveButton() {
get ApproveERC20TokensButton() {
C-Ivan marked this conversation as resolved.
Show resolved Hide resolved
return Matchers.getElementByWebID(
BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID,
TestDappSelectorsWebIDs.APPROVE_ERC_20_TOKENS_BUTTON_ID,
);
}

get ApproveERC721TokenButton() {
C-Ivan marked this conversation as resolved.
Show resolved Hide resolved
return Matchers.getElementByWebID(
BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID,
TestDappSelectorsWebIDs.APPROVE_TOKENS_BUTTON_ID,
TestDappSelectorsWebIDs.APPROVE_ERC_721_TOKEN_BUTTON_ID,
);
}
// This taps on the transfer tokens button under the "SEND TOKENS section"
Expand Down Expand Up @@ -104,8 +116,12 @@ class TestDApp {
await this.tapButton(this.DappConnectButton);
}

async tapApproveButton() {
await this.tapButton(this.ApproveButton);
async tapApproveERC20TokensButton() {
C-Ivan marked this conversation as resolved.
Show resolved Hide resolved
await this.tapButton(this.ApproveERC20TokensButton);
}

async tapApproveERC721TokenButton() {
C-Ivan marked this conversation as resolved.
Show resolved Hide resolved
await this.tapButton(this.ApproveERC721TokenButton);
}

async tapIncreaseAllowanceButton() {
Expand Down Expand Up @@ -150,6 +166,10 @@ class TestDApp {
await Gestures.tap(this.confirmButtonText, 0);
}

async tapApproveButton() {
C-Ivan marked this conversation as resolved.
Show resolved Hide resolved
await Gestures.tap(this.approveButtonText, 0);
}

async tapButton(elementId) {
await Gestures.scrollToWebViewPort(elementId);
await Gestures.tapWebElement(elementId);
Expand Down
3 changes: 2 additions & 1 deletion e2e/selectors/Browser/TestDapp.selectors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const TestDappSelectorsWebIDs = {
APPROVE_TOKENS_BUTTON_ID: 'approveTokens',
APPROVE_ERC_20_TOKENS_BUTTON_ID: 'approveTokens',
C-Ivan marked this conversation as resolved.
Show resolved Hide resolved
APPROVE_ERC_721_TOKEN_BUTTON_ID: 'approveButton',
C-Ivan marked this conversation as resolved.
Show resolved Hide resolved
CONNECT_BUTTON: 'connectButton',
ERC_20_SEND_TOKENS_TRANSFER_TOKENS_BUTTON_ID: 'transferTokens',
INCREASE_ALLOWANCE_BUTTON_ID: 'increaseTokenAllowance',
Expand Down
1 change: 1 addition & 0 deletions e2e/selectors/Transactions/ActivitiesView.selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export const ActivitiesViewSelectorsText = {
SET_APPROVAL_FOR_ALL_METHOD: enContent.transactions.set_approval_for_all,
SWAP: enContent.swaps.transaction_label.swap,
TITLE: enContent.transactions_view.title,

};
2 changes: 1 addition & 1 deletion e2e/specs/confirmations/approve-custom-erc20.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe(SmokeConfirmations('ERC20 tokens'), () => {
await TestDApp.navigateToTestDappWithContract({
contractAddress: hstAddress,
});
await TestDApp.tapApproveButton();
await TestDApp.tapApproveERC20TokensButton();
C-Ivan marked this conversation as resolved.
Show resolved Hide resolved

//Input custom token amount
await Assertions.checkIfVisible(
Expand Down
2 changes: 1 addition & 1 deletion e2e/specs/confirmations/approve-default-erc20.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe(SmokeConfirmations('ERC20 tokens'), () => {
await TestDApp.navigateToTestDappWithContract({
contractAddress: hstAddress,
});
await TestDApp.tapApproveButton();
await TestDApp.tapApproveERC20TokensButton();
C-Ivan marked this conversation as resolved.
Show resolved Hide resolved

await Assertions.checkIfVisible(
ContractApprovalBottomSheet.approveTokenAmount,
Expand Down
61 changes: 61 additions & 0 deletions e2e/specs/confirmations/approve-erc721.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';

import { SmokeConfirmations } from '../../tags';
import TestHelpers from '../../helpers';
import { loginToApp } from '../../viewHelper';

import TabBarComponent from '../../pages/wallet/TabBarComponent';
import TestDApp from '../../pages/Browser/TestDApp';
import FixtureBuilder from '../../fixtures/fixture-builder';
import {
withFixtures,
defaultGanacheOptions,
} from '../../fixtures/fixture-helper';
import { SMART_CONTRACTS } from '../../../app/util/test/smart-contracts';
import { ActivitiesViewSelectorsText } from '../../selectors/Transactions/ActivitiesView.selectors';
import Assertions from '../../utils/Assertions';

describe(SmokeConfirmations('ERC721 tokens'), () => {
const NFT_CONTRACT = SMART_CONTRACTS.NFTS;

beforeAll(async () => {
jest.setTimeout(150000);
await TestHelpers.reverseServerPort();
});

it('approve an ERC721 token from a dapp', async () => {
await withFixtures(
{
dapp: true,
fixture: new FixtureBuilder()
.withGanacheNetwork()
.withPermissionControllerConnectedToTestDapp()
.build(),
restartDevice: true,
ganacheOptions: defaultGanacheOptions,
smartContract: NFT_CONTRACT,
},
async ({ contractRegistry }) => {
const nftsAddress = await contractRegistry.getContractAddress(
NFT_CONTRACT,
);
await loginToApp();
// Navigate to the browser screen
await TabBarComponent.tapBrowser();
await TestDApp.navigateToTestDappWithContract({
contractAddress: nftsAddress,
});
// Approve NFT
await TestDApp.tapApproveERC721TokenButton();
await TestHelpers.delay(3000);
await TestDApp.tapApproveButton();
// Navigate to the activity screen
await TabBarComponent.tapActivity();
// Assert NFT is approved
await Assertions.checkIfTextIsDisplayed(
ActivitiesViewSelectorsText.CONFIRM_TEXT,
);
},
);
});
});
Loading