43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""Toy contract seeds for interoperability testing.
|
|
|
|
This module provides a tiny, self-contained contract seed representing a
|
|
LocalProblem-like contract. It is intended for bootstrapping adapter plumbing and
|
|
interoperability tests without requiring a full production contract pipeline.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from nova_plan.contracts import CaCContract, CaCRegistry, sign_ca_contract, SignedCaCContract, SignerStore
|
|
|
|
|
|
def toy_local_problem_contract() -> CaCContract:
|
|
"""Return a minimal toy CaCContract representing a LocalProblem seed."""
|
|
contract = CaCContract(
|
|
contract_id="toy-lp",
|
|
version=1,
|
|
content={
|
|
"type": "LocalProblemSeed",
|
|
"domain": "space",
|
|
"assets": ["rover1", "habitat1"],
|
|
"objective": {"type": "min-energy"},
|
|
"constraints": ["deadline<=t", "power<=Pmax"],
|
|
},
|
|
)
|
|
CaCRegistry.register(contract)
|
|
return contract
|
|
|
|
|
|
def sign_toy_contract(signer_id: str) -> "SignedCaCContract | None":
|
|
"""Sign the toy contract if a signer key is registered, returning a SignedCaCContract.
|
|
|
|
If no signer key exists, this returns None. This keeps MVP semantics simple.
|
|
"""
|
|
# Ensure the toy contract exists in the registry
|
|
if CaCRegistry.get("toy-lp") is None:
|
|
toy_local_problem_contract()
|
|
|
|
contract = CaCRegistry.get("toy-lp")
|
|
if contract is None:
|
|
return None # pragma: no cover
|
|
signed = sign_ca_contract(contract, signer_id)
|
|
return signed
|