pytest: speed up test_keysend_description_size_limit
What changed, and why it matters
This commit is a straightforward test-only speedup. It refactors a single pytest test so it creates one pair of test nodes and loops through several payload lengths internally, instead of launching fresh nodes for every length. It also adds a stronger assertion checking invoice descriptions and amounts. There is no change to production code, no security fix, and no security-relevant behavior change.
No security action needed. This is a test optimization and can be reviewed as normal code quality/maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies tests/test_pay.py only. It removes the @pytest.mark.parametrize decorator from test_keysend_description_size_limit, changes the test signature to remove the tlv_payload_length parameter, and runs the same set of lengths (638, 639, 640, 641, 1022, 1023, 1024) in a loop against the same two-node setup. It also changes the payload construction from a JSON object to a raw string, updates the expected description set, and asserts that all received invoices match the expected descriptions and amounts. No Core Lightning daemon code is touched.
Changed components
tests/test_pay.pyInspect captured patch +14 / −10
diff --git a/tests/test_pay.py b/tests/test_pay.py
index ebd218a3..3d13fb0b 100644
--- a/tests/test_pay.py
+++ b/tests/test_pay.py
@@ -11,7 +11,6 @@ from utils import (
tu64_encode
)
import copy
-import json
import os
import pytest
import random
@@ -3733,8 +3732,7 @@ def test_keysend_maxfee(node_factory):
assert len(l3.rpc.listinvoices()['invoices']) == 1
-@pytest.mark.parametrize("tlv_payload_length", [638, 639, 640, 641, 1022, 1023, 1024])
-def test_keysend_description_size_limit(node_factory, tlv_payload_length):
+def test_keysend_description_size_limit(node_factory):
"""
Test keysend description handling near BOLT11 field size limits.
@@ -3745,16 +3743,22 @@ def test_keysend_description_size_limit(node_factory, tlv_payload_length):
"""
l1, l2 = node_factory.line_graph(2, wait_for_announce=True)
amt = 10000
- prefix = 'keysend: {"message": ""}'
+ prefix = 'keysend: '
base_len = len(prefix)
- # Prep TLV payload with test length
- body_len = tlv_payload_length - base_len
- tlv_payload = json.dumps({"message": "a" * body_len}).encode().hex()
+ tlv_lens = [638, 639, 640, 641, 1022, 1023, 1024]
+ expected = set()
+ for tlv_payload_length in tlv_lens:
+ # Prep TLV payload with test length
+ body_len = tlv_payload_length - base_len
+ tlv_payload = ("a" * body_len).encode().hex()
+ expected.add(prefix + "a" * body_len)
- # Send keysend payment with test payload
- l1.rpc.keysend(l2.info["id"], amt, extratlvs={7629169: tlv_payload})
- assert len(l2.rpc.listinvoices()["invoices"]) == 1
+ # Send keysend payment with test payload
+ l1.rpc.keysend(l2.info["id"], amt, extratlvs={7629169: tlv_payload})
+
+ assert set(inv['description'] for inv in l2.rpc.listinvoices()["invoices"]) == expected
+ assert all(inv['amount_received_msat'] == amt for inv in l2.rpc.listinvoices()["invoices"])
def test_invalid_onion_channel_update(node_factory):
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.