2023-07-07 07:44:06 +03:00
|
|
|
import { ChainId, CurrencyAmount, WETH9 } from '@uniswap/sdk-core'
|
2023-05-17 19:43:52 +03:00
|
|
|
|
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 WETH = WETH9[ChainId.MAINNET]
|
2023-05-18 23:47:15 +03:00
|
|
|
|
2023-05-22 19:02:54 +03:00
|
|
|
describe('Swap wrap', () => {
|
2023-05-18 23:47:15 +03:00
|
|
|
beforeEach(() => {
|
2023-08-02 08:13:19 +03:00
|
|
|
cy.visit(`/swap?inputCurrency=ETH&outputCurrency=${WETH.address}`).hardhat({ automine: false })
|
2023-05-22 19:02:54 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('ETH to wETH is same value (wrapped swaps have no price impact)', () => {
|
2023-06-07 19:29:23 +03:00
|
|
|
cy.get('#swap-currency-input .token-amount-input').type('0.01').should('have.value', '0.01')
|
2023-05-22 19:02:54 +03:00
|
|
|
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')
|
2023-05-18 23:47:15 +03:00
|
|
|
})
|
|
|
|
|
2023-05-17 19:43:52 +03:00
|
|
|
it('should be able to wrap ETH', () => {
|
2023-06-07 19:29:23 +03:00
|
|
|
getBalance(WETH).then((initialBalance) => {
|
2023-05-18 23:47:15 +03:00
|
|
|
cy.contains('Enter ETH amount')
|
|
|
|
|
2023-06-07 19:29:23 +03:00
|
|
|
// Enter amount to wrap
|
|
|
|
cy.get('#swap-currency-output .token-amount-input').type('1').should('have.value', 1)
|
2023-05-18 23:47:15 +03:00
|
|
|
cy.get('#swap-currency-input .token-amount-input').should('have.value', 1)
|
|
|
|
|
2023-06-07 19:29:23 +03:00
|
|
|
// Submit transaction
|
2023-05-18 23:47:15 +03:00
|
|
|
cy.contains('Wrap').click()
|
2023-06-07 19:29:23 +03:00
|
|
|
cy.wait('@eth_estimateGas').wait('@eth_sendRawTransaction').wait('@eth_getTransactionReceipt')
|
2023-05-18 23:47:15 +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-18 23:47:15 +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('Wrapped')
|
|
|
|
const finalBalance = initialBalance + 1
|
|
|
|
cy.get('#swap-currency-output').contains(`Balance: ${finalBalance}`)
|
|
|
|
getBalance(WETH).should('equal', finalBalance)
|
2023-05-18 23:47:15 +03:00
|
|
|
})
|
2023-05-17 19:43:52 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should be able to unwrap WETH', () => {
|
2023-05-18 23:47:15 +03:00
|
|
|
cy.hardhat().then(async (hardhat) => {
|
|
|
|
await hardhat.fund(hardhat.wallet, CurrencyAmount.fromRawAmount(WETH, 1e18))
|
|
|
|
await hardhat.mine()
|
|
|
|
})
|
|
|
|
|
2023-06-07 19:29:23 +03:00
|
|
|
getBalance(WETH).then((initialBalance) => {
|
|
|
|
// Swap input/output to unwrap WETH
|
2023-05-18 23:47:15 +03:00
|
|
|
cy.get(getTestSelector('swap-currency-button')).click()
|
|
|
|
cy.contains('Enter WETH amount')
|
|
|
|
|
2023-06-07 19:29:23 +03:00
|
|
|
// Enter the amount to unwrap
|
|
|
|
cy.get('#swap-currency-output .token-amount-input').type('1').should('have.value', 1)
|
2023-05-18 23:47:15 +03:00
|
|
|
cy.get('#swap-currency-input .token-amount-input').should('have.value', 1)
|
|
|
|
|
2023-06-07 19:29:23 +03:00
|
|
|
// Submit transaction
|
2023-05-18 23:47:15 +03:00
|
|
|
cy.contains('Unwrap').click()
|
2023-06-07 19:29:23 +03:00
|
|
|
cy.wait('@eth_estimateGas').wait('@eth_sendRawTransaction').wait('@eth_getTransactionReceipt')
|
2023-05-18 23:47:15 +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-18 23:47:15 +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('Unwrapped')
|
|
|
|
const finalBalance = initialBalance - 1
|
|
|
|
cy.get('#swap-currency-input').contains(`Balance: ${finalBalance}`)
|
|
|
|
getBalance(WETH).should('equal', finalBalance)
|
2023-05-18 23:47:15 +03:00
|
|
|
})
|
2023-05-17 19:43:52 +03:00
|
|
|
})
|
|
|
|
})
|