35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import sys
|
|
import pathlib
|
|
|
|
# Ensure repository root is on sys.path so tests can import the package
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
|
|
from cosmic_ledger.delta import DeltaLog, merkle_root
|
|
|
|
|
|
def test_checkpoint_prune_and_query():
|
|
dl = DeltaLog()
|
|
# add five payloads
|
|
for i in range(5):
|
|
dl.add_entry({"v": i})
|
|
|
|
# collect initial digests and root
|
|
initial_digests = [e["digest"] for e in dl.entries]
|
|
initial_root = merkle_root(initial_digests)
|
|
|
|
# create a checkpoint archiving first 2 entries
|
|
cp = dl.checkpoint(prune_before_index=2)
|
|
assert cp["root"] == merkle_root(initial_digests[:2])
|
|
# pruned entries should no longer be active
|
|
active_digests = [e["digest"] for e in dl.entries]
|
|
assert len(active_digests) == 3
|
|
|
|
# but has_digest should still find pruned digests via checkpoint
|
|
assert dl.has_digest(initial_digests[0])
|
|
assert dl.has_digest(initial_digests[1])
|
|
# and should find active ones too
|
|
assert dl.has_digest(initial_digests[2])
|
|
|
|
# new root reflects remaining entries only
|
|
assert dl.root() == merkle_root(initial_digests[2:])
|