idea182-implementation/tests/test_dtn.py

20 lines
665 B
Python

from gravityweave.dtn import CustodyHeader, should_accept_custody
import time
def test_custody_header_and_expiry():
h = CustodyHeader(delta_id="d1", lifetime_secs=1)
assert not h.is_expired()
# wait for expiry
time.sleep(1.1)
assert h.is_expired()
def test_should_accept_custody():
# fresh header with medium priority
h = CustodyHeader(delta_id="d2", lifetime_secs=60, priority_key=(2 << 4) | 8)
# low reputation should often reject
assert not should_accept_custody(h, node_reputation=0.0, min_reputation=0.2)
# decent reputation should accept
assert should_accept_custody(h, node_reputation=0.8, min_reputation=0.2)