uniswap-interface-uncensored/cypress/e2e/swap/errors.test.ts

108 lines
4.8 KiB
TypeScript
Raw Normal View History

import { BigNumber } from '@ethersproject/bignumber'
import { SupportedChainId } from '@uniswap/sdk-core'
import { DEFAULT_DEADLINE_FROM_NOW } from '../../../src/constants/misc'
import { UNI, USDC_MAINNET } from '../../../src/constants/tokens'
import { getBalance, getTestSelector } from '../../utils'
const UNI_MAINNET = UNI[SupportedChainId.MAINNET]
describe('Swap errors', () => {
it('wallet rejection', () => {
cy.visit(`/swap?inputCurrency=ETH&outputCurrency=${USDC_MAINNET.address}`, { ethereum: 'hardhat' })
cy.hardhat().then((hardhat) => {
// Stub the wallet to reject any transaction.
cy.stub(hardhat.wallet, 'sendTransaction').log(false).rejects(new Error('user cancelled'))
// Enter amount to swap
cy.get('#swap-currency-output .token-amount-input').type('1').should('have.value', '1')
cy.get('#swap-currency-input .token-amount-input').should('not.have.value', '')
// Submit transaction
cy.get('#swap-button').click()
cy.contains('Confirm swap').click()
cy.wait('@eth_estimateGas')
// Verify rejection
cy.contains('Review swap')
cy.contains('Confirm swap')
})
})
it('transaction past deadline', () => {
cy.visit(`/swap?inputCurrency=ETH&outputCurrency=${USDC_MAINNET.address}`, { ethereum: 'hardhat' })
cy.hardhat({ automine: false })
getBalance(USDC_MAINNET).then((initialBalance) => {
// Enter amount to swap
cy.get('#swap-currency-output .token-amount-input').type('1').should('have.value', '1')
cy.get('#swap-currency-input .token-amount-input').should('not.have.value', '')
// Submit transaction
cy.get('#swap-button').click()
cy.contains('Confirm swap').click()
cy.wait('@eth_estimateGas').wait('@eth_sendRawTransaction').wait('@eth_getTransactionReceipt')
cy.contains('Transaction submitted')
feat: permit2 flow updates (#6538) * test: swap flow cypress tests * fix: use default parameter * feat: use Swap Component on TDP * feat: auto nav for TDP tokens * chore: merge * chore: merge * chore: merge * chore: merge * fix: remove extra inputCurrency URL parsing logic * fix: undo last change * fix: pass expected chain id to swap component * fix: search for default tokens on unconnected networks if needed * test: e2e test for l2 token * fix: delete irrelevant tests * fix: address comments * fix: lint error * test: update TDP e2e tests * fix: use pageChainId for filter * fix: rename chainId * fix: typecheck * fix: chainId bug * fix: chainId required fixes * fix: bad merge in e2e test * fix: remove unused test util * fix: remove unnecessary variable * fix: token defaults * fix: address comments * fix: address comments and fix tests * fix: e2e test formatting, remove Maybe<> * fix: remove unused variable * fix: use feature flag for swap component on TDP * fix: back button * feat: copy review screen UI from widgetg * fix: modal padding * feat: add final detail row * fix: remove widget comment * fix: update unit tests * fix: code style consistency * fix: remove padding from AutoColumn * fix: update snapshots * fix: use semantic gaps * fix: more px and gaps * fix: design feedbacks * fix: button radius in summary modal * fix: design nits * feat: update design of summary modal * fix: font weight and vertical spacing * fix: update snapshots * fix: css nits * fix: modal flicker when refetching trade * wip: move approval to summary modal * wip: not working * feat: working * fix: fix flow * feat: simplify states and build new modal UI * feat: todos and differs fix * feat: update tx status modal * feat: split up approve and permit * feat: error state * feat: update success and error states * feat: undo changes to TxConfirmationModal * feat: remove step indicators when only one step * feat: move content into PendingModalContent component * fix: lint * fix: correct modal state when moving between steps * fix: comments * fix: code style improvements * feat: require trade to be defined * fix: remove extra props from ThemedTexts * fix: one more trans * fix: remove unused export * feat: remove undefined checks and other fixes * fix: update test * fix: add missing dollar sign * fix: remove null check and update test * fix: remove max width from detail row value * fix: remove isOpen prop * fix: isopen * feat: refactor approval flow into a hook * fix: tradeMeaningfullyDiffers improvement and prepareFlow fix * fix: address comments * feat: add comments explaining async state * fix: nits * fix: address comments * feat: permit2 e2e tests (#6541) * wip: move approval to summary modal * wip: not working * feat: working * fix: fix flow * feat: simplify states and build new modal UI * feat: todos and differs fix * feat: update tx status modal * feat: split up approve and permit * feat: error state * feat: update success and error states * feat: undo changes to TxConfirmationModal * feat: re-order functions * wip: move approval to summary modal * wip: not working * feat: update permit2 e2e tests * feat: tests passing * fix: swap test * fix: bad merge * chore: merge * fix: update tests for new modal * fix: testid fix * fix: test updates * fix: reduce nesting * test: remove line from test for debugging * fix: update tests * fix: more nesting in test * fix: update test * fix: reorganize test code
2023-05-25 23:49:27 +03:00
cy.get(getTestSelector('confirmation-close-icon')).click()
cy.get(getTestSelector('web3-status-connected')).should('contain', '1 Pending')
// Mine transaction
cy.hardhat().then(async (hardhat) => {
// Remove the transaction from the mempool, so that it doesn't fail but it is past the deadline.
// This should result in it being removed from pending transactions, without a failure notificiation.
const transactions = await hardhat.send('eth_pendingTransactions', [])
await hardhat.send('hardhat_dropTransaction', [transactions[0].hash])
// Mine past the deadline
await hardhat.mine(1, DEFAULT_DEADLINE_FROM_NOW + 1)
})
cy.wait('@eth_getTransactionReceipt')
// Verify transaction did not occur
cy.get(getTestSelector('web3-status-connected')).should('not.contain', 'Pending')
cy.get(getTestSelector('popups')).should('not.contain', 'Swap failed')
cy.get('#swap-currency-output').contains(`Balance: ${initialBalance}`)
getBalance(USDC_MAINNET).should('eq', initialBalance)
})
})
it('slippage failure', () => {
cy.visit(`/swap?inputCurrency=ETH&outputCurrency=${UNI_MAINNET.address}`, { ethereum: 'hardhat' })
cy.hardhat({ automine: false })
getBalance(USDC_MAINNET).then((initialBalance) => {
// Gas estimation fails for this transaction (that would normally fail), so we stub it.
cy.hardhat().then((hardhat) => {
const send = cy.stub(hardhat.provider, 'send').log(false)
send.withArgs('eth_estimateGas').resolves(BigNumber.from(2_000_000))
send.callThrough()
})
// Set slippage to a very low value.
cy.get(getTestSelector('open-settings-dialog-button')).click()
cy.get(getTestSelector('max-slippage-settings')).click()
cy.get(getTestSelector('slippage-input')).clear().type('0.01')
cy.get('body').click('topRight') // close modal
cy.get(getTestSelector('slippage-input')).should('not.exist')
// Submit 2 transactions
for (let i = 0; i < 2; i++) {
cy.get('#swap-currency-input .token-amount-input').type('200').should('have.value', '200')
cy.get('#swap-currency-output .token-amount-input').should('not.have.value', '')
cy.get('#swap-button').click()
cy.contains('Confirm swap').click()
cy.wait('@eth_sendRawTransaction').wait('@eth_getTransactionReceipt')
cy.contains('Transaction submitted')
cy.get(getTestSelector('confirmation-close-icon')).click()
}
cy.get(getTestSelector('web3-status-connected')).should('contain', '2 Pending')
// Mine transactions
cy.hardhat().then((hardhat) => hardhat.mine())
cy.wait('@eth_getTransactionReceipt')
// Verify transaction did not occur
cy.get(getTestSelector('web3-status-connected')).should('not.contain', 'Pending')
cy.get(getTestSelector('popups')).contains('Swap failed')
getBalance(UNI_MAINNET).should('eq', initialBalance)
})
})
})