Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/hooks/useTokenLists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ReactNode } from 'react'
import { createElement } from 'react'
import { zeroAddress } from 'viem'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { Token } from '@/src/types/token'
import { type Token, tokenSchema } from '@/src/types/token'
import tokenListsCache, { updateTokenListsCache } from '@/src/utils/tokenListsCache'

vi.mock('@/src/utils/tokenListsCache', () => {
Expand Down Expand Up @@ -155,6 +155,29 @@ describe('fetchTokenList', () => {
expect(result.tokens).toEqual([])
warnSpy.mockRestore()
})

describe("'default' bundled token list", () => {
it('returns a non-empty tokens array', async () => {
const result = await fetchTokenList('default')

expect(result.tokens.length).toBeGreaterThan(0)
expect(mockFetch).not.toHaveBeenCalled()
})

it('every EVM token conforms to tokenSchema', async () => {
const result = await fetchTokenList('default')

// The bundled list includes non-EVM tokens (e.g. Solana with base58 addresses)
// alongside EVM tokens. Non-EVM entries are filtered out downstream by useTokenLists
// via safeParse. Here we validate only the EVM-addressable subset.
const evmTokens = result.tokens.filter(({ address }) => /^0x[a-fA-F0-9]{40}$/.test(address))
expect(evmTokens.length).toBeGreaterThan(0)
for (const token of evmTokens) {
expect(() => tokenSchema.parse(token)).not.toThrow()
}
expect(mockFetch).not.toHaveBeenCalled()
})
})
})

describe('useTokenLists', () => {
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/useTokenLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ function combineTokenLists(results: Array<UseSuspenseQueryResult<TokenList>>): T
new Map(
results
.flatMap((result) => result.data.tokens)
// ensure that only valid tokens are consumed in runtime
// tokenSchema enforces EVM address format (0x + 40 hex chars), so non-EVM entries
// (e.g. Solana tokens from @uniswap/default-token-list v18+) are silently dropped here.
// Supporting non-EVM chains would require changes to the address schema, chain config,
// wallet integration, and contract lookup -- out of scope for this EVM-focused starter kit.
.filter((token) => {
const result = tokenSchema.safeParse(token)

Expand Down
Loading