tests: add TestLNWallet to test lnwallet utils
What changed, and why it matters
This commit only adds a new automated test file for an existing Lightning wallet utility function. It does not change any production code, add new features, or fix any bugs. There is no security relevance.
No action required; this is a test-only addition with no security implications.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit introduces tests/test_lnwallet.py containing a single unittest class TestLNWallet with one test method, test_create_payment_info. The test exercises the existing LNWallet.create_payment_info() utility, verifying that created payment info objects retain expected fields (amount_msat, min_final_cltv_delta, expiry_delay, db_key, status) and that preimages are generated. No application logic is modified.
Changed components
tests/test_lnwallet.pyInspect captured patch +45 / −0
diff --git a/tests/test_lnwallet.py b/tests/test_lnwallet.py
new file mode 100644
index 0000000..6a856df
--- /dev/null
+++ b/tests/test_lnwallet.py
@@ -0,0 +1,45 @@
+import logging
+import os
+
+from . import ElectrumTestCase
+
+from electrum.lnutil import RECEIVED, MIN_FINAL_CLTV_DELTA_ACCEPTED
+from electrum.logging import console_stderr_handler
+from electrum.invoices import LN_EXPIRY_NEVER, PR_UNPAID
+
+
+class TestLNWallet(ElectrumTestCase):
+ TESTNET = True
+
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ console_stderr_handler.setLevel(logging.DEBUG)
+
+ async def asyncSetUp(self):
+ self.lnwallet_anchors = self.create_mock_lnwallet(name='mock_lnwallet_anchors', has_anchors=True)
+ await super().asyncSetUp()
+
+ def test_create_payment_info(self):
+ wallet = self.lnwallet_anchors
+ tests = (
+ (100_000, 200, 100),
+ (0, 200, 100),
+ (None, 200, 100),
+ (None, None, LN_EXPIRY_NEVER),
+ (100_000, None, 0),
+ )
+ for amount_msat, min_final_cltv_delta, exp_delay in tests:
+ payment_hash = wallet.create_payment_info(
+ amount_msat=amount_msat,
+ min_final_cltv_delta=min_final_cltv_delta,
+ exp_delay=exp_delay,
+ )
+ self.assertIsNotNone(wallet.get_preimage(payment_hash))
+ pi = wallet.get_payment_info(payment_hash, direction=RECEIVED)
+ self.assertEqual(pi.amount_msat, amount_msat)
+ self.assertEqual(pi.min_final_cltv_delta, min_final_cltv_delta or MIN_FINAL_CLTV_DELTA_ACCEPTED)
+ self.assertEqual(pi.expiry_delay, exp_delay or LN_EXPIRY_NEVER)
+ self.assertEqual(pi.db_key, f"{payment_hash.hex()}:{int(pi.direction)}")
+ self.assertEqual(pi.status, PR_UNPAID)
+ self.assertIsNone(wallet.get_payment_info(os.urandom(32), direction=RECEIVED))
Why this scored 15/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.