From 784fbfe7b13bfe8e35d62af20e13a5cc4b60d450 Mon Sep 17 00:00:00 2001 From: Kristie Huang Date: Fri, 15 Sep 2023 16:05:56 -0400 Subject: [PATCH] test: add remove-liquidity interface tests (#7309) * fix: duplicate or single-token remove-liquidity routes should show error page * use maxUint256 for nonexistent pool * move tests back to rem-liq * rename pooled token id * nit: use uni address from sdk core * nit: use maxuint256 from sdk core * nit: use liqudityValue for doublecurrencylogo --------- Co-authored-by: Kristie Huang --- cypress/e2e/remove-liquidity.test.ts | 30 ++++++++++++++++++++++++++-- src/pages/RemoveLiquidity/V3.tsx | 15 +++++++------- src/pages/RemoveLiquidity/index.tsx | 4 +++- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/cypress/e2e/remove-liquidity.test.ts b/cypress/e2e/remove-liquidity.test.ts index dc448bdb17..b09f021ed0 100644 --- a/cypress/e2e/remove-liquidity.test.ts +++ b/cypress/e2e/remove-liquidity.test.ts @@ -1,7 +1,33 @@ +import { ChainId, MaxUint256, UNI_ADDRESSES } from '@uniswap/sdk-core' + +const UNI_MAINNET = UNI_ADDRESSES[ChainId.MAINNET] + describe('Remove Liquidity', () => { - it('loads the token pair', () => { - cy.visit('/remove/v2/ETH/0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984') + it('loads the token pair in v2', () => { + cy.visit(`/remove/v2/ETH/${UNI_MAINNET}`) cy.get('#remove-liquidity-tokena-symbol').should('contain.text', 'ETH') cy.get('#remove-liquidity-tokenb-symbol').should('contain.text', 'UNI') }) + + it('loads the token pair in v3', () => { + cy.visit(`/remove/1`) + cy.get('#remove-liquidity-tokens').should('contain.text', 'UNI/ETH') + + cy.get('#remove-pooled-tokena-symbol').should('contain.text', 'Pooled UNI') + cy.get('#remove-pooled-tokenb-symbol').should('contain.text', 'Pooled ETH') + }) + + it('should redirect to error pages if pool does not exist', () => { + // Duplicate-token v2 pools redirect to position unavailable + cy.visit(`/remove/v2/ETH/ETH`) + cy.contains('Position unavailable') + + // Single-token pools don't exist + cy.visit('/remove/v2/ETH') + cy.url().should('match', /\/not-found/) + + // Nonexistent v3 pool + cy.visit(`/remove/${MaxUint256}`) + cy.contains('Position unavailable') + }) }) diff --git a/src/pages/RemoveLiquidity/V3.tsx b/src/pages/RemoveLiquidity/V3.tsx index 7349577466..80f010b5b7 100644 --- a/src/pages/RemoveLiquidity/V3.tsx +++ b/src/pages/RemoveLiquidity/V3.tsx @@ -59,11 +59,11 @@ export default function RemoveLiquidityV3() { } }, [tokenId]) + const { position, loading } = useV3PositionFromTokenId(parsedTokenId ?? undefined) if (parsedTokenId === null || parsedTokenId.eq(0)) { return } - - if (isSupportedChain(chainId)) { + if (isSupportedChain(chainId) && (loading || position)) { return } else { return @@ -312,15 +312,16 @@ function Remove({ tokenId }: { tokenId: BigNumber }) { {`${feeValue0?.currency?.symbol}/${feeValue1?.currency?.symbol}`} + id="remove-liquidity-tokens" + >{`${liquidityValue0?.currency?.symbol}/${liquidityValue1?.currency?.symbol}`} @@ -354,7 +355,7 @@ function Remove({ tokenId }: { tokenId: BigNumber }) { - + Pooled {liquidityValue0?.currency?.symbol}: @@ -365,7 +366,7 @@ function Remove({ tokenId }: { tokenId: BigNumber }) { - + Pooled {liquidityValue1?.currency?.symbol}: diff --git a/src/pages/RemoveLiquidity/index.tsx b/src/pages/RemoveLiquidity/index.tsx index 9d949eec1d..17816e11fe 100644 --- a/src/pages/RemoveLiquidity/index.tsx +++ b/src/pages/RemoveLiquidity/index.tsx @@ -52,7 +52,9 @@ const DEFAULT_REMOVE_LIQUIDITY_SLIPPAGE_TOLERANCE = new Percent(5, 100) export default function RemoveLiquidityWrapper() { const { chainId } = useWeb3React() - if (isSupportedChain(chainId)) { + const { currencyIdA, currencyIdB } = useParams<{ currencyIdA: string; currencyIdB: string }>() + const [currencyA, currencyB] = [useCurrency(currencyIdA) ?? undefined, useCurrency(currencyIdB) ?? undefined] + if (isSupportedChain(chainId) && currencyA !== currencyB) { return } else { return