Intelligence, Advanced Charting & Trading Platform
test(alert): enforce rule symbol/unit/provider and prevent gate-quote substitution
davoodmehraban89 committed
Oct 21, 2026 at 08:58 UTC
3a44d28bddecfa39eb7a535caad5e3cdf7c4d158
1 file changed
+15
-1
packages/market-domain/test/informational-alert-engine.test.mjs
+15
-1
@@ -4,7 +4,7 @@ const at=i=>new Date(Date.parse('2026-10-20T12:00:00Z')+i*60000).toISOString();
4
const q=(i,p,extras={})=>({timestamp:at(i),price:p,provider:'S1',symbol:'USD_IRT_FREE',side:'SELL',unit:'IRT_PER_USD',...extras});
5
const g=x=>({status:'GOOD',alertsSuspended:false,accepted:x});
6
const leg=(type,extras={})=>({type,side:'SELL',threshold:100,position:'LONG',entry:100,...extras});
7
-const rule=(id,legs,extra={})=>({id,legs,...extra});
7
+const rule=(id,legs,extra={})=>({id,symbol:'USD_IRT_FREE',provider:'S1',unit:'IRT_PER_USD',legs,...extra});
8
test('above/below thresholds generate one event, no repeated triggers',()=>{
9
for(const [kind,price] of [['ABOVE',102],['BELOW',98]]){
10
const r=rule('one',[leg(kind)]),tick=q(0,price);
@@ -90,3 +90,17 @@ test('nonmatching quote side and malformed alerts produce no event',()=>{
90
const x=q(0,110,{side:'BUY'});assert.equal(stepAlert(r,null,x,g(x)).reason,'QUOTE_SIDE_OR_PRICE_INVALID');
91
assert.throws(()=>stepAlert({id:'x',legs:[]},null,x,g(x)));
92
});
93
+
94
+test('rejects cross-instrument, provider and unit quote replay',()=>{
95
+ const r=rule('bound',[leg('ABOVE')]);
96
+ for(const change of [{symbol:'GOLD18_IRT'},{provider:'S2'},{unit:'IRR_PER_USD'}]){
97
+ const qx=q(0,111,change),v=stepAlert(r,null,qx,g(qx));
98
+ assert.equal(v.reason,'QUOTE_SIDE_OR_PRICE_INVALID');assert.equal(v.events.length,0)
99
+ }
100
+});
101
+test('rejects gate spoofing by quote mismatch',()=>{
102
+ const r=rule('guard',[leg('ABOVE')]);
103
+ const good=q(0,110),forged=q(0,999);
104
+ const v=stepAlert(r,null,forged,g(good));
105
+ assert.equal(v.reason,'QUALITY_HOLD');assert.equal(v.events.length,0)
106
+});