tests: test_onion_message: mock LNWallet._add_peer
What changed, and why it matters
This commit only changes a test file. It adds a mock (a fake stand-in) for a Lightning Network wallet function so that a test of onion message handling doesn't crash when the code tries to fall back to a direct peer connection. There is no change to production code and no security fix or vulnerability is indicated.
No security action needed. This is a routine test-maintenance change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies tests/test_onion_message.py to patch LNWallet.lnpeermgr._add_peer with an async mock that returns a MockPeer. This prevents the test_request_and_reply test case from raising exceptions during direct-connection fallback paths. No application code is altered.
Changed components
tests/test_onion_message.pyInspect captured patch +7 / −0
diff --git a/tests/test_onion_message.py b/tests/test_onion_message.py
index bddfa4d..dd2be43 100644
--- a/tests/test_onion_message.py
+++ b/tests/test_onion_message.py
@@ -363,6 +363,13 @@ class TestOnionMessageManager(ElectrumTestCase):
n = MockNetwork()
lnw = self.create_mock_lnwallet(name='test_request_and_reply', has_anchors=False)
+ # mock add_peer for direct connection fallback
+ async def mock__add_peer(host, port, node_id):
+ mock_peer = MockPeer(pubkey=node_id)
+ # lnw.lnpeermgr._peers[node_id] = mock_peer
+ return mock_peer
+ lnw.lnpeermgr._add_peer = mock__add_peer
+
def slow(*args, **kwargs):
time.sleep(2*TIME_STEP)
Why this scored 13/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.