Commit 77d46c36 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

test(e2e): de-flake wrap (#6589)

* test(e2e): mv swap to dir

* test(e2e): split swap/wrap/errors

* test(e2e): de-flake wrap
parent 4fb48bdd
import { SupportedChainId, WETH9 } from '@uniswap/sdk-core' import { CurrencyAmount, SupportedChainId, WETH9 } from '@uniswap/sdk-core'
import { getTestSelector } from '../../utils' import { getTestSelector } from '../../utils'
describe('Swap', () => { const WETH = WETH9[SupportedChainId.MAINNET]
it('should be able to wrap ETH', () => {
const BALANCE_INCREMENT = 1 function getWethBalance() {
cy.visit('/swap', { ethereum: 'hardhat' }) return cy
.hardhat() .hardhat()
.then((hardhat) => { .then((hardhat) => hardhat.getBalance(hardhat.wallet, WETH))
cy.then(() => hardhat.getBalance(hardhat.wallet.address, WETH9[SupportedChainId.MAINNET]))
.then((balance) => Number(balance.toFixed(1))) .then((balance) => Number(balance.toFixed(1)))
.then((initialWethBalance) => { }
describe('Swap', () => {
beforeEach(() => {
cy.visit('/swap', { ethereum: 'hardhat' }).hardhat({ automine: false })
})
it('should be able to wrap ETH', () => {
getWethBalance().then((initialWethBalance) => {
// Select WETH for the token output. // Select WETH for the token output.
cy.get('#swap-currency-output .open-currency-select-button').click() cy.get('#swap-currency-output').contains('Select token').click()
cy.contains('WETH').click() cy.contains('WETH').click()
cy.contains('Enter ETH amount')
// Enter the amount to wrap. // Enter the amount to wrap.
cy.get('#swap-currency-output .token-amount-input').clear().type(BALANCE_INCREMENT.toString()) cy.get('#swap-currency-output .token-amount-input').click().type('1')
cy.get('#swap-currency-input .token-amount-input').should('not.equal', '') cy.get('#swap-currency-input .token-amount-input').should('have.value', 1)
// Click the wrap button. // Click the wrap button.
cy.get(getTestSelector('wrap-button')).should('not.be.disabled') cy.contains('Wrap').click()
cy.get(getTestSelector('wrap-button')).click()
// The pending transaction indicator should be visible.
cy.get(getTestSelector('web3-status-connected')).should('have.descendants', ':contains("1 Pending")')
// <automine transaction> // The pending transaction indicator should reflect the state.
cy.get(getTestSelector('web3-status-connected')).should('contain', '1 Pending')
cy.hardhat().then((hardhat) => hardhat.mine())
cy.get(getTestSelector('web3-status-connected')).should('not.contain', 'Pending')
// The pending transaction indicator should be gone. // There should be a successful wrap notification.
cy.get(getTestSelector('web3-status-connected')).should('not.have.descendants', ':contains("1 Pending")') cy.get(getTestSelector('transaction-popup')).contains('Wrapped')
cy.get(getTestSelector('transaction-popup')).contains('1.00 ETH for 1.00 WETH')
// The UI balance should have increased. // The UI balance should have increased.
cy.get('#swap-currency-output [data-testid="balance-text"]').should( cy.get('#swap-currency-output').should('contain', `Balance: ${initialWethBalance + 1}`)
'have.text',
`Balance: ${initialWethBalance + BALANCE_INCREMENT}`
)
// There should be a successful wrap notification.
cy.contains('Wrapped').should('exist')
// The user's WETH account balance should have increased // The user's WETH account balance should have increased
cy.then(() => hardhat.getBalance(hardhat.wallet.address, WETH9[SupportedChainId.MAINNET])) getWethBalance().should('equal', initialWethBalance + 1)
.then((balance) => Number(balance.toFixed(1)))
.should('eq', initialWethBalance + BALANCE_INCREMENT)
})
}) })
}) })
it('should be able to unwrap WETH', () => { it('should be able to unwrap WETH', () => {
const BALANCE_INCREMENT = 1 cy.hardhat().then(async (hardhat) => {
cy.visit('/swap', { ethereum: 'hardhat' }) await hardhat.fund(hardhat.wallet, CurrencyAmount.fromRawAmount(WETH, 1e18))
.hardhat() await hardhat.mine()
.then((hardhat) => { })
cy.then(() => hardhat.getBalance(hardhat.wallet.address, WETH9[SupportedChainId.MAINNET])).then(
(initialBalance) => { getWethBalance().then((initialWethBalance) => {
// Select WETH for the token output. // Select WETH for the token output.
cy.get('#swap-currency-output .open-currency-select-button').click() cy.get('#swap-currency-output').contains('Select token').click()
cy.contains('WETH').click() cy.contains('WETH').click()
// Enter the amount to wrap. // Swap input/output to unwrap WETH.
cy.get('#swap-currency-output .token-amount-input').clear().type(BALANCE_INCREMENT.toString())
cy.get('#swap-currency-input .token-amount-input').should('not.equal', '')
// Click the wrap button.
cy.get(getTestSelector('wrap-button')).should('not.be.disabled')
cy.get(getTestSelector('wrap-button')).click()
// <automine transaction>
// The pending transaction indicator should be visible.
cy.contains('1 Pending').should('exist')
// The user should see a notification telling them they successfully wrapped their ETH.
cy.contains('Wrapped').should('exist')
// Switch to unwrapping the ETH we just wrapped.
cy.get(getTestSelector('swap-currency-button')).click() cy.get(getTestSelector('swap-currency-button')).click()
cy.get(getTestSelector('wrap-button')).should('not.be.disabled') cy.contains('Enter WETH amount')
// Click the Unwrap button.
cy.get(getTestSelector('wrap-button')).click()
// The pending transaction indicator should be visible. // Enter the amount to unwrap.
cy.contains('1 Pending').should('exist') cy.get('#swap-currency-output .token-amount-input').click().type('1')
cy.get('#swap-currency-input .token-amount-input').should('have.value', 1)
// <automine transaction> // Click the unwrap button.
cy.contains('Unwrap').click()
// The pending transaction indicator should be gone. // The pending transaction indicator should reflect the state.
cy.contains('1 Pending').should('not.exist') cy.get(getTestSelector('web3-status-connected')).should('contain', '1 Pending')
// The user should see a notification telling them they successfully unwrapped their ETH. cy.hardhat().then((hardhat) => hardhat.mine())
cy.contains('Unwrapped').should('exist') cy.get(getTestSelector('web3-status-connected')).should('not.contain', 'Pending')
// The UI balance should have decreased. // There should be a successful wrap notification.
cy.get('#swap-currency-input [data-testid="balance-text"]').should( cy.get(getTestSelector('transaction-popup')).contains('Unwrapped')
'have.text', cy.get(getTestSelector('transaction-popup')).contains('1.00 WETH for 1.00 ETH')
`Balance: ${initialBalance.toFixed(0)}`
)
// There should be a successful unwrap notification. // The UI balance should have increased.
cy.contains('Unwrapped').should('exist') cy.get('#swap-currency-input').should('contain', `Balance: ${initialWethBalance - 1}`)
// The user's WETH account balance should not have changed from the initial balance // The user's WETH account balance should have increased
cy.then(() => hardhat.getBalance(hardhat.wallet.address, WETH9[SupportedChainId.MAINNET])) getWethBalance().should('equal', initialWethBalance - 1)
.then((balance) => balance.toFixed(0))
.should('eq', initialBalance.toFixed(0))
}
)
}) })
}) })
}) })
...@@ -22,12 +22,14 @@ const EndColumn = styled(Column)` ...@@ -22,12 +22,14 @@ const EndColumn = styled(Column)`
` `
export default function PortfolioRow({ export default function PortfolioRow({
['data-testid']: testId,
left, left,
title, title,
descriptor, descriptor,
right, right,
onClick, onClick,
}: { }: {
'data-testid'?: string
left: React.ReactNode left: React.ReactNode
title: React.ReactNode title: React.ReactNode
descriptor?: React.ReactNode descriptor?: React.ReactNode
...@@ -36,7 +38,7 @@ export default function PortfolioRow({ ...@@ -36,7 +38,7 @@ export default function PortfolioRow({
onClick?: () => void onClick?: () => void
}) { }) {
return ( return (
<PortfolioRowWrapper onClick={onClick}> <PortfolioRowWrapper data-testid={testId} onClick={onClick}>
{left} {left}
<AutoColumn grow> <AutoColumn grow>
{title} {title}
......
...@@ -29,6 +29,7 @@ function TransactionPopupContent({ tx, chainId }: { tx: TransactionDetails; chai ...@@ -29,6 +29,7 @@ function TransactionPopupContent({ tx, chainId }: { tx: TransactionDetails; chai
return ( return (
<PortfolioRow <PortfolioRow
data-testid="transaction-popup"
left={ left={
success ? ( success ? (
<Column> <Column>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment