diff --git a/tests/pyproject.toml b/tests/pyproject.toml index 70483b9..bcde559 100644 --- a/tests/pyproject.toml +++ b/tests/pyproject.toml @@ -10,7 +10,7 @@ dev = [ "pytest-asyncio>=0.23.8,<2", "pytest-xdist>=3.7,<4", "pytest-timeout>=2.4,<3", - "nostr-sdk>=0.44", + "nostr-sdk>=0.45", "pyln-testing>=25.9", "pyln-client>=25.9", "pyln-proto>=25.9", diff --git a/tests/test_cln-nip47.py b/tests/test_cln-nip47.py index 9b46a41..fbf4742 100644 --- a/tests/test_cln-nip47.py +++ b/tests/test_cln-nip47.py @@ -18,7 +18,6 @@ from nostr_sdk import ( Event, EventBuilder, Filter, - HandleNotification, Keys, KeysendTlvRecord, Kind, @@ -28,14 +27,14 @@ from nostr_sdk import ( Method, NostrSdkError, NostrSigner, + NostrWalletConnect, NostrWalletConnectUri, - Nwc, PayInvoiceRequest, PayKeysendRequest, PublicKey, RelayUrl, + ReqTarget, Tag, - TagKind, TransactionType, ) from pyln.testing.fixtures import * @@ -45,23 +44,7 @@ from util import generate_random_label, get_hold, get_plugin # noqa: F401 LOGGER = logging.getLogger(__name__) -class NotificationHandler(HandleNotification): - def __init__(self, events_list, stop_after): - self.events_list = events_list - self.stop_after = stop_after - self._done = asyncio.Event() - - async def handle(self, relay_url, subscription_id, event: Event): - LOGGER.info(f"Received new event from {relay_url}: {event.as_json()}") - self.events_list.append(event) - if len(self.events_list) >= self.stop_after: - self._done.set() - - async def handle_msg(self, relay_url, msg): - _var = None - - -Action = Union[ +Action = Union[ # noqa: UP007 Callable[[], Awaitable[None]], Callable[[], None], Awaitable[None], @@ -78,15 +61,31 @@ async def fetch_event_responses( ) -> tuple[list[Event], Any]: events = [] response_filter = Filter().kind(Kind(event_kind)).pubkey(client_pubkey) + target = ReqTarget.auto([response_filter]) - id = uuid.uuid4().hex - LOGGER.info(f"Subscribing with id {id} to {response_filter}") - await client.subscribe_with_id(id, response_filter) + subscription_id = uuid.uuid4().hex + LOGGER.info(f"Subscribing with id {subscription_id} to {response_filter}") - handler = NotificationHandler(events, stop_after) - task = asyncio.create_task(client.handle_notifications(handler)) + await client.subscribe(target, subscription_id) + + async def collect_events(): + stream = client.notifications() + + while len(events) < stop_after: + notification = await stream.next() + + if notification.is_new_event(): + event = notification.event + relay_url = notification.relay_url + + LOGGER.info(f"Received new event from {relay_url}: {event.as_json()}") + + events.append(event) + + task = asyncio.create_task(collect_events()) await asyncio.sleep(1) + if inspect.iscoroutine(action): action_result = await action elif inspect.iscoroutinefunction(action): @@ -97,10 +96,10 @@ async def fetch_event_responses( raise TypeError("action must be a callable or an awaitable") try: - await asyncio.wait_for(handler._done.wait(), timeout=timeout) + await asyncio.wait_for(task, timeout=timeout) except asyncio.TimeoutError: print( - f"Timeout reached after {timeout} seconds, collected {len(events)} events" + f"Timeout reached after {timeout} seconds, collected {len(events)} events", ) finally: task.cancel() @@ -109,9 +108,10 @@ async def fetch_event_responses( except asyncio.CancelledError: pass - await client.unsubscribe_all() + await client.unsubscribe_all() + assert len(events) == stop_after - return (events, action_result) + return events, action_result async def fetch_info_event( @@ -119,20 +119,17 @@ async def fetch_info_event( uri: NostrWalletConnectUri, ) -> Event: response_filter = Filter().kind(Kind(13194)).author(uri.public_key()) - events = await client.fetch_events( - response_filter, timeout=timedelta(seconds=TIMEOUT) - ) + target = ReqTarget.auto([response_filter]) + events = await client.fetch_events(target, timeout=timedelta(seconds=TIMEOUT)) start_time = datetime.now() - while events.len() < 1 and (datetime.now() - start_time) < timedelta( + while len(events) < 1 and (datetime.now() - start_time) < timedelta( seconds=TIMEOUT ): await asyncio.sleep(1) - events = await client.fetch_events( - response_filter, timeout=timedelta(seconds=1) - ) - assert events.len() == 1 + events = await client.fetch_events(target, timeout=timedelta(seconds=1)) + assert len(events) == 1 - return events.first() + return events[0] @pytest.mark.asyncio @@ -155,38 +152,35 @@ async def test_get_balance(nostr_relay, node_factory, get_plugin): # noqa: F811 uri_str = l1.rpc.call("nip47-create", ["test1", 3000])["uri"] LOGGER.info(uri_str) uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) balance = await nwc.get_balance() - assert balance == 3000 + assert balance.balance == 3000 uri_str = l1.rpc.call("nip47-create", ["test2"])["uri"] LOGGER.info(uri_str) uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) balance = await nwc.get_balance() - assert balance == node_balance + assert balance.balance == node_balance uri_str = l1.rpc.call("nip47-create", ["test3", 0])["uri"] LOGGER.info(uri_str) uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) balance = await nwc.get_balance() - assert balance == 0 + assert balance.balance == 0 with pytest.raises(RpcError, match="not an integer"): uri_str = l1.rpc.call("nip47-create", ["test3", -1])["uri"] @@ -207,24 +201,23 @@ async def test_get_info(nostr_relay, node_factory, get_plugin): # noqa: F811 uri_str = l1.rpc.call("nip47-create", ["test1", 3000])["uri"] LOGGER.info(uri_str) uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) get_info = await nwc.get_info() assert get_info.alias == node_get_info["alias"] assert get_info.block_height == node_get_info["blockheight"] assert get_info.color == node_get_info["color"] assert get_info.methods == [ - Method.MAKE_INVOICE, - Method.LOOKUP_INVOICE, - Method.LIST_TRANSACTIONS, - Method.GET_BALANCE, - Method.GET_INFO, - Method.PAY_INVOICE, - Method.PAY_KEYSEND, + Method.MAKE_INVOICE(), + Method.LOOKUP_INVOICE(), + Method.LIST_TRANSACTIONS(), + Method.GET_BALANCE(), + Method.GET_INFO(), + Method.PAY_INVOICE(), + Method.PAY_KEYSEND(), ] assert get_info.network == "regtest" assert get_info.notifications == ["payment_received", "payment_sent"] @@ -248,13 +241,13 @@ async def test_get_info(nostr_relay, node_factory, get_plugin): # noqa: F811 assert get_info.block_height == node_get_info["blockheight"] assert get_info.color == node_get_info["color"] assert get_info.methods == [ - Method.MAKE_INVOICE, - Method.LOOKUP_INVOICE, - Method.LIST_TRANSACTIONS, - Method.GET_BALANCE, - Method.GET_INFO, - Method.PAY_INVOICE, - Method.PAY_KEYSEND, + Method.MAKE_INVOICE(), + Method.LOOKUP_INVOICE(), + Method.LIST_TRANSACTIONS(), + Method.GET_BALANCE(), + Method.GET_INFO(), + Method.PAY_INVOICE(), + Method.PAY_KEYSEND(), ] assert get_info.network == "regtest" assert get_info.notifications == [] @@ -264,28 +257,27 @@ async def test_get_info(nostr_relay, node_factory, get_plugin): # noqa: F811 info_event.content() == "make_invoice lookup_invoice list_transactions get_balance get_info pay_invoice pay_keysend" ) - assert ( - info_event.tags().find(TagKind.UNKNOWN("encryption")).content() - == "nip44_v2 nip04" + encryption_tag = next( + tag for tag in info_event.tags() if tag.kind() == "encryption" ) - assert info_event.tags().find(TagKind.UNKNOWN("notifications")) is None + assert encryption_tag.content() == "nip44_v2 nip04" + assert not any(tag.kind() == "notifications" for tag in info_event.tags()) uri_str = l1.rpc.call("nip47-create", ["test2", 0])["uri"] LOGGER.info(uri_str) uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) get_info = await nwc.get_info() assert get_info.methods == [ - Method.MAKE_INVOICE, - Method.LOOKUP_INVOICE, - Method.LIST_TRANSACTIONS, - Method.GET_BALANCE, - Method.GET_INFO, + Method.MAKE_INVOICE(), + Method.LOOKUP_INVOICE(), + Method.LIST_TRANSACTIONS(), + Method.GET_BALANCE(), + Method.GET_INFO(), ] info_event = await fetch_info_event(client, uri) @@ -293,11 +285,11 @@ async def test_get_info(nostr_relay, node_factory, get_plugin): # noqa: F811 info_event.content() == "make_invoice lookup_invoice list_transactions get_balance get_info" ) - assert ( - info_event.tags().find(TagKind.UNKNOWN("encryption")).content() - == "nip44_v2 nip04" + encryption_tag = next( + tag for tag in info_event.tags() if tag.kind() == "encryption" ) - assert info_event.tags().find(TagKind.UNKNOWN("notifications")) is None + assert encryption_tag.content() == "nip44_v2 nip04" + assert not any(tag.kind() == "notifications" for tag in info_event.tags()) @pytest.mark.asyncio @@ -314,12 +306,11 @@ async def test_make_invoice(nostr_relay, node_factory, get_plugin): # noqa: F81 uri_str = l1.rpc.call("nip47-create", ["test1", 3000])["uri"] LOGGER.info(uri_str) uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) timestamp = int(time.time()) invoice = await nwc.make_invoice( MakeInvoiceRequest( @@ -407,12 +398,11 @@ async def test_pay_keysend(nostr_relay, node_factory, get_plugin): # noqa: F811 uri_str = l1.rpc.call("nip47-create", ["test1", 3000])["uri"] LOGGER.info(uri_str) uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) result = await nwc.pay_keysend( PayKeysendRequest( id="id123", amount=1000, pubkey=l3.info["id"], preimage=None, tlv_records=[] @@ -488,12 +478,11 @@ async def test_lookup_invoice(nostr_relay, node_factory, get_plugin): # noqa: F uri_str = l1.rpc.call("nip47-create", ["test1", 3000])["uri"] LOGGER.info(uri_str) uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) invoice = await nwc.make_invoice( MakeInvoiceRequest( amount=3000, description="test1", description_hash=None, expiry=None @@ -715,12 +704,11 @@ async def test_list_transactions(nostr_relay, node_factory, get_plugin): # noqa uri_str = l1.rpc.call("nip47-create", ["test1"])["uri"] LOGGER.info(uri_str) uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) for i in range(10): invoice = l2.rpc.call( "invoice", @@ -803,12 +791,12 @@ async def test_notifications(nostr_relay, node_factory, get_plugin): # noqa: F8 LOGGER.info(uri_str) uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + keys = Keys(uri.secret()) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) invoice = l3.rpc.call( "invoice", @@ -870,11 +858,10 @@ async def test_notifications(nostr_relay, node_factory, get_plugin): # noqa: F8 responses = responses1 + responses2 LOGGER.info(f"response1: {responses1} response2: {responses2}") assert len(responses) == 2 - signer = NostrSigner.keys(Keys(uri.secret())) received_events = [] sent_events = [] for event in responses: - content = await signer.nip04_decrypt(uri.public_key(), event.content()) + content = keys.nip04_decrypt(uri.public_key(), event.content()) content = json.loads(content) LOGGER.info(content) if content["notification_type"] == "payment_received": @@ -973,8 +960,7 @@ async def test_pay_invoice(nostr_relay, node_factory, get_plugin): # noqa: F811 ) uri_str = l1.rpc.call("nip47-create", ["test1", 3001])["uri"] uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) @@ -983,7 +969,7 @@ async def test_pay_invoice(nostr_relay, node_factory, get_plugin): # noqa: F811 "invoice", {"label": generate_random_label(), "description": "test1", "amount_msat": 3000}, ) - nwc = Nwc(NostrWalletConnectUri.parse(uri_str)) + nwc = NostrWalletConnect(NostrWalletConnectUri.parse(uri_str)) result = await nwc.pay_invoice( PayInvoiceRequest(id=None, amount=None, invoice=invoice["bolt11"]) ) @@ -1041,12 +1027,11 @@ async def test_persistency(nostr_relay, node_factory, get_plugin): # noqa: F811 l1.daemon.wait_for_log("All NWC's loaded") await asyncio.sleep(3) uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) result = await nwc.pay_invoice( PayInvoiceRequest(id=None, amount=None, invoice=invoice["bolt11"]) ) @@ -1082,12 +1067,11 @@ async def test_persistency(nostr_relay, node_factory, get_plugin): # noqa: F811 uri_str = l1.rpc.call("nip47-create", ["test1", 3000, "10sec"])["uri"] uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) invoice = l2.rpc.call( "invoice", @@ -1179,14 +1163,13 @@ async def test_budget_command(nostr_relay, node_factory, get_plugin): # noqa: F {"label": generate_random_label(), "description": "test1", "amount_msat": 5000}, ) uri = NostrWalletConnectUri.parse(uri_str) - signer = NostrSigner.keys(Keys(uri.secret())) - client = Client(signer) + client = Client() await client.add_relay(RelayUrl.parse(url)) await client.connect() await fetch_info_event(client, uri) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) balance = await nwc.get_balance() - assert balance == 3000 + assert balance.balance == 3000 with pytest.raises(NostrSdkError.Generic, match="Payment exceeds budget"): await nwc.pay_invoice( @@ -1195,7 +1178,7 @@ async def test_budget_command(nostr_relay, node_factory, get_plugin): # noqa: F l1.rpc.call("nip47-budget", ["test1", 4000]) balance = await nwc.get_balance() - assert balance == 4000 + assert balance.balance == 4000 with pytest.raises(NostrSdkError.Generic, match="Payment exceeds budget"): await nwc.pay_invoice( @@ -1204,7 +1187,7 @@ async def test_budget_command(nostr_relay, node_factory, get_plugin): # noqa: F l1.rpc.call("nip47-budget", ["test1", 5000, "15s"]) balance = await nwc.get_balance() - assert balance == 5000 + assert balance.balance == 5000 with pytest.raises( RpcError, match="`budget_msat` must be greater than 0 if you use `interval`" @@ -1217,17 +1200,17 @@ async def test_budget_command(nostr_relay, node_factory, get_plugin): # noqa: F assert pay.preimage is not None balance = await nwc.get_balance() - assert balance == 0 + assert balance.balance == 0 get_info = await nwc.get_info() assert get_info.methods == [ - Method.MAKE_INVOICE, - Method.LOOKUP_INVOICE, - Method.LIST_TRANSACTIONS, - Method.GET_BALANCE, - Method.GET_INFO, - Method.PAY_INVOICE, - Method.PAY_KEYSEND, + Method.MAKE_INVOICE(), + Method.LOOKUP_INVOICE(), + Method.LIST_TRANSACTIONS(), + Method.GET_BALANCE(), + Method.GET_INFO(), + Method.PAY_INVOICE(), + Method.PAY_KEYSEND(), ] info_event = await fetch_info_event(client, uri) @@ -1236,31 +1219,31 @@ async def test_budget_command(nostr_relay, node_factory, get_plugin): # noqa: F info_event.content() == "make_invoice lookup_invoice list_transactions get_balance get_info pay_invoice pay_keysend notifications" ) - assert ( - info_event.tags().find(TagKind.UNKNOWN("encryption")).content() - == "nip44_v2 nip04" + encryption_tag = next( + tag for tag in info_event.tags() if tag.kind() == "encryption" ) - assert ( - info_event.tags().find(TagKind.UNKNOWN("notifications")).content() - == "payment_received payment_sent" + assert encryption_tag.content() == "nip44_v2 nip04" + notification_tag = next( + tag for tag in info_event.tags() if tag.kind() == "notifications" ) + assert notification_tag.content() == "payment_received payment_sent" await asyncio.sleep(18) balance = await nwc.get_balance() - assert balance == 5000 + assert balance.balance == 5000 l1.rpc.call("nip47-budget", ["test1", 0]) balance = await nwc.get_balance() - assert balance == 0 + assert balance.balance == 0 get_info = await nwc.get_info() assert get_info.methods == [ - Method.MAKE_INVOICE, - Method.LOOKUP_INVOICE, - Method.LIST_TRANSACTIONS, - Method.GET_BALANCE, - Method.GET_INFO, + Method.MAKE_INVOICE(), + Method.LOOKUP_INVOICE(), + Method.LIST_TRANSACTIONS(), + Method.GET_BALANCE(), + Method.GET_INFO(), ] info_event = await fetch_info_event(client, uri) @@ -1268,14 +1251,14 @@ async def test_budget_command(nostr_relay, node_factory, get_plugin): # noqa: F info_event.content() == "make_invoice lookup_invoice list_transactions get_balance get_info notifications" ) - assert ( - info_event.tags().find(TagKind.UNKNOWN("encryption")).content() - == "nip44_v2 nip04" + encryption_tag = next( + tag for tag in info_event.tags() if tag.kind() == "encryption" ) - assert ( - info_event.tags().find(TagKind.UNKNOWN("notifications")).content() - == "payment_received payment_sent" + assert encryption_tag.content() == "nip44_v2 nip04" + notification_tag = next( + tag for tag in info_event.tags() if tag.kind() == "notifications" ) + assert notification_tag.content() == "payment_received payment_sent" @pytest.mark.asyncio @@ -1311,7 +1294,7 @@ async def test_hold_invoice( LOGGER.info(uri_str) uri = NostrWalletConnectUri.parse(uri_str) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) preimage = secrets.token_hex(32) payment_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest() @@ -1325,14 +1308,14 @@ async def test_hold_invoice( }, } content = json.dumps(content) - signer = NostrSigner.keys(Keys(uri.secret())) - encrypted_content = await signer.nip04_encrypt(uri.public_key(), content) + keys = Keys(uri.secret()) + encrypted_content = keys.nip04_encrypt(uri.public_key(), content) event = ( await EventBuilder(Kind(23194), encrypted_content) .tags([Tag.public_key(uri.public_key())]) - .sign(signer) + .finalize_async(keys) ) - client = Client(signer) + client = Client() relay_url = RelayUrl.parse(url) await client.add_relay(relay_url) await client.connect() @@ -1346,7 +1329,7 @@ async def test_hold_invoice( success_events = [] for event in responses1: LOGGER.info(event) - content = await signer.nip04_decrypt(uri.public_key(), event.content()) + content = keys.nip04_decrypt(uri.public_key(), event.content()) content = json.loads(content) LOGGER.info(content) if "result" in content and content["result"] is not None: @@ -1403,7 +1386,7 @@ async def test_hold_invoice( hold_events = [] for event in responses2: LOGGER.info(event) - content = await signer.nip04_decrypt(uri.public_key(), event.content()) + content = keys.nip04_decrypt(uri.public_key(), event.content()) content = json.loads(content) LOGGER.info(content) if content["notification_type"] == "hold_invoice_accepted": @@ -1427,7 +1410,7 @@ async def test_hold_invoice( assert lookup_hold.preimage is None assert lookup_hold.payment_hash == payment_hash assert lookup_hold.transaction_type.name == "INCOMING" - assert lookup_hold.state.name == "PENDING" # TODO ACCEPTED STATE + assert lookup_hold.state.name == "ACCEPTED" assert lookup_hold.settled_at is None content = { @@ -1437,11 +1420,11 @@ async def test_hold_invoice( }, } content = json.dumps(content) - encrypted_content = await signer.nip04_encrypt(uri.public_key(), content) + encrypted_content = keys.nip04_encrypt(uri.public_key(), content) event = ( await EventBuilder(Kind(23194), encrypted_content) .tags([Tag.public_key(uri.public_key())]) - .sign(signer) + .finalize_async(keys) ) (responses3, _res) = await fetch_event_responses( @@ -1451,7 +1434,7 @@ async def test_hold_invoice( success_events = [] for event in responses3: LOGGER.info(event) - content = await signer.nip04_decrypt(uri.public_key(), event.content()) + content = keys.nip04_decrypt(uri.public_key(), event.content()) content = json.loads(content) LOGGER.info(content) if ( @@ -1509,12 +1492,11 @@ async def test_hold_invoice( }, } content = json.dumps(content) - signer = NostrSigner.keys(Keys(uri.secret())) - encrypted_content = await signer.nip04_encrypt(uri.public_key(), content) + encrypted_content = keys.nip04_encrypt(uri.public_key(), content) event = ( await EventBuilder(Kind(23194), encrypted_content) .tags([Tag.public_key(uri.public_key())]) - .sign(signer) + .finalize_async(keys) ) (responses4, _res) = await fetch_event_responses( @@ -1524,7 +1506,7 @@ async def test_hold_invoice( success_events = [] for event in responses4: LOGGER.info(event) - content = await signer.nip04_decrypt(uri.public_key(), event.content()) + content = keys.nip04_decrypt(uri.public_key(), event.content()) content = json.loads(content) LOGGER.info(content) if ( @@ -1558,7 +1540,7 @@ async def test_hold_invoice( hold_events = [] for event in responses5: LOGGER.info(event) - content = await signer.nip04_decrypt(uri.public_key(), event.content()) + content = keys.nip04_decrypt(uri.public_key(), event.content()) content = json.loads(content) LOGGER.info(content) if ( @@ -1575,11 +1557,11 @@ async def test_hold_invoice( }, } content = json.dumps(content) - encrypted_content = await signer.nip04_encrypt(uri.public_key(), content) + encrypted_content = keys.nip04_encrypt(uri.public_key(), content) event = ( await EventBuilder(Kind(23194), encrypted_content) .tags([Tag.public_key(uri.public_key())]) - .sign(signer) + .finalize_async(keys) ) (responses6, _res) = await fetch_event_responses( @@ -1593,7 +1575,7 @@ async def test_hold_invoice( success_events = [] for event in responses6: LOGGER.info(event) - content = await signer.nip04_decrypt(uri.public_key(), event.content()) + content = keys.nip04_decrypt(uri.public_key(), event.content()) content = json.loads(content) LOGGER.info(content) if ( @@ -1639,7 +1621,7 @@ async def test_hold_invoice( ) ) - nwc = Nwc(uri) + nwc = NostrWalletConnect(uri) invoice_lookup1 = await nwc.lookup_invoice( LookupInvoiceRequest( @@ -1699,11 +1681,11 @@ async def test_hold_invoice( }, } content = json.dumps(content) - encrypted_content = await signer.nip04_encrypt(uri.public_key(), content) + encrypted_content = keys.nip04_encrypt(uri.public_key(), content) event = ( await EventBuilder(Kind(23194), encrypted_content) .tags([Tag.public_key(uri.public_key())]) - .sign(signer) + .finalize_async(keys) ) await client.send_event(event) @@ -1718,7 +1700,8 @@ async def test_hold_invoice( ) ) break - except Exception: + except Exception as e: # noqa: BLE001 + LOGGER.error(e) continue lookup_hold = await nwc.lookup_invoice( @@ -1750,11 +1733,11 @@ async def test_hold_invoice( }, } content = json.dumps(content) - encrypted_content = await signer.nip04_encrypt(uri.public_key(), content) + encrypted_content = keys.nip04_encrypt(uri.public_key(), content) event = ( await EventBuilder(Kind(23194), encrypted_content) .tags([Tag.public_key(uri.public_key())]) - .sign(signer) + .finalize_async(keys) ) await client.send_event(event) @@ -1769,7 +1752,8 @@ async def test_hold_invoice( ) ) break - except Exception: + except Exception as e: # noqa: BLE001 + LOGGER.error(e) continue lookup_hold = await nwc.lookup_invoice( @@ -1793,12 +1777,15 @@ async def test_hold_invoice( info_event.content() == "make_invoice lookup_invoice list_transactions get_balance get_info pay_invoice pay_keysend make_hold_invoice cancel_hold_invoice settle_hold_invoice notifications" ) - assert ( - info_event.tags().find(TagKind.UNKNOWN("encryption")).content() - == "nip44_v2 nip04" + encryption_tag = next( + tag for tag in info_event.tags() if tag.kind() == "encryption" + ) + assert encryption_tag.content() == "nip44_v2 nip04" + notification_tag = next( + tag for tag in info_event.tags() if tag.kind() == "notifications" ) assert ( - info_event.tags().find(TagKind.UNKNOWN("notifications")).content() + notification_tag.content() == "payment_received payment_sent hold_invoice_accepted" ) @@ -1816,7 +1803,7 @@ async def test_hold_invoice( hold_events = [] for event in responses7: LOGGER.info(event) - content = await signer.nip04_decrypt(uri.public_key(), event.content()) + content = keys.nip04_decrypt(uri.public_key(), event.content()) content = json.loads(content) LOGGER.info(content) if ( diff --git a/tests/uv.lock b/tests/uv.lock index d90c9ac..c2c260e 100644 --- a/tests/uv.lock +++ b/tests/uv.lock @@ -393,7 +393,7 @@ dev = [ [package.metadata.requires-dev] dev = [ - { name = "nostr-sdk", specifier = ">=0.44" }, + { name = "nostr-sdk", specifier = ">=0.45" }, { name = "pyln-client", specifier = ">=25.9" }, { name = "pyln-proto", specifier = ">=25.9" }, { name = "pyln-testing", specifier = ">=25.9" }, @@ -748,22 +748,22 @@ wheels = [ [[package]] name = "nostr-sdk" -version = "0.44.6" +version = "0.45.0" source = { registry = "https://pypi.org/simple" } wheels = [ - { url = "https://files.pythonhosted.org/packages/61/c3/1fbcb47aff23b368b817e5f6e90f3284b4b299e9bcf08e9a4cd414b80020/nostr_sdk-0.44.6-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:41dabb2539513db0b354c4fd2a3391307e50eb913a60c9325b1565e80e98530f", size = 3365132, upload-time = "2026-07-26T09:02:22.234Z" }, - { url = "https://files.pythonhosted.org/packages/43/08/16525328d477e1fb427d47c0ccc14ce5b25f120871947374457a3267ae99/nostr_sdk-0.44.6-cp39-abi3-macosx_11_0_x86_64.whl", hash = "sha256:326526e6fd736c4dd6ad73b5cf7653d1a0ae46a3fb8d8ed4b4cb221ee64f7feb", size = 3482251, upload-time = "2026-07-26T09:02:23.623Z" }, - { url = "https://files.pythonhosted.org/packages/65/a4/0f210f8490faf4c24dbc4bfbdc1943afc632d907c6fae48f88f0f3b55605/nostr_sdk-0.44.6-cp39-abi3-manylinux_2_17_aarch64.whl", hash = "sha256:811637b021cfa338a38e37dda8df5dbeebe447458d567ad9b700a65199f6874c", size = 3611794, upload-time = "2026-07-26T09:02:24.758Z" }, - { url = "https://files.pythonhosted.org/packages/f2/73/ce525eed5f93969c62984f9397c80acf99883eab52bc055259e189eb1375/nostr_sdk-0.44.6-cp39-abi3-manylinux_2_17_armv7l.whl", hash = "sha256:44cbec5c99a8a8c8e8beeb80ae7427a3ff20b943ca459bd0ba556e41c20dd246", size = 3359056, upload-time = "2026-07-26T09:02:26.101Z" }, - { url = "https://files.pythonhosted.org/packages/c9/ad/f700ddbbfcf2d0ff2285dec9b87b8b290d1f4359add21cb09b568bf52c0f/nostr_sdk-0.44.6-cp39-abi3-manylinux_2_17_i686.whl", hash = "sha256:64e0304313bbbaa05226d9cac98618f94ab20e8e3f5e3a297179454e657d3446", size = 3607461, upload-time = "2026-07-26T09:02:27.393Z" }, - { url = "https://files.pythonhosted.org/packages/c9/ec/947f9fd4161a69da12bdbb8502a377c5ada2ab8e640ce5515c4a001cf81f/nostr_sdk-0.44.6-cp39-abi3-manylinux_2_17_x86_64.whl", hash = "sha256:0234eae16b0fc11e3d72eb08c4c14b0c333a992e700d8fb88f191a42ef017a07", size = 3726683, upload-time = "2026-07-26T09:02:28.925Z" }, - { url = "https://files.pythonhosted.org/packages/01/fe/448443ef9e23433f202c0362c2eb9e1b98dc0efffb5c3f9cae6f6252a5a8/nostr_sdk-0.44.6-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:d16adc26a42cab37ae4ae8e3a8bed03dcedbe88c7862133c48cf9d99cb9e0cf3", size = 3605361, upload-time = "2026-07-26T09:02:30.308Z" }, - { url = "https://files.pythonhosted.org/packages/df/02/b0e83f3f5066e525e5c1fd44c81f6711479cc6942aee298ebcd545fb3e59/nostr_sdk-0.44.6-cp39-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:dccebbc33500718ace5cf8e7ac6ed7fa41ec07f65f157896b392ac5f0b9ab2ed", size = 3360640, upload-time = "2026-07-26T09:02:31.615Z" }, - { url = "https://files.pythonhosted.org/packages/9e/01/7104eacda8609d52a148171354bca1095227a651860022984bf518ead1f2/nostr_sdk-0.44.6-cp39-abi3-musllinux_1_2_i686.whl", hash = "sha256:e73a55e1f52dd4cb006f502725e65ab12b68609cb1b18d96b2ba74a3b245d264", size = 3493797, upload-time = "2026-07-26T09:02:32.973Z" }, - { url = "https://files.pythonhosted.org/packages/00/80/e8de31cf0f1cf4c65ca5691a6c8baabbed19daccdccb427d73968e0335b9/nostr_sdk-0.44.6-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:512229272a68cc651bbe96b1d0ec78d12b899708d871ef92b49ce96eb33ba1fd", size = 3724890, upload-time = "2026-07-26T09:02:34.219Z" }, - { url = "https://files.pythonhosted.org/packages/83/0f/6d4c364bd4f1ad1c76030aeddc43c5f6edd63d79cec289229de6afa5a72d/nostr_sdk-0.44.6-cp39-abi3-win32.whl", hash = "sha256:5eee3919224b653007e71a8e8a43465ee36156132839dfd15c120ee9b54d075c", size = 3164542, upload-time = "2026-07-26T09:02:35.291Z" }, - { url = "https://files.pythonhosted.org/packages/90/f5/11141f5612f8fb361d39dbb95d6ec916059213a8d5625f8f98b58a7cfc70/nostr_sdk-0.44.6-cp39-abi3-win_amd64.whl", hash = "sha256:f89a13a4cec623283cd66218b8efedc8ec618b1b3e33a0e398240469f7b317e6", size = 3383380, upload-time = "2026-07-26T09:02:36.804Z" }, - { url = "https://files.pythonhosted.org/packages/d0/3e/552318b5c8307ab2f725de59b9bedbd06df3f031c252d11b15dcea302511/nostr_sdk-0.44.6-cp39-abi3-win_arm64.whl", hash = "sha256:c36845d218118dc0330f554fdea5c6e0c4a73bc54cb74dcf628750bf9260e01f", size = 3236001, upload-time = "2026-07-26T09:02:37.906Z" }, + { url = "https://files.pythonhosted.org/packages/b9/73/9401a17b0a43bf22542f31e5c5624db7f838f7690977ec786edd72b0880b/nostr_sdk-0.45.0-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:5bd1a6b972e9f5ae8c4f4448a148f668f124a3389b72eafb9de00f714e829059", size = 3835872, upload-time = "2026-08-05T13:14:21.43Z" }, + { url = "https://files.pythonhosted.org/packages/e2/5d/355adf2a676493101357080857cf7896880c6556fe84795281bc283513c5/nostr_sdk-0.45.0-cp39-abi3-macosx_11_0_x86_64.whl", hash = "sha256:a20cb90f4fa225e57118431fc05d1d567a78a047dab54d34897365fcc5b82498", size = 3901388, upload-time = "2026-08-05T13:14:22.92Z" }, + { url = "https://files.pythonhosted.org/packages/a1/72/489cd53d491afe180f71d24c4f4f334f6da38d1bf683e8907771f436bffd/nostr_sdk-0.45.0-cp39-abi3-manylinux_2_17_aarch64.whl", hash = "sha256:00da5e7e387515d1e12779eccfb2c794856f774b4534694200434aa0146a03ed", size = 4323888, upload-time = "2026-08-05T13:14:24.348Z" }, + { url = "https://files.pythonhosted.org/packages/7e/cb/9a5edbea9db9995704ebc44ec4fca153c5f7d9ea07d668cf7837f01ddf1e/nostr_sdk-0.45.0-cp39-abi3-manylinux_2_17_armv7l.whl", hash = "sha256:e5cae5ef56411d6665de78c39822a4e80382231d44b4a6fc3db096b8b203ec26", size = 3867750, upload-time = "2026-08-05T13:14:26.066Z" }, + { url = "https://files.pythonhosted.org/packages/c1/d3/1a464004596e9ea0366a62e1671fc41adefde97b477bf60e69615dedec64/nostr_sdk-0.45.0-cp39-abi3-manylinux_2_17_i686.whl", hash = "sha256:9d91d519a93c48ab4d689f975f406d8ee96e39d6876d2aeaaee58de7e66ded93", size = 4393993, upload-time = "2026-08-05T13:14:27.766Z" }, + { url = "https://files.pythonhosted.org/packages/c1/57/1684e67051af3540666e6aeba4ed5bc9ea027cbe311789dce79863c85b48/nostr_sdk-0.45.0-cp39-abi3-manylinux_2_17_x86_64.whl", hash = "sha256:8152945cb27b48bbf6f89d73d8560bfbadd202b8e5c165bf5b5532e91feed417", size = 4426295, upload-time = "2026-08-05T13:14:29.397Z" }, + { url = "https://files.pythonhosted.org/packages/34/b0/526e134d23e2bdbac523bb38351d940a478cc2d7499c0ee9d1ee499ecfb4/nostr_sdk-0.45.0-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:a7e0a886b427356dc94cd0b1bc8421b01eeb5aa9ea26e1b69c21f0a3cc1bc2ad", size = 4336015, upload-time = "2026-08-05T13:14:30.836Z" }, + { url = "https://files.pythonhosted.org/packages/70/27/764af3a4bc1ec8542401616f11c41bbf9c42fbaef8659bf26bab4097ed6f/nostr_sdk-0.45.0-cp39-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:3b314b5160014bf70b39e95b3cf5cb059050e2fc2f782a0d9916c7ae1559e34f", size = 3864414, upload-time = "2026-08-05T13:14:32.352Z" }, + { url = "https://files.pythonhosted.org/packages/bd/31/1289150239dfce59c1c2afb8313dfd21411040103c68e6121f1ba4515fb7/nostr_sdk-0.45.0-cp39-abi3-musllinux_1_2_i686.whl", hash = "sha256:15346b498f4df4bb42ef2987cecd9e97ba60294b9bc7bb486e1c4b6bee4f528e", size = 4205457, upload-time = "2026-08-05T13:14:33.858Z" }, + { url = "https://files.pythonhosted.org/packages/8b/63/3964d86ed2f36f691374813751fb342de0c169ea0d926609379e50fd761c/nostr_sdk-0.45.0-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:78ccdb4766ae627ac9e2c10a7bb224d1e00da48fc7b61c7f48935ae23241fd64", size = 4410510, upload-time = "2026-08-05T13:14:35.224Z" }, + { url = "https://files.pythonhosted.org/packages/0d/15/a9c8da6d37bbbbfe07cba889a3d149f030985e524758ba51b44ca7a29ca0/nostr_sdk-0.45.0-cp39-abi3-win32.whl", hash = "sha256:45ff1ae2f19fedfa9f91b0c81c1be755b706e2fd1e7865ea46612c2ad1d98a3e", size = 3549588, upload-time = "2026-08-05T13:14:36.642Z" }, + { url = "https://files.pythonhosted.org/packages/99/f0/e03b7abb4dc016ea19dc2f311f367e472df47c187fbb69cee6df3ed2f323/nostr_sdk-0.45.0-cp39-abi3-win_amd64.whl", hash = "sha256:b3904abc4d7e4ac46ed66c8aa528e89748f3f25023708e4bbab58bc81d3a99f7", size = 3870530, upload-time = "2026-08-05T13:14:38.079Z" }, + { url = "https://files.pythonhosted.org/packages/f3/d0/f80080bd2aa73ed25c7a9d8d21020fc73eaa10591b39e13ec2b88228a8ce/nostr_sdk-0.45.0-cp39-abi3-win_arm64.whl", hash = "sha256:5a0fc63b69995bf2dac44e479aaec1ce1af71e687c9f4258891e429ed3db25e5", size = 3704095, upload-time = "2026-08-05T13:14:39.494Z" }, ] [[package]]