Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Add regression cf tests #3797

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cypress/e2e/happypath/sendfunds_connected_wallet.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { createSafes } from '../../support/api/utils_protocolkit'
import { contracts, abi_qtrust, abi_nft_pc2 } from '../../support/api/contracts'
import { getSafes, CATEGORIES } from '../../support/safes/safesHandler.js'

const safeBalanceEth = 305220000000000000n
const qtrustBanance = 95000000000000000025n
const safeBalanceEth = 305230000000000000n
const qtrustBanance = 99000000000000000025n
const transferAmount = '1'

const walletCredentials = JSON.parse(Cypress.env('CYPRESS_WALLET_CREDENTIALS'))
Expand Down
53 changes: 52 additions & 1 deletion cypress/e2e/pages/create_wallet.pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ const cancelBtn = '[data-testid="cancel-btn"]'
const dialogConfirmBtn = '[data-testid="dialog-confirm-btn"]'
const safeActivationSection = '[data-testid="activation-section"]'
const addressAutocompleteOptions = '[data-testid="address-item"]'
export const qrCode = '[data-testid="qr-code"]'
export const addressInfo = '[data-testid="address-info"]'
const choiceBtn = '[data-testid="choice-btn"]'
const addFundsBtn = '[data-testid="add-funds-btn"]'
const createTxBtn = '[data-testid="create-tx-btn"]'
const qrCodeSwitch = '[data-testid="qr-code-switch"]'
export const activateAccountBtn = '[data-testid="activate-account-btn"]'
const notificationsSwitch = '[data-testid="notifications-switch"]'
export const addFundsSection = '[data-testid="add-funds-section"]'
export const noTokensAlert = '[data-testid="no-tokens-alert"]'

const sponsorStr = 'Your account is sponsored by Goerli'
const safeCreationProcessing = 'Transaction is being executed'
Expand All @@ -38,11 +48,52 @@ const policy1_2 = '1/1 policy'
export const walletName = 'test1-sepolia-safe'
export const defaultSepoliaPlaceholder = 'Sepolia Safe'
const welcomeToSafeStr = 'Welcome to Safe'
const initialSteps = '0 of 2 steps completed'
export const addSignerStr = 'Add signer'
export const accountRecoveryStr = 'Account recovery'
export const sendTokensStr = 'Send tokens'

export function checkNotificationsSwitchIs(status) {
cy.get(notificationsSwitch).find('input').should(`be.${status}`)
}

export function clickOnActivateAccountBtn() {
cy.get(activateAccountBtn).click()
}

export function clickOnQRCodeSwitch() {
cy.get(qrCodeSwitch).click()
}

export function checkQRCodeSwitchStatus(state) {
cy.get(qrCodeSwitch).find('input').should(state)
}

export function checkInitialStepsDisplayed() {
cy.contains(initialSteps).should('be.visible')
}

export function clickOnAddFundsBtn() {
cy.get(addFundsBtn).click()
}

export function clickOnCreateTxBtn() {
cy.get(createTxBtn).click()
main.verifyElementsCount(choiceBtn, 6)
}

export function checkAllTxTypesOrder(expectedOrder) {
main.checkTextOrder(choiceBtn, expectedOrder)
}

export function clickOnTxType(tx) {
cy.get(choiceBtn).contains(tx).click()
}

export function verifyNewSafeDialogModal() {
main.verifyElementsIsVisible([dialogConfirmBtn])
}
//

