Skip to content

Commit

Permalink
Improved e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrwitek committed Oct 15, 2024
1 parent 9cfd2a8 commit 6dd09cb
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions packages/dma-contracts/test/e2e/operations/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { asPercentageValue, expect } from '@dma-common/test-utils'
import { RuntimeConfig } from '@dma-common/types/common'
import { balanceOf } from '@dma-common/utils/balances'
import { amountToWei } from '@dma-common/utils/common'
import { calculateFeeOnInputAmount } from '@dma-common/utils/swap'
import { testBlockNumber } from '@dma-contracts/test/config'
import { swapTokens } from '@dma-contracts/test/utils/swap'
import { restoreSnapshot, TestDeploymentSystem, TestHelpers } from '@dma-contracts/utils'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { ERC20, ERC20__factory, WETH, WETH__factory } from '@typechain'
import BigNumber from 'bignumber.js'
import { ethers } from 'ethers'
import hre from 'hardhat'

Expand All @@ -40,6 +40,7 @@ describe('Swap | 1Inch | E2E', async () => {
hre,
blockNumber: testBlockNumber,
useFallbackSwap: false,
debug: false,
})

signer = await SignerWithAddress.create(
Expand All @@ -57,45 +58,43 @@ describe('Swap | 1Inch | E2E', async () => {
DAI = ERC20__factory.connect(ADDRESSES[network].common.DAI, config.signer)
})

it('should exchange ETH for WETH', async () => {
const amountInWei = amountToWei(1)
it('should wrap ETH and not swap when swapping from ETH for WETH', async () => {
const swapInput = amountToWei(1)

const wethBalanceBefore = amountToWei(
await balanceOf(WETH.address, signer.address, { config, isFormatted: true }),
)

await swapTokens(testSystem, config, ETHAddress, WETH.address, amountInWei, slippage, signer)
await swapTokens(testSystem, config, ETHAddress, WETH.address, swapInput, slippage, signer)

const wethBalanceAfter = amountToWei(
await balanceOf(WETH.address, signer.address, { config, isFormatted: true }),
)

const wethReceived = wethBalanceAfter.minus(wethBalanceBefore)
const swapReceived = wethBalanceAfter.minus(wethBalanceBefore)

expect.toBeEqual(wethReceived, amountInWei)
expect.toBeEqual(swapReceived, swapInput)
})

it.skip('should exchange WETH for DAI', async () => {
const amountInWei = amountToWei(10)
const amountWithFeeInWei = calculateFeeOnInputAmount(amountInWei).plus(amountInWei)
it.skip('should swap WETH for DAI', async () => {
const swapInput = amountToWei(1)
await swapTokens(testSystem, config, ETHAddress, WETH.address, swapInput, slippage, signer)

const daiBalanceBefore = amountToWei(
await balanceOf(DAI.address, signer.address, { config, isFormatted: true }),
)

await WETH.approve(system.Swap.contract.address, MAX_UINT)
await swapTokens(
testSystem,
config,
ETHAddress,
WETH.address,
amountWithFeeInWei,
DAI.address,
new BigNumber(100),
slippage,
signer,
)

const daiBalanceBefore = amountToWei(
await balanceOf(DAI.address, signer.address, { config, isFormatted: true }),
)

await WETH.approve(system.Swap.contract.address, MAX_UINT)
await swapTokens(testSystem, config, WETH.address, DAI.address, amountInWei, slippage, signer)

const daiBalanceAfter = amountToWei(
await balanceOf(DAI.address, signer.address, { config, isFormatted: true }),
)
Expand Down

0 comments on commit 6dd09cb

Please sign in to comment.