-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
erc1155-interaction.spec.js
318 lines (284 loc) · 11.6 KB
/
erc1155-interaction.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
const { strict: assert } = require('assert');
const { mockNetworkStateOld } = require('../../../../stub/networks');
const {
withFixtures,
DAPP_URL,
openDapp,
unlockWallet,
WINDOW_TITLES,
defaultGanacheOptions,
} = require('../../../helpers');
const { SMART_CONTRACTS } = require('../../../seeder/smart-contracts');
const FixtureBuilder = require('../../../fixture-builder');
describe('ERC1155 NFTs testdapp interaction', function () {
const smartContract = SMART_CONTRACTS.ERC1155;
it('should mint ERC1155 token', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withNetworkController(
mockNetworkStateOld({
chainId: '0x539',
nickname: 'Localhost 8545',
rpcUrl: 'http://localhost:8545',
ticker: 'ETH',
blockExplorerUrl: 'https://etherscan.io/',
}),
)
.build(),
ganacheOptions: defaultGanacheOptions,
smartContract,
title: this.test.fullTitle(),
},
async ({ driver, _, contractRegistry }) => {
const contract = contractRegistry.getContractAddress(smartContract);
await unlockWallet(driver);
// Open Dapp and wait for deployed contract
await openDapp(driver, contract);
await driver.findClickableElement('#deployButton');
// Mint
await driver.fill('#batchMintTokenIds', '1, 2, 3');
await driver.fill('#batchMintIdAmounts', '1, 1, 1000000000000000');
await driver.clickElement('#batchMintButton');
// Notification
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
// Confirm Mint
await driver.waitForSelector({
css: '.confirm-page-container-summary__action__name',
text: 'Deposit',
});
await driver.clickElementAndWaitForWindowToClose({
text: 'Confirm',
tag: 'button',
});
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await driver.clickElement(
'[data-testid="account-overview__activity-tab"]',
);
await driver.waitForSelector({
css: '[data-testid="activity-list-item-action"]',
text: 'Deposit',
});
await driver.clickElement('[data-testid="activity-list-item-action"]');
await driver.clickElement({
text: 'View on block explorer',
tag: 'a',
});
// Switch to block explorer
await driver.switchToWindowWithTitle('E2E Test Page');
await driver.findElement('[data-testid="empty-page-body"]');
// Verify block explorer
await driver.waitForUrl({
url: 'https://etherscan.io/tx/0xfe4428397f7913875783c5c0dad182937b596148295bc33c7f08d74fdee8897f',
});
// switch to Dapp
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.fill('#watchAssetInput', '1');
await driver.clickElement('#watchAssetButton');
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElementAndWaitForWindowToClose(
'[data-testid="page-container-footer-next"]',
);
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await driver.clickElementSafe('[data-testid="popover-close"]');
await driver.clickElement('[data-testid="account-overview__nfts-tab"]');
await driver.clickElement('[data-testid="nft-item"]');
},
);
});
it('should batch transfers ERC1155 token', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: defaultGanacheOptions,
smartContract,
title: this.test.fullTitle(),
},
async ({ driver, _, contractRegistry }) => {
const contract = contractRegistry.getContractAddress(smartContract);
await unlockWallet(driver);
await openDapp(driver, contract);
await driver.fill('#batchTransferTokenIds', '1, 2, 3');
await driver.fill('#batchTransferTokenAmounts', '1, 1, 1000000000000');
await driver.clickElement('#batchTransferFromButton');
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
// Confirm Transfer
await driver.waitForSelector({
css: '.confirm-page-container-summary__action__name',
text: 'Deposit',
});
await driver.clickElementAndWaitForWindowToClose({
text: 'Confirm',
tag: 'button',
});
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await driver.clickElement(
'[data-testid="account-overview__activity-tab"]',
);
await driver.waitForSelector({
css: '[data-testid="activity-list-item-action"]',
text: 'Deposit',
});
},
);
});
it('should enable approval for a third party address to manage all ERC1155 token', async function () {
// ERC1155 is the name of the test-dapp ERC1155 contract
const expectedMessageTitle =
'Allow access to and transfer all of your NFTs from ERC1155?';
const expectedDescription =
'This allows a third party to access and transfer all of your NFTs from ERC1155 without further notice until you revoke its access.';
const expectedWarningMessage = 'Your NFT may be at risk';
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: defaultGanacheOptions,
smartContract,
title: this.test.fullTitle(),
},
async ({ driver, _, contractRegistry }) => {
const contract = contractRegistry.getContractAddress(smartContract);
await unlockWallet(driver);
// Create a set approval for all erc1155 token request in test dapp
await openDapp(driver, contract);
await driver.clickElement('#setApprovalForAllERC1155Button');
// Wait for notification popup and check the displayed message
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.waitForSelector({
css: '[data-testid="confirm-approve-title"]',
text: expectedMessageTitle,
});
await driver.waitForSelector({
css: '.confirm-approve-content h6',
text: DAPP_URL,
});
await driver.waitForSelector({
css: '.confirm-approve-content__description',
text: expectedDescription,
});
// Check displayed transaction details
await driver.clickElement({
text: 'View full transaction details',
css: '.confirm-approve-content__small-blue-text',
});
const [func, params] = await driver.findElements(
'.confirm-approve-content__data .confirm-approve-content__small-text',
);
assert.equal(await func.getText(), 'Function: SetApprovalForAll');
assert.equal(await params.getText(), 'Parameters: true');
// Check the warning message and confirm set approval for all
await driver.clickElement('[data-testid="page-container-footer-next"]');
const displayedWarning = await driver.findElement(
'.set-approval-for-all-warning__content__header',
);
assert.equal(await displayedWarning.getText(), expectedWarningMessage);
await driver.clickElementAndWaitForWindowToClose({
text: 'Approve',
tag: 'button',
});
// Switch to extension and check set approval for all transaction is displayed in activity tab
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await driver.clickElement(
'[data-testid="account-overview__activity-tab"]',
);
await driver.waitForSelector({
css: '.transaction-list__completed-transactions',
text: 'Approve Token with no spend limit',
});
// Switch back to the dapp and verify that set approval for all action completed message is displayed
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.waitForSelector({
css: '#erc1155Status',
text: 'Set Approval For All completed',
});
},
);
});
it('should revoke approval for a third party address to manage all ERC1155 token', async function () {
// ERC1155 is the name of the test-dapp ERC1155 contract
const expectedMessageTitle =
'Revoke permission to access and transfer all of your NFTs from ERC1155?';
const expectedDescription =
'This revokes the permission for a third party to access and transfer all of your NFTs from ERC1155 without further notice.';
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: defaultGanacheOptions,
smartContract,
title: this.test.fullTitle(),
},
async ({ driver, _, contractRegistry }) => {
const contract = contractRegistry.getContractAddress(smartContract);
await unlockWallet(driver);
// Create a revoke approval for all erc1155 token request in test dapp
await openDapp(driver, contract);
await driver.clickElement('#revokeERC1155Button');
// Wait for notification popup and check the displayed message
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.waitForSelector({
css: '.confirm-approve-content__title',
text: expectedMessageTitle,
});
await driver.waitForSelector({
css: '.confirm-approve-content h6',
text: DAPP_URL,
});
await driver.waitForSelector({
css: '.confirm-approve-content__description',
text: expectedDescription,
});
// Check displayed transaction details
await driver.clickElement({
text: 'View full transaction details',
css: '.confirm-approve-content__small-blue-text',
});
const [func, params] = await driver.findElements(
'.confirm-approve-content__data .confirm-approve-content__small-text',
);
assert.equal(await func.getText(), 'Function: SetApprovalForAll');
assert.equal(await params.getText(), 'Parameters: false');
// Click on extension popup to confirm revoke approval for all
await driver.clickElementAndWaitForWindowToClose(
'[data-testid="page-container-footer-next"]',
);
// Switch to extension and check revoke approval transaction is displayed in activity tab
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await driver.clickElement(
'[data-testid="account-overview__activity-tab"]',
);
await driver.waitForSelector({
css: '.transaction-list__completed-transactions',
text: 'Approve Token with no spend limit',
});
// Switch back to the dapp and verify that revoke approval for all message is displayed
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
const revokeApprovalStatus = await driver.findElement({
css: '#erc1155Status',
text: 'Revoke completed',
});
assert.equal(await revokeApprovalStatus.isDisplayed(), true);
},
);
});
});