40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from gravityweave.receipt import MutualFeasibilityReceipt
|
|
|
|
|
|
def test_receipt_create_and_verify():
|
|
key = b"node-secret"
|
|
prop_hash = "deadbeefcafebabe"
|
|
invariants = ["fuel_bound", "power_bound"]
|
|
|
|
r = MutualFeasibilityReceipt.create(proposal_hash=prop_hash,
|
|
invariant_ids=invariants,
|
|
decision="ok",
|
|
uncertainty=0.1,
|
|
round_nonce=1,
|
|
signer="nodeA",
|
|
key=key)
|
|
|
|
assert r.proposal_hash == prop_hash
|
|
assert r.decision == "ok"
|
|
assert r.verify(key) is True
|
|
|
|
ser = r.serialize()
|
|
# ensure compact size under 512 bytes
|
|
assert len(ser) <= 512
|
|
|
|
r2 = MutualFeasibilityReceipt.deserialize(ser)
|
|
assert r2.receipt_id == r.receipt_id
|
|
# verify with same key
|
|
assert r2.verify(key) is True
|
|
|
|
|
|
def test_receipt_tamper_detection():
|
|
key = b"k"
|
|
r = MutualFeasibilityReceipt.create(proposal_hash="h", invariant_ids=["i"], decision="ok",
|
|
signer="s", key=key)
|
|
ser = r.serialize()
|
|
# tamper with serialized bytes
|
|
s2 = ser.replace(b"ok", b"deny")
|
|
r2 = MutualFeasibilityReceipt.deserialize(s2)
|
|
assert r2.verify(key) is False
|