onion_message: verify LNPeerAddr returned as hint in NoRouteFound
What changed, and why it matters
This commit only adds and updates a test file. It checks that when Electrum cannot find a Lightning route to a peer for an onion message, the error includes the peer's network address. There is no production code change and no security fix or vulnerability evident in the diff.
No security action needed. Treat as routine test maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies tests/test_onion_message.py to import Mock, NetAddress, and LNPeerAddr, sets a mock address for a test peer (eve) in the channel_db, and asserts that a NoRouteFound exception carries the expected LNPeerAddr hint. It is purely a test-case enhancement; no implementation logic is changed.
Changed components
tests/test_onion_message.pyInspect captured patch +7 / −1
diff --git a/tests/test_onion_message.py b/tests/test_onion_message.py
index 25fcba4..bddfa4d 100644
--- a/tests/test_onion_message.py
+++ b/tests/test_onion_message.py
@@ -5,7 +5,9 @@ import time
import dataclasses
import logging
from functools import partial
+from unittest.mock import Mock
from types import MappingProxyType
+from aiorpcx import NetAddress
import electrum_ecc as ecc
from electrum_ecc import ECPrivkey
@@ -17,6 +19,7 @@ from electrum.lnonion import (
get_shared_secrets_along_route, new_onion_packet, ONION_MESSAGE_LARGE_SIZE, HOPS_DATA_SIZE, InvalidPayloadSize,
encrypt_hops_recipient_data)
from electrum.crypto import get_ecdh, privkey_to_pubkey
+from electrum.lntransport import LNPeerAddr
from electrum.lnutil import LnFeatures, Keypair, MIN_FINAL_CLTV_DELTA_ACCEPTED, REMOTE
from electrum.onion_message import (
blinding_privkey, create_blinded_path,OnionMessageManager, NoRouteFound, Timeout, get_blinded_paths_to_me,
@@ -351,8 +354,10 @@ class TestOnionMessageManager(ElectrumTestCase):
payload={'message': {'text': 'no_peer'.encode('utf-8')}},
node_id_or_blinded_path=self.eve.pubkey)
- with self.assertRaises(NoRouteFound):
+ # will not find route to eve, but has eve's address, but we are configured to not direct connect
+ with self.assertRaises(NoRouteFound) as c:
await t5
+ self.assertEqual(c.exception.peer_address, LNPeerAddr('localhost', 1234, self.eve.pubkey))
async def test_request_and_reply(self):
n = MockNetwork()
@@ -375,6 +380,7 @@ class TestOnionMessageManager(ElectrumTestCase):
lnw.lnpeermgr._peers[self.bob.pubkey] = MockPeer(self.bob.pubkey, on_send_message=slow)
lnw.lnpeermgr._peers[self.carol.pubkey] = MockPeer(self.carol.pubkey, on_send_message=partial(withreply, rkey1))
lnw.lnpeermgr._peers[self.dave.pubkey] = MockPeer(self.dave.pubkey, on_send_message=partial(slowwithreply, rkey2))
+ lnw.channel_db._addresses[self.eve.pubkey] = {NetAddress('localhost', '1234'): int(time.time())}
t = OnionMessageManager(lnw)
t.start_network(network=n)
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.