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('ERC721 NFTs testdapp interaction', function () {
|
2023-02-16 20:23:29 +01:00
|
|
|
const smartContract = SMART_CONTRACTS.NFTS;
|
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 transfer a single ERC721 NFT from one account to another', 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');
|
|
|
|
|
|
|
|
// Click Transer
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.fill('#transferTokenInput', '1');
|
|
|
|
await driver.clickElement('#transferFromButton');
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Confirm transfer
|
|
|
|
await driver.waitForSelector({
|
|
|
|
css: '.confirm-page-container-summary__title',
|
|
|
|
text: 'TestDappCollectibles',
|
|
|
|
});
|
|
|
|
await driver.clickElement({ text: 'Confirm', tag: 'button' });
|
|
|
|
await driver.waitUntilXWindowHandles(2);
|
|
|
|
await driver.switchToWindow(extension);
|
|
|
|
await driver.clickElement('[data-testid="home__activity-tab"]');
|
|
|
|
await driver.waitForSelector(
|
|
|
|
'.transaction-list__completed-transactions .transaction-list-item:nth-of-type(1)',
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify transaction
|
2023-04-12 13:51:33 +02:00
|
|
|
await driver.findElement({ text: 'Send TDC' });
|
2022-08-09 15:59:20 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2023-03-10 15:04:45 +01:00
|
|
|
|
|
|
|
it('should approve an address to transfer a single ERC721 NFT', 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');
|
|
|
|
|
|
|
|
// Click Approve
|
2023-03-10 15:04:45 +01:00
|
|
|
const approveInput = await driver.findElement('#approveTokenInput');
|
|
|
|
await approveInput.clear();
|
|
|
|
await approveInput.sendKeys('1');
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.clickElement('#approveButton');
|
2023-03-10 15:04:45 +01:00
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify dialog
|
|
|
|
const title = await driver.findElement(
|
|
|
|
'[data-testid="confirm-approve-title"]',
|
|
|
|
);
|
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] = await driver.findElements(
|
2022-08-09 15:59:20 +02:00
|
|
|
'.confirm-approve-content__data .confirm-approve-content__small-text',
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
await title.getText(),
|
2022-12-05 17:59:15 +01:00
|
|
|
'Allow access to and transfer of your TestDappCollectibles (#1)?',
|
2022-08-09 15:59:20 +02:00
|
|
|
);
|
2022-09-27 17:51:46 +02:00
|
|
|
assert.equal(await func.getText(), 'Function: Approve');
|
2022-08-09 15:59:20 +02:00
|
|
|
|
|
|
|
// Confirm approval
|
|
|
|
await driver.clickElement({ text: 'Confirm', tag: 'button' });
|
|
|
|
await driver.waitUntilXWindowHandles(2);
|
|
|
|
await driver.switchToWindow(extension);
|
|
|
|
await driver.clickElement('[data-testid="home__activity-tab"]');
|
|
|
|
await driver.waitForSelector(
|
|
|
|
'.transaction-list__completed-transactions .transaction-list-item:nth-of-type(1)',
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify transaction
|
2023-03-10 15:04:45 +01:00
|
|
|
const completedTx = await driver.waitForSelector({
|
|
|
|
css: '.list-item__title',
|
|
|
|
text: 'Approve TDC spending cap',
|
|
|
|
});
|
|
|
|
assert.equal(await completedTx.isDisplayed(), true);
|
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 ERC721 NFTs', 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');
|
|
|
|
|
|
|
|
// Enable Set approval for all
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.clickElement('#setApprovalForAllButton');
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify dialog
|
|
|
|
const title = await driver.findElement(
|
|
|
|
'[data-testid="confirm-approve-title"]',
|
|
|
|
);
|
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',
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
await title.getText(),
|
2022-09-06 16:11:13 +02:00
|
|
|
'Allow access to and transfer of all your TestDappCollectibles?',
|
2022-08-09 15:59:20 +02:00
|
|
|
);
|
2022-09-27 17:51:46 +02:00
|
|
|
assert.equal(await func.getText(), 'Function: SetApprovalForAll');
|
|
|
|
assert.equal(await params.getText(), 'Parameters: true');
|
|
|
|
|
|
|
|
// Confirm enabling set approval for all
|
|
|
|
await driver.clickElement({ text: 'Confirm', tag: 'button' });
|
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);
|
|
|
|
await driver.switchToWindow(extension);
|
|
|
|
await driver.clickElement('[data-testid="home__activity-tab"]');
|
|
|
|
await driver.waitForSelector(
|
|
|
|
'.transaction-list__completed-transactions .transaction-list-item:nth-of-type(1)',
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify transaction
|
2023-03-10 15:04:45 +01:00
|
|
|
const completedTx = await driver.waitForSelector({
|
|
|
|
css: '.list-item__title',
|
|
|
|
text: 'Approve TDC with no spend limit',
|
|
|
|
});
|
|
|
|
assert.equal(await completedTx.isDisplayed(), true);
|
2022-09-27 17:51:46 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2023-03-10 15:04:45 +01:00
|
|
|
|
|
|
|
it('should disable approval for a third party address to manage all ERC721 NFTs', async function () {
|
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,
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Open Dapp and wait for deployed contract
|
|
|
|
await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`);
|
|
|
|
await driver.findClickableElement('#deployButton');
|
|
|
|
|
|
|
|
// Disable Set approval for all
|
|
|
|
await driver.clickElement('#revokeButton');
|
|
|
|
await driver.waitUntilXWindowHandles(3);
|
|
|
|
const windowHandles = await driver.getAllWindowHandles();
|
|
|
|
const [extension] = windowHandles;
|
|
|
|
await driver.switchToWindowWithTitle(
|
|
|
|
'MetaMask Notification',
|
|
|
|
windowHandles,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify dialog
|
|
|
|
const title = await driver.findElement(
|
|
|
|
'[data-testid="confirm-approve-title"]',
|
|
|
|
);
|
|
|
|
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',
|
|
|
|
);
|
|
|
|
const proceedWithCautionIsDisplayed = await driver.isElementPresent(
|
|
|
|
'.dialog--error',
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
await title.getText(),
|
2023-01-31 12:27:41 +01:00
|
|
|
'Revoke permission to access and transfer all of your TestDappCollectibles?',
|
2022-09-27 17:51:46 +02:00
|
|
|
);
|
|
|
|
assert.equal(await func.getText(), 'Function: SetApprovalForAll');
|
|
|
|
assert.equal(await params.getText(), 'Parameters: false');
|
|
|
|
assert.equal(proceedWithCautionIsDisplayed, false);
|
2022-08-09 15:59:20 +02:00
|
|
|
|
2022-09-27 17:51:46 +02:00
|
|
|
// Confirm disabling set approval for all
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.clickElement({ text: 'Confirm', tag: 'button' });
|
2022-12-06 21:24:07 +01:00
|
|
|
|
2022-08-09 15:59:20 +02:00
|
|
|
await driver.waitUntilXWindowHandles(2);
|
|
|
|
await driver.switchToWindow(extension);
|
|
|
|
await driver.clickElement('[data-testid="home__activity-tab"]');
|
|
|
|
await driver.waitForSelector(
|
|
|
|
'.transaction-list__completed-transactions .transaction-list-item:nth-of-type(1)',
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify transaction
|
2023-03-10 15:04:45 +01:00
|
|
|
const completedTx = await driver.waitForSelector({
|
|
|
|
css: '.list-item__title',
|
|
|
|
text: 'Approve TDC with no spend limit',
|
|
|
|
});
|
|
|
|
assert.equal(await completedTx.isDisplayed(), true);
|
2022-08-09 15:59:20 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|