Skip to content

Commit 70191cc

Browse files
committed
tests: Add explicit preapprove{invoice,keysend} calls before sendpay
1 parent 4f8bd5d commit 70191cc

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

tests/test_closing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,7 @@ def test_onchaind_replay(node_factory, bitcoind):
18211821
'delay': 101,
18221822
'channel': first_scid(l1, l2)
18231823
}
1824+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
18241825
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
18251826
l1.daemon.wait_for_log('sendrawtx exit 0')
18261827
bitcoind.generate_block(1, wait_for_mempool=1)
@@ -1964,6 +1965,7 @@ def test_onchain_timeout(node_factory, bitcoind, executor, chainparams, anchors)
19641965
'channel': first_scid(l1, l2)
19651966
}
19661967

1968+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
19671969
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'], groupid=1)
19681970
with pytest.raises(RpcError):
19691971
l1.rpc.waitsendpay(rhash)
@@ -2098,6 +2100,7 @@ def test_onchain_middleman_simple(node_factory, bitcoind, chainparams, anchors):
20982100

20992101
q = queue.Queue()
21002102

2103+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
21012104
def try_pay():
21022105
try:
21032106
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
@@ -2237,6 +2240,7 @@ def test_onchain_middleman_their_unilateral_in(node_factory, bitcoind, chainpara
22372240

22382241
q = queue.Queue()
22392242

2243+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
22402244
def try_pay():
22412245
try:
22422246
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
@@ -2349,6 +2353,8 @@ def try_pay():
23492353
try:
23502354
# rhash is fake (so is payment_secret)
23512355
rhash = 'B1' * 32
2356+
# let the signer know this payment is coming
2357+
l1.rpc.preapprovekeysend(l2.info['id'], rhash, 10**8)
23522358
l1.rpc.sendpay(route, rhash, payment_secret=rhash)
23532359
q.put(None)
23542360
except Exception as err:
@@ -2489,6 +2495,7 @@ def test_onchain_feechange(node_factory, bitcoind, executor):
24892495
'channel': first_scid(l1, l2)
24902496
}
24912497

2498+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
24922499
executor.submit(l1.rpc.sendpay, [routestep], rhash, payment_secret=inv['payment_secret'])
24932500

24942501
# l2 will drop to chain.
@@ -2569,6 +2576,7 @@ def test_onchain_all_dust(node_factory, bitcoind, executor):
25692576
'channel': first_scid(l1, l2)
25702577
}
25712578

2579+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
25722580
executor.submit(l1.rpc.sendpay, [routestep], rhash, payment_secret=inv['payment_secret'])
25732581

25742582
# l2 will drop to chain.

tests/test_connection.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ def test_reconnect_sender_add1(node_factory):
844844
l1.daemon.wait_for_log('Already have funding locked in')
845845

846846
# This will send commit, so will reconnect as required.
847+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
847848
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
848849

849850

@@ -874,6 +875,7 @@ def test_reconnect_sender_add(node_factory):
874875
route = [{'amount_msat': amt, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}]
875876

876877
# This will send commit, so will reconnect as required.
878+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
877879
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
878880
# Should have printed this for every reconnect.
879881
for i in range(0, len(disconnects)):
@@ -905,6 +907,7 @@ def test_reconnect_receiver_add(node_factory):
905907
assert only_one(l2.rpc.listinvoices('testpayment2')['invoices'])['status'] == 'unpaid'
906908

907909
route = [{'amount_msat': amt, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}]
910+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
908911
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
909912
for i in range(len(disconnects)):
910913
l1.daemon.wait_for_log('Already have funding locked in')
@@ -934,6 +937,7 @@ def test_reconnect_receiver_fulfill(node_factory):
934937
assert only_one(l2.rpc.listinvoices('testpayment2')['invoices'])['status'] == 'unpaid'
935938

936939
route = [{'amount_msat': amt, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}]
940+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
937941
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
938942
for i in range(len(disconnects)):
939943
l1.daemon.wait_for_log('Already have funding locked in')
@@ -4175,6 +4179,7 @@ def test_multichan(node_factory, executor, bitcoind):
41754179

41764180
before = l2.rpc.listpeerchannels(l3.info['id'])['channels']
41774181
inv1 = l3.rpc.invoice(100000000, "invoice", "invoice")
4182+
l1.rpc.preapproveinvoice(bolt11=inv1['bolt11']) # let the signer know this payment is coming
41784183
l1.rpc.sendpay(route, inv1['payment_hash'], payment_secret=inv1['payment_secret'])
41794184
l1.rpc.waitsendpay(inv1['payment_hash'])
41804185

