Commit 3d8d29fd authored by Jordan Frankfurt's avatar Jordan Frankfurt Committed by GitHub

feat: e2e testing - Handle wallet rejection (#6442)

* chore: ignore hardhat cache files

* test: add forking hardhat config

* test: install cypress-hardhat

* build: add cypress-hardhat

* fix: lint

* build: add hardhat

* build: add @sentry/types

* fix: better origin

* test: update cypress VisitOptions to include hardhat

* fix: default to connected wallet user state

* test: add a hardhat provider

* build: update imports

* chore: comments

* fix: massage eth_sendTransaction

* feat: example swap test (#6415)

* initial commit

* add intercept for amplitude

* fix: destructure result

* click swap submission

* fix: eth_sendTransaction via bridge

* test works

* finish chain interaction test

---------
Co-authored-by: default avatarZach Pomerantz <zzmp@uniswap.org>

* stub sending a transaction to simulate wallet rejection of a transaction

finish test

s

* Update cypress/e2e/swap.test.ts
Co-authored-by: default avatarZach Pomerantz <zzmp@uniswap.org>

* lint

* fix network connection bug

---------
Co-authored-by: default avatarZach Pomerantz <zzmp@uniswap.org>
parent c178da62
......@@ -81,17 +81,21 @@ describe('Swap', () => {
it('can swap ETH for USDC', () => {
const TOKEN_ADDRESS = USDC_MAINNET.address
const BALANCE_INCREMENT = 1
cy.then(() => hardhat.utils.getBalance(hardhat.wallet.address, USDC_MAINNET))
cy.visit('/swap', { ethereum: 'hardhat' })
.then((window) => {
hardhat = window.hardhat
})
.then(() => hardhat.utils.getBalance(hardhat.wallet.address, USDC_MAINNET))
.then((balance) => Number(balance.toFixed(1)))
.then((initialBalance) => {
cy.get('#swap-currency-output .open-currency-select-button').click()
cy.get('[data-testid="token-search-input"]').clear().type(TOKEN_ADDRESS)
cy.get(getTestSelector('token-search-input')).clear().type(TOKEN_ADDRESS)
cy.contains('USDC').click()
cy.get('#swap-currency-output .token-amount-input').clear().type(BALANCE_INCREMENT.toString())
cy.get('#swap-currency-input .token-amount-input').should('not.equal', '')
cy.get('#swap-button').click()
cy.get('#confirm-swap-or-send').click()
cy.get('[data-testid="dismiss-tx-confirmation"]').click()
cy.get(getTestSelector('dismiss-tx-confirmation')).click()
// ui check
cy.get('#swap-currency-output [data-testid="balance-text"]').should(
'have.text',
......@@ -154,6 +158,24 @@ describe('Swap', () => {
cy.get('#swap-currency-output .token-amount-input').should('have.value', '0.01')
})
it('should render and dismiss the wallet rejection modal', () => {
cy.visit('/swap', { ethereum: 'hardhat' }).then((window) => {
hardhat = window.hardhat
cy.stub(hardhat.wallet, 'sendTransaction').rejects(new Error('user cancelled'))
cy.get('#swap-currency-output .open-currency-select-button').click()
cy.get(getTestSelector('token-search-input')).clear().type(USDC_MAINNET.address)
cy.contains('USDC').click()
cy.get('#swap-currency-output .token-amount-input').clear().type('1')
cy.get('#swap-currency-input .token-amount-input').should('not.equal', '')
cy.get('#swap-button').click()
cy.get('#confirm-swap-or-send').click()
cy.contains('Transaction rejected').should('exist')
cy.contains('Dismiss').click()
cy.contains('Transaction rejected').should('not.exist')
})
})
it('Opens and closes the settings menu', () => {
cy.visit('/swap')
cy.contains('Settings').should('not.exist')
......
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