Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
groninge01 committed Sep 30, 2024
1 parent edac8a0 commit 4ceff50
Show file tree
Hide file tree
Showing 82 changed files with 340 additions and 358 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo } from 'react'
import { usePool } from '../../PoolProvider'
import { GqlPoolTokenDetail } from '../../shared/services/api/generated/graphql'
import { fNum } from '../../shared/utils/numbers'
import { GqlPoolTokenDetail } from '../../../../shared/services/api/generated/graphql'
import { fNum } from '../../../../shared/utils/numbers'

type CompositionRow = {
symbol: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GqlChain } from '../../shared/services/api/generated/graphql'
import { Box } from '@chakra-ui/react'
import { motion } from 'framer-motion'
import Image from 'next/image'
import { GqlChain } from '../../../../shared/services/api/generated/graphql'

type Props = {
chain: GqlChain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use client'
/* eslint-disable react-hooks/exhaustive-deps */
import { Box, HStack, Text, VStack, useTheme } from '@chakra-ui/react'
import { useMemo, useRef } from 'react'
import ReactECharts from 'echarts-for-react'
import EChartsReactCore from 'echarts-for-react/lib/core'
import { motion } from 'framer-motion'
import { ChartSizeValues } from './PoolWeightChart'
import { useThemeColorMode } from '../../shared/services/chakra/useThemeColorMode'
import { NoisyCard } from '../../shared/components/containers/NoisyCard'
import { Pool } from '../../PoolProvider'
import { calcTotalStakedBalanceUsd, getUserWalletBalanceUsd } from '../../user-balance.helpers'
import { NoisyCard } from '../../../../shared/components/containers/NoisyCard'
import { useThemeColorMode } from '../../../../shared/services/chakra/useThemeColorMode'

const smallSize: ChartSizeValues = {
chartHeight: '125px',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { Card, HStack, VStack, Text, Grid, GridItem } from '@chakra-ui/react'
import { PoolListItem } from '../../pool.types'
import MainAprTooltip from '../../shared/components/tooltips/apr-tooltip/MainAprTooltip'
import { ReactNode, isValidElement, memo } from 'react'
import { NetworkIcon } from '../../shared/components/icons/NetworkIcon'
import { useCurrency } from '../../shared/hooks/useCurrency'
import { usePoolListQueryState } from '../usePoolListQueryState'
import { TokenIconStack } from '../../modules/tokens/TokenIconStack'
import {
getPoolTypeLabel,
getTotalAprLabel,
Expand All @@ -14,8 +10,12 @@ import {
} from '../../pool.utils'
import { useRouter } from 'next/navigation'
import { PoolName } from '../../PoolName'
import FadeInOnView from '../../shared/components/containers/FadeInOnView'
import { getUserTotalBalanceUsd } from '../../user-balance.helpers'
import FadeInOnView from '../../../../shared/components/containers/FadeInOnView'
import { NetworkIcon } from '../../../../shared/components/icons/NetworkIcon'
import MainAprTooltip from '../../../../shared/components/tooltips/apr-tooltip/MainAprTooltip'
import { useCurrency } from '../../../../shared/hooks/useCurrency'
import { TokenIconStack } from '../../../tokens/TokenIconStack'

interface Props {
pool: PoolListItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import { Box, Center, Grid, Skeleton, Text } from '@chakra-ui/react'
import { PoolListCard } from './PoolListCard'
import { Pagination } from '../../shared/components/pagination/Pagination'
import { usePoolListQueryState } from '../usePoolListQueryState'
import { getPaginationProps } from '../../shared/components/pagination/getPaginationProps'
import { PoolListItem } from '../../pool.types'
import { useIsMounted } from '../../shared/hooks/useIsMounted'
import { useIsMounted } from 'usehooks-ts'
import { getPaginationProps } from '../../../../shared/components/pagination/getPaginationProps'
import { Pagination } from '../../../../shared/components/pagination/Pagination'

interface Props {
pools: PoolListItem[]
Expand Down
8 changes: 4 additions & 4 deletions packages/lib/modules/pool/PoolList/PoolListProvider.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PoolList as PoolListType } from '../../modules/pool/pool.types'
import { defaultPoolListMock, mockPoolList } from '@/test/msw/handlers/PoolList.handlers'
import { aGqlPoolMinimalMock } from '@/test/msw/builders/gqlPoolMinimal.builders'
import { testHook } from '@/test/utils/custom-renderers'
import { aGqlPoolMinimalMock } from '../../../test/msw/builders/gqlPoolMinimal.builders'
import { defaultPoolListMock, mockPoolList } from '../../../test/msw/handlers/PoolList.handlers'
import { testHook } from '../../../test/utils/custom-renderers'
import { _usePoolList } from './PoolListProvider'
import { PoolList as PoolListType } from '../../pool/pool.types'

async function renderUsePoolsList() {
const { result, waitForLoadedUseQuery } = testHook(() => _usePoolList())
Expand Down
3 changes: 1 addition & 2 deletions packages/lib/modules/pool/PoolList/PoolListProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react-hooks/exhaustive-deps */
'use client'

import { createContext, PropsWithChildren, useEffect } from 'react'
Expand All @@ -25,7 +24,7 @@ export function _usePoolList({ fixedPoolTypes }: { fixedPoolTypes?: GqlPoolType[
GetPoolsDocument,
{
variables,
},
}
)

const pools = loading && previousData ? previousData.pools : data?.pools || []
Expand Down
8 changes: 4 additions & 4 deletions packages/lib/modules/pool/PoolList/PoolListSortType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { orderByHash, SortingState } from '../pool.types'
import { usePoolOrderByState } from './usePoolOrderByState'
import { GroupBase, OptionBase, Select, SingleValue } from 'chakra-react-select'
import { ReactNode, useMemo } from 'react'
import { getSelectStyles } from '../../shared/services/chakra/custom/chakra-react-select'
import { useIsMounted } from '../../shared/hooks/useIsMounted'
import { useIsMounted } from 'usehooks-ts'
import { getSelectStyles } from '../../../shared/services/chakra/custom/chakra-react-select'

interface SortOption extends OptionBase {
label: ReactNode
Expand All @@ -34,15 +34,15 @@ export function PoolListSortType() {
},
])
.flat(),
[orderBy],
[orderBy]
)

function handleChange(newOption: SingleValue<SortOption>) {
if (newOption) setSorting(newOption.value)
}

const _value = options.find(
option => option.value[0].id === sorting[0].id && option.value[0].desc === sorting[0].desc,
option => option.value[0].id === sorting[0].id && option.value[0].desc === sorting[0].desc
)

if (!isMounted) return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { testHook } from '@/test/utils/custom-renderers'
import { testHook } from '../../../test/utils/custom-renderers'
import { usePoolListQueryState } from './usePoolListQueryState'

function updateUrlQueryString(queryString: `?${string}`) {
Expand Down
10 changes: 5 additions & 5 deletions packages/lib/modules/pool/PoolProvider.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { GetPoolQuery, GqlChain } from '../../shared/services/api/generated/graphql'
import { defaultPoolMock, defaultPoolResponseMock } from '@/test/msw/handlers/Pool.handlers'
import { testHook } from '@/test/utils/custom-renderers'
import { waitFor } from '@testing-library/react'
import { BaseVariant } from './pool.types'
import { _usePool } from './PoolProvider'
import { defaultTestGaugeAddress } from '@/test/msw/builders/gqlStaking.builders'
import { defaultTestGaugeAddress } from '../../test/msw/builders/gqlStaking.builders'
import { defaultPoolResponseMock, defaultPoolMock } from '../../test/msw/handlers/Pool.handlers'
import { testHook } from '../../test/utils/custom-renderers'

async function testUsePool({
initialData = defaultPoolResponseMock,
Expand Down Expand Up @@ -35,15 +35,15 @@ describe('Gql pool helpers', () => {
const result = await testUsePool()

expect(result.current.poolExplorerLink).toBe(
'https://etherscan.io/address/0x5c6ee304399dbdb9c8ef030ab642b10820db8f56',
'https://etherscan.io/address/0x5c6ee304399dbdb9c8ef030ab642b10820db8f56'
)
})

test('returns gauge explorer link when the pool', async () => {
const result = await testUsePool()

expect(result.current.gaugeExplorerLink).toBe(
`https://etherscan.io/address/0x2d42910d826e5500579d121596e98a6eb33c0a1b`,
`https://etherscan.io/address/0x2d42910d826e5500579d121596e98a6eb33c0a1b`
)
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable max-len */

import { GqlChain, GqlPoolElement, GqlPoolType } from '../../shared/services/api/generated/graphql'
import {
GqlPoolElement,
GqlPoolType,
GqlChain,
} from '../../../shared/services/api/generated/graphql'

export const composableStablePoolMock: GqlPoolElement = {
id: '0x156c02f3f7fef64a3a9d80ccf7085f23cce91d76000000000000000000000570',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { gyro2CLP_USDC_DAI, recoveryModePoolId } from '../../debug-helpers'
import { GqlChain } from '../../shared/services/api/generated/graphql'
import { gyro2CLP_USDC_DAI, recoveryModePoolId } from '../../../debug-helpers'
import { GqlChain } from '../../../shared/services/api/generated/graphql'
import { getPoolMock } from './getPoolMock'

/**
Expand Down
13 changes: 6 additions & 7 deletions packages/lib/modules/pool/__mocks__/getPoolMock.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import fetch from 'cross-fetch'

import { visit } from 'graphql/language/visitor'
import { print } from 'graphql'
import { Address } from 'viem'
import { nested50WETH_50_3poolId } from '../../../debug-helpers'
import {
GqlChain,
GqlPoolElement,
GetPoolDocument,
GetPoolQueryVariables,
GqlChain,
GetPoolQuery,
GqlPoolElement,
} from '../../shared/services/api/generated/graphql'
import { nested50WETH_50_3poolId } from '../../debug-helpers'
import { Address } from 'viem'
} from '../../../shared/services/api/generated/graphql'

function astToQueryString(ast: any): string {
return print(ast)
Expand All @@ -19,7 +18,7 @@ function astToQueryString(ast: any): string {
export async function getPoolMock(
poolId: Address = nested50WETH_50_3poolId,
chain: GqlChain = GqlChain.Mainnet,
userAddress?: Address,
userAddress?: Address
): Promise<GqlPoolElement> {
const queryString = astToQueryString(visit(GetPoolDocument, {}))

Expand Down
4 changes: 1 addition & 3 deletions packages/lib/modules/pool/__mocks__/gyroEPoolMock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable max-len */

import { GqlPoolElement } from '../../shared/services/api/generated/graphql'
import { GqlPoolElement } from '../../../shared/services/api/generated/graphql'

export const gyroEPoolMock: GqlPoolElement = {
id: '0xf01b0684c98cd7ada480bfdf6e43876422fa1fc10002000000000000000005de',
Expand Down
4 changes: 1 addition & 3 deletions packages/lib/modules/pool/__mocks__/gyroPoolMock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable max-len */

import { GqlPoolElement } from '../../shared/services/api/generated/graphql'
import { GqlPoolElement } from '../../../shared/services/api/generated/graphql'

export const gyroPoolMock: GqlPoolElement = {
id: '0xdac42eeb17758daa38caf9a3540c808247527ae3000200000000000000000a2b',
Expand Down
8 changes: 5 additions & 3 deletions packages/lib/modules/pool/__mocks__/metaStablePoolMock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable max-len */

import { GqlChain, GqlPoolElement, GqlPoolType } from '../../shared/services/api/generated/graphql'
import {
GqlPoolElement,
GqlPoolType,
GqlChain,
} from '../../../shared/services/api/generated/graphql'

export const metaStablePoolMock: GqlPoolElement = {
id: '0x32296969ef14eb0c6d29669c550d4a0449130230000200000000000000000080',
Expand Down
4 changes: 1 addition & 3 deletions packages/lib/modules/pool/__mocks__/nestedPoolMock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable max-len */

import { GqlPoolElement } from '../../shared/services/api/generated/graphql'
import { GqlPoolElement } from '../../../shared/services/api/generated/graphql'

export const nestedPoolMock: GqlPoolElement = {
id: '0x08775ccb6674d6bdceb0797c364c2653ed84f3840002000000000000000004f0',
Expand Down
5 changes: 2 additions & 3 deletions packages/lib/modules/pool/__mocks__/notAllowedPoolMock.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable max-len */
import {
GqlPoolType,
GqlChain,
GqlPoolNestingType,
GqlPoolType,
} from '../../shared/services/api/generated/graphql'
} from '../../../shared/services/api/generated/graphql'
import { Pool } from '../PoolProvider'

export const notAllowedPoolMock: Pool = {
Expand Down
4 changes: 1 addition & 3 deletions packages/lib/modules/pool/__mocks__/recoveryPoolMock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable max-len */

import { GqlChain, GqlPoolElement } from '../../shared/services/api/generated/graphql'
import { GqlPoolElement, GqlChain } from '../../../shared/services/api/generated/graphql'

// TODO: remove linear (nested) pools
export const recoveryPoolMock: GqlPoolElement = {
Expand Down
12 changes: 6 additions & 6 deletions packages/lib/modules/pool/actions/LiquidityActionHelpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { aWjAuraWethPoolElementMock } from '@/test/msw/builders/gqlPoolElement.builders'
import {
LiquidityActionHelpers,
areEmptyAmounts,
Expand All @@ -7,6 +6,10 @@ import {
supportsNestedActions,
} from './LiquidityActionHelpers'
import { nestedPoolMock } from '../__mocks__/nestedPoolMock'
import { recoveryPoolMock } from '../__mocks__/recoveryPoolMock'
import { Pool } from '../PoolProvider'
import { mock } from 'vitest-mock-extended'
import { HumanTokenAmountWithAddress } from '../../tokens/token.types'
import {
bpt3PoolAddress,
wETHAddress,
Expand All @@ -16,11 +19,8 @@ import {
usdtAddress,
wjAuraAddress,
ethAddress,
} from '../../debug-helpers'
import { recoveryPoolMock } from '../__mocks__/recoveryPoolMock'
import { Pool } from '../PoolProvider'
import { mock } from 'vitest-mock-extended'
import { HumanTokenAmountWithAddress } from '../../tokens/token.types'
} from '../../../debug-helpers'
import { aWjAuraWethPoolElementMock } from '../../../test/msw/builders/gqlPoolElement.builders'

describe('areEmptyAmounts', () => {
test('when all humanAmounts are empty, zero or zero with decimals', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { balAddress } from '../../debug-helpers'
import { TokenAmount, Token, HumanAmount } from '@balancer/sdk'
import { Address, parseUnits } from 'viem'
import { mock } from 'vitest-mock-extended'
import { balAddress } from '../../../../debug-helpers'

export function aTokenAmountMock(tokenAddress: Address, amount: HumanAmount): TokenAmount {
const defaultTokenAmount: TokenAmount = mock<TokenAmount>({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { balAddress, daiAddress, usdcAddress, usdtAddress, wETHAddress } from '../../debug-helpers'
import { GqlPoolElement } from '../../shared/services/api/generated/graphql'
import { aBalWethPoolElementMock } from '@/test/msw/builders/gqlPoolElement.builders'
import {
DefaultAddLiquidityTestProvider,
buildDefaultPoolTestProvider,
testHook,
} from '@/test/utils/custom-renderers'
import { PropsWithChildren } from 'react'
import { _useAddLiquidity } from './AddLiquidityProvider'
import { nestedPoolMock } from '../../__mocks__/nestedPoolMock'
import {
balAddress,
wETHAddress,
daiAddress,
usdtAddress,
usdcAddress,
} from '../../../../debug-helpers'
import { GqlPoolElement } from '../../../../shared/services/api/generated/graphql'
import { aBalWethPoolElementMock } from '../../../../test/msw/builders/gqlPoolElement.builders'
import {
buildDefaultPoolTestProvider,
DefaultAddLiquidityTestProvider,
testHook,
} from '../../../../test/utils/custom-renderers'

async function testUseAddLiquidity(pool: GqlPoolElement = aBalWethPoolElementMock()) {
const PoolProvider = buildDefaultPoolTestProvider(pool)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* eslint-disable max-len */
import networkConfig from '../../config/networks/mainnet'
import { daiAddress, usdcAddress, usdtAddress, wETHAddress } from '../../debug-helpers'
import { mainnetTestPublicClient } from '@/test/utils/wagmi/wagmi-test-clients'
import { Pool } from '../../../PoolProvider'
import { NestedAddLiquidityHandler } from './NestedAddLiquidity.handler'
import { selectAddLiquidityHandler } from './selectAddLiquidityHandler'
import { defaultTestUserAccount } from '@/test/anvil/anvil-setup'
import { HumanTokenAmountWithAddress } from '../../modules/tokens/token.types'
import { getPoolMock } from '../../../__mocks__/getPoolMock'
import { GqlChain } from '../../shared/services/api/generated/graphql'
import networkConfig from '../../../../../config/networks/arbitrum'
import { daiAddress, wETHAddress, usdcAddress, usdtAddress } from '../../../../../debug-helpers'
import { GqlChain } from '../../../../../shared/services/api/generated/graphql'
import { defaultTestUserAccount } from '../../../../../test/anvil/anvil-setup'
import { mainnetTestPublicClient } from '../../../../../test/utils/wagmi/wagmi-test-clients'
import { HumanTokenAmountWithAddress } from '../../../../tokens/token.types'

function selectNestedHandler(pool: Pool) {
return selectAddLiquidityHandler(pool) as NestedAddLiquidityHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/* eslint-disable max-len */
import networkConfig from '../../config/networks/mainnet'
import { defaultTestUserAccount } from '@/test/anvil/anvil-setup'
import { polygonTestPublicClient } from '@/test/utils/wagmi/wagmi-test-clients'
import networkConfig from '../../../../../config/networks/arbitrum'
import { defaultTestUserAccount } from '../../../../../test/anvil/anvil-setup'
import { polygonTestPublicClient } from '../../../../../test/utils/wagmi/wagmi-test-clients'
import { HumanTokenAmountWithAddress } from '../../../../tokens/token.types'
import { gyroPoolMock } from '../../../__mocks__/gyroPoolMock'
import { Pool } from '../../../PoolProvider'
import { ProportionalAddLiquidityHandler } from './ProportionalAddLiquidity.handler'
import { selectAddLiquidityHandler } from './selectAddLiquidityHandler'
import { HumanTokenAmountWithAddress } from '../../modules/tokens/token.types'

function selectProportionalHandler(pool: Pool) {
return selectAddLiquidityHandler(pool) as ProportionalAddLiquidityHandler
Expand Down
Loading

0 comments on commit 4ceff50

Please sign in to comment.