@@ -4202,6 +4207,7 @@ def test_multichan(node_factory, executor, bitcoind):
42024207
before = l2.rpc.listpeerchannels(l3.info['id'])['channels']
42034208
route[1]['channel'] = scid23b
42044209
inv2 = l3.rpc.invoice(100000000, "invoice2", "invoice2")
4210+
l1.rpc.preapproveinvoice(bolt11=inv2['bolt11']) # let the signer know this payment is coming
42054211
l1.rpc.sendpay(route, inv2['payment_hash'], payment_secret=inv2['payment_secret'])
42064212
l1.rpc.waitsendpay(inv2['payment_hash'])
42074213
# Wait until HTLCs fully settled
@@ -4246,6 +4252,7 @@ def test_multichan(node_factory, executor, bitcoind):
42464252
# We can actually pay by *closed* scid (at least until it's completely forgotten)
42474253
route[1]['channel'] = scid23a
42484254
inv3 = l3.rpc.invoice(100000000, "invoice3", "invoice3")
4255+
l1.rpc.preapproveinvoice(bolt11=inv3['bolt11']) # let the signer know this payment is coming
42494256
l1.rpc.sendpay(route, inv3['payment_hash'], payment_secret=inv3['payment_secret'])
42504257
l1.rpc.waitsendpay(inv3['payment_hash'])
42514258

tests/test_pay.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ def invoice_unpaid(dst, label):
574574
with pytest.raises(RpcError):
575575
rs = copy.deepcopy(routestep)
576576
rs['amount_msat'] = rs['amount_msat'] - 1
577+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
577578
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
578579
l1.rpc.waitsendpay(rhash)
579580
assert invoice_unpaid(l2, 'testpayment2')
@@ -582,6 +583,7 @@ def invoice_unpaid(dst, label):
582583
with pytest.raises(RpcError):
583584
rs = copy.deepcopy(routestep)
584585
rs['amount_msat'] = rs['amount_msat'] * 2 + 1
586+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
585587
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
586588
l1.rpc.waitsendpay(rhash)
587589
assert invoice_unpaid(l2, 'testpayment2')
@@ -590,6 +592,7 @@ def invoice_unpaid(dst, label):
590592
with pytest.raises(RpcError):
591593
rs = copy.deepcopy(routestep)
592594
rs['delay'] = rs['delay'] - 2
595+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
593596
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
594597
l1.rpc.waitsendpay(rhash)
595598
assert invoice_unpaid(l2, 'testpayment2')
@@ -599,17 +602,20 @@ def invoice_unpaid(dst, label):
599602
with pytest.raises(RpcError):
600603
rs = copy.deepcopy(routestep)
601604
rs['id'] = '00000000000000000000000000000000'
605+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
602606
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
603607
assert invoice_unpaid(l2, 'testpayment2')
604608
l1.rpc.check_request_schemas = True
605609

606610
# Bad payment_secret
611+
l1.rpc.preapprovekeysend(l2.info['id'], rhash, routestep['amount_msat'])
607612
l1.rpc.sendpay([routestep], rhash, payment_secret="00" * 32)
608613
with pytest.raises(RpcError):
609614
l1.rpc.waitsendpay(rhash)
610615
assert invoice_unpaid(l2, 'testpayment2')
611616

612617
# Missing payment_secret
618+
l1.rpc.preapprovekeysend(l2.info['id'], rhash, routestep['amount_msat'])
613619
l1.rpc.sendpay([routestep], rhash)
614620
with pytest.raises(RpcError):
615621
l1.rpc.waitsendpay(rhash)
@@ -625,6 +631,7 @@ def invoice_unpaid(dst, label):
625631

626632
# This works.
627633
before = int(time.time())
634+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
628635
details = l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
629636
after = int(time.time())
630637
preimage = l1.rpc.waitsendpay(rhash)['payment_preimage']
@@ -667,6 +674,7 @@ def check_balances():
667674
rhash = inv['payment_hash']
668675
assert only_one(l2.rpc.listinvoices('testpayment3')['invoices'])['status'] == 'unpaid'
669676
routestep = {'amount_msat': amt * 2, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}
677+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
670678
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
671679
preimage3 = l1.rpc.waitsendpay(rhash)['payment_preimage']
672680
assert only_one(l2.rpc.listinvoices('testpayment3')['invoices'])['status'] == 'paid'
@@ -1157,6 +1165,7 @@ def test_forward(node_factory, bitcoind):
11571165
# Unknown other peer
11581166
route = copy.deepcopy(baseroute)
11591167
route[1]['id'] = '031a8dc444e41bb989653a4501e11175a488a57439b0c4947704fd6e3de5dca607'
1168+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
11601169
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
11611170
with pytest.raises(RpcError):
11621171
l1.rpc.waitsendpay(rhash)
@@ -1559,6 +1568,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
15591568

15601569
l2.rpc.close(c23, 1)
15611570

1571+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
15621572
with pytest.raises(RpcError):
15631573
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
15641574
l1.rpc.waitsendpay(payment_hash)
@@ -1584,6 +1594,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
15841594
'delay': 6,
15851595
'channel': c24}]
15861596

