2022-08-09 15:59:20 +02:00
|
|
|
const { strict: assert } = require('assert');
|
2022-09-27 17:51:46 +02:00
|
|
|
const { convertToHexValue, withFixtures } = require('../helpers');
|
2022-08-09 15:59:20 +02:00
|
|
|
const { SMART_CONTRACTS } = require('../seeder/smart-contracts');
|
2022-10-28 10:42:12 +02:00
|
|
|
const FixtureBuilder = require('../fixture-builder');
|
2022-08-09 15:59:20 +02:00
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
describe('ERC1155 NFTs testdapp interaction', function () {
|
|
|
|
const smartContract = SMART_CONTRACTS.ERC1155;
|
2022-08-09 15:59:20 +02:00
|
|
|
const ganacheOptions = {
|
|
|
|
accounts: [
|
|
|
|
{
|
|
|
|
secretKey:
|
|
|
|
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
|
|
|
|
balance: convertToHexValue(25000000000000000000),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2023-03-10 15:04:45 +01:00
|
|
|
|
|
|
|
it('should mint ERC1155 token', async function () {
|
2022-08-09 15:59:20 +02:00
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
dapp: true,
|
2022-10-28 10:42:12 +02:00
|
|
|
fixtures: new FixtureBuilder()
|
|
|
|
.withPermissionControllerConnectedToTestDapp()
|
|
|
|
.build(),
|
2022-08-09 15:59:20 +02:00
|
|
|
ganacheOptions,
|
|
|
|
smartContract,
|
|
|
|
title: this.test.title,
|
|
|
|
failOnConsoleError: false,
|
|
|
|
},
|
|
|
|
async ({ driver, _, contractRegistry }) => {
|
|
|
|
const contract = contractRegistry.getContractAddress(smartContract);
|
|
|
|
await driver.navigate();
|
|
|
|
await driver.fill('#password', 'correct horse battery staple');
|
|
|
|
await driver.press('#password', driver.Key.ENTER);
|
|
|
|
|
2022-09-27 17:51:46 +02:00
|
|
|
// Open Dapp and wait for deployed contract
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`);
|
2022-09-27 17:51:46 +02:00
|
|
|
await driver.findClickableElement('#deployButton');
|
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
// Mint
|
|
|
|
await driver.fill('#batchMintTokenIds', '1, 2, 3');
|
|
|
|
await driver.fill('#batchMintIdAmounts', '1, 1, 1000000000000000');
|
|
|
|
await driver.clickElement('#batchMintButton');
|
|
|
|
|
|
|
|
// Notification
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.waitUntilXWindowHandles(3);
|
|
|
|
const windowHandles = await driver.getAllWindowHandles();
|
2022-09-27 17:51:46 +02:00
|
|
|
const [extension] = windowHandles;
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.switchToWindowWithTitle(
|
|
|
|
'MetaMask Notification',
|
|
|
|
windowHandles,
|
|
|
|
);
|
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
// Confirm Mint
|
2023-03-13 15:31:14 +01:00
|
|
|
await driver.waitForSelector({
|
|
|
|
css: '.confirm-page-container-summary__action__name',
|
|
|
|
text: 'Deposit',
|
|
|
|
});
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.clickElement({ text: 'Confirm', tag: 'button' });
|
|
|
|
await driver.waitUntilXWindowHandles(2);
|
|
|
|
await driver.switchToWindow(extension);
|
|
|
|
await driver.clickElement('[data-testid="home__activity-tab"]');
|
2023-03-10 15:04:45 +01:00
|
|
|
const transactionItem = await driver.waitForSelector({
|
|
|
|
css: '.list-item__title',
|
|
|
|
text: 'Deposit',
|
|
|
|
});
|
|
|
|
assert.equal(
|
|
|
|
await transactionItem.isDisplayed(),
|
|
|
|
true,
|
|
|
|
`transaction item should be displayed in activity tab`,
|
2022-08-09 15:59:20 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2023-03-10 15:04:45 +01:00
|
|
|
|
|
|
|
it('should batch transfers ERC1155 token', async function () {
|
2022-08-09 15:59:20 +02:00
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
dapp: true,
|
2022-10-28 10:42:12 +02:00
|
|
|
fixtures: new FixtureBuilder()
|
|
|
|
.withPermissionControllerConnectedToTestDapp()
|
|
|
|
.build(),
|
2022-08-09 15:59:20 +02:00
|
|
|
ganacheOptions,
|
|
|
|
smartContract,
|
|
|
|
title: this.test.title,
|
|
|
|
failOnConsoleError: false,
|
|
|
|
},
|
|
|
|
async ({ driver, _, contractRegistry }) => {
|
|
|
|
const contract = contractRegistry.getContractAddress(smartContract);
|
|
|
|
await driver.navigate();
|
|
|
|
await driver.fill('#password', 'correct horse battery staple');
|
|
|
|
await driver.press('#password', driver.Key.ENTER);
|
|
|
|
|
|
|
|
await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`);
|
2022-09-27 17:51:46 +02:00
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
await driver.fill('#batchTransferTokenIds', '1, 2, 3');
|
|
|
|
await driver.fill('#batchTransferTokenAmounts', '1, 1, 1000000000000');
|
|
|
|
await driver.clickElement('#batchTransferFromButton');
|
|
|
|
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.waitUntilXWindowHandles(3);
|
|
|
|
const windowHandles = await driver.getAllWindowHandles();
|
2022-09-27 17:51:46 +02:00
|
|
|
const [extension] = windowHandles;
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.switchToWindowWithTitle(
|
|
|
|
'MetaMask Notification',
|
|
|
|
windowHandles,
|
|
|
|
);
|
|
|
|
|
2023-03-13 15:31:14 +01:00
|
|
|
// Confirm Transfer
|
|
|
|
await driver.waitForSelector({
|
|
|
|
css: '.confirm-page-container-summary__action__name',
|
|
|
|
text: 'Deposit',
|
|
|
|
});
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.clickElement({ text: 'Confirm', tag: 'button' });
|
|
|
|
await driver.waitUntilXWindowHandles(2);
|
|
|
|
await driver.switchToWindow(extension);
|
|
|
|
await driver.clickElement('[data-testid="home__activity-tab"]');
|
2023-03-10 15:04:45 +01:00
|
|
|
const transactionItem = await driver.waitForSelector({
|
|
|
|
css: '.list-item__title',
|
|
|
|
text: 'Deposit',
|
|
|
|
});
|
|
|
|
assert.equal(
|
|
|
|
await transactionItem.isDisplayed(),
|
|
|
|
true,
|
|
|
|
`transaction item should be displayed in activity tab`,
|
2022-08-09 15:59:20 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2023-03-10 15:04:45 +01:00
|
|
|
|
|
|
|
it('should enable approval for a third party address to manage all ERC1155 token', async function () {
|
|
|
|
const expectedMessageTitle =
|
2023-03-20 18:05:48 +01:00
|
|
|
'Allow access to and transfer all of your NFTs from this collection?';
|
2023-03-10 15:04:45 +01:00
|
|
|
const expectedDescription =
|
2023-03-20 18:05:48 +01:00
|
|
|
'This allows a third party to access and transfer all of your NFTs from this collection without further notice until you revoke its access.';
|
2023-03-10 15:04:45 +01:00
|
|
|
const expectedWarningMessage = 'Your NFT may be at risk';
|
2022-08-09 15:59:20 +02:00
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
dapp: true,
|
2022-10-28 10:42:12 +02:00
|
|
|
fixtures: new FixtureBuilder()
|
|
|
|
.withPermissionControllerConnectedToTestDapp()
|
|
|
|
.build(),
|
2022-08-09 15:59:20 +02:00
|
|
|
ganacheOptions,
|
|
|
|
smartContract,
|
|
|
|
title: this.test.title,
|
|
|
|
},
|
|
|
|
async ({ driver, _, contractRegistry }) => {
|
|
|
|
const contract = contractRegistry.getContractAddress(smartContract);
|
|
|
|
await driver.navigate();
|
|
|
|
await driver.fill('#password', 'correct horse battery staple');
|
|
|
|
await driver.press('#password', driver.Key.ENTER);
|
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
// Create a set approval for all erc1155 token request in test dapp
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`);
|
2023-03-10 15:04:45 +01:00
|
|
|
await driver.clickElement('#setApprovalForAllERC1155Button');
|
2022-09-27 17:51:46 +02:00
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
// Wait for notification popup and check the displayed message
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.waitUntilXWindowHandles(3);
|
2023-03-10 15:04:45 +01:00
|
|
|
let windowHandles = await driver.getAllWindowHandles();
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.switchToWindowWithTitle(
|
|
|
|
'MetaMask Notification',
|
|
|
|
windowHandles,
|
|
|
|
);
|
2023-03-10 15:04:45 +01:00
|
|
|
const displayedMessageTitle = await driver.findElement(
|
2022-08-09 15:59:20 +02:00
|
|
|
'[data-testid="confirm-approve-title"]',
|
|
|
|
);
|
2023-03-10 15:04:45 +01:00
|
|
|
assert.equal(
|
|
|
|
await displayedMessageTitle.getText(),
|
|
|
|
expectedMessageTitle,
|
|
|
|
);
|
|
|
|
const displayedUrl = await driver.findElement(
|
|
|
|
'.confirm-approve-content h6',
|
|
|
|
);
|
|
|
|
assert.equal(await displayedUrl.getText(), 'http://127.0.0.1:8080');
|
|
|
|
const displayedDescription = await driver.findElement(
|
|
|
|
'.confirm-approve-content__description',
|
|
|
|
);
|
|
|
|
assert.equal(await displayedDescription.getText(), expectedDescription);
|
|
|
|
|
|
|
|
// Check displayed transaction details
|
2022-09-06 15:36:02 +02:00
|
|
|
await driver.clickElement({
|
|
|
|
text: 'View full transaction details',
|
|
|
|
css: '.confirm-approve-content__small-blue-text',
|
|
|
|
});
|
2022-09-27 17:51:46 +02:00
|
|
|
const [func, params] = await driver.findElements(
|
2022-08-09 15:59:20 +02:00
|
|
|
'.confirm-approve-content__data .confirm-approve-content__small-text',
|
|
|
|
);
|
2022-09-27 17:51:46 +02:00
|
|
|
assert.equal(await func.getText(), 'Function: SetApprovalForAll');
|
|
|
|
assert.equal(await params.getText(), 'Parameters: true');
|
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
// 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);
|
2022-12-06 21:24:07 +01:00
|
|
|
await driver.clickElement({ text: 'Approve', tag: 'button' });
|
2022-09-27 17:51:46 +02:00
|
|
|
await driver.waitUntilXWindowHandles(2);
|
2023-03-10 15:04:45 +01:00
|
|
|
|
|
|
|
// Switch to extension and check set approval for all transaction is displayed in activity tab
|
|
|
|
windowHandles = await driver.getAllWindowHandles();
|
|
|
|
await driver.switchToWindowWithTitle('MetaMask', windowHandles);
|
2022-09-27 17:51:46 +02:00
|
|
|
await driver.clickElement('[data-testid="home__activity-tab"]');
|
2023-03-10 15:04:45 +01:00
|
|
|
const setApprovalItem = await driver.findElement({
|
|
|
|
css: '.transaction-list__completed-transactions',
|
|
|
|
text: 'Approve Token with no spend limit',
|
|
|
|
});
|
|
|
|
assert.equal(await setApprovalItem.isDisplayed(), true);
|
2022-09-27 17:51:46 +02:00
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
// Switch back to the dapp and verify that set approval for all action completed message is displayed
|
|
|
|
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
|
|
|
|
const setApprovalStatus = await driver.findElement({
|
|
|
|
css: '#erc1155Status',
|
|
|
|
text: 'Set Approval For All completed',
|
|
|
|
});
|
|
|
|
assert.equal(await setApprovalStatus.isDisplayed(), true);
|
2022-09-27 17:51:46 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2023-03-10 15:04:45 +01:00
|
|
|
|
|
|
|
it('should revoke approval for a third party address to manage all ERC1155 token', async function () {
|
|
|
|
const expectedMessageTitle =
|
2023-03-20 18:05:48 +01:00
|
|
|
'Revoke permission to access and transfer all of your NFTs from this collection?';
|
2023-03-10 15:04:45 +01:00
|
|
|
const expectedDescription =
|
2023-03-20 18:05:48 +01:00
|
|
|
'This revokes the permission for a third party to access and transfer all of your NFTs from this collection without further notice.';
|
2022-09-27 17:51:46 +02:00
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
dapp: true,
|
2022-10-28 10:42:12 +02:00
|
|
|
fixtures: new FixtureBuilder()
|
|
|
|
.withPermissionControllerConnectedToTestDapp()
|
|
|
|
.build(),
|
2022-09-27 17:51:46 +02:00
|
|
|
ganacheOptions,
|
|
|
|
smartContract,
|
|
|
|
title: this.test.title,
|
|
|
|
},
|
|
|
|
async ({ driver, _, contractRegistry }) => {
|
|
|
|
const contract = contractRegistry.getContractAddress(smartContract);
|
|
|
|
await driver.navigate();
|
|
|
|
await driver.fill('#password', 'correct horse battery staple');
|
|
|
|
await driver.press('#password', driver.Key.ENTER);
|
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
// Create a revoke approval for all erc1155 token request in test dapp
|
2022-09-27 17:51:46 +02:00
|
|
|
await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`);
|
2023-03-10 15:04:45 +01:00
|
|
|
await driver.clickElement('#revokeERC1155Button');
|
2022-09-27 17:51:46 +02:00
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
// Wait for notification popup and check the displayed message
|
2022-09-27 17:51:46 +02:00
|
|
|
await driver.waitUntilXWindowHandles(3);
|
2023-03-10 15:04:45 +01:00
|
|
|
let windowHandles = await driver.getAllWindowHandles();
|
2022-09-27 17:51:46 +02:00
|
|
|
await driver.switchToWindowWithTitle(
|
|
|
|
'MetaMask Notification',
|
|
|
|
windowHandles,
|
|
|
|
);
|
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
const displayedMessageTitle = await driver.findElement(
|
|
|
|
'.confirm-approve-content__title',
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
await displayedMessageTitle.getText(),
|
|
|
|
expectedMessageTitle,
|
|
|
|
);
|
|
|
|
const displayedUrl = await driver.findElement(
|
|
|
|
'.confirm-approve-content h6',
|
2022-09-27 17:51:46 +02:00
|
|
|
);
|
2023-03-10 15:04:45 +01:00
|
|
|
assert.equal(await displayedUrl.getText(), 'http://127.0.0.1:8080');
|
|
|
|
const displayedDescription = await driver.findElement(
|
|
|
|
'.confirm-approve-content__description',
|
|
|
|
);
|
|
|
|
assert.equal(await displayedDescription.getText(), expectedDescription);
|
|
|
|
|
|
|
|
// Check displayed transaction details
|
2022-09-27 17:51:46 +02:00
|
|
|
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');
|
2022-12-06 21:24:07 +01:00
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
// Click on extension popup to confirm revoke approval for all
|
|
|
|
await driver.clickElement('[data-testid="page-container-footer-next"]');
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.waitUntilXWindowHandles(2);
|
2023-03-10 15:04:45 +01:00
|
|
|
|
|
|
|
// Switch to extension and check revoke approval transaction is displayed in activity tab
|
|
|
|
windowHandles = await driver.getAllWindowHandles();
|
|
|
|
await driver.switchToWindowWithTitle('MetaMask', windowHandles);
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.clickElement('[data-testid="home__activity-tab"]');
|
2023-03-10 15:04:45 +01:00
|
|
|
const revokeApprovalItem = await driver.findElement({
|
|
|
|
css: '.transaction-list__completed-transactions',
|
|
|
|
text: 'Approve Token with no spend limit',
|
|
|
|
});
|
|
|
|
assert.equal(await revokeApprovalItem.isDisplayed(), true);
|
2022-08-09 15:59:20 +02:00
|
|
|
|
2023-03-10 15:04:45 +01:00
|
|
|
// Switch back to the dapp and verify that revoke approval for all message is displayed
|
|
|
|
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
|
|
|
|
const revokeApprovalStatus = await driver.findElement({
|
|
|
|
css: '#erc1155Status',
|
|
|
|
text: 'Revoke completed',
|
|
|
|
});
|
|
|
|
assert.equal(await revokeApprovalStatus.isDisplayed(), true);
|
2022-08-09 15:59:20 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|