export function verifyCFSafeCreated() {
main.verifyElementsIsVisible([sidebar.pendingActivationIcon, safeActivationSection])
}
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/pages/main.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export function addToLocalStorage(key, jsonValue) {
export function checkTextOrder(selector, expectedTextArray) {
cy.get(selector).each((element, index) => {
const text = Cypress.$(element).text().trim()
expect(text).to.eq(expectedTextArray[index])
expect(text).to.include(expectedTextArray[index])
})
}

Expand Down
152 changes: 152 additions & 0 deletions cypress/e2e/regression/create_safe_cf.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import * as constants from '../../support/constants'
import * as main from '../pages/main.page'
import * as createwallet from '../pages/create_wallet.pages'
import * as owner from '../pages/owners.pages'
import * as navigation from '../pages/navigation.page.js'
import * as ls from '../../support/localstorage_data.js'
import { getSafes, CATEGORIES } from '../../support/safes/safesHandler.js'
import * as safeapps from '../pages/safeapps.pages'

let staticSafes = []
const txOrder = [
'Activate Safe now',
'Add another signer',
'Set up recovery',
'Swap tokens',
'Custom transaction',
'Send token',
]

describe('CF Safe regression tests', () => {
before(async () => {
staticSafes = await getSafes(CATEGORIES.static)
})

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

it('Verify Add native assets and Create tx modals can be opened', () => {
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
cy.reload()
owner.waitForConnectionStatus()
createwallet.clickOnAddFundsBtn()
main.verifyElementsIsVisible([createwallet.qrCode])
navigation.clickOnModalCloseBtn()

createwallet.clickOnCreateTxBtn()
navigation.clickOnModalCloseBtn()
})

it('Verify "0 out of 2 step completed" is shown in the dashboard', () => {
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
cy.reload()
owner.waitForConnectionStatus()
createwallet.checkInitialStepsDisplayed()
})

it('Verify "Add native assets" button opens a modal with a QR code and the safe address', () => {
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
cy.reload()
owner.waitForConnectionStatus()
createwallet.clickOnAddFundsBtn()
main.verifyElementsIsVisible([createwallet.qrCode, createwallet.addressInfo])
})

it('Verify QR code switch status change works in "Add native assets" modal', () => {
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
cy.reload()
owner.waitForConnectionStatus()
createwallet.clickOnAddFundsBtn()
createwallet.checkQRCodeSwitchStatus(constants.checkboxStates.checked)
createwallet.clickOnQRCodeSwitch()
createwallet.checkQRCodeSwitchStatus(constants.checkboxStates.unchecked)
})

it('Verify "Create new transaction" modal contains tx types in sequence', () => {
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
cy.reload()
owner.waitForConnectionStatus()
createwallet.clickOnCreateTxBtn()
createwallet.checkAllTxTypesOrder(txOrder)
})

it('Verify "Add safe now" button takes to a tx "Activate account"', () => {
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
cy.reload()
owner.waitForConnectionStatus()
createwallet.clickOnCreateTxBtn()
createwallet.clickOnTxType(txOrder[0])
main.verifyElementsIsVisible([createwallet.activateAccountBtn])
})

it('Verify "Add another Owner" takes to a tx Add owner', () => {
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
cy.reload()
owner.waitForConnectionStatus()
createwallet.clickOnCreateTxBtn()
createwallet.clickOnTxType(txOrder[1])
main.verifyTextVisibility([createwallet.addSignerStr])
})

it('Verify "Setup recovery" button takes to the "Account recovery" flow', () => {
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
cy.reload()
owner.waitForConnectionStatus()
createwallet.clickOnCreateTxBtn()
createwallet.clickOnTxType(txOrder[2])
main.verifyTextVisibility([createwallet.accountRecoveryStr])
})

it('Verify "Send token" takes to the tx form to send tokens', () => {
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
cy.reload()
owner.waitForConnectionStatus()
createwallet.clickOnCreateTxBtn()
createwallet.clickOnTxType(txOrder[5])
main.verifyTextVisibility([createwallet.sendTokensStr])
})

it('Verify "Custom transaction" takes to the tx builder app ', () => {
const iframeSelector = `iframe[id="iframe-${constants.TX_Builder_url}"]`
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
main.addToLocalStorage(
constants.localStorageKeys.SAFE_v2__SafeApps__infoModal,
ls.appPermissions(constants.safeTestAppurl).infoModalAccepted,
)
cy.reload()
owner.waitForConnectionStatus()
createwallet.clickOnCreateTxBtn()
createwallet.clickOnTxType(txOrder[4])
main.getIframeBody(iframeSelector).within(() => {
cy.contains(safeapps.transactionBuilderStr)
})
})

it('Verify "Notifications" in the settings are disabled', () => {
owner.waitForConnectionStatus()
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
cy.reload()
cy.visit(constants.notificationsUrl + staticSafes.SEP_STATIC_SAFE_14)
createwallet.checkNotificationsSwitchIs(constants.enabledStates.disabled)
})

it('Verify in assets, that a "Add funds" block is present', () => {
owner.waitForConnectionStatus()
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
cy.reload()
cy.visit(constants.BALANCE_URL + staticSafes.SEP_STATIC_SAFE_14)
main.verifyElementsIsVisible([createwallet.addFundsSection, createwallet.noTokensAlert])
})

it('Verify clicking on "Activate now" button opens safe activation flow', () => {
owner.waitForConnectionStatus()
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__undeployedSafes, ls.undeployedSafe.safe1)
cy.reload()
cy.visit(constants.BALANCE_URL + staticSafes.SEP_STATIC_SAFE_14)
createwallet.clickOnActivateAccountBtn()
main.verifyElementsIsVisible([createwallet.activateAccountBtn])
})
})
2 changes: 1 addition & 1 deletion cypress/e2e/regression/spending_limits.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Spending limits tests', () => {
})

