Skip to content

Commit bdf3c1d

Browse files
test: add coverage for fetchTokenList('default') bundled token path
Test that the bundled @uniswap/default-token-list returns a non-empty tokens array and that all EVM-addressable entries conform to tokenSchema. The v18 list also includes Solana tokens (base58 addresses) which are expected to fail the EVM address regex and are filtered out downstream by useTokenLists via safeParse. Closes #438
1 parent 34c81d3 commit bdf3c1d

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/hooks/useTokenLists.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { ReactNode } from 'react'
44
import { createElement } from 'react'
55
import { zeroAddress } from 'viem'
66
import { beforeEach, describe, expect, it, vi } from 'vitest'
7-
import type { Token } from '@/src/types/token'
7+
import { type Token, tokenSchema } from '@/src/types/token'
88
import tokenListsCache, { updateTokenListsCache } from '@/src/utils/tokenListsCache'
99

1010
vi.mock('@/src/utils/tokenListsCache', () => {
@@ -155,6 +155,28 @@ describe('fetchTokenList', () => {
155155
expect(result.tokens).toEqual([])
156156
warnSpy.mockRestore()
157157
})
158+
159+
describe("'default' bundled token list", () => {
160+
it('returns a non-empty tokens array', async () => {
161+
const result = await fetchTokenList('default')
162+
163+
expect(Array.isArray(result.tokens)).toBe(true)
164+
expect(result.tokens.length).toBeGreaterThan(0)
165+
})
166+
167+
it('every EVM token entry conforms to tokenSchema', async () => {
168+
const result = await fetchTokenList('default')
169+
170+
// The bundled list includes non-EVM tokens (e.g. Solana with base58 addresses)
171+
// alongside EVM tokens. Non-EVM entries are filtered out downstream by useTokenLists
172+
// via safeParse. Here we validate only the EVM-addressable subset.
173+
const evmTokens = result.tokens.filter(({ address }) => /^0x[a-fA-F0-9]{40}$/.test(address))
174+
expect(evmTokens.length).toBeGreaterThan(0)
175+
for (const token of evmTokens) {
176+
expect(() => tokenSchema.parse(token)).not.toThrow()
177+
}
178+
})
179+
})
158180
})
159181

160182
describe('useTokenLists', () => {

0 commit comments

Comments
 (0)