From 11c79dd629e5ad6855a3b2f56798da5d2eb3397c Mon Sep 17 00:00:00 2001 From: chloeYue <105063779+chloeYue@users.noreply.github.com> Date: Fri, 10 Mar 2023 15:04:45 +0100 Subject: [PATCH] Add e2e tests approval for all for erc1155 token (#18047) add tests approval for all --- test/e2e/nft/erc1155-interaction.spec.js | 295 ++++++++++++++++++ .../erc721-intercation.spec.js} | 43 ++- test/e2e/tests/erc1155.spec.js | 109 ------- 3 files changed, 323 insertions(+), 124 deletions(-) create mode 100644 test/e2e/nft/erc1155-interaction.spec.js rename test/e2e/{tests/nfts.spec.js => nft/erc721-intercation.spec.js} (89%) delete mode 100644 test/e2e/tests/erc1155.spec.js diff --git a/test/e2e/nft/erc1155-interaction.spec.js b/test/e2e/nft/erc1155-interaction.spec.js new file mode 100644 index 000000000..a1dcde156 --- /dev/null +++ b/test/e2e/nft/erc1155-interaction.spec.js @@ -0,0 +1,295 @@ +const { strict: assert } = require('assert'); +const { convertToHexValue, withFixtures } = 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; + const ganacheOptions = { + accounts: [ + { + secretKey: + '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', + balance: convertToHexValue(25000000000000000000), + }, + ], + }; + + it('should mint ERC1155 token', async function () { + await withFixtures( + { + dapp: true, + fixtures: new FixtureBuilder() + .withPermissionControllerConnectedToTestDapp() + .build(), + 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'); + + // Mint + await driver.fill('#batchMintTokenIds', '1, 2, 3'); + await driver.fill('#batchMintIdAmounts', '1, 1, 1000000000000000'); + await driver.clickElement('#batchMintButton'); + + // Notification + await driver.waitUntilXWindowHandles(3); + const windowHandles = await driver.getAllWindowHandles(); + const [extension] = windowHandles; + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + + // Confirm Mint + await driver.clickElement({ text: 'Confirm', tag: 'button' }); + await driver.waitUntilXWindowHandles(2); + await driver.switchToWindow(extension); + await driver.clickElement('[data-testid="home__activity-tab"]'); + 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`, + ); + }, + ); + }); + + it('should batch transfers ERC1155 token', async function () { + await withFixtures( + { + dapp: true, + fixtures: new FixtureBuilder() + .withPermissionControllerConnectedToTestDapp() + .build(), + 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}`); + + await driver.fill('#batchTransferTokenIds', '1, 2, 3'); + await driver.fill('#batchTransferTokenAmounts', '1, 1, 1000000000000'); + await driver.clickElement('#batchTransferFromButton'); + + await driver.waitUntilXWindowHandles(3); + const windowHandles = await driver.getAllWindowHandles(); + const [extension] = windowHandles; + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + + await driver.clickElement({ text: 'Confirm', tag: 'button' }); + await driver.waitUntilXWindowHandles(2); + await driver.switchToWindow(extension); + await driver.clickElement('[data-testid="home__activity-tab"]'); + 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`, + ); + }, + ); + }); + + it('should enable approval for a third party address to manage all ERC1155 token', async function () { + const expectedMessageTitle = + 'Allow access to and transfer of all your NFT?'; + const expectedDescription = + 'This allows a third party to access and transfer the following NFTs 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, + 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); + + // Create a set approval for all erc1155 token request in test dapp + await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`); + await driver.clickElement('#setApprovalForAllERC1155Button'); + + // Wait for notification popup and check the displayed message + await driver.waitUntilXWindowHandles(3); + let windowHandles = await driver.getAllWindowHandles(); + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + const displayedMessageTitle = await driver.findElement( + '[data-testid="confirm-approve-title"]', + ); + 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 + 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.clickElement({ text: 'Approve', tag: 'button' }); + await driver.waitUntilXWindowHandles(2); + + // Switch to extension and check set approval for all transaction is displayed in activity tab + windowHandles = await driver.getAllWindowHandles(); + await driver.switchToWindowWithTitle('MetaMask', windowHandles); + await driver.clickElement('[data-testid="home__activity-tab"]'); + const setApprovalItem = await driver.findElement({ + css: '.transaction-list__completed-transactions', + text: 'Approve Token with no spend limit', + }); + assert.equal(await setApprovalItem.isDisplayed(), true); + + // 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); + }, + ); + }); + + it('should revoke approval for a third party address to manage all ERC1155 token', async function () { + const expectedMessageTitle = + 'Revoke permission to access and transfer all of your NFT?'; + const expectedDescription = + 'This revokes the permission for a third party to access and transfer all of your NFT without further notice.'; + await withFixtures( + { + dapp: true, + fixtures: new FixtureBuilder() + .withPermissionControllerConnectedToTestDapp() + .build(), + 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); + + // Create a revoke approval for all erc1155 token request in test dapp + await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`); + await driver.clickElement('#revokeERC1155Button'); + + // Wait for notification popup and check the displayed message + await driver.waitUntilXWindowHandles(3); + let windowHandles = await driver.getAllWindowHandles(); + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + + const displayedMessageTitle = await driver.findElement( + '.confirm-approve-content__title', + ); + 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 + 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.clickElement('[data-testid="page-container-footer-next"]'); + await driver.waitUntilXWindowHandles(2); + + // Switch to extension and check revoke approval transaction is displayed in activity tab + windowHandles = await driver.getAllWindowHandles(); + await driver.switchToWindowWithTitle('MetaMask', windowHandles); + await driver.clickElement('[data-testid="home__activity-tab"]'); + const revokeApprovalItem = await driver.findElement({ + css: '.transaction-list__completed-transactions', + text: 'Approve Token with no spend limit', + }); + assert.equal(await revokeApprovalItem.isDisplayed(), true); + + // 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); + }, + ); + }); +}); diff --git a/test/e2e/tests/nfts.spec.js b/test/e2e/nft/erc721-intercation.spec.js similarity index 89% rename from test/e2e/tests/nfts.spec.js rename to test/e2e/nft/erc721-intercation.spec.js index 5de71dfe1..967c33f1e 100644 --- a/test/e2e/tests/nfts.spec.js +++ b/test/e2e/nft/erc721-intercation.spec.js @@ -3,7 +3,7 @@ const { convertToHexValue, withFixtures } = require('../helpers'); const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); const FixtureBuilder = require('../fixture-builder'); -describe('NFTs', function () { +describe('ERC721 NFTs testdapp interaction', function () { const smartContract = SMART_CONTRACTS.NFTS; const ganacheOptions = { accounts: [ @@ -14,7 +14,8 @@ describe('NFTs', function () { }, ], }; - it('should transfer a single NFT from one account to another', async function () { + + it('should transfer a single ERC721 NFT from one account to another', async function () { await withFixtures( { dapp: true, @@ -68,7 +69,8 @@ describe('NFTs', function () { }, ); }); - it('should approve an address to transfer a single NFT', async function () { + + it('should approve an address to transfer a single ERC721 NFT', async function () { await withFixtures( { dapp: true, @@ -91,8 +93,11 @@ describe('NFTs', function () { await driver.findClickableElement('#deployButton'); // Click Approve - await driver.fill('#approveTokenInput', '1'); + const approveInput = await driver.findElement('#approveTokenInput'); + await approveInput.clear(); + await approveInput.sendKeys('1'); await driver.clickElement('#approveButton'); + await driver.waitUntilXWindowHandles(3); const windowHandles = await driver.getAllWindowHandles(); const [extension] = windowHandles; @@ -129,13 +134,16 @@ describe('NFTs', function () { ); // Verify transaction - const completedTx = await driver.findElement('.list-item__title'); - const completedTxText = await completedTx.getText(); - assert.equal(completedTxText, 'Approve TDC spending cap'); + const completedTx = await driver.waitForSelector({ + css: '.list-item__title', + text: 'Approve TDC spending cap', + }); + assert.equal(await completedTx.isDisplayed(), true); }, ); }); - it('should enable approval for a third party address to manage all NFTs', async function () { + + it('should enable approval for a third party address to manage all ERC721 NFTs', async function () { await withFixtures( { dapp: true, @@ -198,13 +206,16 @@ describe('NFTs', function () { ); // Verify transaction - const completedTx = await driver.findElement('.list-item__title'); - const completedTxText = await completedTx.getText(); - assert.equal(completedTxText, 'Approve TDC with no spend limit'); + const completedTx = await driver.waitForSelector({ + css: '.list-item__title', + text: 'Approve TDC with no spend limit', + }); + assert.equal(await completedTx.isDisplayed(), true); }, ); }); - it('should disable approval for a third party address to manage all NFTs', async function () { + + it('should disable approval for a third party address to manage all ERC721 NFTs', async function () { await withFixtures( { dapp: true, @@ -270,9 +281,11 @@ describe('NFTs', function () { ); // Verify transaction - const completedTx = await driver.findElement('.list-item__title'); - const completedTxText = await completedTx.getText(); - assert.equal(completedTxText, 'Approve TDC with no spend limit'); + const completedTx = await driver.waitForSelector({ + css: '.list-item__title', + text: 'Approve TDC with no spend limit', + }); + assert.equal(await completedTx.isDisplayed(), true); }, ); }); diff --git a/test/e2e/tests/erc1155.spec.js b/test/e2e/tests/erc1155.spec.js deleted file mode 100644 index 7f0513990..000000000 --- a/test/e2e/tests/erc1155.spec.js +++ /dev/null @@ -1,109 +0,0 @@ -const { convertToHexValue, withFixtures } = require('../helpers'); -const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); -const FixtureBuilder = require('../fixture-builder'); - -describe('ERC1155', function () { - const smartContract = SMART_CONTRACTS.ERC1155; - const ganacheOptions = { - accounts: [ - { - secretKey: - '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', - balance: convertToHexValue(25000000000000000000), - }, - ], - }; - - it('should mint', async function () { - await withFixtures( - { - dapp: true, - fixtures: new FixtureBuilder() - .withPermissionControllerConnectedToTestDapp() - .build(), - 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'); - - // Mint - await driver.fill('#batchMintTokenIds', '1, 2, 3'); - await driver.fill('#batchMintIdAmounts', '1, 1, 1000000000000000'); - await driver.clickElement('#batchMintButton'); - - // Notification - await driver.waitUntilXWindowHandles(3); - const windowHandles = await driver.getAllWindowHandles(); - const [extension] = windowHandles; - await driver.switchToWindowWithTitle( - 'MetaMask Notification', - windowHandles, - ); - - // Confirm Mint - 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)', - { timeout: 10000 }, - ); - }, - ); - }); - - it('should batch transfers', async function () { - await withFixtures( - { - dapp: true, - fixtures: new FixtureBuilder() - .withPermissionControllerConnectedToTestDapp() - .build(), - 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}`); - - await driver.fill('#batchTransferTokenIds', '1, 2, 3'); - await driver.fill('#batchTransferTokenAmounts', '1, 1, 1000000000000'); - await driver.clickElement('#batchTransferFromButton'); - - await driver.waitUntilXWindowHandles(3); - const windowHandles = await driver.getAllWindowHandles(); - const [extension] = windowHandles; - await driver.switchToWindowWithTitle( - 'MetaMask Notification', - windowHandles, - ); - - 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)', - { timeout: 10000 }, - ); - }, - ); - }); -});