deltatrace-deterministic-re.../tests/test_basic.py

27 lines
1016 B
Python

import time
from deltatrace.core import LocalEvent, PlanDelta, ReplayEngine
def test_replay_root_is_deterministic():
d1 = PlanDelta(delta_id="d1", timestamp=1.0, author="alice", contract_id="c1", signature="sig1")
d2 = PlanDelta(delta_id="d2", timestamp=2.0, author="bob", contract_id="c2", signature="sig2")
events = [
{"type": "order", "order_id": "o1", "ts": 1.5},
{"type": "fill", "fill_id": "f1", "order_id": "o1", "ts": 1.7},
]
engine = ReplayEngine([d1, d2], events)
root1 = engine.compute_root()
# Recompute should yield the same root
engine2 = ReplayEngine([d1, d2], events)
root2 = engine2.compute_root()
assert root1 == root2
def test_path_length_and_structure():
d = PlanDelta(delta_id="d", timestamp=0.1, author="a", contract_id="c", signature="sig")
engine = ReplayEngine([d], [])
path = engine.replay_path()
assert isinstance(path, dict)
assert "path" in path and isinstance(path["path"], list)
assert "root" in path