34 lines
1.1 KiB
Python
34 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, BloomFilter
|
|
|
|
|
|
def test_checkpoint_includes_bloom_and_membership():
|
|
dl = DeltaLog()
|
|
# add several payloads
|
|
for i in range(8):
|
|
dl.add_entry({"v": i})
|
|
|
|
# create checkpoint archiving first 5 entries
|
|
cp = dl.checkpoint(prune_before_index=5)
|
|
|
|
assert "bloom" in cp
|
|
assert cp["bloom"] is not None
|
|
|
|
# load bloom and check that all archived digests are (probably) present
|
|
bf = BloomFilter.from_dict(cp["bloom"])
|
|
archived = cp["digests"]
|
|
# Bloom filters may have false positives but must not have false negatives
|
|
for d in archived:
|
|
assert d in bf
|
|
|
|
# non-archived digest may or may not be in bloom (allow either)
|
|
remaining = [e["digest"] for e in dl.entries]
|
|
if remaining:
|
|
# ensure at least one remaining digest is not erroneously marked as missing
|
|
_ = remaining[0] # presence not asserted
|