import { describe, it, expect } from 'vitest'; import { Satoshis } from '~/src/satoshis'; describe('Success cases', () => { // Test cases with single representation for each unit type ConversionCase = { raw: bigint; units: { sats: number | bigint; satoshis: number | bigint; bits: number; mBCH: number; bch: number; }; }; const testCases: ConversionCase[] = [ { raw: 1n, units: { sats: 1, satoshis: 1, bits: 0.01, mBCH: 0.00001, bch: 0.00000001, }, }, { raw: 333333333n, units: { sats: 333333333, satoshis: 333333333, bits: 3333333.33, mBCH: 3333.33333, bch: 3.33333333, }, }, ]; // Test from methods with their respective types const fromMethods = [ { name: 'fromSats', key: 'sats' }, { name: 'fromSatoshis', key: 'satoshis' }, { name: 'fromBits', key: 'bits' }, { name: 'fromMBCH', key: 'mBCH' }, { name: 'fromBCH', key: 'bch' }, ] as const; fromMethods.forEach(({ name, key }) => { it.each(testCases)(`${name}()`, ({ raw, units }) => { const satoshis = Satoshis[name](units[key]); expect(satoshis.toRaw()).toStrictEqual(raw); }); }); // Test to methods with their respective types const toMethods = [ { name: 'toSats', key: 'sats' }, { name: 'toSatoshis', key: 'satoshis' }, { name: 'toBits', key: 'bits' }, { name: 'toMBCH', key: 'mBCH' }, { name: 'toBCH', key: 'bch' }, ] as const; toMethods.forEach(({ name, key }) => { it.each(testCases)(`${name}()`, ({ raw, units }) => { const satoshis = Satoshis.fromRaw(raw); expect(satoshis[name]()).toStrictEqual(units[key]); }); }); });