Files
05cab32f0e tests(web): connect wallet via seeded storage in e2e (#8350)
* tests(web): connect wallet via seeded storage in e2e

Replace the UI-driven connectSigner flow with storage-seeded auto-reconnect
across the Cypress suite. Adds connectSignerViaStorage (seed on visit, or seed
+ reload) and migrates 139 entry connects; keeps UI connectSigner for the 27
connect/switch-flow sites that act on in-page state.

* tests(web): seed batch via single page load in batch e2e

Add optional extraStorage to connectSignerViaStorage so localStorage is
seeded in onBeforeLoad on the initial visit. Split batch_tx into
build-via-UI and pre-seeded describes, dropping addToLocalStorage +
cy.reload() double-loads.

* tests(web): seed state on a single page load across e2e specs

Replace visit-then-write-then-reload double-loads with a single seeded
load (extraStorage on connectSignerViaStorage, or onBeforeLoad on
cy.visit), and drop the arbitrary post-reload settle waits. Covers the
multichain, nested-safes, batch, address-book, safe-selector and
create-safe specs (regression, smoke, visual).

* tests(web): seed state on a single page load in more e2e specs

Fold pre-seeded localStorage into the initial visit (extraStorage /
onBeforeLoad) and drop the follow-up reloads across the address-book,
messages-popup, CF-safe, import/export and load-safe specs. Split specs
whose shared beforeEach served both seeding and non-seeding tests into
nested describes so no test double-loads.

* tests(web): remove redundant wallet reconnect reloads in e2e specs

Pass the URL to connectSignerViaStorage so the wallet is seeded on the
initial visit instead of visiting then reconnecting (which reloaded).
Where a shared beforeEach served both connected and disconnected (or
differently-seeded) tests, split into nested describes so no test
double-loads. Covers proposers, swaps, twaps, assets, swaps_tokens,
sidebar, spending_limits, bulk_execution, proposers_2, safe_selector.

* tests(web): single-load owner-management e2e specs

Split add/remove/replace-owner specs into connected / disconnected /
non-owner / pre-seeded describes so the wallet is seeded on the initial
visit (no reconnect reload) without forcing a connect onto tests that
assert disconnected or non-owner state.

* tests(web): wait for wallet connection after seeded connect

The last wallet reconnects asynchronously after the page loads, so
connectSignerViaStorage now waits for the connected-wallet header chip
(open-account-center) before resolving, instead of letting tests proceed
while still disconnected. Opt out via waitForConnection:false for pages
without that chip (welcome/accounts in safe_selector).

* tests(web): address review on seeded-connect PR

- Drop the explicit 30s timeout on the connected-wallet wait; the repo
  default (10s) is plenty for the post-load reconnect and fails faster.
- Make recovery.cy.js consistent: the remaining connectSigner calls now
  use connectSignerViaStorage like the rest of the file. All connects are
  at test start (none mid-flow), matching the already-converted tests.

* fix: wait for the wallet connection to establish to avoid failing tests due to disconnected wallet

---------

Co-authored-by: vmosharova <[email protected]>
2026-07-31 17:00:56 +02:00

113 lines
4.7 KiB
JavaScript

import * as batch from '../pages/batches.pages'
import * as constants from '../../support/constants'
import * as owner from '../../e2e/pages/owners.pages.js'
import { getSafes, CATEGORIES } from '../../support/safes/safesHandler.js'
import * as wallet from '../../support/utils/wallet.js'
import * as ls from '../../support/localstorage_data.js'
import * as navigation from '../pages/navigation.page.js'
import { getMockAddress } from '../../support/utils/ethers.js'
const currentNonce = 3
const funds_first_tx = '0.001'
const funds_second_tx = '0.002'
let staticSafes = []
const walletCredentials = JSON.parse(Cypress.env('CYPRESS_WALLET_CREDENTIALS'))
const signer = walletCredentials.OWNER_4_PRIVATE_KEY
const signer2 = walletCredentials.OWNER_3_PRIVATE_KEY
describe('Batch transaction tests', { defaultCommandTimeout: 30000 }, () => {
before(async () => {
staticSafes = await getSafes(CATEGORIES.static)
})
describe('Building a batch', () => {
beforeEach(() => {
wallet.connectSignerViaStorage(signer, constants.BALANCE_URL + staticSafes.SEP_STATIC_SAFE_2)
owner.waitForConnectionStatus()
})
it('Verify the Add batch button is present in a transaction form', () => {
//The "true" is to validate that the add to batch button is not visible if "Yes, execute" is selected
batch.addNewTransactionToBatch(getMockAddress(), currentNonce, funds_first_tx)
})
it('Verify a second transaction can be added to the batch', () => {
batch.addNewTransactionToBatch(getMockAddress(), currentNonce, funds_first_tx)
cy.wait(1000)
batch.addNewTransactionToBatch(getMockAddress(), currentNonce, funds_first_tx)
batch.verifyBatchIconCount(2)
batch.clickOnBatchCounter()
batch.verifyAmountTransactionsInBatch(2)
})
it('Verify the "New transaction" button in Add batch modal is enabled/disabled for different users types', () => {
navigation.clickOnWalletExpandMoreIcon()
navigation.clickOnDisconnectBtn()
wallet.connectSigner(signer)
batch.openBatchtransactionsModal()
batch.verifyNewTxButtonStatus(constants.enabledStates.enabled)
batch.closeBatchtransactionsModal()
navigation.clickOnWalletExpandMoreIcon()
navigation.clickOnDisconnectBtn()
wallet.connectSigner(signer2)
owner.waitForConnectionStatus()
batch.verifyNewTxButtonStatus(constants.enabledStates.disabled)
navigation.clickOnWalletExpandMoreIcon()
navigation.clickOnDisconnectBtn()
batch.verifyNewTxButtonStatus(constants.enabledStates.disabled)
})
it('Verify that the Add batch button is not present on non-safe pages', () => {
const urls = [constants.welcomeUrl, constants.appSettingsUrl, constants.appsUrl]
urls.forEach((url) => {
cy.visit(url)
cy.get(batch.batchTxTopBar).should('not.exist')
})
})
it('Verify a transaction can be added to the batch', () => {
batch.addNewTransactionToBatch(constants.EOA, currentNonce, funds_first_tx)
batch.verifyBatchIconCount(1)
batch.clickOnBatchCounter()
batch.verifyAmountTransactionsInBatch(1)
})
})
describe('Operating on a pre-seeded batch', () => {
beforeEach(() => {
wallet.connectSignerViaStorage(signer, constants.BALANCE_URL + staticSafes.SEP_STATIC_SAFE_2, {
extraStorage: { [constants.localStorageKeys.SAFE_v2__batch]: ls.batchData.entry0 },
})
owner.waitForConnectionStatus()
})
it('Verify that clicking on "Confirm batch" button opens confirm batch modal with listed transactions', () => {
batch.clickOnBatchCounter()
batch.clickOnConfirmBatchBtn()
cy.contains(funds_first_tx).parents('ul').as('TransactionList')
cy.get('@TransactionList').find('li').eq(0).contains(funds_first_tx)
cy.get('@TransactionList').find('li').eq(1).contains(funds_second_tx)
cy.contains(batch.addToBatchBtn).should('have.length', 0)
})
it('Verify a batched tx can be expanded and collapsed', () => {
batch.clickOnBatchCounter()
cy.contains(funds_first_tx).parents('ul').as('TransactionList')
cy.get('@TransactionList').find('li').eq(0).contains(funds_first_tx).click()
batch.isTxExpanded(0, true)
cy.get('@TransactionList').find('li').eq(0).contains(funds_first_tx).click()
batch.isTxExpanded(0, false)
})
it('Verify a transaction can be removed from the batch', () => {
batch.clickOnBatchCounter()
cy.contains(batch.batchedTransactionsStr).should('be.visible').parents('aside').find('ul > li').as('BatchList')
cy.get('@BatchList').find(batch.deleteTransactionbtn).eq(0).click()
cy.get('@BatchList').should('have.length', 1)
cy.get('@BatchList').contains(funds_first_tx).should('not.exist')
})
})
})