You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.3 KiB
76 lines
2.3 KiB
"""Outgoing interaction rows for profile activity column.""" |
|
|
|
import tempfile |
|
from pathlib import Path |
|
from typing import cast |
|
|
|
from imwald.core.database import Database |
|
from imwald.core.nostr_crypto import build_signed_event, pubkey_hex_from_secret |
|
|
|
|
|
def _sk() -> bytes: |
|
return bytes.fromhex("3501454135014541350145413501453fefb02227e449e57cf4d3a3ce05378683") |
|
|
|
|
|
def _sk_other() -> bytes: |
|
"""Second valid curve key (distinct from :func:`_sk`).""" |
|
return (3).to_bytes(32, "big") |
|
|
|
|
|
def test_list_pubkey_outgoing_interactions_excludes_self_reply() -> None: |
|
sk = _sk() |
|
pk = pubkey_hex_from_secret(sk) |
|
root = build_signed_event( |
|
_sk_other(), |
|
created_at=1, |
|
kind=1, |
|
tags=[], |
|
content="their note", |
|
) |
|
rid = cast(str, root["id"]) |
|
to_other = build_signed_event( |
|
sk, |
|
created_at=2, |
|
kind=1, |
|
tags=[["e", rid, "", "reply"]], |
|
content="hi there", |
|
) |
|
to_self = build_signed_event( |
|
sk, |
|
created_at=3, |
|
kind=1, |
|
tags=[["e", to_other["id"], "", "reply"]], |
|
content="talk to myself", |
|
) |
|
with tempfile.TemporaryDirectory() as td: |
|
db = Database(Path(td) / "pi.sqlite") |
|
db.connect() |
|
db.upsert_event(root) |
|
db.upsert_event(to_other) |
|
db.upsert_event(to_self) |
|
got = db.list_pubkey_outgoing_interactions(pk, limit=20) |
|
assert len(got) == 1 |
|
assert got[0]["id"] == to_other["id"] |
|
assert str(got[0]["target_event_id"]).lower() == rid.lower() |
|
assert str(got[0]["target_pubkey"]).lower() == str(root["pubkey"]).lower() |
|
|
|
|
|
def test_list_pubkey_outgoing_interactions_includes_reaction() -> None: |
|
sk = _sk() |
|
pk = pubkey_hex_from_secret(sk) |
|
root = build_signed_event( |
|
_sk_other(), |
|
created_at=10, |
|
kind=1, |
|
tags=[], |
|
content="note", |
|
) |
|
rid = cast(str, root["id"]) |
|
rx = build_signed_event(sk, created_at=11, kind=7, tags=[["e", rid]], content="+") |
|
with tempfile.TemporaryDirectory() as td: |
|
db = Database(Path(td) / "pi2.sqlite") |
|
db.connect() |
|
db.upsert_event(root) |
|
db.upsert_event(rx) |
|
got = db.list_pubkey_outgoing_interactions(pk, limit=20) |
|
assert len(got) == 1 and int(got[0]["kind"]) == 7
|
|
|