Skip to content

Commit 1dac0e1

Browse files
committed
test: Enhance Trezor ERC-721 e2e tests with deployment, minting, and approval actions
- Added tests for deploying, minting, and approving ERC-721 tokens using Trezor hardware wallets. - Refactored existing test structure to improve clarity and maintainability. - Integrated smart contract and DApp URL into test fixtures for better configuration. - Ensured proper validation of account balances and transaction confirmations throughout the test cases.
1 parent 736f1f2 commit 1dac0e1

File tree

1 file changed

+221
-87
lines changed

1 file changed

+221
-87
lines changed
Lines changed: 221 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Suite } from 'mocha';
22
import TestDappPage from '../../../page-objects/pages/test-dapp';
33
import FixtureBuilder from '../../../fixture-builder';
4-
import { WINDOW_TITLES, withFixtures } from '../../../helpers';
4+
import { DAPP_URL, WINDOW_TITLES, withFixtures } from '../../../helpers';
55
import { KNOWN_PUBLIC_KEY_ADDRESSES } from '../../../../stub/keyring-bridge';
66
import { loginWithBalanceValidation } from '../../../page-objects/flows/login.flow';
77
import CreateContractModal from '../../../page-objects/pages/dialog/create-contract';
@@ -10,98 +10,232 @@ import HomePage from '../../../page-objects/pages/home/homepage';
1010
import NFTListPage from '../../../page-objects/pages/home/nft-list';
1111
import SetApprovalForAllTransactionConfirmation from '../../../page-objects/pages/confirmations/redesign/set-approval-for-all-transaction-confirmation';
1212
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';
1316

