Repository Public
1// Pure pieces of the QA/polish pass of 2026-11-11: who issues a registry deployment, what an API error says, what2// "signed but never broadcast" means, and locale-aware numbers.3import { describe, expect, it } from 'vitest';4import { errText, type Key } from '../src/i18n';5import { issuerOf, LIQUID_HINT } from '../src/issuer';6import { numFmt, testNotSent, trimAmt } from '../src/ui';78// the translator of the tests: the key and its variables, so that assertions do not depend on wording9const t = (k: Key, v?: Record<string, string | number>) => (v ? `${k}(${Object.entries(v).map(([a, b]) => `${a}=${b}`).join(',')})` : String(k));1011describe('issuerOf', () => {12 it('reads the issuer of a pegged token from the deployment name, whatever its ticker', () => {13 expect(issuerOf(t, 'ETH', 'Binance-Peg Ethereum')).toEqual({ kind: 'pegged', text: 'qaIssBinancePeg' });14 expect(issuerOf(t, 'USDC', 'Binance-Peg USD Coin')?.kind).toBe('pegged');15 expect(issuerOf(t, 'USDT', 'Binance-Peg BSC-USD (USDT)')?.kind).toBe('pegged');16 expect(issuerOf(t, 'BTCB', 'Binance-Peg BTCB')).toEqual({ kind: 'pegged', text: 'qaIss_BTCB' }); // the custodian sentence of the reviewed table17 });18 it('names the bridge of a bridged token', () => {19 expect(issuerOf(t, 'USDT', 'Bridged USDT (Base Standard Bridge)')).toEqual({ kind: 'bridged', text: 'qaIssBridged(bridge=Base Standard Bridge)' });20 expect(issuerOf(t, 'USDC.e', 'Bridged USDC (Arbitrum bridge)')?.text).toBe('qaIssBridged(bridge=Arbitrum Bridge)');21 });22 it('keeps the custodian of a reviewed wrapper and adds the bridge it came through', () => {23 expect(issuerOf(t, 'WBTC', 'Wrapped Bitcoin')).toEqual({ kind: 'wrapped', text: 'qaIss_WBTC(sym=WBTC,under=BTC)' });24 expect(issuerOf(t, 'WBTC', 'Wrapped BTC (Arbitrum bridge)')?.text).toBe('qaIss_WBTC(sym=WBTC,under=BTC) ; qaIssVia(bridge=Arbitrum Bridge)');25 expect(issuerOf(t, 'cbXRP', 'Coinbase Wrapped XRP')?.text).toBe('qaIss_cb(sym=cbXRP,under=XRP)');26 expect(issuerOf(t, 'EURC', 'EURC')?.kind).toBe('pegged');27 });28 it('says nothing about an original issue or a native coin', () => {29 for (const [sym, name] of [['USDC', 'USD Coin'], ['USDT', 'Tether USD'], ['LINK', 'Chainlink'], ['ETH', 'Ether'], ['AERO', 'Aerodrome']] as const) expect(issuerOf(t, sym, name)).toBeNull();30 });31 it('falls back to the server sentence for a wrapper it does not know', () => expect(issuerOf(t, 'xFOO', 'Foo', 'someone (custodian)')).toEqual({ kind: 'wrapped', text: 'someone (custodian)' }));32 it('the liquidity hint is a hint: BTCB on BNB Chain, nothing else', () => expect(LIQUID_HINT).toEqual({ bsc: { BTC: 'BTCB' } }));33});3435describe('errText', () => {36 const e = (code: string, message: string) => ({ code, message });37 it('a translated code speaks for itself; the English detail is kept only when it carries a figure', () => {38 expect(errText(t, e('bad_address', 'invalid Base address: invalid EVM address'))).toBe('e_bad_address');39 expect(errText(t, e('bad_address', 'invalid Solana address: Unknown letter "0". Allowed: 123456789ABC'))).toBe('e_bad_address');40 expect(errText(t, e('insufficient_funds', 'balance 3.5 USDC, needed 5'))).toBe('e_insufficient_funds (balance 3.5 USDC, needed 5)');41 expect(errText(t, e('insufficient_funds', 'insufficient balance'))).toBe('e_insufficient_funds');42 });43 it('an unknown code still shows what the server said', () => expect(errText(t, e('never_heard_of_it', 'something specific'))).toBe('something specific'));44 it('a generic server failure is not shown as "internal error"', () => expect(errText(t, e('internal', 'internal error'))).toBe('e_internal'));45 it('an account that is not activated yet is explained', () => expect(errText(t, e('insufficient_funds', "this wallet's XRP account is not activated yet: it must first receive at least 1 XRP"))).toBe('qaErrNotActivated'));46 it('a cancelled passkey prompt is silent', () => expect(errText(t, { name: 'NotAllowedError' })).toBe(''));47});4849describe('display helpers', () => {50 it('signed on a server that does not broadcast is not "sent"', () => {51 expect(testNotSent({ state: 'broadcast', error: 'broadcast disabled (test mode)' })).toBe(true);52 expect(testNotSent({ state: 'broadcast', error: null })).toBe(false);53 expect(testNotSent({ state: 'failed', error: 'broadcast disabled (test mode)' })).toBe(false);54 expect(testNotSent(null)).toBe(false);55 });56 it('numbers follow the locale', () => {57 expect(numFmt(1.2649, 'fr', 2)).toBe('1,26');58 expect(numFmt(1.2649, 'en', 2)).toBe('1.26');59 expect(numFmt(0.5, 'fr', 2, 2)).toBe('0,50');60 });61 it('an 18-decimal amount is trimmed, never rounded up', () => {62 expect(trimAmt('7.344872000000000000', 8)).toBe('7.344872');63 expect(trimAmt('0.999999999999999999', 6)).toBe('0.999999');64 expect(trimAmt('100.000000000000000000')).toBe('100');65 });66});67