62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
import pytest
|
|
|
|
from gridguard_secure_attested_cross_domain_e.contracts import SecurityContractsRegistry
|
|
from gridguard_secure_attested_cross_domain_e.optimization import VerifiableOptimization
|
|
from gridguard_secure_attested_cross_domain_e.attestation import AttestedAgent
|
|
from gridguard_secure_attested_cross_domain_e.governance import GovernanceLedger, DeltaSync
|
|
from gridguard_secure_attested_cross_domain_e.transport import TransportLayer
|
|
from gridguard_secure_attested_cross_domain_e.privacy import SecureAggregator
|
|
from gridguard_secure_attested_cross_domain_e.marketplace import AdaptersMarketplace
|
|
from gridguard_secure_attested_cross_domain_e.simulation import SimulationHarness
|
|
|
|
|
|
def test_security_contract_registry():
|
|
reg = SecurityContractsRegistry()
|
|
reg.register_contract("v1", {"policy": "no_raw_data"})
|
|
assert reg.get_contract("v1")["policy"] == "no_raw_data"
|
|
|
|
|
|
def test_verifiable_optimization():
|
|
obj = {"x": 10, "y": 5}
|
|
constr = {"limit": 20}
|
|
sol, proof = VerifiableOptimization.run_local_solver(obj, constr, seed=7)
|
|
assert isinstance(sol, dict)
|
|
assert isinstance(proof, str) and proof.startswith("ZK_PROOF_")
|
|
|
|
|
|
def test_attested_agent():
|
|
agent = AttestedAgent("agent-1")
|
|
ok = agent.attest()
|
|
assert ok is True
|
|
assert agent.credential is not None
|
|
|
|
|
|
def test_governance_ledger_and_delta_sync():
|
|
ledger = GovernanceLedger()
|
|
event = {"action": "deploy", "agent": "agent-1"}
|
|
entry = ledger.append_event(event)
|
|
assert "signature" in entry
|
|
# DeltaSync
|
|
local = {"budget": 100}
|
|
remote = {"budget": 95}
|
|
reconciled = DeltaSync.reconcile(local, remote, {"valid": True})
|
|
assert reconciled["budget"] == 95
|
|
|
|
|
|
def test_adapters_marketplace():
|
|
market = AdaptersMarketplace()
|
|
market.register_adapter("attestation-adapter", {"type": "attestation", "version": "1.0"})
|
|
adapters = market.list_adapters()
|
|
assert any(a["name"] == "attestation-adapter" for a in adapters) or adapters
|
|
|
|
|
|
def test_simulation_harness():
|
|
sim = SimulationHarness.simulate({"grid": "test"})
|
|
assert sim["state"] == "initialized"
|
|
|
|
|
|
def test_secure_aggregator_basic():
|
|
total, proof = SecureAggregator.aggregate([1.0, 2.0, 3.0])
|
|
assert total == 6.0
|
|
assert isinstance(proof, str) and proof.startswith("PROOF-")
|