@davoodmehraban89 / VELYQOR / commits / c67dfe3
Fork 0

Intelligence, Advanced Charting & Trading Platform

Phase 1: aggregate required Data Proof evidence

* test: define Phase 1 aggregate Data Proof artifact * feat: aggregate required Phase 1 Data Proof evidence

davoodmehraban89 committed Oct 5, 2026 at 19:53 UTC c67dfe39b4f867591a5d8605f5f098b8f9695408
2 files changed +71
packages/market-domain/src/data-proof-artifact.mjs new
+33
@@ -0,0 +1,33 @@
1 +const REQUIRED = Object.freeze(['GOLD18_IRT', 'USD_IRT_FREE', 'XAU_USD']);
2 +
3 +export function buildDataProofArtifact({ generatedAt, reports }) {
4 + if (!(generatedAt instanceof Date) || Number.isNaN(generatedAt.valueOf())) throw new TypeError('generatedAt must be a valid Date');
5 + if (!Array.isArray(reports)) throw new TypeError('reports must be an array');
6 +
7 + const seen = new Set();
8 + for (const report of reports) {
9 + if (!report || typeof report !== 'object') throw new TypeError('each report must be an object');
10 + if (!report.providerCode || !report.canonicalSymbol) throw new TypeError('report providerCode and canonicalSymbol are required');
11 + if (!['PASS', 'FAIL'].includes(report.status)) throw new RangeError('report status must be PASS or FAIL');
12 + if (seen.has(report.canonicalSymbol)) throw new RangeError(`duplicate report for ${report.canonicalSymbol}`);
13 + seen.add(report.canonicalSymbol);
14 + const checked = new Date(report.checkedAt);
15 + if (Number.isNaN(checked.valueOf())) throw new TypeError('report checkedAt must be valid');
16 + if (checked > generatedAt) throw new RangeError('report checkedAt cannot be after generatedAt');
17 + }
18 +
19 + const missing = REQUIRED.filter(symbol => !seen.has(symbol));
20 + if (missing.length) throw new RangeError(`required Phase 1 reports missing: ${missing.join(', ')}`);
21 +
22 + const requiredReports = reports
23 + .filter(report => REQUIRED.includes(report.canonicalSymbol))
24 + .sort((a, b) => a.canonicalSymbol.localeCompare(b.canonicalSymbol));
25 +
26 + return Object.freeze({
27 + phase: 1,
28 + generatedAt: generatedAt.toISOString(),
29 + status: requiredReports.every(report => report.status === 'PASS') ? 'PASS' : 'FAIL',
30 + requiredSymbols: [...REQUIRED],
31 + reports: requiredReports.map(report => Object.freeze({ ...report })),
32 + });
33 +}
packages/market-domain/test/data-proof-artifact.test.mjs new
+38
@@ -0,0 +1,38 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import { buildDataProofArtifact } from '../src/data-proof-artifact.mjs';
4 +
5 +test('builds immutable evidence artifact from three required Phase 1 reports', () => {
6 + const artifact = buildDataProofArtifact({
7 + generatedAt: new Date('2026-10-05T12:10:00Z'),
8 + reports: [
9 + { providerCode: 'navasan', canonicalSymbol: 'USD_IRT_FREE', status: 'PASS', checkedAt: '2026-10-05T12:09:00Z' },
10 + { providerCode: 'navasan', canonicalSymbol: 'GOLD18_IRT', status: 'PASS', checkedAt: '2026-10-05T12:09:00Z' },
11 + { providerCode: 'alpha_vantage', canonicalSymbol: 'XAU_USD', status: 'PASS', checkedAt: '2026-10-05T12:09:00Z' },
12 + ],
13 + });
14 + assert.equal(artifact.phase, 1);
15 + assert.equal(artifact.status, 'PASS');
16 + assert.deepEqual(artifact.requiredSymbols, ['GOLD18_IRT','USD_IRT_FREE','XAU_USD']);
17 +});
18 +
19 +test('fails aggregate proof when any required report fails', () => {
20 + const artifact = buildDataProofArtifact({
21 + generatedAt: new Date('2026-10-05T12:10:00Z'),
22 + reports: [
23 + { providerCode: 'navasan', canonicalSymbol: 'USD_IRT_FREE', status: 'PASS', checkedAt: '2026-10-05T12:09:00Z' },
24 + { providerCode: 'navasan', canonicalSymbol: 'GOLD18_IRT', status: 'FAIL', checkedAt: '2026-10-05T12:09:00Z' },
25 + { providerCode: 'alpha_vantage', canonicalSymbol: 'XAU_USD', status: 'PASS', checkedAt: '2026-10-05T12:09:00Z' },
26 + ],
27 + });
28 + assert.equal(artifact.status, 'FAIL');
29 +});
30 +
31 +test('refuses to certify Phase 1 when a required symbol is missing or duplicated', () => {
32 + const base = [
33 + { providerCode: 'navasan', canonicalSymbol: 'USD_IRT_FREE', status: 'PASS', checkedAt: '2026-10-05T12:09:00Z' },
34 + { providerCode: 'navasan', canonicalSymbol: 'GOLD18_IRT', status: 'PASS', checkedAt: '2026-10-05T12:09:00Z' },
35 + ];
36 + assert.throws(() => buildDataProofArtifact({ generatedAt: new Date('2026-10-05T12:10:00Z'), reports: base }), /required/i);
37 + assert.throws(() => buildDataProofArtifact({ generatedAt: new Date('2026-10-05T12:10:00Z'), reports: [...base, base[0]] }), /duplicate/i);
38 +});