Switch to nostr-sdk

This commit is contained in:
thePR0M3TH3AN
2025-06-30 22:49:04 -04:00
parent 0ea1a7b54f
commit 9594c5a2f8
6 changed files with 111 additions and 92 deletions

View File

@@ -14,31 +14,40 @@ def setup_client(tmp_path):
key = Fernet.generate_key()
enc_mgr = EncryptionManager(key, tmp_path)
with patch("nostr.client.WebSocketRelayManager"), patch(
with patch("nostr.client.ClientBuilder"), patch(
"nostr.client.KeyManager"
), patch.object(NostrClient, "initialize_client_pool"), patch.object(
) as MockKM, patch.object(NostrClient, "initialize_client_pool"), patch.object(
enc_mgr, "decrypt_parent_seed", return_value="seed"
):
km_inst = MockKM.return_value
km_inst.keys.private_key_hex.return_value = "1" * 64
km_inst.keys.public_key_hex.return_value = "2" * 64
client = NostrClient(enc_mgr, "fp")
return client
class FakeEvent:
KIND_TEXT_NOTE = 1
KIND_ENCRYPT = 2
def __init__(self):
self._id = "id"
def __init__(self, kind, content, pub_key=None):
self.kind = kind
self.content = content
self.pubkey = pub_key
self.id = "id"
def id(self):
return self._id
def sign(self, _):
pass
class FakeUnsignedEvent:
def sign_with_keys(self, _):
return FakeEvent()
class FakeBuilder:
def build(self, _):
return FakeUnsignedEvent()
def test_publish_json_success():
with TemporaryDirectory() as tmpdir, patch("nostr.client.Event", FakeEvent):
with TemporaryDirectory() as tmpdir, patch(
"nostr.client.EventBuilder.text_note", return_value=FakeBuilder()
):
client = setup_client(Path(tmpdir))
with patch.object(client, "publish_event") as mock_pub:
assert client.publish_json_to_nostr(b"data") is True
@@ -46,7 +55,9 @@ def test_publish_json_success():
def test_publish_json_failure():
with TemporaryDirectory() as tmpdir, patch("nostr.client.Event", FakeEvent):
with TemporaryDirectory() as tmpdir, patch(
"nostr.client.EventBuilder.text_note", return_value=FakeBuilder()
):
client = setup_client(Path(tmpdir))
with patch.object(client, "publish_event", side_effect=Exception("boom")):
assert client.publish_json_to_nostr(b"data") is False