beforeEach(() => {
cy.visit(constants.securityUrl + staticSafes.SEP_STATIC_SAFE_8)
cy.visit(constants.setupUrl + staticSafes.SEP_STATIC_SAFE_8)
cy.clearLocalStorage()
main.acceptCookies()
owner.waitForConnectionStatus()
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/regression/spending_limits_nonowner.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Spending limits non-owner tests', () => {
})

beforeEach(() => {
cy.visit(constants.securityUrl + staticSafes.SEP_STATIC_SAFE_3)
cy.visit(constants.setupUrl + staticSafes.SEP_STATIC_SAFE_3)
cy.clearLocalStorage()
main.acceptCookies()
owner.waitForConnectionStatus()
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/smoke/spending_limits.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('[SMOKE] Spending limits tests', () => {
})

beforeEach(() => {
cy.visit(constants.securityUrl + staticSafes.SEP_STATIC_SAFE_8)
cy.visit(constants.setupUrl + staticSafes.SEP_STATIC_SAFE_8)
cy.clearLocalStorage()
main.acceptCookies()
owner.waitForConnectionStatus()
Expand Down
3 changes: 2 additions & 1 deletion cypress/fixtures/safes/static.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"SEP_STATIC_SAFE_10": "sep:0xc2F3645bfd395516d1a18CA6ad9298299d328C01",
"SEP_STATIC_SAFE_11": "sep:0x10B45a24640E2170B6AA63ea3A289D723a0C9cba",
"SEP_STATIC_SAFE_12": "sep:0xFFfaC243A24EecE6553f0Da278322aCF1Fb6CeF1",
"SEP_STATIC_SAFE_13": "sep:0x027bBe128174F0e5e5d22ECe9623698E01cd3970"
"SEP_STATIC_SAFE_13": "sep:0x027bBe128174F0e5e5d22ECe9623698E01cd3970",
"SEP_STATIC_SAFE_14": "sep:0xe41D568F5040FD9adeE8B64200c6B7C363C68c41"
}
4 changes: 2 additions & 2 deletions cypress/fixtures/txhistory_data_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@
}
},
"deleteSpendingLimit": {
"title": "Contract interaction",
"title": "AllowanceModule",
"summaryTxInfo": "deleteAllowance",
"summaryTime": "11:08 AM",
"description": "Delete spending limit",
"altImage": "Contract interaction",
"altImage": "AllowanceModule",
"beneficiary": "Beneficiary",
"beneficiaryAddress": "sep:0xC16Db0251654C0a72E91B190d81eAD367d2C6fED",
"transactionHash": "0xd6e8...de8b",
Expand Down
4 changes: 3 additions & 1 deletion cypress/support/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export const getPermissionsUrl = '/get-permissions'
export const appSettingsUrl = '/settings/safe-apps'
export const setupUrl = '/settings/setup?safe='
export const dataSettingsUrl = '/settings/data?safe='
export const securityUrl = '/settings/setup?safe='
export const securityUrl = '/settings/security?safe='
export const notificationsUrl = '/settings/notifications?safe='
export const invalidAppUrl = 'https://my-invalid-custom-app.com/manifest.json'
export const validAppUrlJson = 'https://my-valid-custom-app.com/manifest.json'
export const validAppUrl = 'https://my-valid-custom-app.com'
Expand Down Expand Up @@ -235,6 +236,7 @@ export const localStorageKeys = {
SAFE_v2__customSafeApps_11155111: 'SAFE_v2__customSafeApps-11155111',
SAFE_v2__SafeApps__browserPermissions: 'SAFE_v2__SafeApps__browserPermissions',
SAFE_v2__SafeApps__infoModal: 'SAFE_v2__SafeApps__infoModal',
SAFE_v2__undeployedSafes: 'SAFE_v2__undeployedSafes',
}

export const connectWalletNames = {
Expand Down
18 changes: 18 additions & 0 deletions cypress/support/localstorage_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,21 @@ export const cookies = {
acceptedCookies: { necessary: true, updates: true, analytics: true },
acceptedTokenListOnboarding: true,
}

export const undeployedSafe = {
safe1: {
11155111: {
'0xe41D568F5040FD9adeE8B64200c6B7C363C68c41': {
props: {
safeAccountConfig: {
threshold: 1,
owners: ['0xC16Db0251654C0a72E91B190d81eAD367d2C6fED'],
fallbackHandler: '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804',
},
safeDeploymentConfig: { saltNonce: '20', safeVersion: '1.3.0' },
},
status: { status: 'AWAITING_EXECUTION' },
},
},
},
}
2 changes: 1 addition & 1 deletion src/components/common/AddFunds/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const AddFundsCTA = () => {
const qrCode = `${qrPrefix}${safeAddress}`

return (
<Paper>
<Paper data-testid="add-funds-section">
<Grid container gap={3} alignItems="center" justifyContent="center" p={4}>
<Grid item>
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/ChoiceButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ChoiceButton = ({
chip?: string
}) => {
return (
<ButtonBase className={css.txButton} onClick={onClick} disabled={disabled}>
<ButtonBase data-testid="choice-btn" className={css.txButton} onClick={onClick} disabled={disabled}>
<Box
className={css.iconBg}
sx={{ backgroundColor: iconColor ? `var(--color-${iconColor}-background) !important` : '' }}
Expand Down
14 changes: 12 additions & 2 deletions src/components/dashboard/FirstSteps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const AddFundsWidget = ({ completed }: { completed: boolean }) => {
{(isOk) => (
<Track {...OVERVIEW_EVENTS.ADD_FUNDS}>
<Button
data-testid="add-funds-btn"
onClick={toggleDialog}
variant="contained"
size="small"
Expand All @@ -157,14 +158,15 @@ const AddFundsWidget = ({ completed }: { completed: boolean }) => {
>
<Box px={4} pb={5} pt={4}>
<Grid container spacing={2} alignItems="center" justifyContent="center" mb={4}>
<Grid item textAlign="center">
<Grid data-testid="qr-code" item textAlign="center">
<Box p={1} border={1} borderRadius="6px" borderColor="border.light" display="inline-flex">
<QRCode value={qrCode} size={132} />
</Box>
<Box>
<FormControlLabel
control={
<Switch
data-testid="qr-code-switch"
checked={settings.shortName.qr}
onChange={(e) => dispatch(setQrShortName(e.target.checked))}
/>
Expand All @@ -183,7 +185,14 @@ const AddFundsWidget = ({ completed }: { completed: boolean }) => {
account.
</Typography>

<Box bgcolor="background.main" p={2} borderRadius="6px" alignSelf="flex-start" fontSize="14px">
<Box
data-testid="address-info"
bgcolor="background.main"
p={2}
borderRadius="6px"
alignSelf="flex-start"
fontSize="14px"
>
<EthHashInfo
address={safeAddress}
showName={false}
Expand Down Expand Up @@ -234,6 +243,7 @@ const FirstTransactionWidget = ({ completed }: { completed: boolean }) => {
{(isOk) => (
<Track {...OVERVIEW_EVENTS.NEW_TRANSACTION} label="onboarding">
<Button
data-testid="create-tx-btn"
onClick={() => setOpen(true)}
variant="outlined"
size="small"
Expand Down
Loading
Loading