Skip to content

Commit

Permalink
chore: add Single token remove v3 integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
agualis committed Sep 19, 2024
1 parent bcd81d4 commit c853791
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NEXT_PUBLIC_APP_ENV=test
NEXT_PUBLIC_BALANCER_API_URL=https://test-api-v3.balancer.fi/graphql
NEXT_PUBLIC_BALANCER_API_URL=https://api-v3.balancer.fi/graphql
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import networkConfig from '@/lib/config/networks/mainnet'
import { balAddress, wETHAddress } from '@/lib/debug-helpers'
import { balAddress, sepoliaRouter, wETHAddress } from '@/lib/debug-helpers'
import { aBalWethPoolElementMock } from '@/test/msw/builders/gqlPoolElement.builders'
import { defaultTestUserAccount } from '@/test/anvil/anvil-setup'
import { Pool } from '../../../PoolProvider'
import { QueryRemoveLiquidityInput, RemoveLiquidityType } from '../remove-liquidity.types'
import { SingleTokenRemoveLiquidityHandler } from './SingleTokenRemoveLiquidity.handler'
import { selectRemoveLiquidityHandler } from './selectRemoveLiquidityHandler'

const poolMock = aBalWethPoolElementMock() // 80BAL-20WETH
// import { getPoolMock } from '../../../__mocks__/getPoolMock'
// import { GqlChain } from '@/lib/shared/services/api/generated/graphql'

function selectSingleTokenHandler(pool: Pool): SingleTokenRemoveLiquidityHandler {
return selectRemoveLiquidityHandler(
Expand All @@ -23,9 +23,11 @@ const defaultQueryInput: QueryRemoveLiquidityInput = {

const defaultBuildInput = { account: defaultTestUserAccount, slippagePercent: '0.2' }

describe('When removing unbalanced liquidity for a weighted pool', () => {
describe('When removing unbalanced liquidity for a weighted V2 pool', () => {
const v2poolMock = aBalWethPoolElementMock() // 80BAL-20WETH

test('queries amounts out', async () => {
const handler = selectSingleTokenHandler(poolMock)
const handler = selectSingleTokenHandler(v2poolMock)

const result = await handler.simulate(defaultQueryInput)

Expand All @@ -39,7 +41,7 @@ describe('When removing unbalanced liquidity for a weighted pool', () => {
})

test('builds Tx Config', async () => {
const handler = selectSingleTokenHandler(poolMock)
const handler = selectSingleTokenHandler(v2poolMock)

const inputs: QueryRemoveLiquidityInput = {
humanBptIn: '1',
Expand All @@ -54,3 +56,43 @@ describe('When removing unbalanced liquidity for a weighted pool', () => {
expect(result.data).toBeDefined()
})
})

// TODO: unskip this test when sepolia V3 pools are available in production api
describe('When removing unbalanced liquidity for a weighted V3 pool', async () => {
// Sepolia
const balAddress = '0xb19382073c7a0addbb56ac6af1808fa49e377b75'
const wethAddress = '0x7b79995e5f793a07bc00c21412e50ecae098e7f9'
// const poolId = '0xec1b5ca86c83c7a85392063399e7d2170d502e00' // Sepolia B-50BAL-50WETH
// const v3Pool = await getPoolMock(poolId, GqlChain.Sepolia)
const v3Pool = {} as unknown as Pool

const defaultQueryInput: QueryRemoveLiquidityInput = {
humanBptIn: '0.001',
tokenOut: balAddress,
}

test('queries amounts out', async () => {
const handler = selectSingleTokenHandler(v3Pool)

const result = await handler.simulate(defaultQueryInput)

const [wEthTokenAmountOut, balTokenAmountOut] = result.amountsOut

expect(wEthTokenAmountOut.token.address).toBe(wethAddress)
expect(wEthTokenAmountOut.amount).toBe(0n)

expect(balTokenAmountOut.token.address).toBe(balAddress)
expect(balTokenAmountOut.amount).toBeGreaterThan(50000000000000000n)
})

test('builds Tx Config', async () => {
const handler = selectSingleTokenHandler(v3Pool)

const queryOutput = await handler.simulate(defaultQueryInput)

const result = await handler.buildCallData({ ...defaultBuildInput, queryOutput })

expect(result.to).toBe(sepoliaRouter)
expect(result.data).toBeDefined()
})
})

0 comments on commit c853791

Please sign in to comment.