Spaces:
Sleeping
Sleeping
| """P3: plan hash integrity tests.""" | |
| from trading.plan_integrity import compute_plan_hash, verify_plan_hash, bind_plan_hash | |
| def _sample_plan(**over): | |
| base = { | |
| "symbol": "BTCUSDT", | |
| "decision": "LONG", | |
| "entry": 100.0, | |
| "stop_loss": 95.0, | |
| "take_profit": 110.0, | |
| "leverage": 5, | |
| "quantity": 1.0, | |
| "risk_profile": "moderate", | |
| "futuresVerified": True, | |
| "noTradeGuard": False, | |
| "trading_readiness": "ready", | |
| "executable": True, | |
| "expires_at": "2099-01-01T00:00:00Z", | |
| } | |
| base.update(over) | |
| return base | |
| def test_hash_stable(): | |
| a = compute_plan_hash(_sample_plan()) | |
| b = compute_plan_hash(_sample_plan()) | |
| assert a == b | |
| assert len(a) == 64 | |
| def test_hash_changes_on_field(): | |
| a = compute_plan_hash(_sample_plan()) | |
| b = compute_plan_hash(_sample_plan(entry=101.0)) | |
| assert a != b | |
| def test_verify_and_bind(): | |
| plan = bind_plan_hash(_sample_plan()) | |
| assert "plan_hash" in plan | |
| assert verify_plan_hash(plan, plan["plan_hash"]) | |
| plan["entry"] = 999.0 | |
| assert not verify_plan_hash(plan, plan["plan_hash"]) | |