Skip to content

Commit

Permalink
Tests: Add more multichain tests (#4522)
Browse files Browse the repository at this point in the history
* Add more multichain tests
  • Loading branch information
mike10ca authored Nov 14, 2024
1 parent b9fc13e commit fe37198
Show file tree
Hide file tree
Showing 15 changed files with 341 additions and 150 deletions.
100 changes: 100 additions & 0 deletions cypress/e2e/happypath_2/add_owner.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import * as constants from '../../support/constants'
import * as main from '../../e2e/pages/main.page'
import * as owner from '../pages/owners.pages'
import * as addressBook from '../pages/address_book.page'
import { getSafes, CATEGORIES } from '../../support/safes/safesHandler.js'
import * as wallet from '../../support/utils/wallet.js'
import * as createTx from '../pages/create_tx.pages.js'
import * as navigation from '../pages/navigation.page'
import { getEvents, events, checkDataLayerEvents } from '../../support/utils/gtag.js'

let staticSafes = []
const walletCredentials = JSON.parse(Cypress.env('CYPRESS_WALLET_CREDENTIALS'))
const signer = walletCredentials.OWNER_4_PRIVATE_KEY
const signer2 = walletCredentials.OWNER_1_PRIVATE_KEY

describe('Happy path Add Owners tests', () => {
before(async () => {
staticSafes = await getSafes(CATEGORIES.static)
})

beforeEach(() => {
cy.visit(constants.setupUrl + staticSafes.SEP_STATIC_SAFE_4)
cy.contains(owner.safeAccountNonceStr, { timeout: 10000 })
})

it(
'Verify creation, confirmation and deletion of Add owner tx. GA tx_confirm',
{ defaultCommandTimeout: 30000 },
() => {
const tx_confirmed = [
{
eventLabel: events.txConfirmedAddOwner.eventLabel,
eventCategory: events.txConfirmedAddOwner.category,
eventType: events.txConfirmedAddOwner.eventType,
safeAddress: staticSafes.SEP_STATIC_SAFE_24.slice(6),
},
]
function step1() {
// Clean txs in the queue
cy.visit(constants.transactionQueueUrl + staticSafes.SEP_STATIC_SAFE_24)
wallet.connectSigner(signer2)
cy.wait(5000)
createTx.deleteAllTx()
navigation.clickOnWalletExpandMoreIcon()
navigation.clickOnDisconnectBtn()

cy.visit(constants.setupUrl + staticSafes.SEP_STATIC_SAFE_24)
wallet.connectSigner(signer2)
owner.waitForConnectionStatus()
owner.openAddOwnerWindow()
owner.typeOwnerAddress(constants.SEPOLIA_OWNER_2)
createTx.changeNonce(1)
owner.clickOnNextBtn()
createTx.clickOnSignTransactionBtn()
createTx.clickViewTransaction()

navigation.clickOnWalletExpandMoreIcon()
navigation.clickOnDisconnectBtn()
wallet.connectSigner(signer)
}

function step2() {
createTx.clickOnConfirmTransactionBtn()
createTx.clickOnNoLaterOption()
createTx.clickOnSignTransactionBtn()

navigation.clickOnWalletExpandMoreIcon()
navigation.clickOnDisconnectBtn()
getEvents()
checkDataLayerEvents(tx_confirmed)
wallet.connectSigner(signer2)
createTx.deleteTx()
}

step1()
cy.get('body').then(($body) => {
if ($body.find(`button:contains("${createTx.executeStr}")`).length > 0) {
navigation.clickOnWalletExpandMoreIcon()
navigation.clickOnDisconnectBtn()
wallet.connectSigner(signer2)
createTx.deleteTx()
cy.wait(5000)
step1()
step2()
} else {
createTx.clickOnConfirmTransactionBtn()
createTx.clickOnNoLaterOption()
createTx.clickOnSignTransactionBtn()

navigation.clickOnWalletExpandMoreIcon()
navigation.clickOnDisconnectBtn()
getEvents()
checkDataLayerEvents(tx_confirmed)
wallet.connectSigner(signer2)
createTx.deleteTx()
}
})
},
)
})
50 changes: 50 additions & 0 deletions cypress/e2e/happypath_2/multichain_create_safe.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as constants from '../../support/constants.js'
import * as main from '../pages/main.page.js'
import { getSafes, CATEGORIES } from '../../support/safes/safesHandler.js'
import * as wallet from '../../support/utils/wallet.js'
import * as createwallet from '../pages/create_wallet.pages'
import * as createtx from '../pages/create_tx.pages.js'
import * as tx from '../pages/transactions.page.js'
import * as owner from '../pages/owners.pages'
import * as navigation from '../pages/navigation.page.js'

let staticSafes = []

const walletCredentials = JSON.parse(Cypress.env('CYPRESS_WALLET_CREDENTIALS'))
const signer = walletCredentials.OWNER_4_PRIVATE_KEY

describe('Happy path Multichain safe creation tests', { defaultCommandTimeout: 60000 }, () => {
before(async () => {
staticSafes = await getSafes(CATEGORIES.static)
})

beforeEach(() => {
cy.visit(constants.welcomeUrl + '?chain=sep')
cy.wait(2000)
wallet.connectSigner(signer)
})

it('Verify that L2 safe created during multichain safe creation has 1.4.1 L2 contract after deployment', () => {
createwallet.clickOnContinueWithWalletBtn()
createwallet.clickOnCreateNewSafeBtn()
createwallet.clickOnNetwrokRemoveIcon()
createwallet.selectMultiNetwork(1, constants.networks.ethereum.toLowerCase())
createwallet.selectMultiNetwork(1, constants.networks.sepolia.toLowerCase())
createwallet.selectMultiNetwork(1, constants.networks.polygon.toLowerCase())
createwallet.clickOnNextBtn()
createwallet.clickOnNextBtn()
createwallet.clickOnReviewStepNextBtn()
createwallet.clickOnLetsGoBtn()

cy.url().then((currentUrl) => {
const safe = `sep:${main.getSafeAddressFromUrl(currentUrl)}`
cy.visit(constants.homeUrl + safe)
createwallet.clickOnActivateAccountBtn(0)
createwallet.selectRelayOption()
createwallet.clickOnFinalActivateAccountBtn()
createwallet.clickOnLetsGoBtn()
cy.visit(constants.setupUrl + safe)
main.verifyValuesExist(navigation.setupSection, [constants.safeContractVersions.v1_4_1_L2])
})
})
})
99 changes: 99 additions & 0 deletions cypress/e2e/happypath_2/swaps.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import * as constants from '../../support/constants.js'
import * as main from '../pages/main.page.js'
import * as swaps from '../pages/swaps.pages.js'
import * as tx from '../pages/transactions.page.js'
import * as create_tx from '../pages/create_tx.pages.js'
import { getSafes, CATEGORIES } from '../../support/safes/safesHandler.js'
import * as owner from '../pages/owners.pages'
import * as wallet from '../../support/utils/wallet.js'
import * as swaps_data from '../../fixtures/swaps_data.json'
import * as navigation from '../pages/navigation.page'
import { getEvents, events, checkDataLayerEvents } from '../../support/utils/gtag.js'

const walletCredentials = JSON.parse(Cypress.env('CYPRESS_WALLET_CREDENTIALS'))
const signer = walletCredentials.OWNER_4_PRIVATE_KEY
const signer2 = walletCredentials.OWNER_3_WALLET_ADDRESS
const signer3 = walletCredentials.OWNER_1_PRIVATE_KEY

let staticSafes = []

let iframeSelector

const swapOrder = swaps_data.type.orderDetails

describe('Happy path Swaps tests', () => {
before(async () => {
staticSafes = await getSafes(CATEGORIES.static)
})

beforeEach(() => {
cy.visit(constants.swapUrl + staticSafes.SEP_STATIC_SAFE_1)
main.waitForHistoryCallToComplete()
wallet.connectSigner(signer)
iframeSelector = `iframe[src*="${constants.swapWidget}"]`
})

it(
'Verify an order can be created, signed by second signer and deleted. GA tx_confirm, tx_created',
{ defaultCommandTimeout: 30000 },
() => {
const tx_created = [
{
eventLabel: events.txCreatedSwap.eventLabel,
eventCategory: events.txCreatedSwap.category,
eventType: events.txCreatedSwap.eventType,
safeAddress: staticSafes.SEP_STATIC_SAFE_30.slice(6),
},
]
const tx_confirmed = [
{
eventLabel: events.txConfirmedSwap.eventLabel,
eventCategory: events.txConfirmedSwap.category,
eventType: events.txConfirmedSwap.eventType,
safeAddress: staticSafes.SEP_STATIC_SAFE_30.slice(6),
},
]
// Clean txs in the queue
cy.visit(constants.transactionQueueUrl + staticSafes.SEP_STATIC_SAFE_30)
cy.wait(5000)
create_tx.deleteAllTx()

cy.visit(constants.swapUrl + staticSafes.SEP_STATIC_SAFE_30)
swaps.acceptLegalDisclaimer()
cy.wait(4000)
main.getIframeBody(iframeSelector).within(() => {
swaps.clickOnSettingsBtn()
swaps.setSlippage('0.30')
swaps.setExpiry('2')
swaps.clickOnSettingsBtn()
swaps.selectInputCurrency(swaps.swapTokens.cow)
swaps.setInputValue(200)
swaps.selectOutputCurrency(swaps.swapTokens.dai)
swaps.clickOnExceeFeeChkbox()
swaps.clickOnSwapBtn()
swaps.clickOnSwapBtn()
})
create_tx.changeNonce(0)
create_tx.clickOnSignTransactionBtn()
create_tx.clickViewTransaction()
navigation.clickOnWalletExpandMoreIcon()
navigation.clickOnDisconnectBtn()
wallet.connectSigner(signer3)

cy.wait(5000)
create_tx.verifyConfirmTransactionBtnIsVisible()
create_tx.clickOnConfirmTransactionBtn()
create_tx.clickOnNoLaterOption()

create_tx.clickOnSignTransactionBtn()
navigation.clickOnWalletExpandMoreIcon()
navigation.clickOnDisconnectBtn()
wallet.connectSigner(signer)
create_tx.deleteTx()

getEvents()
checkDataLayerEvents(tx_created)
checkDataLayerEvents(tx_confirmed)
},
)
})
1 change: 1 addition & 0 deletions cypress/e2e/pages/create_tx.pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const gasLimitInput = '[name="gasLimit"]'
const rotateLeftIcon = '[data-testid="RotateLeftIcon"]'
export const transactionItem = '[data-testid="transaction-item"]'
export const connectedWalletExecMethod = '[data-testid="connected-wallet-execution-method"]'
export const relayExecMethod = '[data-testid="relay-execution-method"]'
export const payNowExecMethod = '[data-testid="pay-now-execution-method"]'
const addToBatchBtn = '[data-track="batching: Add to batch"]'
const accordionDetails = '[data-testid="accordion-details"]'
Expand Down
20 changes: 17 additions & 3 deletions cypress/e2e/pages/create_wallet.pages.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as main from '../pages/main.page'
import { connectedWalletExecMethod } from '../pages/create_tx.pages'
import { connectedWalletExecMethod, relayExecMethod } from '../pages/create_tx.pages'
import * as sidebar from '../pages/sidebar.pages'
import * as constants from '../../support/constants'

Expand Down Expand Up @@ -35,6 +35,7 @@ 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-cf"]'
export const activateFlowAccountBtn = '[data-testid="activate-account-flow-btn"]'
const notificationsSwitch = '[data-testid="notifications-switch"]'
export const addFundsSection = '[data-testid="add-funds-section"]'
export const noTokensAlert = '[data-testid="no-tokens-alert"]'
Expand All @@ -49,6 +50,7 @@ export const reviewStepThreshold = '[data-testid="review-step-threshold"]'
export const cfSafeCreationSuccessMsg = '[data-testid="account-success-message"]'
export const cfSafeActivationMsg = '[data-testid="safe-activation-message"]'
export const cfSafeInfo = '[data-testid="safe-info"]'
const connectWalletBtn = '[data-testid="connect-wallet-btn"]'

const sponsorStr = 'Your account is sponsored by Goerli'
const safeCreationProcessing = 'Transaction is being executed'
Expand All @@ -64,8 +66,7 @@ export const accountRecoveryStr = 'Account recovery'
export const sendTokensStr = 'Send tokens'
const noWalletConnectedMsg = 'No wallet connected'
export const deployWalletStr = 'about to deploy this Safe Account'

const connectWalletBtn = '[data-testid="connect-wallet-btn"]'
const showAllNetworksStr = 'Show all networks'

export function waitForConnectionMsgDisappear() {
cy.contains(noWalletConnectedMsg).should('not.exist')
Expand All @@ -78,6 +79,10 @@ export function clickOnActivateAccountBtn(index) {
cy.get(activateAccountBtn).eq(index).click()
}

export function clickOnFinalActivateAccountBtn(index) {
cy.get(activateFlowAccountBtn).click()
}

export function clickOnQRCodeSwitch() {
cy.get(qrCodeSwitch).click()
}
Expand Down Expand Up @@ -114,6 +119,11 @@ export function verifyCFSafeCreated() {
export function selectPayLaterOption() {
cy.get(connectedWalletExecMethod).click()
}

export function selectRelayOption() {
cy.get(relayExecMethod).click()
}

export function cancelWalletCreation() {
cy.get(cancelBtn).click()
cy.get('button').contains(continueWithWalletBtn).should('be.visible')
Expand Down Expand Up @@ -227,6 +237,10 @@ export function clearNetworkInput(index) {
cy.get(cancelIcon).click()
}

export function clickOnNetwrokRemoveIcon() {
cy.get(cancelIcon).click()
}

export function clickOnNextBtn() {
cy.get(nextBtn).should('be.enabled').click()
}
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 @@ -368,3 +368,9 @@ export function getAddedSafeAddressFromLocalStorage(chainId, index) {
export function changeSafeChainName(originalChain, newChain) {
return originalChain.replace(/^[^:]+:/, newChain + ':')
}

export function getSafeAddressFromUrl(url) {
const addressPattern = /0x[a-fA-F0-9]{40}/
const match = url.match(addressPattern)
return match ? match[0] : null
}
Loading

0 comments on commit fe37198

Please sign in to comment.