Skip to content

Commit

Permalink
fix: links and pool e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
OlaStenberg committed Aug 9, 2024
1 parent 2278ba2 commit d94ecbc
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const ConcentratedPositionsTable: FC<ConcentratedPositionsTableProps> =
{!hideNewPositionButton ? (
<LinkInternal
shallow={true}
href={`/pool/${chainId}:${poolId}/positions/create`}
href={`/${chainId}/pool/v3/${address}/positions/create`}
>
<Button icon={PlusIcon} asChild size="sm">
Create position
Expand All @@ -165,7 +165,7 @@ export const ConcentratedPositionsTable: FC<ConcentratedPositionsTableProps> =
testId="concentrated-positions"
loading={isInitialLoading}
linkFormatter={(row) =>
`/pool/${row.chainId}:${
`/${row.chainId}/pool/v3/${
row.address
}/positions/${row.tokenId.toString()}`
}
Expand Down
220 changes: 118 additions & 102 deletions apps/web/test/helpers/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,10 @@ export class PoolPage extends BaseActions {
fee: SushiSwapV3FeeAmount.HIGH,
})
const url = BASE_URL.concat(
`/${this.chainId.toString()}/pool/v3/${poolAddress}/positions/create`,
) // TODO: fix url, must contain the position ID
`/${this.chainId.toString()}/pool/v3/${poolAddress.toLowerCase()}/positions`,
)
await this.page.goto(url)
await this.connect()
await this.page.locator('[testdata-id=my-positions-button]').click()

const concentratedPositionTableSelector = this.page.locator(
'[testdata-id=concentrated-positions-loading-0]',
Expand All @@ -277,7 +276,6 @@ export class PoolPage extends BaseActions {
)
await expect(firstPositionSelector).toBeVisible()
await firstPositionSelector.click()

const removeLiquidityTabSelector = this.page.locator(
'[testdata-id=remove-tab]',
)
Expand Down Expand Up @@ -314,7 +312,7 @@ export class PoolPage extends BaseActions {
})

const url = BASE_URL.concat(
`/${this.chainId.toString()}/pool/v2/${poolAddress}/remove`,
`/${this.chainId.toString()}/pool/v2/${poolAddress.toLowerCase()}/remove`,
)
await this.page.goto(url)
await this.connect()
Expand Down Expand Up @@ -421,108 +419,126 @@ export class PoolPage extends BaseActions {
console.error('>>>>>>>>> UNKNOWN PROTOCOL')
throw Error('Unknown protocol')
}

const mockPool = {
id: `${this.chainId}:${address}`.toLowerCase(),
address: address.toLowerCase(),
name: `${tokenA.symbol}-${tokenB.symbol}`,
chainId: this.chainId,
protocol,
swapFee: fee / (protocol === 'SUSHISWAP_V3' ? 1000000 : 10000),
twapEnabled: false,
totalSupply: '83920283456658325128353',
liquidityUSD: '0',
volumeUSD: '0',
feeApr1h: 0,
feeApr1d: 0,
feeApr1w: 0,
feeApr1m: 0,
totalApr1h: 0,
totalApr1d: 0,
totalApr1w: 0,
totalApr1m: 0,
incentiveApr: 0,
isIncentivized: false,
wasIncentivized: false,
fees1h: '0',
fees1d: '0',
fees1w: '0',
fees1m: '0',
feesChange1h: 0,
feesChange1d: 0,
feesChange1w: 0,
feesChange1m: 0,
volume1h: '0',
volume1d: '0',
volume1w: '0',
volume1m: '0',
volumeChange1h: 0,
volumeChange1d: 0,
volumeChange1w: 0,
volumeChange1m: 0,
liquidityUSDChange1h: 0,
liquidityUSDChange1d: 0,
liquidityUSDChange1w: 0,
liquidityUSDChange1m: 0,
isBlacklisted: false,
token0: {
id: `${tokenA.chainId}:${tokenA.address}`.toLowerCase(),
address: tokenA.address.toLowerCase(),
name: tokenA.name,
symbol: tokenA.symbol,
decimals: tokenA.decimals,
chainId: tokenA.chainId,
},
token1: {
id: `${tokenB.chainId}:${tokenB.address}`.toLowerCase(),
address: tokenB.address.toLowerCase(),
name: tokenB.name,
symbol: tokenB.symbol,
decimals: tokenB.decimals,
chainId: tokenB.chainId,
},
incentives: [],
hadEnabledSteerVault: false,
hasEnabledSteerVault: false,
steerVaults: [],
}

// console.log({ url: request.url.toLowerCase() })

if (request.url.toLowerCase().endsWith('/pool/api/pools')) {
// console.log('RETURN POOLS MOCK')

return new Response(JSON.stringify([mockPool]), {
headers: {
'Content-Type': 'application/json',
},
})
} else if (
request.url
.toLowerCase()
.endsWith(`/pool/api/pools/${this.chainId}/${address}`.toLowerCase())
) {
// console.log('RETURN POOL MOCK')
const mockPool =
protocol === 'SUSHISWAP_V2'
? {
data: {
v2Pool: {
id: `${this.chainId}:${address}`.toLowerCase(),
chainId: this.chainId,
name: 'WMATIC / FT',
address,
createdAt: '1630455405',
protocol,
// swapFee: fee / (protocol === 'SUSHISWAP_V3' ? 1000000 : 10000),
swapFee: fee / 10000,

token0: {
id: `${tokenA.chainId}:${tokenA.address}`.toLowerCase(),
address: tokenA.address.toLowerCase(),
name: tokenA.name,
symbol: tokenA.symbol,
decimals: tokenA.decimals,
chainId: tokenA.chainId,
},
token1: {
id: `${tokenB.chainId}:${tokenB.address}`.toLowerCase(),
address: tokenB.address.toLowerCase(),
name: tokenB.name,
symbol: tokenB.symbol,
decimals: tokenB.decimals,
chainId: tokenB.chainId,
},
source: 'SUBGRAPH',
reserve0: '14632715635223519232',
reserve1: '66374911905262165000000',
liquidity: '736541498034438406144',
volumeUSD: 56162969.922308594,
liquidityUSD: 71429.02585542823,
token0Price: 0.0002204555187373958,
token1Price: 4536.062448004257,
volumeUSD1d: 1444.4034653156996,
feeUSD1d: 4.333210395940114,
txCount1d: 104,
feeApr1d: 0.022142564252791732,
totalApr1d: 0.022142564252791732,
volumeUSD1dChange: -0.43870093251068154,
feeUSD1dChange: -0.4387009325124158,
txCount1dChange: -0.11864406779661019,
liquidityUSD1dChange: 0.01395086513190713,
incentiveApr: 0,
isIncentivized: false,
wasIncentivized: false,
incentives: [],
},
},
}
: {
data: {
v3Pool: {
id: `${this.chainId}:${address}`.toLowerCase(),
chainId: this.chainId,
name: 'WMATIC / FT',
address,
createdAt: '1630455405',
protocol,
swapFee: fee / 1_000_000,

token0: {
id: `${tokenA.chainId}:${tokenA.address}`.toLowerCase(),
address: tokenA.address.toLowerCase(),
name: tokenA.name,
symbol: tokenA.symbol,
decimals: tokenA.decimals,
chainId: tokenA.chainId,
},
token1: {
id: `${tokenB.chainId}:${tokenB.address}`.toLowerCase(),
address: tokenB.address.toLowerCase(),
name: tokenB.name,
symbol: tokenB.symbol,
decimals: tokenB.decimals,
chainId: tokenB.chainId,
},
source: 'SUBGRAPH',
reserve0: '97138000822798992',
reserve1: '251532847196719',
liquidity: '190259449333200569961',
sqrtPrice: '77543082754135133119551574769',
tick: '-430',
observationIndex: '0',
feeGrowthGlobal0X128: '1913748811595781336300706674643883',
feeGrowthGlobal1X128: '1490989199114543008131607233327172',
volumeUSD: 124770.3303415501,
liquidityUSD: 327.7942814599597,
token0Price: 1.0439339999465262,
token1Price: 0.9579149640218858,
volumeUSD1d: 0,
feeUSD1d: 0,
txCount1d: 0,
feeApr1d: 0,
totalApr1d: 0,
volumeUSD1dChange: 0,
feeUSD1dChange: 0,
txCount1dChange: 0,
liquidityUSD1dChange: 0,
incentiveApr: 0,
hadSmartPool: false,
hasSmartPool: false,
isIncentivized: false,
wasIncentivized: false,
incentives: [],
vaults: [],
},
},
}

if (request.url.toLowerCase().endsWith('/graphql')) {
return new Response(JSON.stringify(mockPool), {
headers: {
'Content-Type': 'application/json',
},
})
} else if (
request.url
.toLowerCase()
.endsWith('/pool/api/pools/count'.toLowerCase())
) {
// console.log('RETURN POOL COUNT MOCK')
return new Response(JSON.stringify({ count: 1 }), {
headers: {
'Content-Type': 'application/json',
},
})
} else if (
request.url.toLowerCase().endsWith('/pool/api/graphPools'.toLowerCase())
) {
console.log('RETURN GRAPH POOLS MOCK')
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/test/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const config: PlaywrightTestConfig = {
quiet: !!process.env.CI,
testMatch: [
'pool.test.ts',
// 'simple.test.ts',
'simple.test.ts',
// 'smart.test.ts',
// 'cross-chain.test.ts',
],
Expand Down
64 changes: 11 additions & 53 deletions apps/web/test/pool/pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,64 +68,22 @@ test.beforeEach(async ({ page, next }) => {
console.error('error mockking token api', error)
}

// TEMP: Mock V2 POOL..
await page.route(
'https://data.sushi.com', // TODO: update url
async (route) => {
try {
await page.route(`**/price/v1/${chainId}`, async (route) => {
// const response = await route.fetch()
// const json = await response.json()
await route.fulfill({
json: {
data: {
v2Pool: {
id: '137:0x3221022e37029923ace4235d812273c5a42c322d',
chainId: 42161,
name: 'WMATIC / FT',
address: '0x3221022e37029923ace4235d812273c5a42c322d',
createdAt: '1630455405',
swapFee: 0.003,
protocol: 'SUSHISWAP_V2',
token0: {
id: '137:0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270',
address: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270',
chainId: 137,
decimals: 18,
name: 'Wrapped Matic',
symbol: 'WMATIC',
},
token1: FAKE_TOKEN,
source: 'SUBGRAPH',
reserve0: '14632715635223519232',
reserve1: '66374911905262165000000',
liquidity: '736541498034438406144',
volumeUSD: 56162969.922308594,
liquidityUSD: 71429.02585542823,
token0Price: 0.0002204555187373958,
token1Price: 4536.062448004257,
volumeUSD1d: 1444.4034653156996,
feeUSD1d: 4.333210395940114,
txCount1d: 104,
feeApr1d: 0.022142564252791732,
totalApr1d: 0.022142564252791732,
volumeUSD1dChange: -0.43870093251068154,
feeUSD1dChange: -0.4387009325124158,
txCount1dChange: -0.11864406779661019,
liquidityUSD1dChange: 0.01395086513190713,
incentiveApr: 0,
isIncentivized: false,
wasIncentivized: false,
incentives: [],
},
},
},
json: {},
})
},
)
})
} catch (error) {
console.error('error mockking token api', error)
}

await page.route('http://localhost:3000/api/**/*', async (route) => {
await route.abort()
})
await page.route('http://localhost:3000/pool/api/**/*', async (route) => {
await route.abort()
})

try {
await interceptAnvil(page, next)
} catch (error) {
Expand Down Expand Up @@ -179,7 +137,7 @@ test.describe('V3', () => {
amountBelongsToToken0: false,
})

// await poolPage.removeLiquidityV3(FAKE_TOKEN) // TODO: enable once you can determine what the position ID will be
await poolPage.removeLiquidityV3(FAKE_TOKEN) // TODO: enable once you can determine what the position ID will be
})
})

Expand Down

0 comments on commit d94ecbc

Please sign in to comment.