import { describe, it, expect } from 'vitest' import { toEvmValueBigInt } from './transactions' describe('toEvmValueBigInt', () => { const oneEth = 1000000000000000000n it('returns 0n for undefined or null', () => { expect(toEvmValueBigInt(undefined)).toBe(0n) expect(toEvmValueBigInt(null as unknown as undefined)).toBe(0n) }) it('passes a bigint through unchanged', () => { expect(toEvmValueBigInt(oneEth)).toBe(oneEth) }) it.each([ ['decimal string', '1000000000000000000'], ['hex string', '0xde0b6b3a7640000'], ['whitespace-padded', ' 1000000000000000000 '] ])('parses %s to the same bigint', (_l, value) => { expect(toEvmValueBigInt(value)).toBe(oneEth) }) it.each(['', ' '])('throws on empty/whitespace value %j', value => { expect(() => toEvmValueBigInt(value)).toThrow( 'Invalid EVM value: empty string' ) }) it.each(['abc', '1.5', '1e18', '0x'])( 'throws with context on malformed value %j', value => { expect(() => toEvmValueBigInt(value)).toThrow(/Invalid EVM value/) } ) it.each(['-1', '0b1010', '0o17'])( 'rejects negative and binary/octal value %j', value => { expect(() => toEvmValueBigInt(value)).toThrow(/Invalid EVM value/) } ) it('rejects a negative bigint', () => { expect(() => toEvmValueBigInt(-1n)).toThrow(/Invalid EVM value/) }) it('rejects a non-string/non-bigint value with a clear error', () => { expect(() => toEvmValueBigInt(100 as unknown as string)).toThrow( /expected bigint or string, got number/ ) }) })