@davoodmehraban89 / VELYQOR / commits / 0246e76
Fork 0

Intelligence, Advanced Charting & Trading Platform

test: define auditable live data proof report contract

davoodmehraban89 committed Oct 5, 2026 at 17:24 UTC 0246e761c1b2489863ad9ae2b7c5d18c04b38cec
1 file changed +46
packages/market-domain/test/data-proof-report.test.mjs new
+46
@@ -0,0 +1,46 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import { buildDataProofReport } from '../src/data-proof-report.mjs';
4 +
5 +test('passes a clean provider window with explicit thresholds', () => {
6 + const report = buildDataProofReport({
7 + providerCode: 'navasan',
8 + canonicalSymbol: 'USD_IRT_FREE',
9 + observations: [
10 + { timestamp: '2026-10-05T12:00:00Z', price: 100000 },
11 + { timestamp: '2026-10-05T12:01:00Z', price: 100100 },
12 + { timestamp: '2026-10-05T12:02:00Z', price: 100050 },
13 + ],
14 + checkedAt: new Date('2026-10-05T12:02:10Z'),
15 + thresholds: { maxGapMs: 90_000, maxFreshnessMs: 60_000, maxDuplicateCount: 0, maxOutOfOrderCount: 0 },
16 + });
17 + assert.equal(report.status, 'PASS');
18 + assert.deepEqual(report.failures, []);
19 + assert.equal(report.metrics.freshnessMs, 10_000);
20 +});
21 +
22 +test('fails stale, gapped and duplicate data with auditable reasons', () => {
23 + const report = buildDataProofReport({
24 + providerCode: 'navasan',
25 + canonicalSymbol: 'GOLD18_IRT',
26 + observations: [
27 + { timestamp: '2026-10-05T12:00:00Z', price: 100 },
28 + { timestamp: '2026-10-05T12:00:00Z', price: 100 },
29 + { timestamp: '2026-10-05T12:05:00Z', price: 101 },
30 + ],
31 + checkedAt: new Date('2026-10-05T12:10:00Z'),
32 + thresholds: { maxGapMs: 120_000, maxFreshnessMs: 60_000, maxDuplicateCount: 0, maxOutOfOrderCount: 0 },
33 + });
34 + assert.equal(report.status, 'FAIL');
35 + assert.ok(report.failures.includes('MAX_GAP_EXCEEDED'));
36 + assert.ok(report.failures.includes('STALE_LATEST_OBSERVATION'));
37 + assert.ok(report.failures.includes('DUPLICATE_TIMESTAMPS'));
38 +});
39 +
40 +test('refuses to certify an empty observation window', () => {
41 + assert.throws(() => buildDataProofReport({
42 + providerCode: 'alpha_vantage', canonicalSymbol: 'XAU_USD', observations: [],
43 + checkedAt: new Date('2026-10-05T12:00:00Z'),
44 + thresholds: { maxGapMs: 60_000, maxFreshnessMs: 60_000, maxDuplicateCount: 0, maxOutOfOrderCount: 0 },
45 + }), /observation/i);
46 +});