import * as Fees from './Fees.js' describe('fromGas', () => { test('behavior: scales attodollar gas math to token units with ceiling division', () => { // 100k gas × 1e6 atto = 1e11 atto rounds up to one token unit. expect(Fees.fromGas(100_000n, 1_000_000n)).toBe(1n) // 1M gas × 5e11 atto = 5e17 atto = $0.50 exactly. expect(Fees.fromGas(1_000_000n, 500_000_000_000n)).toBe(500_000n) // Any remainder rounds up, mirroring `calc_gas_balance_spending`. expect(Fees.fromGas(1n, 1_000_000_000_001n)).toBe(2n) expect(Fees.fromGas(0n, 0n)).toBe(0n) }) }) describe('maxOf', () => { test('behavior: computes the signed cap from bigint or hex quantity fields', () => { expect(Fees.maxOf({ gas: 1_000_000n, maxFeePerGas: 500_000_000_000n })).toBe(500_000n) // Fills carry hex quantities: 0xf4240 = 1M gas, 0x746a528800 = 5e11 atto. expect(Fees.maxOf({ gas: '0xf4240', maxFeePerGas: '0x746a528800' })).toBe(500_000n) // Zero fields are computable (a zero cap), not absent. expect(Fees.maxOf({ gas: 0n, maxFeePerGas: 0n })).toBe(0n) }) test('behavior: yields undefined when either fee field is missing or unparseable', () => { expect(Fees.maxOf({})).toBeUndefined() expect(Fees.maxOf({ gas: 21_000n })).toBeUndefined() expect(Fees.maxOf({ maxFeePerGas: 1_000_000n })).toBeUndefined() // Decimal strings are not hex quantities; callers fail closed. expect(Fees.maxOf({ gas: '21000', maxFeePerGas: 1_000_000n })).toBeUndefined() expect(Fees.maxOf({ gas: null, maxFeePerGas: 1_000_000n })).toBeUndefined() }) })