58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
import json
|
|
from promptledger_verifiable_provenance_and_l import (
|
|
LocalProvenanceBlock,
|
|
MerkleAuditLog,
|
|
DeltaSync,
|
|
BlenderAdapter,
|
|
FigmaAdapter,
|
|
attach_signature,
|
|
)
|
|
|
|
|
|
def test_merkle_audit_log_basic():
|
|
log = MerkleAuditLog()
|
|
blk1 = LocalProvenanceBlock("alice", "Blender", "create_asset", {"asset_type": "mesh"}, "CC-BY-4.0")
|
|
attach_signature(blk1)
|
|
log.append(blk1)
|
|
|
|
blk2 = LocalProvenanceBlock("bob", "Figma", "update_design", {"frame": "Intro"}, "MIT")
|
|
attach_signature(blk2)
|
|
log.append(blk2)
|
|
|
|
root = log.get_root()
|
|
assert isinstance(root, str) and len(root) > 0
|
|
# Recompute by creating a new log with same blocks and ensure root matches
|
|
log2 = MerkleAuditLog()
|
|
log2.append(blk1)
|
|
log2.append(blk2)
|
|
assert log2.get_root() == root
|
|
|
|
|
|
def test_delta_sync_roundtrip():
|
|
log = MerkleAuditLog()
|
|
delta_sync = DeltaSync(log)
|
|
|
|
a = LocalProvenanceBlock("carol", "Blender", "create_asset", {"asset_type": "texture"}, "CC0")
|
|
attach_signature(a)
|
|
log.append(a)
|
|
|
|
delta1 = delta_sync.create_delta()
|
|
# Simulate recipient with empty log getting delta
|
|
recipient_log = MerkleAuditLog()
|
|
recipient_sync = DeltaSync(recipient_log)
|
|
recipient_sync.apply_delta(delta1)
|
|
assert recipient_log.get_root() == log.get_root()
|
|
|
|
|
|
def test_adapters_emit_and_sign():
|
|
blender = BlenderAdapter("dave")
|
|
figma = FigmaAdapter("eve")
|
|
|
|
b = blender.emit()
|
|
attach_signature(b)
|
|
f = figma.emit()
|
|
attach_signature(f)
|
|
|
|
assert b.tool == "Blender" and b.author == "dave"
|
|
assert f.tool == "Figma" and f.author == "eve"
|