Files
explorer-monorepo/frontend/src/services/api/nativeAssetPricing.test.ts
defiQUG 1aa81f454a
Some checks failed
phoenix-deploy Deploy failed: Command failed: bash scripts/deployment/phoenix-deploy-explorer-live-from-workspace.sh nginx: the configuration file /et
Deploy Explorer Live / deploy (push) Failing after 4m8s
feat(explorer): add live token/native pricing and legacy tx route compatibility
2026-04-25 23:45:07 -07:00

33 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { estimateNativeUsdValue, estimateTokenUsdValue, getNativeAssetDescriptor } from './nativeAssetPricing'
describe('nativeAssetPricing', () => {
it('resolves the chain 138 native asset descriptor', () => {
expect(getNativeAssetDescriptor(138)).toEqual({
symbol: 'ETH',
pricingAddress: '0xc02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
})
})
it('estimates USD values from wei using the live asset price', () => {
expect(estimateNativeUsdValue('970000000000000', 2490)).toBe('2.4153')
expect(estimateNativeUsdValue('1000000000000000000', 2490)).toBe('2490')
})
it('returns undefined when pricing inputs are unavailable', () => {
expect(estimateNativeUsdValue(undefined, 2490)).toBeUndefined()
expect(estimateNativeUsdValue('970000000000000', undefined)).toBeUndefined()
expect(estimateNativeUsdValue('not-a-number', 2490)).toBeUndefined()
})
it('estimates token USD values using token decimals', () => {
expect(estimateTokenUsdValue('1000000', 6, 1)).toBe('1')
expect(estimateTokenUsdValue('250000000', 8, 2)).toBe('5')
})
it('preserves precision for large raw balances', () => {
expect(estimateNativeUsdValue('123456789012345678901234567890', 2316.7203872128002)).toBeTruthy()
})
})