Skip to content

Commit 3b21251

Browse files
Merge pull request #447 from BootNodeDev/chore/438
test: add coverage for fetchTokenList('default') bundled token path
2 parents 466dd00 + 74c0362 commit 3b21251

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/hooks/useTokenLists.test.ts

Lines changed: 24 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,29 @@ 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(result.tokens.length).toBeGreaterThan(0)
164+
expect(mockFetch).not.toHaveBeenCalled()
165+
})
166+
167+
it('every EVM token 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+
expect(mockFetch).not.toHaveBeenCalled()
179+
})
180+
})
158181
})
159182

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

src/hooks/useTokenLists.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ function combineTokenLists(results: Array<UseSuspenseQueryResult<TokenList>>): T
9898
new Map(
9999
results
100100
.flatMap((result) => result.data.tokens)
101-
// ensure that only valid tokens are consumed in runtime
101+
// tokenSchema enforces EVM address format (0x + 40 hex chars), so non-EVM entries
102+
// (e.g. Solana tokens from @uniswap/default-token-list v18+) are silently dropped here.
103+
// Supporting non-EVM chains would require changes to the address schema, chain config,
104+
// wallet integration, and contract lookup -- out of scope for this EVM-focused starter kit.
102105
.filter((token) => {
103106
const result = tokenSchema.safeParse(token)
104107

0 commit comments

Comments
 (0)