Skip to content

Commit

Permalink
Tests: add tests for messages (safe-global#3677)
Browse files Browse the repository at this point in the history
* tests: add tests for messages
  • Loading branch information
mike10ca authored May 8, 2024
1 parent 788ddaa commit 9e0beef
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 5 deletions.
30 changes: 29 additions & 1 deletion cypress/e2e/pages/create_tx.pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ export const transactionItem = '[data-testid="transaction-item"]'
export const connectedWalletExecMethod = '[data-testid="connected-wallet-execution-method"]'
const addToBatchBtn = '[data-track="batching: Add to batch"]'
const accordionDetails = '[data-testid="accordion-details"]'
const accordionMessageDetails = '[data-testid="accordion-msg-details"]'
const copyIcon = '[data-testid="copy-btn-icon"]'
const transactionSideList = '[data-testid="transaction-actions-list"]'
const confirmationVisibilityBtn = '[data-testid="confirmation-visibility-btn"]'
const expandAllBtn = '[data-testid="expande-all-btn"]'
const collapseAllBtn = '[data-testid="collapse-all-btn"]'
const txRowTitle = '[data-testid="tx-row-title"]'
export const txRowTitle = '[data-testid="tx-row-title"]'
const advancedDetails = '[data-testid="tx-advanced-details"]'
const baseGas = '[data-testid="tx-bas-gas"]'
const requiredConfirmation = '[data-testid="required-confirmations"]'
Expand All @@ -30,6 +31,7 @@ const spamTokenWarningIcon = '[data-testid="warning"]'
const untrustedTokenWarningModal = '[data-testid="untrusted-token-warning"]'
const sendTokensBtn = '[data-testid="send-tokens-btn"]'
export const replacementNewSigner = '[data-testid="new-owner"]'
const messageItem = '[data-testid="message-item"]'

const viewTransactionBtn = 'View transaction'
const transactionDetailsTitle = 'Transaction details'
Expand All @@ -49,6 +51,7 @@ const noLaterStr = 'No, later'
const signBtnStr = 'Sign'
const expandAllBtnStr = 'Expand all'
const collapseAllBtnStr = 'Collapse all'
export const messageNestedStr = `"nestedString": "Test message 3 off-chain"`

export function clickOnSendTokensBtn() {
cy.get(sendTokensBtn).click()
Expand Down Expand Up @@ -129,6 +132,14 @@ export function clickOnTransactionItemByName(name, token) {
})
}

export function clickOnTransactionItemByIndex(index) {
cy.get(messageItem)
.eq(index)
.then(($elements) => {
cy.wrap($elements).click({ force: true })
})
}

export function verifyExpandedDetails(data, warning) {
main.checkTextsExistWithinElement(accordionDetails, data)
if (warning) cy.get(warning).should('be.visible')
Expand Down Expand Up @@ -212,6 +223,23 @@ export function verifySummaryByName(name, token, data, alt, altToken) {
})
}

export function verifySummaryByIndex(index, data, alt) {
cy.get(messageItem)
.eq(index)
.then(($elements) => {
cy.wrap($elements).then(($element) => {
if (Array.isArray(data)) {
data.forEach((text) => {
cy.wrap($element).contains(text).should('be.visible')
})
} else {
cy.wrap($element).contains(data).should('be.visible')
}
if (alt) cy.wrap($element).find('img').eq(0).should('have.attr', 'alt', alt).should('be.visible')
})
})
}

