import test from 'node:test'; import assert from 'node:assert/strict'; import { buildInventorySnapshot } from '../src/core/inventory.mjs'; import { routeHistoryRecord } from '../src/core/history-records.mjs'; test('inventory snapshot keeps pending funding out of spendable balances', () => { const snapshot = buildInventorySnapshot({ accountId: 'solver.near', balances: { 'nep141:btc.omft.near': '1000', 'nep141:eure.omft.near': '2000', }, recentDeposits: [ { asset_id: 'nep141:eure.omft.near', amount: '300', status: 'PENDING', }, ], trackedWithdrawals: [ { withdrawal_hash: 'wd-1', asset_id: 'nep141:btc.omft.near', amount: '25', status: 'PENDING', }, ], assetRegistry: new Map([ ['nep141:btc.omft.near', { decimals: 8 }], ['nep141:eure.omft.near', { decimals: 18 }], ]), observedAt: '2026-04-02T10:00:00.000Z', }); assert.equal(snapshot.spendable['nep141:eure.omft.near'], '2000'); assert.equal(snapshot.pending_inbound['nep141:eure.omft.near'], '300'); assert.equal(snapshot.pending_outbound['nep141:btc.omft.near'], '25'); }); test('history writer routes decision events into the decision table family', () => { const routed = routeHistoryRecord({ topic: 'decision.trade_decision', event: { event_id: 'evt-1', event_type: 'trade_decision', venue: 'near-intents', schema_version: 1, ingested_at: '2026-04-02T10:00:00.000Z', payload: { decision_id: 'decision-1', quote_id: 'quote-1', pair: 'a->b', direction: 'btc_to_eure', decision: 'rejected', decision_reason: 'strategy_disarmed', }, }, }); assert.equal(routed.table, 'trade_decisions'); assert.equal(routed.record.decision_key, 'decision-1'); assert.equal(routed.record.quote_id, 'quote-1'); });