Skip to content

Commit

Permalink
test: approve erc721 token e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Ivan committed Dec 18, 2024
1 parent e335f05 commit 69818fc
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 7 deletions.
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() {
return Matchers.getElementByText(APPROVE_BUTTON_TEXT);
}

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

get ApproveButton() {
get ApproveERC20TokensButton() {
return Matchers.getElementByWebID(
BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID,
TestDappSelectorsWebIDs.APPROVE_ERC_20_TOKENS_BUTTON_ID,
);
}

get ApproveERC721TokenButton() {
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 @@ -98,8 +110,12 @@ class TestDApp {
await this.tapButton(this.DappConnectButton);
}

async tapApproveButton() {
await this.tapButton(this.ApproveButton);
async tapApproveERC20TokensButton() {
await this.tapButton(this.ApproveERC20TokensButton);
}

async tapApproveERC721TokenButton() {
await this.tapButton(this.ApproveERC721TokenButton);
}

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

async tapApproveButton() {
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',
APPROVE_ERC_721_TOKEN_BUTTON_ID: 'approveButton',
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();

//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();

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,
);
},
);
});
});

0 comments on commit 69818fc

Please sign in to comment.