Skip to content

Commit

Permalink
Tests: Fix happy path tests (#3849)
Browse files Browse the repository at this point in the history
* Fix happy path tests
  • Loading branch information
mike10ca committed Jun 20, 2024
1 parent c69b303 commit 62db3d8
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 261 deletions.
168 changes: 88 additions & 80 deletions cypress/e2e/happypath/sendfunds_connected_wallet.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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 = 305240000000000000n
const safeBalanceEth = 505320000000000000n
const qtrustBanance = 99000000000000000025n
const transferAmount = '1'

Expand Down Expand Up @@ -49,7 +49,7 @@ function visit(url) {
cy.visit(url)
}

describe('Send funds with connected signer happy path tests', { defaultCommandTimeout: 60000 }, () => {
describe('Send funds with connected signer happy path tests', { defaultCommandTimeout: 600000 }, () => {
before(async () => {
safesData = await getSafes(CATEGORIES.funds)
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__cookies, ls.cookies.acceptedCookies)
Expand All @@ -75,7 +75,7 @@ describe('Send funds with connected signer happy path tests', { defaultCommandTi
protocolKitOwner2_S3 = safes[1]
})

it('Verify tx creation and execution of NFT with connected signer', () => {
it('Verify tx creation and execution of NFT with connected signer', { defaultCommandTimeout: 300000 }, () => {
cy.wait(2000)
const originatingSafe = safesData.SEP_FUNDS_SAFE_7.substring(4)

Expand Down Expand Up @@ -107,88 +107,96 @@ describe('Send funds with connected signer happy path tests', { defaultCommandTi
})
})

it('Verify tx creation and execution of native token with connected signer', () => {
cy.wait(2000)
const targetSafe = safesData.SEP_FUNDS_SAFE_12.substring(4)
function executeTransactionFlow(fromSafe, toSafe, tokenAmount) {
visit(constants.BALANCE_URL + fromSafe)
assets.clickOnSendBtn(0)
loadsafe.inputOwnerAddress(0, toSafe)
assets.checkSelectedToken(constants.tokenAbbreviation.sep)
assets.enterAmount(tokenAmount)
navigation.clickOnNewTxBtnS()
tx.executeFlow_1()
cy.wait(5000)
}
cy.wrap(null)
.then(() => {
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,
it(
'Verify tx creation and execution of native token with connected signer',
{ defaultCommandTimeout: 300000 },
() => {
cy.wait(2000)
const targetSafe = safesData.SEP_FUNDS_SAFE_12.substring(4)
function executeTransactionFlow(fromSafe, toSafe, tokenAmount) {
visit(constants.BALANCE_URL + fromSafe)
assets.clickOnSendBtn(0)
loadsafe.inputOwnerAddress(0, toSafe)
assets.checkSelectedToken(constants.tokenAbbreviation.sep)
assets.enterAmount(tokenAmount)
navigation.clickOnNewTxBtnS()
tx.executeFlow_1()
cy.wait(5000)
}
cy.wrap(null)
.then(() => {
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,
})

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 pendingTransactions = await apiKit.getPendingTransactions(safeAddress)
const safeTxHashofExistingTx = pendingTransactions.results[0].safeTxHash

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 signature = await protocolKitOwner2_S3.signHash(safeTxHashofExistingTx)
await apiKit.confirmTransaction(safeTxHashofExistingTx, signature.data)

it('Verify tx creation and execution of non-native token with connected signer', () => {
cy.wait(2000)
const originatingSafe = safesData.SEP_FUNDS_SAFE_11.substring(4)
const amount = ethers.parseUnits(transferAmount, unit_eth).toString()
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)
})
},
)

it(
'Verify tx creation and execution of non-native token with connected signer',
{ defaultCommandTimeout: 300000 },
() => {
cy.wait(2000)
const originatingSafe = safesData.SEP_FUNDS_SAFE_11.substring(4)
const amount = ethers.parseUnits(transferAmount, unit_eth).toString()

function executeTransactionFlow(fromSafe, toSafe) {
visit(constants.BALANCE_URL + fromSafe)
assets.selectTokenList(assets.tokenListOptions.allTokens)
assets.clickOnSendBtn(1)
loadsafe.inputOwnerAddress(0, toSafe)
assets.enterAmount(1)
navigation.clickOnNewTxBtnS()
tx.executeFlow_1()
cy.wait(5000)
}
cy.wrap(null)
.then(() => {
return main.fetchCurrentNonce(network_pref + originatingSafe)
})
.then(async (currentNonce) => {
executeTransactionFlow(originatingSafe, walletAddress.toString(), transferAmount)

function executeTransactionFlow(fromSafe, toSafe) {
visit(constants.BALANCE_URL + fromSafe)
assets.selectTokenList(assets.tokenListOptions.allTokens)
assets.clickOnSendBtn(1)
loadsafe.inputOwnerAddress(0, toSafe)
assets.enterAmount(1)
navigation.clickOnNewTxBtnS()
tx.executeFlow_1()
cy.wait(5000)
}
cy.wrap(null)
.then(() => {
return main.fetchCurrentNonce(network_pref + originatingSafe)
})
.then(async (currentNonce) => {
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)
})
})
},
)
})
66 changes: 35 additions & 31 deletions cypress/e2e/happypath/sendfunds_queue_1.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,37 +78,41 @@ describe('Send funds from queue happy path tests 1', () => {
protocolKitOwner2_S3 = safes[3]
})

it('Verify confirmation and execution of native token queued tx by second signer with connected wallet', () => {
cy.wrap(null)
.then(() => {
return main.fetchCurrentNonce(network_pref + existingSafeAddress1)
})
.then(async (currentNonce) => {
const amount = ethers.parseUnits(tokenAmount, unit_eth).toString()
const safeTransactionData = {
to: receiver,
data: '0x',
value: amount.toString(),
}

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

await apiKit.proposeTransaction({
safeAddress,
safeTransactionData: safeTransaction.data,
safeTxHash,
senderAddress: await owner1Signer.getAddress(),
senderSignature: senderSignature.data,
it(
'Verify confirmation and execution of native token queued tx by second signer with connected wallet',
{ defaultCommandTimeout: 300000 },
() => {
cy.wrap(null)
.then(() => {
return main.fetchCurrentNonce(network_pref + existingSafeAddress1)
})

executeTransactionFlow(safeAddress)
cy.wait(5000)
main.verifyNonceChange(network_pref + safeAddress, currentNonce + 1)
})
})
.then(async (currentNonce) => {
const amount = ethers.parseUnits(tokenAmount, unit_eth).toString()
const safeTransactionData = {
to: receiver,
data: '0x',
value: amount.toString(),
}

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

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

executeTransactionFlow(safeAddress)
cy.wait(5000)
main.verifyNonceChange(network_pref + safeAddress, currentNonce + 1)
})
},
)

it.skip('Verify confirmation and execution of native token queued tx by second signer with relayer', () => {
function executeTransactionFlow(fromSafe) {
Expand Down Expand Up @@ -148,7 +152,7 @@ describe('Send funds from queue happy path tests 1', () => {
})
})

it('Verify 1 signer can execute a tx confirmed by 2 signers', () => {
it('Verify 1 signer can execute a tx confirmed by 2 signers', { defaultCommandTimeout: 300000 }, () => {
function executeTransaction(fromSafe) {
visit(constants.transactionQueueUrl + fromSafe)
assets.clickOnExecuteBtn(0)
Expand Down
76 changes: 41 additions & 35 deletions cypress/e2e/happypath/sendfunds_relay.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 = 405210000000000000n
const qtrustBanance = 59000000000000000000n
const safeBalanceEth = 405240000000000000n
const qtrustBanance = 60000000000000000000n
const transferAmount = '1'

const walletCredentials = JSON.parse(Cypress.env('CYPRESS_WALLET_CREDENTIALS'))
Expand Down Expand Up @@ -48,7 +48,8 @@ function visit(url) {
cy.visit(url)
}

describe('Send funds with relay happy path tests', { defaultCommandTimeout: 60000 }, () => {
// TODO: Relay only allows 5 txs per hour.
describe('Send funds with relay happy path tests', { defaultCommandTimeout: 300000 }, () => {
before(async () => {
safesData = await getSafes(CATEGORIES.funds)
main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__cookies, ls.cookies.acceptedCookies)
Expand All @@ -74,7 +75,7 @@ describe('Send funds with relay happy path tests', { defaultCommandTimeout: 6000
protocolKitOwner2_S3 = safes[1]
})

it.skip('Verify tx creation and execution of NFT with relay', () => {
it('Verify tx creation and execution of NFT with relay', { defaultCommandTimeout: 300000 }, () => {
cy.wait(2000)
const originatingSafe = safesData.SEP_FUNDS_SAFE_9.substring(4)
function executeTransactionFlow(fromSafe, toSafe) {
Expand Down Expand Up @@ -106,7 +107,7 @@ describe('Send funds with relay happy path tests', { defaultCommandTimeout: 6000
})
})

it.skip('Verify tx creation and execution of native token with relay', () => {
it('Verify tx creation and execution of native token with relay', { defaultCommandTimeout: 300000 }, () => {
cy.wait(2000)
const targetSafe = safesData.SEP_FUNDS_SAFE_1.substring(4)
function executeTransactionFlow(fromSafe, toSafe, tokenAmount) {
Expand Down Expand Up @@ -158,38 +159,43 @@ describe('Send funds with relay happy path tests', { defaultCommandTimeout: 6000
})
})

it.skip('Verify tx creation and execution of non-native token with with relay', () => {
cy.wait(2000)
const originatingSafe = safesData.SEP_FUNDS_SAFE_2.substring(4)
const amount = ethers.parseUnits(transferAmount, unit_eth).toString()

function executeTransactionFlow(fromSafe, toSafe) {
visit(constants.BALANCE_URL + fromSafe)
assets.selectTokenList(assets.tokenListOptions.allTokens)
assets.clickOnSendBtn(1)
// TODO: Too many requests error occurs. Skip until resolved.
it.skip(
'Verify tx creation and execution of non-native token with with relay',
{ defaultCommandTimeout: 300000 },
() => {
cy.wait(2000)
const originatingSafe = safesData.SEP_FUNDS_SAFE_2.substring(4)
const amount = ethers.parseUnits(transferAmount, unit_eth).toString()

function executeTransactionFlow(fromSafe, toSafe) {
visit(constants.BALANCE_URL + fromSafe)
assets.selectTokenList(assets.tokenListOptions.allTokens)
assets.clickOnSendBtn(1)

loadsafe.inputOwnerAddress(0, toSafe)
assets.enterAmount(1)
navigation.clickOnNewTxBtnS()
tx.executeFlow_2()
cy.wait(5000)
}

loadsafe.inputOwnerAddress(0, toSafe)
assets.enterAmount(1)
navigation.clickOnNewTxBtnS()
tx.executeFlow_2()
cy.wait(5000)
}
cy.wrap(null)
.then(() => {
return main.fetchCurrentNonce(network_pref + originatingSafe)
})
.then(async (currentNonce) => {
executeTransactionFlow(originatingSafe, walletAddress.toString(), transferAmount)

cy.wrap(null)
.then(() => {
return main.fetchCurrentNonce(network_pref + originatingSafe)
})
.then(async (currentNonce) => {
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)
})
})
},
)
})
Loading

0 comments on commit 62db3d8

Please sign in to comment.