mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-10 00:09:04 +00:00
Merge pull request #736 from PR0M3TH3AN/codex/fix-import-and-migration-for-older-index
nostr: support legacy manifest id
This commit is contained in:
49
src/tests/test_nostr_legacy_manifest_id.py
Normal file
49
src/tests/test_nostr_legacy_manifest_id.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import asyncio
|
||||
|
||||
from helpers import TEST_SEED, dummy_nostr_client
|
||||
from nostr.backup_models import KIND_MANIFEST
|
||||
from nostr.client import MANIFEST_ID_PREFIX, NostrClient
|
||||
|
||||
|
||||
def test_fetch_latest_snapshot_legacy_identifier(dummy_nostr_client, monkeypatch):
|
||||
client, relay = dummy_nostr_client
|
||||
data = b"legacy"
|
||||
asyncio.run(client.publish_snapshot(data))
|
||||
relay.manifests[-1].tags = [MANIFEST_ID_PREFIX.rstrip("-")]
|
||||
relay.filters.clear()
|
||||
|
||||
orig_fetch = relay.fetch_events
|
||||
|
||||
async def fetch_events(self, f, timeout):
|
||||
identifier = f.ids[0] if getattr(f, "ids", None) else None
|
||||
kind = getattr(f, "kind_val", None)
|
||||
if kind == KIND_MANIFEST:
|
||||
events = [m for m in self.manifests if identifier in m.tags]
|
||||
self.filters.append(f)
|
||||
|
||||
class Res:
|
||||
def __init__(self, evs):
|
||||
self._evs = evs
|
||||
|
||||
def to_vec(self):
|
||||
return self._evs
|
||||
|
||||
return Res(events)
|
||||
return await orig_fetch(f, timeout)
|
||||
|
||||
monkeypatch.setattr(
|
||||
relay, "fetch_events", fetch_events.__get__(relay, relay.__class__)
|
||||
)
|
||||
|
||||
enc_mgr = client.encryption_manager
|
||||
monkeypatch.setattr(
|
||||
enc_mgr, "decrypt_parent_seed", lambda: TEST_SEED, raising=False
|
||||
)
|
||||
monkeypatch.setattr("nostr.client.KeyManager", type(client.key_manager))
|
||||
client2 = NostrClient(enc_mgr, "fp")
|
||||
relay.filters.clear()
|
||||
result = asyncio.run(client2.fetch_latest_snapshot())
|
||||
assert result is not None
|
||||
ids = [f.ids[0] for f in relay.filters]
|
||||
assert ids[0] == f"{MANIFEST_ID_PREFIX}fp"
|
||||
assert MANIFEST_ID_PREFIX.rstrip("-") in ids
|
Reference in New Issue
Block a user