Skip to content

Commit

Permalink
Tests: Add tests for spam token (#3023)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike10ca authored Dec 15, 2023
1 parent 4a87e96 commit 9967dae
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
37 changes: 37 additions & 0 deletions cypress/e2e/pages/create_tx.pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 + '")')
Expand Down
5 changes: 5 additions & 0 deletions cypress/e2e/regression/tx_history_2.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
17 changes: 17 additions & 0 deletions cypress/e2e/smoke/tx_history.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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()
})
})
11 changes: 11 additions & 0 deletions cypress/fixtures/txhistory_data_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
}
}
}
2 changes: 1 addition & 1 deletion src/components/common/CopyTooltip/ConfirmCopyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ConfirmCopyModal = ({ open, onClose, onCopy, children }: ConfirmCopyModalP
return (
<Dialog open={open} onClose={onClose}>
<DialogTitle>
<Box display="flex" flexDirection="row" alignItems="center" gap={1}>
<Box data-testid="untrusted-token-warning" display="flex" flexDirection="row" alignItems="center" gap={1}>
<SvgIcon component={WarningIcon} inheritViewBox color="warning" sx={{ mb: -0.4 }} />
<Typography variant="h6" fontWeight={700}>
Before you copy
Expand Down

0 comments on commit 9967dae

Please sign in to comment.