tests: make test_delpay_works deterministic
What changed, and why it matters
This commit only changes a test file to make a flaky test more reliable. It does not modify any production code, so it has no security impact on real users.
No security action needed; this is a test-only reliability improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies tests/test_pay.py to make test_delpay_works deterministic. Previously the test used a forced disconnect and timing-dependent channel failure; now it uses the fail_htlcs.py test plugin to reliably reject the first payment attempt. It also renames a variable from ‘failed’ to ‘success’. No production code is affected.
Changed components
tests/test_pay.pyInspect captured patch +16 / −16
### tests/test_pay.py
@@ -5907,34 +5907,34 @@ def test_delpay_works(node_factory, bitcoind, xpay_handle_pay):
"""
One failure, one success; deleting the success works (groupid=1, partid=2)
"""
+ opts = [
+ {"allow-deprecated-apis": True, "xpay-handle-pay": xpay_handle_pay},
+ {"plugin": os.path.join(os.getcwd(), "tests/plugins/fail_htlcs.py")},
+ {},
+ ]
l1, l2, l3 = node_factory.line_graph(
- 3,
- fundamount=10**5,
- wait_for_announce=True,
- opts={"allow-deprecated-apis": True, "xpay-handle-pay": xpay_handle_pay},
+ 3, fundamount=10**5, wait_for_announce=True, opts=opts
)
# Expensive route!
- l4 = node_factory.get_node(options={'fee-per-satoshi': 1000,
- 'fee-base': 2000})
+ l4 = node_factory.get_node(options={"fee-per-satoshi": 1000, "fee-base": 2000})
node_factory.join_nodes([l1, l4, l3], wait_for_announce=True)
# Don't give a hint, so l1 chooses cheapest.
inv = l3.dev_invoice(10**5, 'lbl', 'desc', dev_routes=[])
- l3.rpc.disconnect(l2.info['id'], force=True)
l1.rpc.pay(inv['bolt11'])
assert len(l1.rpc.listsendpays()['payments']) == 2
- failed = [p for p in l1.rpc.listsendpays()['payments'] if p['status'] == 'complete'][0]
- l1.rpc.delpay(payment_hash=failed['payment_hash'],
- status=failed['status'],
- groupid=failed['groupid'],
- partid=failed['partid'])
+ success = [p for p in l1.rpc.listsendpays()['payments'] if p['status'] == 'complete'][0]
+ l1.rpc.delpay(payment_hash=success['payment_hash'],
+ status=success['status'],
+ groupid=success['groupid'],
+ partid=success['partid'])
with pytest.raises(RpcError, match=r'No payment for that payment_hash'):
- l1.rpc.delpay(payment_hash=failed['payment_hash'],
- status=failed['status'],
- groupid=failed['groupid'],
- partid=failed['partid'])
+ l1.rpc.delpay(payment_hash=success['payment_hash'],
+ status=success['status'],
+ groupid=success['groupid'],
+ partid=success['partid'])
def test_fetchinvoice_with_no_quantity(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.