Skip to content

Commit

Permalink
Tests: update send funds tests (#3578)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike10ca authored Apr 18, 2024
1 parent 178b8ae commit e075e65
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
13 changes: 8 additions & 5 deletions cypress/e2e/happypath/sendfunds_connected_wallet.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import * as loadsafe from '../pages/load_safe.pages'
import * as navigation from '../pages/navigation.page'
import * as tx from '../pages/transactions.page'
import * as nfts from '../pages/nfts.pages'
import * as ls from '../../support/localstorage_data.js'
import { ethers } from 'ethers'
import SafeApiKit from '@safe-global/api-kit'
import { createEthersAdapter, createSigners } from '../../support/api/utils_ether'
import { createSafes } from '../../support/api/utils_protocolkit'
import { contracts, abi_qtrust, abi_nft_pc2 } from '../../support/api/contracts'

const safeBalanceEth = 5200000000000000n
const qtrustBanance = 91000000000000000025n
const safeBalanceEth = 305220000000000000n
const qtrustBanance = 93000000000000000025n
const transferAmount = '1'

const walletCredentials = JSON.parse(Cypress.env('CYPRESS_WALLET_CREDENTIALS'))
Expand Down Expand Up @@ -44,12 +45,15 @@ const ethAdapterOwner2 = createEthersAdapter(owner2Signer)

function visit(url) {
cy.visit(url)
cy.clearLocalStorage()
main.acceptCookies()
}

describe('Send funds with connected signer happy path tests', { defaultCommandTimeout: 60000 }, () => {
before(async () => {
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__cookies, ls.cookies.acceptedCookies)
main.addToLocalStorage(
constants.localStorageKeys.SAFE_v2__tokenlist_onboarding,
ls.cookies.acceptedTokenListOnboarding,
)
apiKit = new SafeApiKit({
chainId: BigInt(1),
txServiceUrl: constants.stagingTxServiceUrl,
Expand Down Expand Up @@ -94,7 +98,6 @@ describe('Send funds with connected signer happy path tests', { defaultCommandTi
const tx = await contractWithWallet.safeTransferFrom(walletAddress.toString(), originatingSafe, 1, {
gasLimit: 200000,
})

await tx.wait()
main.verifyNonceChange(network_pref + originatingSafe, currentNonce + 1)
})
Expand Down
10 changes: 7 additions & 3 deletions cypress/e2e/happypath/sendfunds_relay.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import * as loadsafe from '../pages/load_safe.pages'
import * as navigation from '../pages/navigation.page'
import * as tx from '../pages/transactions.page'
import * as nfts from '../pages/nfts.pages'
import * as ls from '../../support/localstorage_data.js'
import { ethers } from 'ethers'
import SafeApiKit from '@safe-global/api-kit'
import { createEthersAdapter, createSigners } from '../../support/api/utils_ether'
import { createSafes } from '../../support/api/utils_protocolkit'
import { contracts, abi_qtrust, abi_nft_pc2 } from '../../support/api/contracts'

const safeBalanceEth = 105200000000000000n
const safeBalanceEth = 405200000000000000n
const qtrustBanance = 59000000000000000000n
const transferAmount = '1'

Expand Down Expand Up @@ -43,12 +44,15 @@ const ethAdapterOwner2 = createEthersAdapter(owner2Signer)

function visit(url) {
cy.visit(url)
cy.clearLocalStorage()
main.acceptCookies()
}

describe('Send funds with relay happy path tests', { defaultCommandTimeout: 60000 }, () => {
before(async () => {
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__cookies, ls.cookies.acceptedCookies)
main.addToLocalStorage(
constants.localStorageKeys.SAFE_v2__tokenlist_onboarding,
ls.cookies.acceptedTokenListOnboarding,
)
apiKit = new SafeApiKit({
chainId: BigInt(1),
txServiceUrl: constants.stagingTxServiceUrl,
Expand Down
25 changes: 20 additions & 5 deletions cypress/e2e/pages/main.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const getSafeNFTs = (safeAddress, chain) => {
})
.then((response) => {
expect(response.status).to.eq(200)
return response
})
}

Expand Down Expand Up @@ -105,11 +106,25 @@ export function checkNFTBalance(safeAddress, tokenSymbol, expectedBalance) {
}

export function checkTokenBalanceIsNull(safeAddress, tokenSymbol) {
cy.wait(2000)
getSafeNFTs(safeAddress.substring(4), constants.networkKeys.sepolia).then((response) => {
const targetToken = response.body.results.find((token) => token.tokenSymbol === tokenSymbol)
expect(targetToken).to.be.undefined
})
let pollCount = 0

function poll() {
getSafeNFTs(safeAddress.substring(4), constants.networkKeys.sepolia).then((response) => {
const targetToken = response.body.results.find((token) => token.tokenSymbol === tokenSymbol)
if (targetToken === undefined) {
console.log('Token is undefined as expected. Stopping polling.')
return true
} else if (pollCount < 9) {
pollCount++
console.log('Token is not undefined, retrying...')
cy.wait(1000)
poll()
} else {
throw new Error('Failed to validate token status -undefined- within the allowed polling attempts.')
}
})
}
cy.wrap(null).then(poll).should('be.true')
}

export function acceptCookies(index = 0) {
Expand Down
2 changes: 2 additions & 0 deletions cypress/support/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ export const localStorageKeys = {
SAFE_v2__settings: 'SAFE_v2__settings',
SAFE_v2__addedSafes: 'SAFE_v2__addedSafes',
SAFE_v2__safeApps: 'SAFE_v2__safeApps',
SAFE_v2__cookies: 'SAFE_v2__cookies',
SAFE_v2__tokenlist_onboarding: 'SAFE_v2__tokenlist_onboarding',
}

export const connectWalletNames = {
Expand Down
5 changes: 5 additions & 0 deletions cypress/support/localstorage_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,3 +614,8 @@ export const addedSafes = {
export const pinnedApps = {
transactionBuilder: { 11155111: { pinned: [24], opened: [] } },
}

export const cookies = {
acceptedCookies: { necessary: true, updates: true, analytics: true },
acceptedTokenListOnboarding: true,
}

0 comments on commit e075e65

Please sign in to comment.