1417
describe('Trezor Hardware', function (this: Suite) {
15-
it('can perform actions on an ERC-721 token', async function () {
16-
await withFixtures(
17-
{
18-
fixtures: new FixtureBuilder()
19-
.withTrezorAccount()
20-
.withPermissionControllerConnectedToTestDapp({
21-
account: KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
22-
})
23-
.build(),
24-
title: this.test?.fullTitle(),
25-
dapp: true,
26-
},
27-
async ({ driver, localNodes }) => {
28-
(await localNodes?.[0]?.setAccountBalance(
29-
KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
30-
'0x100000000000000000000',
31-
)) ?? console.error('localNodes is undefined or empty');
32-
await loginWithBalanceValidation(
18+
const smartContract = SMART_CONTRACTS.NFTS;
19+
20+
describe('can perform actions on an ERC-721 token', function () {
21+
it('deploys an ERC-721 token', async function () {
22+
await withFixtures(
23+
{
24+
fixtures: new FixtureBuilder()
25+
.withTrezorAccount()
26+
.withPermissionControllerConnectedToTestDapp({
27+
account: KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
28+
})
29+
.build(),
30+
title: this.test?.fullTitle(),
31+
smartContract,
32+
dapp: true,
33+
},
34+
async ({ driver, localNodes }) => {
35+
await localNodes?.[0]?.setAccountBalance(
36+
KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
37+
'0x100000000000000000000',
38+
);
39+
await loginWithBalanceValidation(
40+
driver,
41+
undefined,
42+
undefined,
43+
'1208925.8196',
44+
);
45+
46+
// deploy action
47+
const testDappPage = new TestDappPage(driver);
48+
await testDappPage.openTestDappPage();
49+
await testDappPage.checkPageIsLoaded();
50+
await testDappPage.clickERC721DeployButton();
51+
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
52+
const createContractModal = new CreateContractModal(driver);
53+
await createContractModal.checkPageIsLoaded();
54+
await createContractModal.clickConfirm();
55+
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
56+
await testDappPage.checkERC721TokenAddressesValue(
57+
'0xcB17707e0623251182A654BEdaE16429C78A7424',
58+
);
59+
},
60+
);
61+
});
62+
63+
it('mints an ERC-721 token', async function () {
64+
await withFixtures(
65+
{
66+
fixtures: new FixtureBuilder()
67+
.withTrezorAccount()
68+
.withPermissionControllerConnectedToTestDapp({
69+
account: KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
70+
})
71+
.build(),
72+
title: this.test?.fullTitle(),
73+
smartContract,
74+
dapp: true,
75+
},
76+
async ({
77+
driver,
78+
localNodes,
79+
contractRegistry,
80+
}: TestSuiteArguments) => {
81+
await localNodes?.[0]?.setAccountBalance(
82+
KNOWN_PUBLIC_KEY_ADDRESSES[0].address as `0x${string}`,
83+
'0x100000000000000000000',
84+
);
85+
await loginWithBalanceValidation(
86+
driver,
87+
undefined,
88+
undefined,
89+
'1208925.8196',
90+
);
91+
const contractAddress = await (
92+
contractRegistry as ContractAddressRegistry
93+
).getContractAddress(smartContract);
94+
95+
const testDappPage = new TestDappPage(driver);
96+
await testDappPage.openTestDappPage({
97+
contractAddress,
98+
url: DAPP_URL,
99+
});
100+
await testDappPage.checkPageIsLoaded();
101+
102+
await testDappPage.clickERC721MintButton();
103+
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
104+
const mintConfirmation = new TransactionConfirmation(driver);
105+
await mintConfirmation.clickFooterConfirmButton();
106+
await driver.switchToWindowWithTitle(
107+
WINDOW_TITLES.ExtensionInFullScreenView,
108+
);
109+
const homePage = new HomePage(driver);
110+
await homePage.goToNftTab();
111+
const nftListPage = new NFTListPage(driver);
112+
// Check that NFT image is displayed in NFT tab on homepagexp
113+
await nftListPage.checkNftImageIsDisplayed();
114+
await homePage.goToActivityList();
115+
const activityListPage = new ActivityListPage(driver);
116+
await activityListPage.checkTransactionActivityByText('Deposit');
117+
await activityListPage.checkWaitForTransactionStatus('confirmed');
118+
},
119+
);
120+
});
121+
122+
it('approves an ERC-721 token', async function () {
123+
await withFixtures(
124+
{
125+
fixtures: new FixtureBuilder()
126+
.withTrezorAccount()
127+
.withPermissionControllerConnectedToTestDapp({
128+
account: KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
129+
})
130+
.build(),
131+
title: this.test?.fullTitle(),
132+
smartContract,
133+
dapp: true,
134+
},
135+
async ({
33136
driver,
34-
undefined,
35-
undefined,
36-
'1208925.8196',
37-
);
137+
localNodes,
138+
contractRegistry,
139+
}: TestSuiteArguments) => {
140+
await localNodes?.[0]?.setAccountBalance(
141+
KNOWN_PUBLIC_KEY_ADDRESSES[0].address as `0x${string}`,
142+
'0x100000000000000000000',
143+
);
144+
await loginWithBalanceValidation(
145+
driver,
146+
undefined,
147+
undefined,
148+
'1208925.8196',
149+
);
150+
const contractAddress = await (
151+
contractRegistry as ContractAddressRegistry
152+
).getContractAddress(smartContract);
153+
154+
const testDappPage = new TestDappPage(driver);
155+
await testDappPage.openTestDappPage({
156+
contractAddress,
157+
url: DAPP_URL,
158+
});
159+
await testDappPage.checkPageIsLoaded();
38160

39-
// deploy action
40-
const testDappPage = new TestDappPage(driver);
41-
await testDappPage.openTestDappPage();
42-
await testDappPage.checkPageIsLoaded();
43-
await testDappPage.clickERC721DeployButton();
44-
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
45-
const createContractModal = new CreateContractModal(driver);
46-
await createContractModal.checkPageIsLoaded();
47-
await createContractModal.clickConfirm();
48-
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
49-
await testDappPage.checkERC721TokenAddressesValue(
50-
'0xcB17707e0623251182A654BEdaE16429C78A7424',
51-
);
161+
await testDappPage.clickERC721ApproveButton();
162+
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
163+
const approveConfirmation = new TransactionConfirmation(driver);
164+
await approveConfirmation.clickFooterConfirmButton();
165+
await driver.switchToWindowWithTitle(
166+
WINDOW_TITLES.ExtensionInFullScreenView,
167+
);
52168

53-
// mint action
54-
await testDappPage.clickERC721MintButton();
55-
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
56-
const mintConfirmation = new TransactionConfirmation(driver);
57-
await mintConfirmation.clickFooterConfirmButton();
58-
await driver.switchToWindowWithTitle(
59-
WINDOW_TITLES.ExtensionInFullScreenView,
60-
);
61-
const homePage = new HomePage(driver);
62-
await homePage.goToNftTab();
63-
const nftListPage = new NFTListPage(driver);
64-
// Check that NFT image is displayed in NFT tab on homepagexp
65-
await nftListPage.checkNftImageIsDisplayed();
66-
await homePage.goToActivityList();
67-
const activityListPage = new ActivityListPage(driver);
68-
await activityListPage.checkTransactionActivityByText('Deposit');
69-
await activityListPage.checkWaitForTransactionStatus('confirmed');
169+
const homePage = new HomePage(driver);
170+
const activityListPage = new ActivityListPage(driver);
171+
await homePage.goToActivityList();
172+
await activityListPage.checkTransactionActivityByText(
173+
'Approve TDN spending cap',
174+
);
175+
await activityListPage.checkWaitForTransactionStatus('confirmed');
176+
},
177+
);
178+
});
179+
180+
it('sets approval for all an ERC-721 token', async function () {
181+
await withFixtures(
182+
{
183+
fixtures: new FixtureBuilder()
184+
.withTrezorAccount()
185+
.withPermissionControllerConnectedToTestDapp({
186+
account: KNOWN_PUBLIC_KEY_ADDRESSES[0].address as `0x${string}`,
187+
})
188+
.build(),
189+
title: this.test?.fullTitle(),
190+
smartContract,
191+
dapp: true,
192+
},
193+
async ({
194+
driver,
195+
localNodes,
196+
contractRegistry,
197+
}: TestSuiteArguments) => {
198+
await localNodes?.[0]?.setAccountBalance(
199+
KNOWN_PUBLIC_KEY_ADDRESSES[0].address as `0x${string}`,
200+
'0x100000000000000000000',
201+
);
202+
await loginWithBalanceValidation(
203+
driver,
204+
undefined,
205+
undefined,
206+
'1208925.8196',
207+
);
208+
const contractAddress = await (
209+
contractRegistry as ContractAddressRegistry
210+
).getContractAddress(smartContract);
211+
const testDappPage = new TestDappPage(driver);
212+
await testDappPage.openTestDappPage({
213+
contractAddress,
214+
url: DAPP_URL,
215+
});
216+
await testDappPage.checkPageIsLoaded();
70217

71-
// approve action
72-
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
73-
await testDappPage.clickERC721ApproveButton();
74-
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
75-
const approveConfirmation = new TransactionConfirmation(driver);
76-
await approveConfirmation.clickFooterConfirmButton();
77-
await driver.switchToWindowWithTitle(
78-
WINDOW_TITLES.ExtensionInFullScreenView,
79-
);
80-
await homePage.goToActivityList();
81-
await activityListPage.checkTransactionActivityByText(
82-
'Approve TDN spending cap',
83-
);
84-
await activityListPage.checkWaitForTransactionStatus('confirmed');
218+
await testDappPage.clickERC721SetApprovalForAllButton();
219+
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
220+
const setApprovalForAllConfirmation =
221+
new SetApprovalForAllTransactionConfirmation(driver);
222+
await setApprovalForAllConfirmation.checkSetApprovalForAllTitle();
223+
await setApprovalForAllConfirmation.checkSetApprovalForAllSubHeading();
224+
await setApprovalForAllConfirmation.clickScrollToBottomButton();
225+
await setApprovalForAllConfirmation.clickFooterConfirmButton();
226+
await driver.switchToWindowWithTitle(
227+
WINDOW_TITLES.ExtensionInFullScreenView,
228+
);
85229

86-
// set approval for all
87-
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
88-
await testDappPage.clickERC721SetApprovalForAllButton();
89-
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
90-
const setApprovalForAllConfirmation =
91-
new SetApprovalForAllTransactionConfirmation(driver);
92-
await setApprovalForAllConfirmation.checkSetApprovalForAllTitle();
93-
await setApprovalForAllConfirmation.checkSetApprovalForAllSubHeading();
94-
await setApprovalForAllConfirmation.clickScrollToBottomButton();
95-
await setApprovalForAllConfirmation.clickFooterConfirmButton();
96-
await driver.switchToWindowWithTitle(
97-
WINDOW_TITLES.ExtensionInFullScreenView,
98-
);
99-
await homePage.goToActivityList();
100-
await activityListPage.checkTransactionActivityByText(
101-
'Approve TDN with no spend limit',
102-
);
103-
await activityListPage.checkWaitForTransactionStatus('confirmed');
104-
},
105-
);
230+
const homePage = new HomePage(driver);
231+
const activityListPage = new ActivityListPage(driver);
232+
await homePage.goToActivityList();
233+
await activityListPage.checkTransactionActivityByText(
234+
'Approve TDN with no spend limit',
235+
);
236+
await activityListPage.checkWaitForTransactionStatus('confirmed');
237+
},
238+
);
239+
});
106240
});
107241
});

0 commit comments

Comments
 (0)