Skip to content

Commit 4d5aabd

Browse files
committed
tests: add explicit preapprove{invoice,keysend} calls before sendpay
1 parent 36ac83c commit 4d5aabd

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

tests/test_closing.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,7 @@ def test_onchaind_replay(node_factory, bitcoind):
18111811
'delay': 101,
18121812
'channel': first_scid(l1, l2)
18131813
}
1814+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
18141815
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
18151816
l1.daemon.wait_for_log('sendrawtx exit 0')
18161817
bitcoind.generate_block(1, wait_for_mempool=1)
@@ -1954,6 +1955,7 @@ def test_onchain_timeout(node_factory, bitcoind, executor, chainparams, anchors)
19541955
'channel': first_scid(l1, l2)
19551956
}
19561957

1958+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
19571959
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'], groupid=1)
19581960
with pytest.raises(RpcError):
19591961
l1.rpc.waitsendpay(rhash)
@@ -2088,6 +2090,7 @@ def test_onchain_middleman_simple(node_factory, bitcoind, chainparams, anchors):
20882090

20892091
q = queue.Queue()
20902092

2093+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
20912094
def try_pay():
20922095
try:
20932096
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
@@ -2227,6 +2230,7 @@ def test_onchain_middleman_their_unilateral_in(node_factory, bitcoind, chainpara
22272230

22282231
q = queue.Queue()
22292232

2233+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
22302234
def try_pay():
22312235
try:
22322236
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
@@ -2339,6 +2343,8 @@ def try_pay():
23392343
try:
23402344
# rhash is fake (so is payment_secret)
23412345
rhash = 'B1' * 32
2346+
# let the signer know this payment is coming
2347+
l1.rpc.preapprovekeysend(l2.info['id'], rhash, 10**8)
23422348
l1.rpc.sendpay(route, rhash, payment_secret=rhash)
23432349
q.put(None)
23442350
except Exception as err:
@@ -2479,6 +2485,7 @@ def test_onchain_feechange(node_factory, bitcoind, executor):
24792485
'channel': first_scid(l1, l2)
24802486
}
24812487

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

24842491
# l2 will drop to chain.
@@ -2559,6 +2566,7 @@ def test_onchain_all_dust(node_factory, bitcoind, executor):
25592566
'channel': first_scid(l1, l2)
25602567
}
25612568

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

25642572
# l2 will drop to chain.
@@ -3740,6 +3748,7 @@ def test_closing_anchorspend_htlc_tx_rbf(node_factory, bitcoind):
37403748
'delay': 12,
37413749
'channel': first_scid(l1, l2)
37423750
}
3751+
l1.rpc.preapprovekeysend(routestep['id'], rhash, routestep['amount_msat'])
37433752
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
37443753
l2.daemon.wait_for_log('dev_disconnect')
37453754
l2.stop()
@@ -3807,6 +3816,7 @@ def test_htlc_no_force_close(node_factory, bitcoind, anchors):
38073816
'id': l3.info['id'],
38083817
'delay': 10,
38093818
'channel': first_scid(l2, l3)}]
3819+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
38103820
l1.rpc.sendpay(route, inv['payment_hash'],
38113821
payment_secret=inv['payment_secret'])
38123822
l3.daemon.wait_for_log('dev_disconnect')
@@ -3928,6 +3938,7 @@ def test_peer_anchor_push(node_factory, bitcoind, executor, chainparams):
39283938
amt = 100_000_000
39293939
sticky_inv = l3.rpc.invoice(amt, 'sticky', 'sticky')
39303940
route = l1.rpc.getroute(l3.info['id'], amt, 1)['route']
3941+
l1.rpc.preapproveinvoice(bolt11=sticky_inv['bolt11']) # let the signer know this payment is coming
39313942
l1.rpc.sendpay(route, sticky_inv['payment_hash'], payment_secret=sticky_inv['payment_secret'])
39323943
l3.daemon.wait_for_log('dev_disconnect: -WIRE_UPDATE_FULFILL_HTLC')
39333944

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')
@@ -4165,6 +4169,7 @@ def test_multichan(node_factory, executor, bitcoind):
41654169

41664170
before = l2.rpc.listpeerchannels(l3.info['id'])['channels']
41674171
inv1 = l3.rpc.invoice(100000000, "invoice", "invoice")
4172+
l1.rpc.preapproveinvoice(bolt11=inv1['bolt11']) # let the signer know this payment is coming
41684173
l1.rpc.sendpay(route, inv1['payment_hash'], payment_secret=inv1['payment_secret'])
41694174
l1.rpc.waitsendpay(inv1['payment_hash'])
41704175

@@ -4192,6 +4197,7 @@ def test_multichan(node_factory, executor, bitcoind):
41924197
before = l2.rpc.listpeerchannels(l3.info['id'])['channels']
41934198
route[1]['channel'] = scid23b
41944199
inv2 = l3.rpc.invoice(100000000, "invoice2", "invoice2")
4200+
l1.rpc.preapproveinvoice(bolt11=inv2['bolt11']) # let the signer know this payment is coming
41954201
l1.rpc.sendpay(route, inv2['payment_hash'], payment_secret=inv2['payment_secret'])
41964202
l1.rpc.waitsendpay(inv2['payment_hash'])
41974203
# Wait until HTLCs fully settled
@@ -4236,6 +4242,7 @@ def test_multichan(node_factory, executor, bitcoind):
42364242
# We can actually pay by *closed* scid (at least until it's completely forgotten)
42374243
route[1]['channel'] = scid23a
42384244
inv3 = l3.rpc.invoice(100000000, "invoice3", "invoice3")
4245+
l1.rpc.preapproveinvoice(bolt11=inv3['bolt11']) # let the signer know this payment is coming
42394246
l1.rpc.sendpay(route, inv3['payment_hash'], payment_secret=inv3['payment_secret'])
42404247
l1.rpc.waitsendpay(inv3['payment_hash'])
42414248