1597+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
15871598
with pytest.raises(RpcError):
15881599
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
15891600
l1.rpc.waitsendpay(payment_hash)
@@ -1610,6 +1621,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
16101621
'delay': 6,
16111622
'channel': c25}]
16121623

1624+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
16131625
with pytest.raises(RpcError):
16141626
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
16151627
l1.rpc.waitsendpay(payment_hash)
@@ -1633,6 +1645,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
16331645
# Replace id with a different pubkey, so onion encoded badly at l2 hop.
16341646
route[1]['id'] = mangled_nodeid
16351647

1648+
l6.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
16361649
with pytest.raises(RpcError):
16371650
l6.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
16381651
l6.rpc.waitsendpay(payment_hash)
@@ -1660,6 +1673,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
16601673
'delay': 5,
16611674
'channel': c24}]
16621675

1676+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
16631677
executor.submit(l1.rpc.sendpay, route, payment_hash, payment_secret=inv['payment_secret'])
16641678

16651679
l4.daemon.wait_for_log('permfail')
@@ -1715,6 +1729,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17151729

17161730
# L2 tries to pay
17171731
r = l2.rpc.getroute(l4.info['id'], 10**8, 1)["route"]
1732+
l2.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
17181733
l2.rpc.sendpay(r, h, payment_secret=inv['payment_secret'])
17191734

17201735
# Now increment CLTV
@@ -1723,6 +1738,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17231738

17241739
# L1 tries to pay
17251740
r = l1.rpc.getroute(l4.info['id'], 10**8, 1)["route"]
1741+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
17261742
l1.rpc.sendpay(r, h, payment_secret=inv['payment_secret'])
17271743

17281744
# Now increment CLTV
@@ -1731,6 +1747,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17311747

17321748
# L3 tries to pay
17331749
r = l3.rpc.getroute(l4.info['id'], 10**8, 1)["route"]
1750+
l3.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
17341751
l3.rpc.sendpay(r, h, payment_secret=inv['payment_secret'])
17351752

17361753
# Give them time to go through.
@@ -1796,6 +1813,7 @@ def exhaust_channel(opener, peer, scid, already_spent=0):
17961813
'delay': 10,
17971814
'channel': scid
17981815
}
1816+
opener.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
17991817
opener.rpc.sendpay([routestep], inv['payment_hash'], payment_secret=inv['payment_secret'])
18001818
opener.rpc.waitsendpay(inv['payment_hash'])
18011819

@@ -2513,6 +2531,7 @@ def test_channel_spendable(node_factory, bitcoind):
25132531

25142532
# Exact amount should succeed.
25152533
route = l1.rpc.getroute(l2.info['id'], amount, riskfactor=1, fuzzpercent=0)['route']
2534+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
25162535
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
25172536

25182537
# Amount should drop to 0 once HTLC is sent; we have time, thanks to
@@ -2538,6 +2557,7 @@ def test_channel_spendable(node_factory, bitcoind):
25382557

25392558
# Exact amount should succeed.
25402559
route = l2.rpc.getroute(l1.info['id'], amount, riskfactor=1, fuzzpercent=0)['route']
2560+
l2.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
25412561
l2.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
25422562

25432563
# Amount should drop to 0 once HTLC is sent; we have time, thanks to
@@ -2697,6 +2717,7 @@ def test_htlc_too_dusty_outgoing(node_factory, bitcoind, chainparams):
26972717
route = l1.rpc.getroute(l2.info['id'], non_dust_htlc_val_sat * 1000, 1)['route']
26982718
for i in range(0, 3):
26992719
inv = l2.rpc.invoice((non_dust_htlc_val_sat * 1000), str(i + 100), str(i + 100))
2720+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27002721
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27012722
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
27022723
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])
@@ -2706,20 +2727,23 @@ def test_htlc_too_dusty_outgoing(node_factory, bitcoind, chainparams):
27062727
route = l1.rpc.getroute(l2.info['id'], htlc_val_msat, 1)['route']
27072728
for i in range(0, num_dusty_htlcs):
27082729
inv = l2.rpc.invoice(htlc_val_msat, str(i), str(i))
2730+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27092731
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27102732
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
27112733
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])
27122734
assert res['status'] == 'pending'
27132735

27142736
# one more should tip it over, and return a payment failure
27152737
inv = l2.rpc.invoice(htlc_val_msat, str(num_dusty_htlcs), str(num_dusty_htlcs))
2738+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27162739
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27172740
l1.daemon.wait_for_log('CHANNEL_ERR_DUST_FAILURE')
27182741
wait_for(lambda: only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])['status'] == 'failed')
27192742

27202743
# but we can still add a non dust htlc
27212744
route = l1.rpc.getroute(l2.info['id'], non_dust_htlc_val_sat * 1000, 1)['route']
27222745
inv = l2.rpc.invoice((10000 * 1000), str(120), str(120))
2746+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27232747
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27242748
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
27252749
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])

0 commit comments

Comments
 (0)