import { describe, expect, it } from 'bun:test' import { PAYMENT_LAYER_ABI, ROUTER_PAYMENT_LAYER, depositRouterCredit } from './router-payment' describe('Router Payment Layer constants (verified Jun 16 2026)', () => { it('pins the mainnet + testnet Payment Layer addresses', () => { expect(ROUTER_PAYMENT_LAYER['0g-mainnet']).toBe('0xA3b15Bd2aD18BFB6b5f92D8AA9F444Dd59d1cE32') expect(ROUTER_PAYMENT_LAYER['0g-testnet']).toBe('0x0AD9690e0b34aB2d493DE02cDF149ee34f6C9939') }) it('exposes balanceOf (view) + depositFor (payable)', () => { const balanceOf = PAYMENT_LAYER_ABI.find(f => f.name === 'balanceOf') const depositFor = PAYMENT_LAYER_ABI.find(f => f.name === 'depositFor') expect(balanceOf?.stateMutability).toBe('view') expect(balanceOf?.inputs[0]?.type).toBe('address') expect(depositFor?.stateMutability).toBe('payable') expect(depositFor?.inputs[0]?.type).toBe('address') }) }) describe('depositRouterCredit amount guard', () => { const KEY = `0x${'1'.repeat(64)}` as const it('rejects a sub-minimum (scientific-notation) amount with a clear error before any RPC', async () => { // (5e-7).toString() === '5e-7' would make viem.parseEther throw a cryptic // decimal error; the guard fails clearly instead, before makeViemClients. await expect( depositRouterCredit({ network: '0g-mainnet', privkeyHex: KEY, amountOg: 5e-7 }), ).rejects.toThrow(/minimum/i) }) it('rejects NaN/Infinity amounts', async () => { await expect( depositRouterCredit({ network: '0g-mainnet', privkeyHex: KEY, amountOg: Number.NaN }), ).rejects.toThrow(/invalid/i) }) })