From c853791decc75b9d8c60c26feb9ba378fa8ca9c9 Mon Sep 17 00:00:00 2001 From: Alberto Gualis Date: Thu, 19 Sep 2024 10:34:32 +0200 Subject: [PATCH] chore: add Single token remove v3 integration test --- .env.test | 2 +- ...emoveLiquidity.handler.integration.spec.ts | 54 ++++++++++++++++--- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/.env.test b/.env.test index 0ca870982..e3ed2e3eb 100644 --- a/.env.test +++ b/.env.test @@ -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 diff --git a/lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.integration.spec.ts b/lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.integration.spec.ts index 9f3a10e63..32a6e2b2a 100644 --- a/lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.integration.spec.ts +++ b/lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.integration.spec.ts @@ -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( @@ -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) @@ -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', @@ -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() + }) +})