Skip to content

Commit

Permalink
Add confirmSpending command
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Aug 19, 2024
1 parent 25fa4d4 commit 1b316ce
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
4 changes: 2 additions & 2 deletions packages/arb-token-bridge-ui/synpress.cctp.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ export default defineConfig({
provider: sepoliaProvider,
networkType: 'parentChain',
sourceWallet: localWallet,
amount: utils.parseUnits('0.0001', 6)
amount: utils.parseUnits('0.0002', 6)
}),
fundUsdc({
address: userWalletAddress,
provider: arbSepoliaProvider,
networkType: 'childChain',
sourceWallet: localWallet,
amount: utils.parseUnits('0.0001', 6)
amount: utils.parseUnits('0.0002', 6)
})
])

Expand Down
4 changes: 3 additions & 1 deletion packages/arb-token-bridge-ui/tests/e2e/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
findTransactionDetailsCustomDestinationAddress,
findTransactionInTransactionHistory,
findClaimButton,
selectTransactionsPanelTab
selectTransactionsPanelTab,
confirmSpending
} from '../support/commands'
import { NetworkType, NetworkName } from '../support/common'

Expand Down Expand Up @@ -62,6 +63,7 @@ declare global {
findTransactionDetailsCustomDestinationAddress: typeof findTransactionDetailsCustomDestinationAddress
findTransactionInTransactionHistory: typeof findTransactionInTransactionHistory
findClaimButton: typeof findClaimButton
confirmSpending: typeof confirmSpending
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ describe('Approve token and deposit afterwards', () => {
cy.findByRole('button', {
name: /Pay approval fee of/
}).click()
cy.confirmMetamaskPermissionToSpend({
spendLimit: '1',
cy.confirmSpending({
shouldWaitForPopupClosure: true
}).then(approved => {
cy.wrap(approved).should('be.true')
})

// TODO: add an assertion here
})
})
})
12 changes: 3 additions & 9 deletions packages/arb-token-bridge-ui/tests/e2e/specs/depositCctp.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Deposit USDC through CCTP', () => {
tokenAddress: CommonAddress.Sepolia.USDC
})

cy.typeAmount(USDCAmountToSend)
cy.findByPlaceholderText(/enter amount/i).type(String(USDCAmountToSend))
cy.findGasFeeSummary(zeroToLessThanOneETH)
cy.findGasFeeForChain('Sepolia', zeroToLessThanOneETH)
cy.findGasFeeForChain(
Expand All @@ -88,11 +88,8 @@ describe('Deposit USDC through CCTP', () => {
cy.findMoveFundsButton().click()

confirmAndApproveCctpDeposit()
cy.confirmMetamaskPermissionToSpend({
spendLimit: USDCAmountToSend.toString(),
cy.confirmSpending({
shouldWaitForPopupClosure: true
}).then(approved => {
cy.wrap(approved).should('be.true')
})

// eslint-disable-next-line
Expand All @@ -110,11 +107,8 @@ describe('Deposit USDC through CCTP', () => {
cy.findMoveFundsButton().click()
confirmAndApproveCctpDeposit()

cy.confirmMetamaskPermissionToSpend({
spendLimit: USDCAmountToSend.toString(),
cy.confirmSpending({
shouldWaitForPopupClosure: true
}).then(approved => {
cy.wrap(approved).should('be.true')
})

// eslint-disable-next-line
Expand Down
16 changes: 4 additions & 12 deletions packages/arb-token-bridge-ui/tests/e2e/specs/withdrawCctp.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ describe('Withdraw USDC through CCTP', () => {
tokenName: 'USDC',
tokenAddress: CommonAddress.ArbitrumSepolia.USDC
})

cy.findByPlaceholderText(/enter amount/i).type(String(USDCAmountToSend))
})

it('should initiate withdrawing USDC to the same address through CCTP successfully', () => {
cy.typeAmount(USDCAmountToSend)
cy.findByText('Gas estimates are not available for this action.').should(
'be.visible'
)
Expand All @@ -78,13 +79,9 @@ describe('Withdraw USDC through CCTP', () => {
cy.findMoveFundsButton().click()

confirmAndApproveCctpWithdrawal()
cy.confirmMetamaskPermissionToSpend({
spendLimit: USDCAmountToSend.toString(),
cy.confirmSpending({
shouldWaitForPopupClosure: true
}).then(approved => {
cy.wrap(approved).should('be.true')
})

// eslint-disable-next-line
cy.wait(40_000)
cy.confirmMetamaskTransaction(undefined)
Expand All @@ -96,17 +93,12 @@ describe('Withdraw USDC through CCTP', () => {
})

it('should initiate withdrawing USDC to custom destination address through CCTP successfully', () => {
cy.typeAmount(USDCAmountToSend)
// cy.findByPlaceholderText(/enter amount/i).type(String(USDCAmountToSend))
cy.fillCustomDestinationAddress()
cy.findMoveFundsButton().click()
confirmAndApproveCctpWithdrawal()

cy.confirmMetamaskPermissionToSpend({
spendLimit: USDCAmountToSend.toString(),
cy.confirmSpending({
shouldWaitForPopupClosure: true
}).then(approved => {
cy.wrap(approved).should('be.true')
})

// eslint-disable-next-line
Expand Down
14 changes: 13 additions & 1 deletion packages/arb-token-bridge-ui/tests/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ export function findClaimButton(
return cy.findByLabelText(`Claim ${amountToClaim}`)
}

/**
* Currently, Synpress confirmMetamaskPermissionToSpend is clicking only once
* We need to call it twice to confirm it
*/
export function confirmSpending(
params: Parameters<typeof cy.confirmMetamaskPermissionToSpend>[0]
) {
cy.confirmMetamaskPermissionToSpend(params)
cy.confirmMetamaskPermissionToSpend(params)
}

Cypress.Commands.addAll({
connectToApp,
login,
Expand All @@ -340,5 +351,6 @@ Cypress.Commands.addAll({
closeTransactionDetails,
findTransactionInTransactionHistory,
findClaimButton,
findTransactionDetailsCustomDestinationAddress
findTransactionDetailsCustomDestinationAddress,
confirmSpending
})

0 comments on commit 1b316ce

Please sign in to comment.