Files
wownerogue/test/chainProfile_ultra.test.js
T
jwinterm f9d49f34ee feat(chain): ChainProfile registry for Smirk's 5 chains + centralize decimals
New src/chain/chainProfile.js — one data-driven source for chain params (decimals, mean block time, adapter family, URI scheme) across WOW/XMR/BTC/LTC/GRIN, all PoW/high-variance. inferCurrencyDecimals now delegates to it: WOW=11/XMR=12 unchanged, and BTC=8/LTC=8/GRIN=9 are fixed (were silently defaulting to 12). This is the seam the daemon/wallet/address adapters and the block-time difficulty-scaling plug into. +6 tests, suite 50/350 green.

P2 foundation on branch feat/credits-catalog-foundation.
2026-07-10 16:38:25 -04:00

50 lines
2.3 KiB
JavaScript

/**
* ChainProfile registry (Pillar 3 foundation) — one source for chain params across Smirk's five
* PoW chains, and the fix for decimals silently defaulting to 12 for anything but WOW/XMR.
*/
const ChainProfile = require('../src/chain/chainProfile');
const { inferCurrencyDecimals } = require('../src/game/helpers/gameModeUtils');
describe('ChainProfile', () => {
test('decimals are correct for every Smirk chain', () => {
expect(ChainProfile.decimalsFor('WOW')).toBe(11);
expect(ChainProfile.decimalsFor('XMR')).toBe(12);
expect(ChainProfile.decimalsFor('BTC')).toBe(8);
expect(ChainProfile.decimalsFor('LTC')).toBe(8);
expect(ChainProfile.decimalsFor('GRIN')).toBe(9);
});
test('mean block time + adapter family per chain', () => {
expect(ChainProfile.meanBlockTimeMsFor('GRIN')).toBe(60000); // ~1 min, fast floor
expect(ChainProfile.meanBlockTimeMsFor('BTC')).toBe(600000); // ~10 min, slow end
expect(ChainProfile.familyFor('WOW')).toBe('monero');
expect(ChainProfile.familyFor('BTC')).toBe('utxo');
expect(ChainProfile.familyFor('LTC')).toBe('utxo');
expect(ChainProfile.familyFor('GRIN')).toBe('mimblewimble');
});
test('atomic divisor is a BigInt of the right scale', () => {
expect(ChainProfile.atomicDivisor('WOW')).toBe(100000000000n); // 1e11
expect(ChainProfile.atomicDivisor('BTC')).toBe(100000000n); // 1e8
expect(ChainProfile.atomicDivisor('GRIN')).toBe(1000000000n); // 1e9
});
test('case-insensitive; unknown falls back safely', () => {
expect(ChainProfile.getProfile('grin').decimals).toBe(9);
expect(ChainProfile.isSupported('DOGE')).toBe(false);
const fb = ChainProfile.getProfile('DOGE');
expect(fb.decimals).toBe(12);
expect(fb.family).toBe('monero');
});
});
describe('inferCurrencyDecimals now delegates to ChainProfile', () => {
test('WOW/XMR unchanged; BTC/GRIN fixed (were silently 12)', () => {
expect(inferCurrencyDecimals('WOW')).toBe(11);
expect(inferCurrencyDecimals('XMR')).toBe(12);
expect(inferCurrencyDecimals('BTC')).toBe(8);
expect(inferCurrencyDecimals('GRIN')).toBe(9);
expect(inferCurrencyDecimals('')).toBe(12);
});
});