export function clickOnTransactionItem(item) {
cy.get(transactionItem).eq(item).scrollIntoView().click({ force: true })
}
Expand Down
6 changes: 6 additions & 0 deletions cypress/e2e/pages/main.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,9 @@ export function formatAddressInCaps(address) {
export function getElementText(element) {
return cy.get(element).invoke('text')
}

export function verifyTextVisibility(stringsArray) {
stringsArray.forEach((string) => {
cy.contains(string).should('be.visible')
})
}
74 changes: 74 additions & 0 deletions cypress/e2e/regression/messages_offchain.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as constants from '../../support/constants.js'
import * as main from '../pages/main.page.js'
import * as createTx from '../pages/create_tx.pages.js'
import * as msg_data from '../../fixtures/txmessages_data.json'
import { getSafes, CATEGORIES } from '../../support/safes/safesHandler.js'

let staticSafes = []

const typeMessagesGeneral = msg_data.type.general
const typeMessagesOffchain = msg_data.type.offChain

describe('Offchain Messages tests', () => {
before(async () => {
staticSafes = await getSafes(CATEGORIES.static)
})

beforeEach(() => {
cy.clearLocalStorage()
cy.visit(constants.transactionsMessagesUrl + staticSafes.SEP_STATIC_SAFE_10)
main.acceptCookies()
})

it('Verify summary for off-chain unsigned messages', () => {
createTx.verifySummaryByIndex(
0,
[typeMessagesGeneral.sign, typeMessagesGeneral.oneOftwo, typeMessagesOffchain.walletConnect],
typeMessagesOffchain.altTmage,
)
createTx.verifySummaryByIndex(
2,
[typeMessagesGeneral.sign, typeMessagesGeneral.oneOftwo, typeMessagesOffchain.walletConnect],
typeMessagesOffchain.altTmage,
)
})

it('Verify summary for off-chain signed messages', () => {
createTx.verifySummaryByIndex(
1,
[typeMessagesGeneral.confirmed, typeMessagesGeneral.twoOftwo, typeMessagesOffchain.walletConnect],
typeMessagesOffchain.altTmage,
)
createTx.verifySummaryByIndex(
3,
[typeMessagesGeneral.confirmed, typeMessagesGeneral.twoOftwo, typeMessagesOffchain.walletConnect],
typeMessagesOffchain.altTmage,
)
})

it('Verify exapanded details for simple off-chain message', () => {
createTx.clickOnTransactionItemByIndex(2)
cy.contains(typeMessagesOffchain.message2).should('be.visible')
})

it('Verify exapanded details for EIP 712 off-chain message', () => {
const jsonString = createTx.messageNestedStr
const values = [
typeMessagesOffchain.name,
typeMessagesOffchain.testStringNested,
typeMessagesOffchain.EIP712Domain,
typeMessagesOffchain.message3,
]

createTx.clickOnTransactionItemByIndex(1)
cy.get(createTx.txRowTitle)
.next()
.then(($section) => {
expect($section.text()).to.include(jsonString)
const count = $section.text().split(jsonString).length - 1
expect(count).to.eq(3)
})

main.verifyTextVisibility(values)
})
})
57 changes: 57 additions & 0 deletions cypress/e2e/regression/messages_onchain.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as constants from '../../support/constants.js'
import * as main from '../pages/main.page.js'
import * as createTx from '../pages/create_tx.pages.js'
import * as msg_data from '../../fixtures/txmessages_data.json'
import { getSafes, CATEGORIES } from '../../support/safes/safesHandler.js'

let staticSafes = []

const typeMessagesOnchain = msg_data.type.onChain

describe('Onchain Messages tests', () => {
before(async () => {
staticSafes = await getSafes(CATEGORIES.static)
})

beforeEach(() => {
cy.clearLocalStorage()
cy.visit(constants.transactionsHistoryUrl + staticSafes.SEP_STATIC_SAFE_10)
main.acceptCookies()
})

it('Verify exapanded details for signed on-chain message', () => {
createTx.clickOnTransactionItemByName(typeMessagesOnchain.contractName)
createTx.verifyExpandedDetails([
typeMessagesOnchain.contractName,
typeMessagesOnchain.contractAddress,
typeMessagesOnchain.delegateCall,
])
})

it('Verify exapanded details for unsigned on-chain message', () => {
cy.visit(constants.transactionQueueUrl + staticSafes.SEP_STATIC_SAFE_10)
createTx.clickOnTransactionItemByName(typeMessagesOnchain.contractName)
createTx.verifyExpandedDetails([
typeMessagesOnchain.contractName,
typeMessagesOnchain.contractAddress,
typeMessagesOnchain.delegateCall,
])
})

it('Verify summary for unsigned on-chain message', () => {
cy.visit(constants.transactionQueueUrl + staticSafes.SEP_STATIC_SAFE_10)
createTx.verifySummaryByName(
typeMessagesOnchain.contractName,
[typeMessagesOnchain.oneOftwo, typeMessagesOnchain.signMessage],
typeMessagesOnchain.altTmage,
)
})

it('Verify summary for signed on-chain message', () => {
createTx.verifySummaryByName(
typeMessagesOnchain.contractName,
[typeMessagesOnchain.success, typeMessagesOnchain.signMessage],
typeMessagesOnchain.altTmage,
)
})
})
6 changes: 3 additions & 3 deletions cypress/e2e/smoke/create_tx.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getSafes, CATEGORIES } from '../../support/safes/safesHandler.js'
let staticSafes = []

