import * as TestApp from '../../../../test/App.js' import * as Runtime from '../../../../test/runtime.js' import * as VerifiedTokens from '../../../internal/VerifiedTokens.js' import * as Tokenlist from './tokenlist.js' /** Reader key for the data routes. */ const reader = { id: 'key_reader', orgId: 'org_test', scopes: ['data:read'], token: 'secret_reader', } satisfies TestApp.kvStore.Key /** A known list published into the store before exercising the read endpoint. */ const seedList = [ { address: '0x20c0000000000000000000000000000000001001', currency: 'USD', decimals: 6, logoUri: 'https://example.com/susd.svg', name: 'Seed USD', symbol: 'sUSD' }, // prettier-ignore { address: '0x20c0000000000000000000000000000000001002', currency: 'EUR', decimals: 2, name: 'Seed EUR', symbol: 'sEUR' }, // prettier-ignore ] as const const chainId = Runtime.get().chainId /** RequestInit carrying a bearer token for the given key. */ function as(key: { token: string }) { return { headers: { authorization: `Bearer ${key.token}` } } as const } /** Client whose verified-token store holds a published {@link seedList} snapshot. */ async function seeded() { const db = TestApp.database() await VerifiedTokens.replace(db, chainId, seedList) return TestApp.client({ auth: { keys: [reader] }, db, }) } describe('GET /tokenlist', () => { test('serves verified tokens in the Uniswap token-list format', async () => { const response = await (await seeded()).v1.tokenlist.$get({ query: {} }, as(reader)) expect(response.status).toBe(200) const body = await TestApp.json(response, Tokenlist.schema.getTokenList.Response) expect(body.name).toMatch(/^Tempo/) expect(body.version).toEqual({ major: 1, minor: 0, patch: 2 }) // Token entries carry the standard fields, scoped to the requested chain, // with no `extensions`; a curated `logoUri` is preserved when present. expect(body.tokens).toEqual([ { address: '0x20c0000000000000000000000000000000001001', chainId, decimals: 6, logoURI: 'https://example.com/susd.svg', name: 'Seed USD', symbol: 'sUSD', }, { address: '0x20c0000000000000000000000000000000001002', chainId, decimals: 2, name: 'Seed EUR', symbol: 'sEUR', }, ]) expect(body.tokens[0]).not.toHaveProperty('extensions') }) test('serves an empty list for a chain with no verified tokens', async () => { const response = await ( await seeded() ).v1.tokenlist.$get({ query: { chainId: '4217' } }, as(reader)) expect(response.status).toBe(200) const body = await TestApp.json(response, Tokenlist.schema.getTokenList.Response) expect(body.name).toBe('Tempo Mainnet') expect(body.tokens).toEqual([]) expect(body.version.patch).toBe(0) }) test('refreshes cached reads after a snapshot publish', async () => { const db = TestApp.database() await VerifiedTokens.replace(db, chainId, seedList) const client = TestApp.client({ auth: { keys: [reader] }, db }) await client.v1.tokenlist.$get({ query: {} }, as(reader)) await VerifiedTokens.replace(db, chainId, seedList.slice(1)) const response = await client.v1.tokenlist.$get({ query: {} }, as(reader)) const body = await TestApp.json(response, Tokenlist.schema.getTokenList.Response) expect(body.tokens.map((token) => token.address)).toEqual( seedList.slice(1).map((token) => token.address), ) }) })