import { describe, expect, it } from 'vitest' import { boolToHex, bytesToHex, formatAbi, formatEther, getAddress, hexToBigInt, hexToBytes, hexToNumber, isAddress, isHex, keccak256, numberToHex, parseAbi, parseEther, stringToHex, toBytes, toHex, } from './viem.js' describe('viem re-exports', () => { it('should properly export parseAbi and formatAbi', () => { const abi = parseAbi(['function transfer(address to, uint256 amount) returns (bool)']) expect(abi).toBeInstanceOf(Array) expect(abi[0].type).toBe('function') expect(abi[0].name).toBe('transfer') // Just test formatAbi exists and is a function expect(typeof formatAbi).toBe('function') }) it('should properly export byte conversion utilities', () => { const bytes = new Uint8Array([0x12, 0x34]) const hex = bytesToHex(bytes) expect(hex).toBe('0x1234') const convertedBytes = hexToBytes(hex) expect(convertedBytes).toEqual(bytes) }) it('should properly export hex conversion utilities', () => { expect(hexToBigInt('0x1234')).toBe(4660n) expect(hexToNumber('0xff')).toBe(255) expect(numberToHex(255)).toBe('0xff') expect(boolToHex(true)).toBe('0x1') expect(stringToHex('hello')).toBe('0x68656c6c6f') }) it('should properly export toBytes and toHex', () => { expect(toBytes('hello')).toEqual(new Uint8Array([104, 101, 108, 108, 111])) expect(toHex(255)).toBe('0xff') }) it('should properly export keccak256', () => { const hash = keccak256(new Uint8Array([1, 2, 3])) expect(hash).toMatch(/^0x[0-9a-f]{64}$/) }) it('should properly export address utilities', () => { const address = '0x1234567890123456789012345678901234567890' expect(isAddress(address)).toBe(true) const checksummedAddress = getAddress(address) expect(isAddress(checksummedAddress)).toBe(true) }) it('should properly export isHex utility', () => { expect(isHex('0x1234')).toBe(true) expect(isHex('hello')).toBe(false) }) it('should properly export ether conversion utilities', () => { const wei = parseEther('1.0') expect(wei).toBe(1000000000000000000n) const ether = formatEther(wei) expect(ether).toBe('1') }) })