From 9967daec8cda0a892c50e72163a9b8c0fea7ecd2 Mon Sep 17 00:00:00 2001 From: Michael <30682308+mike10ca@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:30:08 +0100 Subject: [PATCH] Tests: Add tests for spam token (#3023) --- cypress/e2e/pages/create_tx.pages.js | 37 +++++++++++++++++++ cypress/e2e/regression/tx_history_2.cy.js | 5 +++ cypress/e2e/smoke/tx_history.cy.js | 17 +++++++++ cypress/fixtures/txhistory_data_data.json | 11 ++++++ .../common/CopyTooltip/ConfirmCopyModal.tsx | 2 +- 5 files changed, 71 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/pages/create_tx.pages.js b/cypress/e2e/pages/create_tx.pages.js index b159133673..75eb5f9362 100644 --- a/cypress/e2e/pages/create_tx.pages.js +++ b/cypress/e2e/pages/create_tx.pages.js @@ -26,6 +26,8 @@ const advancedDetails = '[data-testid="tx-advanced-details"]' const baseGas = '[data-testid="tx-bas-gas"]' const requiredConfirmation = '[data-testid="required-confirmations"]' const txDate = '[data-testid="tx-date"]' +const spamTokenWarningIcon = '[data-testid="warning"]' +const untrustedTokenWarningModal = '[data-testid="untrusted-token-warning"]' const viewTransactionBtn = 'View transaction' const transactionDetailsTitle = 'Transaction details' @@ -55,6 +57,30 @@ export function checkRequiredThreshold(count) { cy.get(requiredConfirmation).should('be.visible').and('include.text', count) } +export function verifyAddressNotCopied(index, data) { + cy.get(copyIcon) + .parent() + .eq(index) + .trigger('click') + .wait(1000) + .then(() => + cy.window().then((win) => { + win.navigator.clipboard.readText().then((text) => { + expect(text).not.to.contain(data) + }) + }), + ) + cy.get(untrustedTokenWarningModal).should('be.visible') +} + +export function verifyWarningModalVisible() { + cy.get(untrustedTokenWarningModal).should('be.visible') +} + +export function clickOnCopyBtn(index) { + cy.get(copyIcon).parent().eq(index).trigger('click') +} + export function verifyCopyIconWorks(index, data) { cy.get(copyIcon) .parent() @@ -145,6 +171,17 @@ export function verifyActionListExists(data) { main.verifyElementsIsVisible([confirmationVisibilityBtn]) } +export function verifySpamIconIsDisplayed(name, token) { + cy.get(transactionItem) + .filter(':contains("' + name + '")') + .filter(':contains("' + token + '")') + .then(($elements) => { + cy.wrap($elements.first()).then(($element) => { + cy.wrap($element).find(spamTokenWarningIcon).should('be.visible') + }) + }) +} + export function verifySummaryByName(name, token, data, alt, altToken) { cy.get(transactionItem) .filter(':contains("' + name + '")') diff --git a/cypress/e2e/regression/tx_history_2.cy.js b/cypress/e2e/regression/tx_history_2.cy.js index 1913466a0e..8bf9bcf0d8 100644 --- a/cypress/e2e/regression/tx_history_2.cy.js +++ b/cypress/e2e/regression/tx_history_2.cy.js @@ -149,4 +149,9 @@ describe('Tx history tests 2', () => { ) createTx.checkRequiredThreshold(2) }) + + it('Verify that sender address of untrusted token will not be copied until agreed in warning popup', () => { + createTx.clickOnTransactionItemByName(typeUntrustedToken.summaryTitle, typeUntrustedToken.summaryTxInfo) + createTx.verifyAddressNotCopied(0, typeUntrustedToken.senderAddress) + }) }) diff --git a/cypress/e2e/smoke/tx_history.cy.js b/cypress/e2e/smoke/tx_history.cy.js index ee04e4a7f1..b12147af42 100644 --- a/cypress/e2e/smoke/tx_history.cy.js +++ b/cypress/e2e/smoke/tx_history.cy.js @@ -9,6 +9,7 @@ const typeReceive = data.type.receive const typeSend = data.type.send const typeDeleteAllowance = data.type.deleteSpendingLimit const typeGeneral = data.type.general +const typeUntrustedToken = data.type.untrustedReceivedToken describe('[SMOKE] Tx history tests', () => { beforeEach(() => { @@ -67,4 +68,20 @@ describe('[SMOKE] Tx history tests', () => { typeDeleteAllowance.altImage, ) }) + + it('[SMOKE] Verify summary for untrusted token', () => { + createTx.verifySummaryByName( + typeUntrustedToken.summaryTitle, + typeUntrustedToken.summaryTxInfo, + [typeUntrustedToken.summaryTxInfo, typeGeneral.statusOk], + typeUntrustedToken.altImage, + ) + createTx.verifySpamIconIsDisplayed(typeUntrustedToken.title, typeUntrustedToken.summaryTxInfo) + }) + + it('[SMOKE] Verify that copying sender address of untrusted token shows warning popup', () => { + createTx.clickOnTransactionItemByName(typeUntrustedToken.summaryTitle, typeUntrustedToken.summaryTxInfo) + createTx.clickOnCopyBtn(0) + createTx.verifyWarningModalVisible() + }) }) diff --git a/cypress/fixtures/txhistory_data_data.json b/cypress/fixtures/txhistory_data_data.json index f2eafdb609..bc62cd3f58 100644 --- a/cypress/fixtures/txhistory_data_data.json +++ b/cypress/fixtures/txhistory_data_data.json @@ -177,6 +177,17 @@ "resetBaseMin": "0", "delegateAddressTitle": "delegate(address)" } + }, + "untrustedReceivedToken": { + "title": "Receive", + "summaryTitle": "Received", + "summaryTxInfo": "5 TTONE", + "receivedFrom": "", + "senderAddress": "sep:0x06373d5e45AD31BD354CeBfA8dB4eD2c75B8708e", + "transactionHash": "0x54e7...2a7c", + "transactionHashCopied":"0x54e7e766b08d4210bc1cfcc84d84ca4782a0cc1efe9e7d9c032d305060ed2a7c", + "altImage": "Received", + "altToken": "" } } } \ No newline at end of file diff --git a/src/components/common/CopyTooltip/ConfirmCopyModal.tsx b/src/components/common/CopyTooltip/ConfirmCopyModal.tsx index a29448c2eb..b2c0398988 100644 --- a/src/components/common/CopyTooltip/ConfirmCopyModal.tsx +++ b/src/components/common/CopyTooltip/ConfirmCopyModal.tsx @@ -33,7 +33,7 @@ const ConfirmCopyModal = ({ open, onClose, onCopy, children }: ConfirmCopyModalP return ( - + Before you copy