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

91 lines
4.3 KiB
TypeScript
Raw Normal View History

feat: upgrade sdk-core to 3.2.6 and add AVAX (#6757) * init refactor * upgrade to 3.2.6 and refactor more uses of chainid * cleaned up lock file * remove console log and add placeholder * use supported chains type for switch fn * allow passing of all chainIds to switcher * additional typecast * better casting solution * yarn.lock cleanup * prettier * better casting for rpc * prettier * deprecate no longer needed addresses * better isSupported checking * deprecate redundant fn * cleanup toSupportedChainId * address initial ocmments * pretier * includes testnet * remove unused export * merge conflicts * spread for mutable copy * explorer text * check is supported before activating chain * remove extra uses of mumbai * remove cast to MockChainId * retain var name supportedChainId * updated prettier * use t for explorer translation * use mockchainid for test * feat: Add Avalanche support (#6776) * init avax * add most avax props * add logo * correct subgraph * update avax blocksPerFetch * add square logo * upgrade ur sdk * version syntax * correct tokens * remove unused token * remove unused token * update token list and add coming soon to searchbar * add coming soon to token explore page * names to ids * cleaned up routing * usdc token * upgrade default token list * update SOR * upgrade SOR * merge conflicts * snowtrace * upgrade SOR * handle be avax support * temp hide avax * show pool positions * whole * spotprice update * not yet supported * BACKEND_SUPPORTED_CHAINS * add avax to BE not supported * update multicall blocks to 5 * add todo * updated prettier --------- Co-authored-by: Charles Bachmeier <charlie@genie.xyz> * be added avax token balances * validateUrlChainParam should return eth for backend unsupported chain * readonly * respond to comments --------- Co-authored-by: Charles Bachmeier <charlie@genie.xyz>
2023-07-07 07:44:06 +03:00
import { ChainId } from '@uniswap/sdk-core'
import { UNI, USDC_MAINNET } from '../../../src/constants/tokens'
import { getBalance, getTestSelector } from '../../utils'
feat: upgrade sdk-core to 3.2.6 and add AVAX (#6757) * init refactor * upgrade to 3.2.6 and refactor more uses of chainid * cleaned up lock file * remove console log and add placeholder * use supported chains type for switch fn * allow passing of all chainIds to switcher * additional typecast * better casting solution * yarn.lock cleanup * prettier * better casting for rpc * prettier * deprecate no longer needed addresses * better isSupported checking * deprecate redundant fn * cleanup toSupportedChainId * address initial ocmments * pretier * includes testnet * remove unused export * merge conflicts * spread for mutable copy * explorer text * check is supported before activating chain * remove extra uses of mumbai * remove cast to MockChainId * retain var name supportedChainId * updated prettier * use t for explorer translation * use mockchainid for test * feat: Add Avalanche support (#6776) * init avax * add most avax props * add logo * correct subgraph * update avax blocksPerFetch * add square logo * upgrade ur sdk * version syntax * correct tokens * remove unused token * remove unused token * update token list and add coming soon to searchbar * add coming soon to token explore page * names to ids * cleaned up routing * usdc token * upgrade default token list * update SOR * upgrade SOR * merge conflicts * snowtrace * upgrade SOR * handle be avax support * temp hide avax * show pool positions * whole * spotprice update * not yet supported * BACKEND_SUPPORTED_CHAINS * add avax to BE not supported * update multicall blocks to 5 * add todo * updated prettier --------- Co-authored-by: Charles Bachmeier <charlie@genie.xyz> * be added avax token balances * validateUrlChainParam should return eth for backend unsupported chain * readonly * respond to comments --------- Co-authored-by: Charles Bachmeier <charlie@genie.xyz>
2023-07-07 07:44:06 +03:00
const UNI_MAINNET = UNI[ChainId.MAINNET]
describe('Swap', () => {
describe('Swap on main page', () => {
it('starts with ETH selected by default', () => {
cy.visit('/swap')
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 ', () => {
cy.visit(`/swap?inputCurrency=${UNI_MAINNET.address}`)
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')
cy.visit(`/swap?outputCurrency=${UNI_MAINNET.address}`)
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')
cy.visit(`/swap?inputCurrency=ETH&outputCurrency=${UNI_MAINNET.address}`)
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', '')
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', '')
})
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')
})
it('swaps ETH for USDC', () => {
cy.visit('/swap', { ethereum: 'hardhat' })
cy.hardhat({ automine: false })
getBalance(USDC_MAINNET).then((initialBalance) => {
// Select USDC
cy.get('#swap-currency-output .open-currency-select-button').click()
cy.get(getTestSelector('token-search-input')).type(USDC_MAINNET.address)
cy.contains('USDC').click()
// 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('Review swap')
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.contains('Transaction submitted').should('not.exist')
cy.get(getTestSelector('web3-status-connected')).should('contain', '1 Pending')
// Mine transaction
cy.hardhat().then((hardhat) => hardhat.mine())
cy.wait('@eth_getTransactionReceipt')
// 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)
})
})
})
})