import tempfile from pathlib import Path from typing import Any from imwald.core.database import Database from imwald.core.nostr_crypto import build_signed_event from imwald.core.ranker import Ranker, WEIGHT_FOLLOW_AUTHOR, WEIGHT_KIND30000_LIST_AUTHOR def _fake_sk() -> bytes: return bytes.fromhex("3501454135014541350145413501453fefb02227e449e57cf4d3a3ce05378683") def test_list30000_pubkeys_from_p_tags() -> None: with tempfile.TemporaryDirectory() as td: db = Database(Path(td) / "t.sqlite") db.connect() listed = "b" * 64 other = "c" * 64 sk = _fake_sk() tags = [["d", "testlist"], ["p", listed], ["p", other]] ev = build_signed_event(sk, created_at=100, kind=30000, tags=tags, content="") me = ev["pubkey"] db.upsert_event(ev) got = db.list_kind30000_list_pubkeys(me) assert listed in got and other in got def test_ranker_follow_beats_kind30000() -> None: with tempfile.TemporaryDirectory() as td: db = Database(Path(td) / "t2.sqlite") db.connect() r = Ranker(db) me = "f" * 64 follow_pk = "a" * 64 list_pk = "b" * 64 ev_f: dict[str, Any] = { "id": "1" * 64, "pubkey": follow_pk, "created_at": 1, "kind": 1, "tags": [], "content": "x", } ev_l: dict[str, Any] = { "id": "2" * 64, "pubkey": list_pk, "created_at": 2, "kind": 1, "tags": [], "content": "y", } sf, _ = r.score_event(ev_f, my_pubkey=me, following={follow_pk}, list30000_pubkeys={list_pk}) sl, _ = r.score_event(ev_l, my_pubkey=me, following={follow_pk}, list30000_pubkeys={list_pk}) assert sf > sl assert sf >= WEIGHT_FOLLOW_AUTHOR assert WEIGHT_KIND30000_LIST_AUTHOR <= sl < WEIGHT_FOLLOW_AUTHOR