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

79 lines
3.1 KiB
TypeScript
Raw Permalink 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, CurrencyAmount, WETH9 } from '@uniswap/sdk-core'
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 WETH = WETH9[ChainId.MAINNET]
describe('Swap wrap', () => {
beforeEach(() => {
cy.visit(`/swap?inputCurrency=ETH&outputCurrency=${WETH.address}`).hardhat({ automine: false })
})
it('ETH to wETH is same value (wrapped swaps have no price impact)', () => {
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('have.value', '0.01')
cy.get('#swap-currency-output .token-amount-input').clear().type('0.02').should('have.value', '0.02')
cy.get('#swap-currency-input .token-amount-input').should('have.value', '0.02')
})
it('should be able to wrap ETH', () => {
getBalance(WETH).then((initialBalance) => {
cy.contains('Enter ETH amount')
// Enter amount to wrap
cy.get('#swap-currency-output .token-amount-input').type('1').should('have.value', 1)
cy.get('#swap-currency-input .token-amount-input').should('have.value', 1)
// Submit transaction
cy.contains('Wrap').click()
cy.wait('@eth_estimateGas').wait('@eth_sendRawTransaction').wait('@eth_getTransactionReceipt')
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('Wrapped')
const finalBalance = initialBalance + 1
cy.get('#swap-currency-output').contains(`Balance: ${finalBalance}`)
getBalance(WETH).should('equal', finalBalance)
})
})
it('should be able to unwrap WETH', () => {
cy.hardhat().then(async (hardhat) => {
await hardhat.fund(hardhat.wallet, CurrencyAmount.fromRawAmount(WETH, 1e18))
await hardhat.mine()
})
getBalance(WETH).then((initialBalance) => {
// Swap input/output to unwrap WETH
cy.get(getTestSelector('swap-currency-button')).click()
cy.contains('Enter WETH amount')
// Enter the amount to unwrap
cy.get('#swap-currency-output .token-amount-input').type('1').should('have.value', 1)
cy.get('#swap-currency-input .token-amount-input').should('have.value', 1)
// Submit transaction
cy.contains('Unwrap').click()
cy.wait('@eth_estimateGas').wait('@eth_sendRawTransaction').wait('@eth_getTransactionReceipt')
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('Unwrapped')
const finalBalance = initialBalance - 1
cy.get('#swap-currency-input').contains(`Balance: ${finalBalance}`)
getBalance(WETH).should('equal', finalBalance)
})
})
})