idea119-regflow-verifiable-pre/tests/test_core.py

41 lines
1.2 KiB
Python

import json
import regflow
def test_compile_basic_dsl():
dsl = """
constraint max_position venue1 AAPL 1000
constraint min_cash venue1 5000
"""
ir = regflow.compile_dsl(dsl)
assert isinstance(ir, dict)
assert "rules" in ir
assert len(ir["rules"]) == 2
r0 = ir["rules"][0]
assert r0["type"] == "max_position"
assert r0["venue"] == "venue1"
assert r0["instrument"] == "AAPL"
assert r0["limit"] == 1000
def test_generate_proof_all_good():
ir = regflow.compile_dsl("""constraint max_position venue1 AAPL 1000
constraint min_cash venue1 5000
""")
trade = {"venue": "venue1", "instrument": "AAPL", "qty": 900, "cash": 6000}
proof = regflow.generate_proof(ir, trade)
assert proof["valid"] is True
assert proof["summary"].startswith("all applicable")
def test_generate_proof_failure():
ir = regflow.compile_dsl("""constraint max_position venue1 AAPL 1000
constraint min_cash venue1 5000
""")
trade = {"venue": "venue1", "instrument": "AAPL", "qty": 1500, "cash": 4000}
proof = regflow.generate_proof(ir, trade)
assert proof["valid"] is False
# At least one detail should indicate a violation
assert any(d["ok"] is False for d in proof["details"])