- Introduced a new Diagnostics struct to capture transaction visibility state and activity state. - Updated BuildSnapshot function to return diagnostics alongside snapshot, completeness, and sampling. - Enhanced test cases to validate the new diagnostics data. - Updated frontend components to utilize the new diagnostics information for improved user feedback on freshness context. This change improves the observability of transaction activity and enhances the user experience by providing clearer insights into the freshness of data.
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
isWatchlistEntry,
|
|
normalizeWatchlistAddress,
|
|
parseStoredWatchlist,
|
|
sanitizeWatchlistEntries,
|
|
toggleWatchlistEntry,
|
|
} from './watchlist'
|
|
|
|
describe('watchlist utils', () => {
|
|
it('normalizes only valid addresses', () => {
|
|
expect(normalizeWatchlistAddress(' 0x1234567890123456789012345678901234567890 ')).toBe(
|
|
'0x1234567890123456789012345678901234567890',
|
|
)
|
|
expect(normalizeWatchlistAddress('not-an-address')).toBe('')
|
|
})
|
|
|
|
it('filters invalid entries and deduplicates case-insensitively', () => {
|
|
expect(
|
|
sanitizeWatchlistEntries([
|
|
'0x1234567890123456789012345678901234567890',
|
|
'0x1234567890123456789012345678901234567890',
|
|
'0x1234567890123456789012345678901234567890'.toUpperCase(),
|
|
'bad',
|
|
42,
|
|
]),
|
|
).toEqual(['0x1234567890123456789012345678901234567890'])
|
|
})
|
|
|
|
it('parses stored JSON safely', () => {
|
|
expect(parseStoredWatchlist('["0x1234567890123456789012345678901234567890"]')).toEqual([
|
|
'0x1234567890123456789012345678901234567890',
|
|
])
|
|
expect(parseStoredWatchlist('not json')).toEqual([])
|
|
})
|
|
|
|
it('matches saved addresses case-insensitively', () => {
|
|
const entries = ['0x1234567890123456789012345678901234567890']
|
|
expect(
|
|
isWatchlistEntry(entries, '0x1234567890123456789012345678901234567890'.toUpperCase()),
|
|
).toBe(true)
|
|
})
|
|
|
|
it('toggles watchlist entries on and off case-insensitively', () => {
|
|
const address = '0x1234567890123456789012345678901234567890'
|
|
expect(toggleWatchlistEntry([], address)).toEqual([address])
|
|
expect(toggleWatchlistEntry([address], address.toUpperCase())).toEqual([])
|
|
})
|
|
})
|