26 lines
874 B
Python
26 lines
874 B
Python
import hashlib
|
|
from gravityweave.pcp import create_entry, build_chain, inclusion_proof, head_hash, verify_inclusion
|
|
|
|
|
|
def test_create_and_chain_basic():
|
|
ops = [("add-c1", "nodeA"), ("add-c2", "nodeB"), ("mutate-c1", "nodeA")]
|
|
chain = build_chain(ops)
|
|
assert len(chain) == 3
|
|
# each entry hash should be a valid sha256 hex
|
|
for e in chain:
|
|
h = e.get("hash")
|
|
assert isinstance(h, str) and len(h) == 64
|
|
|
|
|
|
def test_inclusion_proof_and_head():
|
|
ops = [("op1", "A"), ("op2", "B"), ("op3", "C")]
|
|
chain = build_chain(ops)
|
|
head = head_hash(chain)
|
|
# pick middle entry
|
|
target = chain[1]
|
|
proof = inclusion_proof(chain, target_entry_id=target["entry_id"])
|
|
assert proof[0] == target["hash"]
|
|
assert proof[-1] == head
|
|
# verify inclusion using head-only verification (best-effort)
|
|
assert verify_inclusion(head, proof)
|