Skip to content

Commit b51120b

Browse files
committed
pytest: test that xpay doesn't use MPP if invoice doesn't permit it.
Signed-off-by: Rusty Russell <[email protected]>
1 parent d5946e6 commit b51120b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_xpay.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ def test_xpay_fake_channeld(node_factory, bitcoind, chainparams):
254254
f"currency={chainparams['bip173_prefix']}",
255255
f"p={hash_hex}",
256256
f"s={'00' * 32}",
257+
"9=020000", # option_basic_mpp
257258
f"d=Paying node {n}",
258259
f"amount={AMOUNT}msat"]).decode('utf-8').strip()
259260
assert l1.rpc.decode(inv)['payee'] == nodeids[n]
@@ -286,6 +287,7 @@ def test_xpay_fake_channeld(node_factory, bitcoind, chainparams):
286287
"encode",
287288
n.to_bytes(length=8, byteorder=sys.byteorder).hex() + '01' * 24,
288289
f"p={hash_hex}",
290+
"9=020000", # option_basic_mpp
289291
f"s={'00' * 32}",
290292
f"d=Paying node {n}",
291293
f"amount={AMOUNT}msat"]).decode('utf-8').strip()
@@ -556,6 +558,7 @@ def test_xpay_maxfee(node_factory, bitcoind, chainparams):
556558
n.to_bytes(length=8, byteorder=sys.byteorder).hex() + '01' * 24,
557559
f"currency={chainparams['bip173_prefix']}",
558560
f"p={hash_hex}",
561+
"9=020000", # option_basic_mpp
559562
f"s={'00' * 32}",
560563
f"d=Paying node {n} with maxfee",
561564
f"amount={AMOUNT}msat"]).decode('utf-8').strip()
@@ -616,3 +619,34 @@ def test_xpay_zeroconf(node_factory):
616619
offer = l2.rpc.offer('any')['bolt12']
617620
b12 = l1.rpc.fetchinvoice(offer, '100000msat')['invoice']
618621
l1.rpc.xpay(b12)
622+
623+
624+
@pytest.mark.xfail(strict=True)
625+
def test_xpay_no_mpp(node_factory, chainparams):
626+
"""Suppress mpp, resulting in a single payment part"""
627+
l1, l2, l3, l4 = node_factory.get_nodes(4)
628+
node_factory.join_nodes([l1, l2, l3], wait_for_announce=True)
629+
node_factory.join_nodes([l1, l4, l3], wait_for_announce=True)
630+
631+
# Amount needs to be enought that it bothers splitting, but not
632+
# so much that it can't pay without mpp.
633+
AMOUNT = 500000000
634+
635+
# We create a version of this which doesn't support MPP
636+
no_mpp = l3.rpc.invoice(AMOUNT, 'test_xpay_no_mpp2', 'test_xpay_no_mpp without mpp')
637+
b11_no_mpp = subprocess.check_output(["devtools/bolt11-cli",
638+
"encode",
639+
# secret for l3
640+
"dae24b3853e1443a176daba5544ee04f7db33ebe38e70bdfdb1da34e89512c10",
641+
f"currency={chainparams['bip173_prefix']}",
642+
f"p={no_mpp['payment_hash']}",
643+
f"s={no_mpp['payment_secret']}",
644+
f"d=Paying l3 without mpp",
645+
f"amount={AMOUNT}"]).decode('utf-8').strip()
646+
647+
# This should not mpp!
648+
ret = l1.rpc.xpay(b11_no_mpp)
649+
assert ret['failed_parts'] == 0
650+
assert ret['successful_parts'] == 1
651+
assert ret['amount_msat'] == AMOUNT
652+
assert ret['amount_sent_msat'] == AMOUNT + AMOUNT // 100000 + 1

0 commit comments

Comments
 (0)