33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
import math
|
|
from catopt_query.protocol import PrivacyBudget, AuditLog, PolicyBlock, GraphOfContracts, SharedVariables, PlanDelta
|
|
|
|
|
|
def test_privacy_budget_roundtrip():
|
|
d = {
|
|
"signal": 0.5,
|
|
"budget": 1.5,
|
|
"expiry": 1700000000.0,
|
|
}
|
|
pb = PrivacyBudget.from_dict(d)
|
|
assert pb.signal == 0.5
|
|
assert pb.budget == 1.5
|
|
assert pb.expiry == 1700000000.0
|
|
assert PrivacyBudget.from_dict(pb.to_dict()) == pb
|
|
|
|
|
|
def test_audit_log_roundtrip():
|
|
al = AuditLog(entry="test-entry", signer="alice", timestamp=1234.5, contract_id="c1", version=2)
|
|
as_dict = al.to_dict()
|
|
al2 = AuditLog.from_dict(as_dict)
|
|
assert al2 == al
|
|
|
|
|
|
def test_policy_block_roundtrip():
|
|
pb = PolicyBlock(safety="strict", exposure_controls={"read": True, "write": False})
|
|
assert PolicyBlock.from_dict(pb.to_dict()) == pb
|
|
|
|
|
|
def test_graph_of_contracts_roundtrip():
|
|
go = GraphOfContracts(adapter_id="mongo", supported_domains=["finance", "sensor"], contract_version="v1")
|
|
assert GraphOfContracts.from_dict(go.to_dict()) == go
|