Skip to content

Commit

Permalink
test: erc 1155 batch transfer (#12800)
Browse files Browse the repository at this point in the history
## **Description**

This PR is within the scope of the Quality Quest.

We're including an e2e test case to check the batch transfer for ERC1155
in test dApp.

**Steps:**
Given I am on the test dapp
When I tap on the batch transfer button in the ERC-1155 section
Then the contract bottom sheet should appear
When I submit the transaction
Then the transaction should appear in the transaction history

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

### **Before**

### **After**

## **Pre-merge author checklist**

- [✓] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [✓] I've completed the PR template to the best of my ability
- [✓] I’ve included tests if applicable
- [✓] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [✓] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
C-Ivan authored Dec 20, 2024
1 parent c87ac20 commit c7eee9c
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
8 changes: 8 additions & 0 deletions e2e/pages/Browser/ContractApprovalBottomSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class ContractApprovalBottomSheet {
);
}

get confirmButton() {
return Matchers.getElementByText(ContractApprovalBottomSheetSelectorsText.CONFIRM);
}

async tapAddNickName() {
await Gestures.waitAndTap(this.addNickName);
}
Expand All @@ -63,6 +67,10 @@ class ContractApprovalBottomSheet {
await Gestures.waitAndTap(this.approveButton);
}

async tapConfirmButton() {
await Gestures.waitAndTap(this.confirmButton);
}

async tapToCopyContractAddress() {
await Gestures.waitAndTap(this.contractAddress);
}
Expand Down
11 changes: 11 additions & 0 deletions e2e/pages/Browser/TestDApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ class TestDApp {
);
}

get erc1155BatchTransferButton() {
return Matchers.getElementByWebID(
BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID,
TestDappSelectorsWebIDs.BATCH_TRANSFER_ERC1155_BUTTON_ID,
);
}

async connect() {
await this.tapButton(this.DappConnectButton);
}
Expand Down Expand Up @@ -181,6 +188,10 @@ class TestDApp {
await Gestures.tap(this.approveButtonText, 0);
}

async tapERC1155BatchTransferButton() {
await this.tapButton(this.erc1155BatchTransferButton);
}

async tapButton(elementId) {
await Gestures.scrollToWebViewPort(elementId);
await Gestures.tapWebElement(elementId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const ContractApprovalBottomSheetSelectorsText = {
APPROVE: enContent.transactions.tx_review_approve,
REJECT: enContent.transaction.reject,
NEXT: enContent.transaction.next,
CONFIRM: enContent.transaction.confirm,
};

export const ContractApprovalBottomSheetSelectorsIDs = {
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 @@ -13,4 +13,5 @@ export const TestDappSelectorsWebIDs = {
SIGN_TYPE_DATA_V4: 'signTypedDataV4',
ETHEREUM_SIGN: 'siwe',
ADD_TOKENS_TO_WALLET_BUTTON: 'watchAssets',
BATCH_TRANSFER_ERC1155_BUTTON_ID: 'batchTransferFromButton',
};
73 changes: 73 additions & 0 deletions e2e/specs/confirmations/batch-transfer-erc1155.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'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';
import { ContractApprovalBottomSheetSelectorsText } from '../../selectors/Browser/ContractApprovalBottomSheet.selectors';
import ContractApprovalBottomSheet from '../../pages/Browser/ContractApprovalBottomSheet';

describe(SmokeConfirmations('ERC1155 token'), () => {
const ERC1155_CONTRACT = SMART_CONTRACTS.ERC1155;

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

it('batch transfer ERC1155 tokens', async () => {
await withFixtures(
{
dapp: true,
fixture: new FixtureBuilder()
.withGanacheNetwork()
.withPermissionControllerConnectedToTestDapp()
.build(),
restartDevice: true,
ganacheOptions: defaultGanacheOptions,
smartContract: ERC1155_CONTRACT,
},
async ({ contractRegistry }) => {
const erc1155Address = await contractRegistry.getContractAddress(
ERC1155_CONTRACT,
);
await loginToApp();

// Navigate to the browser screen
await TabBarComponent.tapBrowser();
await TestDApp.navigateToTestDappWithContract({
contractAddress: erc1155Address,
});

// Send batch transfer for ERC1155 tokens
await TestDApp.tapERC1155BatchTransferButton();
await Assertions.checkIfTextIsDisplayed(
ContractApprovalBottomSheetSelectorsText.CONFIRM,
);

// Tap confirm button
await ContractApprovalBottomSheet.tapConfirmButton();

// Navigate to the activity screen
await TabBarComponent.tapActivity();

// Assert that the ERC1155 activity is an smart contract interaction and it is confirmed
await Assertions.checkIfTextIsDisplayed(
ActivitiesViewSelectorsText.SMART_CONTRACT_INTERACTION,
);
await Assertions.checkIfTextIsDisplayed(
ActivitiesViewSelectorsText.CONFIRM_TEXT,
);
},
);
});
});

0 comments on commit c7eee9c

Please sign in to comment.