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 relay check #3909

Merged
merged 1 commit into from
Jul 5, 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
104 changes: 59 additions & 45 deletions cypress/e2e/happypath/sendfunds_relay.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { contracts, abi_qtrust, abi_nft_pc2 } from '../../support/api/contracts'
import { getSafes, CATEGORIES } from '../../support/safes/safesHandler.js'
import * as wallet from '../../support/utils/wallet.js'

const safeBalanceEth = 405240000000000000n
const safeBalanceEth = 405250000000000000n
const qtrustBanance = 60000000000000000000n
const transferAmount = '1'

Expand Down Expand Up @@ -97,15 +97,19 @@ describe('Send funds with relay happy path tests', { defaultCommandTimeout: 3000
return main.fetchCurrentNonce(network_pref + originatingSafe)
})
.then(async (currentNonce) => {
executeTransactionFlow(originatingSafe, walletAddress.toString(), transferAmount).then(async () => {
main.checkTokenBalanceIsNull(network_pref + originatingSafe, constants.tokenAbbreviation.tpcc)
const contractWithWallet = nftContract.connect(owner1Signer)
const tx = await contractWithWallet.safeTransferFrom(walletAddress.toString(), originatingSafe, 2, {
gasLimit: 200000,
return main.getRelayRemainingAttempts(originatingSafe).then((remainingAttempts) => {
if (remainingAttempts < 1) {
throw new Error(main.noRelayAttemptsError)
}
executeTransactionFlow(originatingSafe, walletAddress.toString(), transferAmount).then(async () => {
main.checkTokenBalanceIsNull(network_pref + originatingSafe, constants.tokenAbbreviation.tpcc)
const contractWithWallet = nftContract.connect(owner1Signer)
const tx = await contractWithWallet.safeTransferFrom(walletAddress.toString(), originatingSafe, 2, {
gasLimit: 200000,
})
await tx.wait()
main.verifyNonceChange(network_pref + originatingSafe, currentNonce + 1)
})

await tx.wait()
main.verifyNonceChange(network_pref + originatingSafe, currentNonce + 1)
})
})
})
Expand All @@ -129,37 +133,42 @@ describe('Send funds with relay happy path tests', { defaultCommandTimeout: 3000
return main.fetchCurrentNonce(network_pref + targetSafe)
})
.then(async (currentNonce) => {
executeTransactionFlow(targetSafe, walletAddress.toString(), tokenAmount2)
const amount = ethers.parseUnits(tokenAmount2, unit_eth).toString()
const safeTransactionData = {
to: targetSafe,
data: '0x',
value: amount.toString(),
}

const safeTransaction = await protocolKitOwner1_S3.createTransaction({ transactions: [safeTransactionData] })
const safeTxHash = await protocolKitOwner1_S3.getTransactionHash(safeTransaction)
const senderSignature = await protocolKitOwner1_S3.signHash(safeTxHash)
const safeAddress = outgoingSafeAddress

await apiKit.proposeTransaction({
safeAddress,
safeTransactionData: safeTransaction.data,
safeTxHash,
senderAddress: await owner1Signer.getAddress(),
senderSignature: senderSignature.data,
})
return main.getRelayRemainingAttempts(targetSafe).then(async (remainingAttempts) => {
if (remainingAttempts < 1) {
throw new Error(main.noRelayAttemptsError)
}
executeTransactionFlow(targetSafe, walletAddress.toString(), tokenAmount2)
const amount = ethers.parseUnits(tokenAmount2, unit_eth).toString()
const safeTransactionData = {
to: targetSafe,
data: '0x',
value: amount.toString(),
}

const safeTransaction = await protocolKitOwner1_S3.createTransaction({ transactions: [safeTransactionData] })
const safeTxHash = await protocolKitOwner1_S3.getTransactionHash(safeTransaction)
const senderSignature = await protocolKitOwner1_S3.signHash(safeTxHash)
const safeAddress = outgoingSafeAddress

await apiKit.proposeTransaction({
safeAddress,
safeTransactionData: safeTransaction.data,
safeTxHash,
senderAddress: await owner1Signer.getAddress(),
senderSignature: senderSignature.data,
})

const pendingTransactions = await apiKit.getPendingTransactions(safeAddress)
const safeTxHashofExistingTx = pendingTransactions.results[0].safeTxHash
const pendingTransactions = await apiKit.getPendingTransactions(safeAddress)
const safeTxHashofExistingTx = pendingTransactions.results[0].safeTxHash

const signature = await protocolKitOwner2_S3.signHash(safeTxHashofExistingTx)
await apiKit.confirmTransaction(safeTxHashofExistingTx, signature.data)
const signature = await protocolKitOwner2_S3.signHash(safeTxHashofExistingTx)
await apiKit.confirmTransaction(safeTxHashofExistingTx, signature.data)

const safeTx = await apiKit.getTransaction(safeTxHashofExistingTx)
await protocolKitOwner2_S3.executeTransaction(safeTx)
main.verifyNonceChange(network_pref + targetSafe, currentNonce + 1)
main.checkTokenBalance(network_pref + targetSafe, constants.tokenAbbreviation.eth, safeBalanceEth)
const safeTx = await apiKit.getTransaction(safeTxHashofExistingTx)
await protocolKitOwner2_S3.executeTransaction(safeTx)
main.verifyNonceChange(network_pref + targetSafe, currentNonce + 1)
main.checkTokenBalance(network_pref + targetSafe, constants.tokenAbbreviation.eth, safeBalanceEth)
})
})
})

