Skip to content

Commit f2fda7a

Browse files
authored
feat: add e2e tests for trezor ERC721 NFT deployment and management. (#35383)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Link to this plan [Trezor ERC712](MetaMask/accounts-planning#968) This PR has implemented a e2e tests for trezor ERC721 NFT deployment and management. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/35383?quickstart=1) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: ## **Related issues** Fixes: MetaMask/accounts-planning#968 ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] 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.
1 parent 469e570 commit f2fda7a

File tree

1 file changed

+247
-0
lines changed

1 file changed

+247
-0
lines changed
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
import { Suite } from 'mocha';
2+
import TestDappPage from '../../../page-objects/pages/test-dapp';
3+
import FixtureBuilder from '../../../fixture-builder';
4+
import { DAPP_URL, WINDOW_TITLES, withFixtures } from '../../../helpers';
5+
import { KNOWN_PUBLIC_KEY_ADDRESSES } from '../../../../stub/keyring-bridge';
6+
import { loginWithBalanceValidation } from '../../../page-objects/flows/login.flow';
7+
import CreateContractModal from '../../../page-objects/pages/dialog/create-contract';
8+
import TransactionConfirmation from '../../../page-objects/pages/confirmations/redesign/transaction-confirmation';
9+
import HomePage from '../../../page-objects/pages/home/homepage';
10+
import NFTListPage from '../../../page-objects/pages/home/nft-list';
11+
import SetApprovalForAllTransactionConfirmation from '../../../page-objects/pages/confirmations/redesign/set-approval-for-all-transaction-confirmation';
12+
import ActivityListPage from '../../../page-objects/pages/home/activity-list';
13+
import { SMART_CONTRACTS } from '../../../seeder/smart-contracts';
14+
import ContractAddressRegistry from '../../../seeder/contract-address-registry';
15+
import { TestSuiteArguments } from '../../confirmations/transactions/shared';
16+
import { Driver } from '../../../webdriver/driver';
17+
18+
describe('Trezor Hardware', function (this: Suite) {
19+
const smartContract = SMART_CONTRACTS.NFTS;
20+
21+
describe('can perform actions on an ERC-721 token', function () {
22+
async function deployContract(testDappPage: TestDappPage, driver: Driver) {
23+
await testDappPage.clickERC721DeployButton();
24+
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
25+
const createContractModal = new CreateContractModal(driver);
26+
await createContractModal.checkPageIsLoaded();
27+
await createContractModal.clickConfirm();
28+
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
29+
await testDappPage.checkERC721TokenAddressesValue(
30+
'0xcB17707e0623251182A654BEdaE16429C78A7424',
31+
);
32+
}
33+
34+
async function mintNft(testDappPage: TestDappPage, driver: Driver) {
35+
await testDappPage.clickERC721MintButton();
36+
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
37+
const mintConfirmation = new TransactionConfirmation(driver);
38+
await mintConfirmation.clickFooterConfirmButton();
39+
await driver.switchToWindowWithTitle(
40+
WINDOW_TITLES.ExtensionInFullScreenView,
41+
);
42+
const homePage = new HomePage(driver);
43+
await homePage.goToNftTab();
44+
const nftListPage = new NFTListPage(driver);
45+
// Check that NFT image is displayed in NFT tab on homepagexp
46+
await nftListPage.checkNftImageIsDisplayed();
47+
await homePage.goToActivityList();
48+
const activityListPage = new ActivityListPage(driver);
49+
await activityListPage.checkTransactionActivityByText('Deposit');
50+
await activityListPage.checkWaitForTransactionStatus('confirmed');
51+
}
52+
53+
it('deploys an ERC-721 token', async function () {
54+
await withFixtures(
55+
{
56+
fixtures: new FixtureBuilder()
57+
.withTrezorAccount()
58+
.withPermissionControllerConnectedToTestDapp({
59+
account: KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
60+
})
61+
.build(),
62+
title: this.test?.fullTitle(),
63+
smartContract,
64+
dapp: true,
65+
},
66+
async ({ driver, localNodes }) => {
67+
await localNodes?.[0]?.setAccountBalance(
68+
KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
69+
'0x100000000000000000000',
70+
);
71+
await loginWithBalanceValidation(
72+
driver,
73+
undefined,
74+
undefined,
75+
'1208925.8196',
76+
);
77+
78+
// deploy action
79+
const testDappPage = new TestDappPage(driver);
80+
await testDappPage.openTestDappPage();
81+
await testDappPage.checkPageIsLoaded();
82+
await deployContract(testDappPage, driver);
83+
},
84+
);
85+
});
86+
87+
it('mints an ERC-721 token', async function () {
88+
await withFixtures(
89+
{
90+
fixtures: new FixtureBuilder()
91+
.withTrezorAccount()
92+
.withPermissionControllerConnectedToTestDapp({
93+
account: KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
94+
})
95+
.build(),
96+
title: this.test?.fullTitle(),
97+
smartContract,
98+
dapp: true,
99+
},
100+
async ({
101+
driver,
102+
localNodes,
103+
contractRegistry,
104+
}: TestSuiteArguments) => {
105+
await localNodes?.[0]?.setAccountBalance(
106+
KNOWN_PUBLIC_KEY_ADDRESSES[0].address as `0x${string}`,
107+
'0x100000000000000000000',
108+
);
109+
await loginWithBalanceValidation(
110+
driver,
111+
undefined,
112+
undefined,
113+
'1208925.8196',
114+
);
115+
116+
const contractAddress = await (
117+
contractRegistry as ContractAddressRegistry
118+
).getContractAddress(smartContract);
119+
120+
const testDappPage = new TestDappPage(driver);
121+
await testDappPage.openTestDappPage({
122+
contractAddress,
123+
url: DAPP_URL,
124+
});
125+
await testDappPage.checkPageIsLoaded();
126+
127+
await mintNft(testDappPage, driver);
128+
},
129+
);
130+
});
131+
132+
it('approves an ERC-721 token', async function () {
133+
// Approve function is difference since caller must be owner of contract,
134+
// so we need to deploy and mint token first to make sure contract belong to caller.
135+
await withFixtures(
136+
{
137+
fixtures: new FixtureBuilder()
138+
.withTrezorAccount()
139+
.withPermissionControllerConnectedToTestDapp({
140+
account: KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
141+
})
142+
.build(),
143+
title: this.test?.fullTitle(),
144+
dapp: true,
145+
},
146+
async ({ driver, localNodes }: TestSuiteArguments) => {
147+
await localNodes?.[0]?.setAccountBalance(
148+
KNOWN_PUBLIC_KEY_ADDRESSES[0].address as `0x${string}`,
149+
'0x100000000000000000000',
150+
);
151+
await loginWithBalanceValidation(
152+
driver,
153+
undefined,
154+
undefined,
155+
'1208925.8196',
156+
);
157+
158+
const testDappPage = new TestDappPage(driver);
159+
await testDappPage.openTestDappPage();
160+
await testDappPage.checkPageIsLoaded();
161+
await deployContract(testDappPage, driver);
162+
163+
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
164+
await mintNft(testDappPage, driver);
165+
166+
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
167+
await testDappPage.clickERC721ApproveButton();
168+
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
169+
const approveConfirmation = new TransactionConfirmation(driver);
170+
await approveConfirmation.clickFooterConfirmButton();
171+
await driver.switchToWindowWithTitle(
172+
WINDOW_TITLES.ExtensionInFullScreenView,
173+
);
174+
175+
const homePage = new HomePage(driver);
176+
const activityListPage = new ActivityListPage(driver);
177+
await homePage.goToActivityList();
178+
await activityListPage.checkTransactionActivityByText(
179+
'Approve TDN spending cap',
180+
);
181+
await activityListPage.checkWaitForTransactionStatus('confirmed');
182+
},
183+
);
184+
});
185+
186+
it('sets approval for all an ERC-721 token', async function () {
187+
await withFixtures(
188+
{
189+
fixtures: new FixtureBuilder()
190+
.withTrezorAccount()
191+
.withPermissionControllerConnectedToTestDapp({
192+
account: KNOWN_PUBLIC_KEY_ADDRESSES[0].address as `0x${string}`,
193+
})
194+
.build(),
195+
title: this.test?.fullTitle(),
196+
smartContract,
197+
dapp: true,
198+
},
199+
async ({
200+
driver,
201+
localNodes,
202+
contractRegistry,
203+
}: TestSuiteArguments) => {
204+
await localNodes?.[0]?.setAccountBalance(
205+
KNOWN_PUBLIC_KEY_ADDRESSES[0].address as `0x${string}`,
206+
'0x100000000000000000000',
207+
);
208+
await loginWithBalanceValidation(
209+
driver,
210+
undefined,
211+
undefined,
212+
'1208925.8196',
213+
);
214+
const contractAddress = await (
215+
contractRegistry as ContractAddressRegistry
216+
).getContractAddress(smartContract);
217+
const testDappPage = new TestDappPage(driver);
218+
await testDappPage.openTestDappPage({
219+
contractAddress,
220+
url: DAPP_URL,
221+
});
222+
await testDappPage.checkPageIsLoaded();
223+
224+
await testDappPage.clickERC721SetApprovalForAllButton();
225+
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
226+
const setApprovalForAllConfirmation =
227+
new SetApprovalForAllTransactionConfirmation(driver);
228+
await setApprovalForAllConfirmation.checkSetApprovalForAllTitle();
229+
await setApprovalForAllConfirmation.checkSetApprovalForAllSubHeading();
230+
await setApprovalForAllConfirmation.clickScrollToBottomButton();
231+
await setApprovalForAllConfirmation.clickFooterConfirmButton();
232+
await driver.switchToWindowWithTitle(
233+
WINDOW_TITLES.ExtensionInFullScreenView,
234+
);
235+
236+
const homePage = new HomePage(driver);
237+
const activityListPage = new ActivityListPage(driver);
238+
await homePage.goToActivityList();
239+
await activityListPage.checkTransactionActivityByText(
240+
'Approve TDN with no spend limit',
241+
);
242+
await activityListPage.checkWaitForTransactionStatus('confirmed');
243+
},
244+
);
245+
});
246+
});
247+
});

0 commit comments

Comments
 (0)