2023-05-17 19:43:52 +03:00
|
|
|
import { SupportedChainId } from '@uniswap/sdk-core'
|
|
|
|
|
|
|
|
import { UNI, USDC_MAINNET } from '../../../src/constants/tokens'
|
2023-05-22 19:02:54 +03:00
|
|
|
import { getBalance, getTestSelector } from '../../utils'
|
2023-05-17 19:43:52 +03:00
|
|
|
|
|
|
|
const UNI_MAINNET = UNI[SupportedChainId.MAINNET]
|
|
|
|
|
|
|
|
describe('Swap', () => {
|
|
|
|
describe('Swap on main page', () => {
|
|
|
|
it('starts with ETH selected by default', () => {
|
2023-05-22 19:02:54 +03:00
|
|
|
cy.visit('/swap')
|
2023-05-17 19:43:52 +03:00
|
|
|
cy.get(`#swap-currency-input .token-amount-input`).should('have.value', '')
|
|
|
|
cy.get(`#swap-currency-input .token-symbol-container`).should('contain.text', 'ETH')
|
|
|
|
cy.get(`#swap-currency-output .token-amount-input`).should('not.have.value')
|
|
|
|
cy.get(`#swap-currency-output .token-symbol-container`).should('contain.text', 'Select token')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should default inputs from URL params ', () => {
|
2023-05-22 19:02:54 +03:00
|
|
|
cy.visit(`/swap?inputCurrency=${UNI_MAINNET.address}`)
|
2023-05-17 19:43:52 +03:00
|
|
|
cy.get(`#swap-currency-input .token-symbol-container`).should('contain.text', 'UNI')
|
|
|
|
cy.get(`#swap-currency-output .token-symbol-container`).should('contain.text', 'Select token')
|
|
|
|
|
2023-05-22 19:02:54 +03:00
|
|
|
cy.visit(`/swap?outputCurrency=${UNI_MAINNET.address}`)
|
2023-05-17 19:43:52 +03:00
|
|
|
cy.get(`#swap-currency-input .token-symbol-container`).should('contain.text', 'Select token')
|
|
|
|
cy.get(`#swap-currency-output .token-symbol-container`).should('contain.text', 'UNI')
|
|
|
|
|
2023-05-22 19:02:54 +03:00
|
|
|
cy.visit(`/swap?inputCurrency=ETH&outputCurrency=${UNI_MAINNET.address}`)
|
2023-05-17 19:43:52 +03:00
|
|
|
cy.get(`#swap-currency-input .token-symbol-container`).should('contain.text', 'ETH')
|
|
|
|
cy.get(`#swap-currency-output .token-symbol-container`).should('contain.text', 'UNI')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('inputs reset when navigating between pages', () => {
|
|
|
|
cy.visit('/swap')
|
|
|
|
cy.get('#swap-currency-input .token-amount-input').should('have.value', '')
|
2023-05-22 19:02:54 +03:00
|
|
|
cy.get('#swap-currency-input .token-amount-input').type('0.01').should('have.value', '0.01')
|
|
|
|
cy.visit('/pool').visit('/swap')
|
|
|
|
cy.get('#swap-currency-input .token-amount-input').should('have.value', '')
|
2023-05-17 19:43:52 +03:00
|
|
|
})
|
|
|
|
|
2023-06-16 02:05:57 +03:00
|
|
|
it('resets the dependent input when the independent input is cleared', () => {
|
|
|
|
cy.visit(`/swap?inputCurrency=ETH&outputCurrency=${UNI_MAINNET.address}`)
|
|
|
|
cy.get('#swap-currency-input .token-amount-input').should('have.value', '')
|
|
|
|
cy.get(`#swap-currency-output .token-amount-input`).should('have.value', '')
|
|
|
|
|
|
|
|
cy.get('#swap-currency-input .token-amount-input').type('0.01').should('have.value', '0.01')
|
|
|
|
cy.get(`#swap-currency-output .token-amount-input`).should('not.have.value', '')
|
|
|
|
cy.get('#swap-currency-input .token-amount-input').clear()
|
|
|
|
cy.get(`#swap-currency-output .token-amount-input`).should('not.have.value')
|
|
|
|
|
|
|
|
cy.window().trigger('blur')
|
|
|
|
cy.get(`#swap-currency-output .token-amount-input`).should('not.have.value')
|
|
|
|
})
|
|
|
|
|
2023-05-22 19:02:54 +03:00
|
|
|
it('swaps ETH for USDC', () => {
|
|
|
|
cy.visit('/swap', { ethereum: 'hardhat' })
|
|
|
|
cy.hardhat({ automine: false })
|
|
|
|
getBalance(USDC_MAINNET).then((initialBalance) => {
|
2023-06-07 19:29:23 +03:00
|
|
|
// Select USDC
|
2023-05-22 19:02:54 +03:00
|
|
|
cy.get('#swap-currency-output .open-currency-select-button').click()
|
2023-06-07 19:29:23 +03:00
|
|
|
cy.get(getTestSelector('token-search-input')).type(USDC_MAINNET.address)
|
2023-05-22 19:02:54 +03:00
|
|
|
cy.contains('USDC').click()
|
2023-06-07 19:29:23 +03:00
|
|
|
|
|
|
|
// Enter amount to swap
|
|
|
|
cy.get('#swap-currency-output .token-amount-input').type('1').should('have.value', '1')
|
2023-05-22 19:02:54 +03:00
|
|
|
cy.get('#swap-currency-input .token-amount-input').should('not.have.value', '')
|
2023-06-07 19:29:23 +03:00
|
|
|
|
|
|
|
// Submit transaction
|
2023-05-22 19:02:54 +03:00
|
|
|
cy.get('#swap-button').click()
|
2023-06-07 19:29:23 +03:00
|
|
|
cy.contains('Review swap')
|
|
|
|
cy.contains('Confirm swap').click()
|
|
|
|
cy.wait('@eth_estimateGas').wait('@eth_sendRawTransaction').wait('@eth_getTransactionReceipt')
|
|
|
|
cy.contains('Transaction submitted')
|
2023-05-25 23:49:27 +03:00
|
|
|
cy.get(getTestSelector('confirmation-close-icon')).click()
|
2023-06-07 19:29:23 +03:00
|
|
|
cy.contains('Transaction submitted').should('not.exist')
|
2023-05-22 19:02:54 +03:00
|
|
|
cy.get(getTestSelector('web3-status-connected')).should('contain', '1 Pending')
|
|
|
|
|
2023-06-07 19:29:23 +03:00
|
|
|
// Mine transaction
|
|
|
|
cy.hardhat().then((hardhat) => hardhat.mine())
|
|
|
|
cy.wait('@eth_getTransactionReceipt')
|
2023-05-22 19:02:54 +03:00
|
|
|
|
2023-06-07 19:29:23 +03:00
|
|
|
// Verify transaction
|
|
|
|
cy.get(getTestSelector('web3-status-connected')).should('not.contain', 'Pending')
|
|
|
|
cy.get(getTestSelector('popups')).contains('Swapped')
|
|
|
|
const finalBalance = initialBalance + 1
|
|
|
|
cy.get('#swap-currency-output').contains(`Balance: ${finalBalance}`)
|
|
|
|
getBalance(USDC_MAINNET).should('eq', finalBalance)
|
2023-05-17 19:43:52 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|