pytest: fix broken test_pay_bolt11_metadata
What changed, and why it matters
This commit fixes a failing test in the Core Lightning test suite. The test previously relied on a hard-coded invoice that has now expired, causing automated tests to fail. The update dynamically generates a fresh invoice and adds payment metadata using a developer tool. There is no security vulnerability or product code change here—only a test maintenance fix.
No security action needed. This is a routine test fix. Reviewers may optionally verify that the new test still exercises the intended payment_metadata rejection path and that the hard-coded private key is only used in a regtest/dev environment.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change modifies tests/test_pay.py::test_pay_bolt11_metadata. It removes a hard-coded, expired BOLT11 invoice and the use of old_hsmsecret, replacing them with a freshly generated invoice from l2.rpc.invoice and re-encoding it with devtools/bolt11-cli to inject payment metadata. The test still verifies that xpay rejects an invoice with unexpected payment_metadata and that the expected log line appears. No production code is altered.
Changed components
tests/test_pay.pyInspect captured patch +28 / −15
diff --git a/tests/test_pay.py b/tests/test_pay.py
index 76aff48d..c68b4ba3 100644
--- a/tests/test_pay.py
+++ b/tests/test_pay.py
@@ -5327,24 +5327,37 @@ def test_pay_manual_exclude(node_factory, bitcoind):
@unittest.skipIf(TEST_NETWORK != 'regtest', "Invoice is network specific")
-def test_pay_bolt11_metadata(node_factory, bitcoind):
- l1, l2 = node_factory.line_graph(2, opts={'old_hsmsecret': True})
-
- # BOLT #11:
- # > ### Please send 0.01 BTC with payment metadata 0x01fafaf0
- # > lnbc10m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp9wpshjmt9de6zqmt9w3skgct5vysxjmnnd9jx2mq8q8a04uqsp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q2gqqqqqqsgq7hf8he7ecf7n4ffphs6awl9t6676rrclv9ckg3d3ncn7fct63p6s365duk5wrk202cfy3aj5xnnp5gs3vrdvruverwwq7yzhkf5a3xqpd05wjc
-
- b11 = l1.rpc.decode('lnbc10m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp9wpshjmt9de6zqmt9w3skgct5vysxjmnnd9jx2mq8q8a04uqsp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q2gqqqqqqsgq7hf8he7ecf7n4ffphs6awl9t6676rrclv9ckg3d3ncn7fct63p6s365duk5wrk202cfy3aj5xnnp5gs3vrdvruverwwq7yzhkf5a3xqpd05wjc')
- assert b11['payment_metadata'] == '01fafaf0'
+def test_pay_bolt11_metadata(node_factory, chainparams):
+ l1, l2 = node_factory.line_graph(2)
- # I previously hacked lightningd to add "this is metadata" to metadata.
- # After CI started failing, I *also* hacked it to set expiry to BIGNUM.
- inv = "lnbcrt1230n1p3yzgcxsp5q8g040f9rl9mu2unkjuj0vn262s6nyrhz5hythk3ueu2lfzahmzspp5ve584t0cv27hwmy0cx9ca8uwyqyfw9y9dm3r8vus9fv36r2l9yjsdq8v3jhxccmq6w35xjueqd9ejqmt9w3skgct5vyxqxra2q2qcqp99q2sqqqqqysgqfw6efxpzk5x5vfj8se46yg667x5cvhyttnmuqyk0q7rmhx3gs249qhtdggnek8c5adm2pztkjddlwyn2art2zg9xap2ckczzl3fzz4qqsej6mf"
- # Make l2 "know" about this invoice.
- l2.rpc.invoice(amount_msat=123000, label='label1', description='desc', preimage='00' * 32)
+ # Generate a normal invoice on l2, then use bolt11-cli to re-encode it with
+ # payment metadata added. old_hsmsecret gives l2 a known private key.
+ inv = l2.rpc.invoice(amount_msat=123000, label='label1', description='desc', preimage='00' * 32)
+ inv_decoded = l1.rpc.decode(inv['bolt11'])
+ inv_with_metadata = subprocess.check_output(['devtools/bolt11-cli', 'encode',
+ # l2's private key (old_hsmsecret, WIF byte stripped)
+ '0c633a7c17c701a0980158f5483035e01fa8bd091b47fadf2e86e589a9f93fca',
+ f"currency={chainparams['bip173_prefix']}",
+ f"p={inv['payment_hash']}",
+ f"s={inv['payment_secret']}",
+ "d=desc",
+ "amount=123000msat",
+ f"x={inv_decoded['expiry']}",
+ f"c={inv_decoded['min_final_cltv_expiry']}",
+ f"9={inv_decoded['features']}",
+ "m=" + b'this is metadata'.hex()]).decode('utf-8').strip()
+
+ # They should be basically identical
+ post_decoded = l1.rpc.decode(inv_with_metadata)
+ del inv_decoded['signature']
+ del post_decoded['signature']
+ del post_decoded['payment_metadata']
+ del inv_decoded['created_at']
+ del post_decoded['created_at']
+ assert inv_decoded == post_decoded
with pytest.raises(RpcError, match=r'Unexpected error \(invalid_onion_payload\) from final node'):
- l1.rpc.xpay(inv)
+ l1.rpc.xpay(inv_with_metadata)
l2.daemon.wait_for_log("Unexpected payment_metadata {}".format(b'this is metadata'.hex()))
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.