2023-07-07 07:44:06 +03:00
|
|
|
import { ChainId } from '@uniswap/sdk-core'
|
2023-05-17 19:43:52 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
2023-07-07 07:44:06 +03:00
|
|
|
const UNI_MAINNET = UNI[ChainId.MAINNET]
|
2023-05-17 19:43:52 +03:00
|
|
|
|
|
|
|
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')
|
2023-07-15 00:46:59 +03:00
|
|
|
cy.contains('Swap submitted')
|
2023-05-25 23:49:27 +03:00
|
|
|
cy.get(getTestSelector('confirmation-close-icon')).click()
|
2023-07-15 00:46:59 +03:00
|
|
|
cy.contains('Swap 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
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|