@davoodmehraban89 / VELYQOR / commits / 71670bc
Fork 0

Intelligence, Advanced Charting & Trading Platform

test(paper): block stale, unauthorized, replayed and non-tradable indicative quotes

davoodmehraban89 committed Oct 14, 2026 at 23:52 UTC 71670bc9b16a1e69466b95d9d8131e6b4cadab1e
1 file changed +68
packages/market-domain/test/paper-quote-guard.test.mjs new
+68
@@ -0,0 +1,68 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import {validatePaperQuote} from '../src/paper-quote-guard.mjs';
4 +
5 +const NOW='2026-10-14T20:00:00Z';
6 +const q=()=>({
7 + symbol:'XAU_USD',source:'licensed_paper_feed',unit:'USD_PER_TROY_OUNCE',
8 + dataKind:'bid_ask_quote',usage:'PAPER_ONLY_BID_ASK',entitlement:'reviewed_simulation_display',
9 + quality:'GOOD',isMarketOpen:true,sequence:2,bid:'100',ask:'100.2',
10 + sourceTimestamp:'2026-10-14T19:59:55Z',receivedAt:'2026-10-14T19:59:57Z'
11 +});
12 +const opts=(side='LONG')=>({symbol:'XAU_USD',side,now:NOW,lastSequence:1,approvedSources:['licensed_paper_feed']});
13 +test('LONG uses bid as conservative hypothetical exit mark',()=>{
14 + const out=validatePaperQuote(q(),opts());
15 + assert.equal(out.hypotheticalExitMark,100);
16 + assert.equal(out.kind,'PAPER_QUOTE_ELIGIBLE');
17 +});
18 +test('SHORT uses ask as conservative hypothetical exit mark',()=>{
19 + assert.equal(validatePaperQuote(q(),opts('SHORT')).hypotheticalExitMark,100.2);
20 +});
21 +test('rejects ECB reference points and unapproved sources',()=>{
22 + let x=q();x.dataKind='daily_reference_point_not_ohlc';
23 + assert.throws(()=>validatePaperQuote(x,opts()),/type\/usage/);
24 + x=q();x.source='ecb_exr';
25 + assert.throws(()=>validatePaperQuote(x,opts()),/source not approved/);
26 +});
27 +test('rejects stale source and stale receive timestamps',()=>{
28 + let x=q();x.sourceTimestamp='2026-10-14T19:00:00Z';
29 + assert.throws(()=>validatePaperQuote(x,opts()),/stale/);
30 + x=q();x.receivedAt='2026-10-14T19:00:00Z';
31 + assert.throws(()=>validatePaperQuote(x,opts()),/stale/);
32 +});
33 +test('rejects replay, missing sequence, future timestamp',()=>{
34 + let x=q();x.sequence=1;
35 + assert.throws(()=>validatePaperQuote(x,opts()),/replayed/);
36 + x=q();x.sequence=1.1;
37 + assert.throws(()=>validatePaperQuote(x,opts()),/replayed/);
38 + x=q();x.receivedAt='2026-10-14T20:03:00Z';
39 + assert.throws(()=>validatePaperQuote(x,opts()),/future/);
40 +});
41 +test('rejects market closure or bad quality',()=>{
42 + let x=q();x.quality='STALE';
43 + assert.throws(()=>validatePaperQuote(x,opts()),/not healthy/);
44 + x=q();x.isMarketOpen=false;
45 + assert.throws(()=>validatePaperQuote(x,opts()),/not healthy/);
46 +});
47 +test('rejects missing simulation entitlement',()=>{
48 + let x=q();delete x.entitlement;
49 + assert.throws(()=>validatePaperQuote(x,opts()),/not authorized/);
50 +});
51 +test('rejects crossed quotes and excessive spreads',()=>{
52 + let x=q();x.bid=102;
53 + assert.throws(()=>validatePaperQuote(x,opts()),/crossed/);
54 + x=q();x.ask=110;
55 + assert.throws(()=>validatePaperQuote(x,opts()),/spread/);
56 +});
57 +test('rejects invalid symbol, side, units and nonpositive prices',()=>{
58 + let x=q();x.bid='0';
59 + assert.throws(()=>validatePaperQuote(x,opts()),/positive/);
60 + x=q();x.unit='USD/?';
61 + assert.throws(()=>validatePaperQuote(x,opts()),/canonical/);
62 + assert.throws(()=>validatePaperQuote(q(),opts('BUY')),/side/);
63 + assert.throws(()=>validatePaperQuote(q(),{...opts(),symbol:'BTC_USD'}),/symbol mismatch/);
64 +});
65 +test('rejects unattested source lists and invalid tolerances',()=>{
66 + assert.throws(()=>validatePaperQuote(q(),{...opts(),approvedSources:[]}),/source not approved/);
67 + assert.throws(()=>validatePaperQuote(q(),{...opts(),maxAgeMs:100000}),/freshness/);
68 +});