@davoodmehraban89 / VELYQOR / commits / 367815c
Fork 0

Intelligence, Advanced Charting & Trading Platform

test: specify theoretical gold and premium behavior

davoodmehraban89 committed Oct 5, 2026 at 10:21 UTC 367815c689260396ffc4ab32809083aeea9d285b
1 file changed +41
packages/market-domain/test/gold-pricing.test.mjs new
+41
@@ -0,0 +1,41 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import { theoreticalGold18Irt, goldPremium, alignSources } from '../src/gold-pricing.mjs';
4 +
5 +test('calculates theoretical 18K gold in IRT per gram', () => {
6 + const result = theoreticalGold18Irt({ xauUsdPerTroyOunce: 4000, usdIrt: 100000 });
7 + const expected = (4000 / 31.1034768) * 0.75 * 100000;
8 + assert.ok(Math.abs(result - expected) < 1e-8);
9 +});
10 +
11 +test('calculates absolute and percentage premium', () => {
12 + const result = goldPremium({ marketIrtPerGram: 10_500_000, theoreticalIrtPerGram: 10_000_000 });
13 + assert.deepEqual(result, { absoluteIrt: 500_000, percent: 5 });
14 +});
15 +
16 +test('rejects zero or negative market inputs', () => {
17 + assert.throws(() => theoreticalGold18Irt({ xauUsdPerTroyOunce: 0, usdIrt: 100000 }), /positive/);
18 + assert.throws(() => goldPremium({ marketIrtPerGram: -1, theoreticalIrtPerGram: 10 }), /positive/);
19 +});
20 +
21 +test('marks aligned sources stale when either source exceeds threshold', () => {
22 + const target = new Date('2026-10-05T12:00:00Z');
23 + const aligned = alignSources({
24 + target,
25 + xau: { value: 4000, timestamp: new Date('2026-10-05T11:59:40Z') },
26 + usdIrt: { value: 100000, timestamp: new Date('2026-10-05T11:57:00Z') },
27 + maxAgeMs: 60_000,
28 + });
29 + assert.equal(aligned.quality, 'STALE');
30 + assert.equal(aligned.xauAgeMs, 20_000);
31 + assert.equal(aligned.usdIrtAgeMs, 180_000);
32 +});
33 +
34 +test('rejects future source observations for a target timestamp', () => {
35 + assert.throws(() => alignSources({
36 + target: new Date('2026-10-05T12:00:00Z'),
37 + xau: { value: 4000, timestamp: new Date('2026-10-05T12:00:01Z') },
38 + usdIrt: { value: 100000, timestamp: new Date('2026-10-05T11:59:59Z') },
39 + maxAgeMs: 60_000,
40 + }), /after target/);
41 +});