Expand All @@ -186,16 +195,21 @@ describe('Send funds with relay happy path tests', { defaultCommandTimeout: 3000
return main.fetchCurrentNonce(network_pref + originatingSafe)
})
.then(async (currentNonce) => {
executeTransactionFlow(originatingSafe, walletAddress.toString(), transferAmount)
return main.getRelayRemainingAttempts(originatingSafe).then(async (remainingAttempts) => {
if (remainingAttempts < 1) {
throw new Error(main.noRelayAttemptsError)
}
executeTransactionFlow(originatingSafe, walletAddress.toString(), transferAmount)

const contractWithWallet = tokenContract.connect(signers[0])
const tx = await contractWithWallet.transfer(originatingSafe, amount, {
gasLimit: 200000,
})

const contractWithWallet = tokenContract.connect(signers[0])
const tx = await contractWithWallet.transfer(originatingSafe, amount, {
gasLimit: 200000,
await tx.wait()
main.verifyNonceChange(network_pref + originatingSafe, currentNonce + 1)
main.checkTokenBalance(network_pref + originatingSafe, constants.tokenAbbreviation.qtrust, qtrustBanance)
})

await tx.wait()
main.verifyNonceChange(network_pref + originatingSafe, currentNonce + 1)
main.checkTokenBalance(network_pref + originatingSafe, constants.tokenAbbreviation.qtrust, qtrustBanance)
})
})
})
25 changes: 25 additions & 0 deletions cypress/e2e/pages/main.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const acceptSelection = 'Save settings'
const executeStr = 'Execute'
const connectedOwnerBlock = '[data-testid="open-account-center"]'
export const modalDialogCloseBtn = '[data-testid="modal-dialog-close-btn"]'
export const noRelayAttemptsError = 'Not enough relay attempts remaining'

export function checkElementBackgroundColor(element, color) {
cy.get(element).should('have.css', 'background-color', color)
Expand Down Expand Up @@ -84,6 +85,23 @@ export function fetchCurrentNonce(safeAddress) {
)
}

export const getRelayRemainingAttempts = (safeAddress) => {
const chain = constants.networkKeys.sepolia

return cy
.request({
method: 'GET',
url: `${constants.stagingCGWUrlv1}${constants.stagingCGWChains}${chain}${constants.relayPath}${safeAddress}`,
headers: {
accept: 'application/json',
},
})
.then((response) => {
console.log('Remaining relay attempts: ', response.body.remaining)
return response.body.remaining
})
}

export function verifyNonceChange(safeAddress, expectedNonce) {
fetchCurrentNonce(safeAddress).then((newNonce) => {
expect(newNonce).to.equal(expectedNonce)
Expand All @@ -98,6 +116,13 @@ export function checkTokenBalance(safeAddress, tokenSymbol, expectedBalance) {
})
}

export function getTokenBalance(safeAddress, tokenSymbol) {
getSafeBalance(safeAddress.substring(4), constants.networkKeys.sepolia).then((response) => {
const targetToken = response.body.items.find((token) => token.tokenInfo.symbol === tokenSymbol)
console.log('**** TOKEN BALANCE', targetToken.balance)
})
}

export function checkNFTBalance(safeAddress, tokenSymbol, expectedBalance) {
getSafeNFTs(safeAddress.substring(4), constants.networkKeys.sepolia).then((response) => {
const targetToken = response.body.results.find((token) => token.tokenSymbol === tokenSymbol)
Expand Down
1 change: 1 addition & 0 deletions cypress/support/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const stagingCGWChains = '/chains/'
export const stagingCGWSafes = '/safes/'
export const stagingCGWNone = '/nonces/'
export const stagingCGWCollectibles = '/collectibles/'
export const relayPath = '/relay/'
export const stagingCGWAllTokensBalances = '/balances/USD?trusted=false&exclude_spam=false'

export const proposeEndpoint = '/**/propose'
Expand Down
Loading