tests/test_pay.py

Lines changed: 26 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'
@@ -702,6 +710,7 @@ def test_repay(node_factory):
702710
'delay': 5,
703711
'channel': first_scid(l1, l2)
704712
}
713+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
705714
l1.rpc.sendpay([routestep], inv['payment_hash'], payment_secret=inv['payment_secret'])
706715
l1.daemon.wait_for_log("Sending 200000000msat over 1 hops to deliver 200000000msat")
707716
l1.rpc.waitsendpay(inv['payment_hash'])['payment_preimage']
@@ -730,6 +739,7 @@ def test_wait_sendpay(node_factory, executor):
730739
'delay': 5,
731740
'channel': first_scid(l1, l2)
732741
}
742+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
733743
l1.rpc.sendpay([routestep], inv['payment_hash'], payment_secret=inv['payment_secret'])
734744
assert wait_created.result(TIMEOUT) == {'subsystem': 'sendpays',
735745
'created': 1,
@@ -1157,6 +1167,7 @@ def test_forward(node_factory, bitcoind):
11571167
# Unknown other peer
11581168
route = copy.deepcopy(baseroute)
11591169
route[1]['id'] = '031a8dc444e41bb989653a4501e11175a488a57439b0c4947704fd6e3de5dca607'
1170+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
11601171
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
11611172
with pytest.raises(RpcError):
11621173
l1.rpc.waitsendpay(rhash)
@@ -1559,6 +1570,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
15591570

15601571
l2.rpc.close(c23, 1)
15611572

1573+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
15621574
with pytest.raises(RpcError):
15631575
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
15641576
l1.rpc.waitsendpay(payment_hash)
@@ -1584,6 +1596,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
15841596
'delay': 6,
15851597
'channel': c24}]
15861598

1599+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
15871600
with pytest.raises(RpcError):
15881601
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
15891602
l1.rpc.waitsendpay(payment_hash)
@@ -1610,6 +1623,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
16101623
'delay': 6,
16111624
'channel': c25}]
16121625

1626+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
16131627
with pytest.raises(RpcError):
16141628
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
16151629
l1.rpc.waitsendpay(payment_hash)
@@ -1633,6 +1647,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
16331647
# Replace id with a different pubkey, so onion encoded badly at l2 hop.
16341648
route[1]['id'] = mangled_nodeid
16351649

1650+
l6.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
16361651
with pytest.raises(RpcError):
16371652
l6.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
16381653
l6.rpc.waitsendpay(payment_hash)
@@ -1660,6 +1675,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
16601675
'delay': 5,
16611676
'channel': c24}]
16621677

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

16651681
l4.daemon.wait_for_log('permfail')
@@ -1715,6 +1731,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17151731

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

17201737
# Now increment CLTV
@@ -1723,6 +1740,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17231740

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

17281746
# Now increment CLTV
@@ -1731,6 +1749,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17311749

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

17361755
# Give them time to go through.
@@ -1796,6 +1815,7 @@ def exhaust_channel(opener, peer, scid, already_spent=0):
17961815
'delay': 10,
17971816
'channel': scid
17981817
}
1818+
opener.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
17991819
opener.rpc.sendpay([routestep], inv['payment_hash'], payment_secret=inv['payment_secret'])
18001820
opener.rpc.waitsendpay(inv['payment_hash'])
18011821

@@ -2513,6 +2533,7 @@ def test_channel_spendable(node_factory, bitcoind):
25132533

25142534
# Exact amount should succeed.
25152535
route = l1.rpc.getroute(l2.info['id'], amount, riskfactor=1, fuzzpercent=0)['route']
2536+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
25162537
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
25172538

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

25392560
# Exact amount should succeed.
25402561
route = l2.rpc.getroute(l1.info['id'], amount, riskfactor=1, fuzzpercent=0)['route']
2562+
l2.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
25412563
l2.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
25422564

25432565
# Amount should drop to 0 once HTLC is sent; we have time, thanks to
@@ -2697,6 +2719,7 @@ def test_htlc_too_dusty_outgoing(node_factory, bitcoind, chainparams):
26972719
route = l1.rpc.getroute(l2.info['id'], non_dust_htlc_val_sat * 1000, 1)['route']
26982720
for i in range(0, 3):
26992721
inv = l2.rpc.invoice((non_dust_htlc_val_sat * 1000), str(i + 100), str(i + 100))
2722+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27002723
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27012724
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
27022725
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])
@@ -2706,20 +2729,23 @@ def test_htlc_too_dusty_outgoing(node_factory, bitcoind, chainparams):
27062729
route = l1.rpc.getroute(l2.info['id'], htlc_val_msat, 1)['route']
27072730
for i in range(0, num_dusty_htlcs):
27082731
inv = l2.rpc.invoice(htlc_val_msat, str(i), str(i))
2732+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27092733
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27102734
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
27112735
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])
27122736
assert res['status'] == 'pending'
27132737

27142738
# one more should tip it over, and return a payment failure
27152739
inv = l2.rpc.invoice(htlc_val_msat, str(num_dusty_htlcs), str(num_dusty_htlcs))
2740+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27162741
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27172742
l1.daemon.wait_for_log('CHANNEL_ERR_DUST_FAILURE')
27182743
wait_for(lambda: only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])['status'] == 'failed')
27192744

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

0 commit comments

Comments
 (0)