49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
from edgemind.plan_cert import PlanCert, sign_plan_cert, verify_plan_cert, make_plan_proof, verify_plan_proof
|
|
|
|
|
|
def test_plan_cert_sign_and_verify():
|
|
key = b"supersecretkey"
|
|
cert = PlanCert(
|
|
plan_id="plan-1",
|
|
preconditions={"battery": ">=20"},
|
|
postconditions={"position": "near-target"},
|
|
invariants={"no-collision": True},
|
|
worst_case_energy=12.5,
|
|
wcet_ms=500,
|
|
provenance={"planner_version": "v0.1", "seed": 42, "env_hash": "abc"},
|
|
)
|
|
|
|
signed = sign_plan_cert(cert, key)
|
|
assert signed.signature is not None
|
|
assert verify_plan_cert(signed, key) is True
|
|
|
|
|
|
def test_plan_cert_tamper_detection():
|
|
key = b"k"
|
|
cert = PlanCert(
|
|
plan_id="p2",
|
|
preconditions={},
|
|
postconditions={},
|
|
invariants={},
|
|
provenance={"planner_version": "x"},
|
|
)
|
|
signed = sign_plan_cert(cert, key)
|
|
# Tamper a field
|
|
signed.worst_case_energy = 999.0
|
|
assert verify_plan_cert(signed, key) is False
|
|
|
|
|
|
def test_plan_proof_sign_and_verify():
|
|
key = b"k2"
|
|
cert = PlanCert(
|
|
plan_id="p3",
|
|
preconditions={},
|
|
postconditions={},
|
|
invariants={},
|
|
provenance={"planner_version": "x"},
|
|
)
|
|
# create a proof and sign it
|
|
proof = make_plan_proof(cert, accepted=True, score=0.95, verifier="test-verifier", key=key)
|
|
assert proof.signature is not None
|
|
assert verify_plan_proof(proof, key) is True
|