const sendValue = 0.00002
const currentNonce = 3
const currentNonce = 5

function happyPathToStepTwo() {
createtx.typeRecipientAddress(constants.EOA)
Expand Down Expand Up @@ -57,15 +57,15 @@ describe('[SMOKE] Create transactions tests', () => {
createtx.verifyTooltipMessage(constants.nonceTooltipMsg.muchHigherThanRecommended)
})

it('[SMOKE] Verify advance parameters gas limit input', () => {
it.skip('[SMOKE] Verify advance parameters gas limit input', () => {
happyPathToStepTwo()
createtx.changeNonce(currentNonce)
createtx.selectCurrentWallet()
createtx.openExecutionParamsModal()
createtx.verifyAndSubmitExecutionParams()
})

it('[SMOKE] Verify a transaction shows relayer and addToBatch button', () => {
it.skip('[SMOKE] Verify a transaction shows relayer and addToBatch button', () => {
happyPathToStepTwo()
createtx.verifySubmitBtnIsEnabled()
createtx.verifyNativeTokenTransfer()
Expand Down
33 changes: 33 additions & 0 deletions cypress/fixtures/txmessages_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"type": {
"general": {
"confirmed": "Confirmed",
"sign": "Sign",
"oneOftwo": "1 out of 2",
"twoOftwo": "2 out of 2"
},
"offChain": {
"walletConnect": "WalletConnect",
"altTmage": "Message type",
"sign": "Sign",
"oneOftwo": "1 out of 2",
"twoOftwo": "2 out of 2",
"message2": "Test message 2 off-chain",
"message3": "Test message 3 off-chain",
"EIP712Domain": "EIP712Domain",
"name": "EIP-1271 Example DApp",
"testString": "Test message 3 off-chain",
"testStringNested": "testNested(Nested)",
"testNestedArray": "testNestedArray(Nested[])"
},
"onChain": {
"contractName": "Safe: SignMessageLib 1.3.0",
"contractAddress": "sep:0x98FFBBF51bb33A056B08ddf711f289936AafF717",
"delegateCall": "Delegate call",
"signMessage": "signMessage",
"oneOftwo": "1 out of 2",
"altImage": "Safe: SignMessageLib 1.3.0",
"success": "Success"
}
}
}
1 change: 1 addition & 0 deletions cypress/support/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const BALANCE_URL = '/balances?safe='
export const balanceNftsUrl = '/balances/nfts?safe='
export const transactionQueueUrl = '/transactions/queue?safe='
export const transactionsHistoryUrl = '/transactions/history?safe='
export const transactionsMessagesUrl = '/transactions/messages?safe='
export const openAppsUrl = '/apps/open?safe='
export const homeUrl = '/home?safe='
export const welcomeUrl = '/welcome'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import txListItemCss from '@/components/transactions/TxListItem/styles.module.cs
const ExpandableMsgItem = ({ msg }: { msg: SafeMessage }): ReactElement => {
return (
<Accordion disableGutters elevation={0} className={txListItemCss.accordion}>
<AccordionSummary expandIcon={<ExpandMoreIcon />} sx={{ justifyContent: 'flex-start', overflowX: 'auto' }}>
<AccordionSummary
data-testid="message-item"
expandIcon={<ExpandMoreIcon />}
sx={{ justifyContent: 'flex-start', overflowX: 'auto' }}
>
<MsgSummary msg={msg} />
</AccordionSummary>

Expand Down

0 comments on commit 9e0beef

Please sign in to comment.