Add timestamp tracking to dummy relay and update tests

This commit is contained in:
thePR0M3TH3AN committed 2025-07-14 08:55:55 -04:00
1 parent 2a329a40bb
commit e45483c6eb
5 files changed
+14 -6

No files matched your search

+3 -1
View File
@@ -163,6 +163,7 @@ class DummySendResult:
class DummyRelayClient:
def __init__(self):
self.counter = 0
self.ts_counter = 0
self.manifests: list[DummyEvent] = []
self.chunks: dict[str, DummyEvent] = {}
self.deltas: list[DummyEvent] = []
@@ -196,7 +197,8 @@ class DummyRelayClient:
self.chunks[ident] = event
elif event.kind == KIND_DELTA:
if not hasattr(event, "created_at"):
event.created_at = int(time.time())
self.ts_counter += 1
event.created_at = self.ts_counter
self.deltas.append(event)
return DummySendResult(eid)
+3 -3
View File
@@ -29,7 +29,7 @@ def _init_pm(dir_path: Path, client) -> PasswordManager:
return pm
def test_full_sync_roundtrip(dummy_nostr_client, monkeypatch):
def test_full_sync_roundtrip(dummy_nostr_client):
client, relay = dummy_nostr_client
with TemporaryDirectory() as tmpdir:
base = Path(tmpdir)
@@ -54,9 +54,9 @@ def test_full_sync_roundtrip(dummy_nostr_client, monkeypatch):
# Manager A publishes delta with second entry
pm_a.entry_manager.add_entry("site2", 12)
delta_bytes = pm_a.vault.get_encrypted_index() or b""
# Use a constant timestamp so dummy relay returns the delta
monkeypatch.setattr("nostr.client.time.time", lambda: 1)
asyncio.run(client.publish_delta(delta_bytes, manifest_id))
delta_ts = relay.deltas[-1].created_at
assert relay.manifests[-1].delta_since == delta_ts
# Manager B fetches delta and updates
pm_b.sync_index_from_nostr()
+3 -2
View File
@@ -29,7 +29,7 @@ def _init_pm(dir_path: Path, client) -> PasswordManager:
return pm
def test_full_sync_roundtrip(dummy_nostr_client, monkeypatch):
def test_full_sync_roundtrip(dummy_nostr_client):
client, relay = dummy_nostr_client
with TemporaryDirectory() as tmpdir:
base = Path(tmpdir)
@@ -54,8 +54,9 @@ def test_full_sync_roundtrip(dummy_nostr_client, monkeypatch):
# Manager A publishes delta with second entry
pm_a.entry_manager.add_entry("site2", 12)
delta_bytes = pm_a.vault.get_encrypted_index() or b""
monkeypatch.setattr("nostr.client.time.time", lambda: 1)
asyncio.run(client.publish_delta(delta_bytes, manifest_id))
delta_ts = relay.deltas[-1].created_at
assert relay.manifests[-1].delta_since == delta_ts
# Manager B fetches delta and updates
pm_b.sync_index_from_nostr()
@@ -67,5 +67,6 @@ def test_generate_test_profile_sync(monkeypatch, dummy_nostr_client):
assert result is not None
_manifest, chunks = result
assert _manifest.delta_since is None
retrieved = gzip.decompress(b"".join(chunks))
assert retrieved == encrypted
+4
View File
@@ -49,6 +49,10 @@ def test_publish_and_fetch_deltas(dummy_nostr_client):
d1 = b"d1"
d2 = b"d2"
asyncio.run(client.publish_delta(d1, manifest_id))
first_ts = relay.deltas[-1].created_at
asyncio.run(client.publish_delta(d2, manifest_id))
second_ts = relay.deltas[-1].created_at
assert second_ts > first_ts
assert relay.manifests[-1].delta_since == second_ts
deltas = asyncio.run(client.fetch_deltas_since(0))
assert deltas == [d1, d2]