Skip to content

Commit 985b009

Browse files
committed
tests: Add explicit preapprove{invoice,keysend} calls before sendpay
1 parent f48c7ee commit 985b009

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
@@ -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.
@@ -3753,6 +3761,7 @@ def test_closing_anchorspend_htlc_tx_rbf(node_factory, bitcoind):
37533761
'delay': 12,
37543762
'channel': first_scid(l1, l2)
37553763
}
3764+
l1.rpc.preapprovekeysend(routestep['id'], rhash, routestep['amount_msat'])
37563765
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
37573766
l2.daemon.wait_for_log('dev_disconnect')
37583767
l2.stop()
@@ -3820,6 +3829,7 @@ def test_htlc_no_force_close(node_factory, bitcoind, anchors):
38203829
'id': l3.info['id'],
38213830
'delay': 10,
38223831
'channel': first_scid(l2, l3)}]
3832+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
38233833
l1.rpc.sendpay(route, inv['payment_hash'],
38243834
payment_secret=inv['payment_secret'])
38253835
l3.daemon.wait_for_log('dev_disconnect')
@@ -3941,6 +3951,7 @@ def test_peer_anchor_push(node_factory, bitcoind, executor, chainparams):
39413951
amt = 100_000_000
39423952
sticky_inv = l3.rpc.invoice(amt, 'sticky', 'sticky')
39433953
route = l1.rpc.getroute(l3.info['id'], amt, 1)['route']
3954+
l1.rpc.preapproveinvoice(bolt11=sticky_inv['bolt11']) # let the signer know this payment is coming
39443955
l1.rpc.sendpay(route, sticky_inv['payment_hash'], payment_secret=sticky_inv['payment_secret'])
39453956
l3.daemon.wait_for_log('dev_disconnect: -WIRE_UPDATE_FULFILL_HTLC')
39463957

tests/test_connection.py

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

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

851852

@@ -876,6 +877,7 @@ def test_reconnect_sender_add(node_factory):
876877
route = [{'amount_msat': amt, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}]
877878

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

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

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

41794183
before = l2.rpc.listpeerchannels(l3.info['id'])['channels']
41804184
inv1 = l3.rpc.invoice(100000000, "invoice", "invoice")
4185+
l1.rpc.preapproveinvoice(bolt11=inv1['bolt11']) # let the signer know this payment is coming
41814186
l1.rpc.sendpay(route, inv1['payment_hash'], payment_secret=inv1['payment_secret'])
41824187
l1.rpc.waitsendpay(inv1['payment_hash'])
41834188

@@ -4205,6 +4210,7 @@ def test_multichan(node_factory, executor, bitcoind):
42054210
before = l2.rpc.listpeerchannels(l3.info['id'])['channels']
42064211
route[1]['channel'] = scid23b
42074212
inv2 = l3.rpc.invoice(100000000, "invoice2", "invoice2")
4213+
l1.rpc.preapproveinvoice(bolt11=inv2['bolt11']) # let the signer know this payment is coming
42084214
l1.rpc.sendpay(route, inv2['payment_hash'], payment_secret=inv2['payment_secret'])
42094215
l1.rpc.waitsendpay(inv2['payment_hash'])
42104216
# Wait until HTLCs fully settled
@@ -4249,6 +4255,7 @@ def test_multichan(node_factory, executor, bitcoind):
42494255
# We can actually pay by *closed* scid (at least until it's completely forgotten)
42504256
route[1]['channel'] = scid23a
42514257
inv3 = l3.rpc.invoice(100000000, "invoice3", "invoice3")
4258+
l1.rpc.preapproveinvoice(bolt11=inv3['bolt11']) # let the signer know this payment is coming
42524259
l1.rpc.sendpay(route, inv3['payment_hash'], payment_secret=inv3['payment_secret'])
42534260
l1.rpc.waitsendpay(inv3['payment_hash'])
42544261

tests/test_pay.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ def invoice_unpaid(dst, label):
575575
with pytest.raises(RpcError):
576576
rs = copy.deepcopy(routestep)
577577
rs['amount_msat'] = rs['amount_msat'] - 1
578+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
578579
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
579580
l1.rpc.waitsendpay(rhash)
580581
assert invoice_unpaid(l2, 'testpayment2')
@@ -583,6 +584,7 @@ def invoice_unpaid(dst, label):
583584
with pytest.raises(RpcError):
584585
rs = copy.deepcopy(routestep)
585586
rs['amount_msat'] = rs['amount_msat'] * 2 + 1
587+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
586588
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
587589
l1.rpc.waitsendpay(rhash)
588590
assert invoice_unpaid(l2, 'testpayment2')
@@ -591,6 +593,7 @@ def invoice_unpaid(dst, label):
591593
with pytest.raises(RpcError):
592594
rs = copy.deepcopy(routestep)
593595
rs['delay'] = rs['delay'] - 2
596+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
594597
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
595598
l1.rpc.waitsendpay(rhash)
596599
assert invoice_unpaid(l2, 'testpayment2')
@@ -600,17 +603,20 @@ def invoice_unpaid(dst, label):
600603
with pytest.raises(RpcError):
601604
rs = copy.deepcopy(routestep)
602605
rs['id'] = '00000000000000000000000000000000'
606+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
603607
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
604608
assert invoice_unpaid(l2, 'testpayment2')
605609
l1.rpc.check_request_schemas = True
606610

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

613618
# Missing payment_secret
619+
l1.rpc.preapprovekeysend(l2.info['id'], rhash, routestep['amount_msat'])
614620
l1.rpc.sendpay([routestep], rhash)
615621
with pytest.raises(RpcError):
616622
l1.rpc.waitsendpay(rhash)
@@ -626,6 +632,7 @@ def invoice_unpaid(dst, label):
626632

627633
# This works.
628634
before = int(time.time())
635+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
629636
details = l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
630637
after = int(time.time())
631638
preimage = l1.rpc.waitsendpay(rhash)['payment_preimage']
@@ -668,6 +675,7 @@ def check_balances():
668675
rhash = inv['payment_hash']
669676
assert only_one(l2.rpc.listinvoices('testpayment3')['invoices'])['status'] == 'unpaid'
670677
routestep = {'amount_msat': amt * 2, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}
678+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
671679
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
672680
preimage3 = l1.rpc.waitsendpay(rhash)['payment_preimage']
673681
assert only_one(l2.rpc.listinvoices('testpayment3')['invoices'])['status'] == 'paid'
@@ -703,6 +711,7 @@ def test_repay(node_factory):
703711
'delay': 5,
704712
'channel': first_scid(l1, l2)
705713
}
714+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
706715
l1.rpc.sendpay([routestep], inv['payment_hash'], payment_secret=inv['payment_secret'])
707716
l1.daemon.wait_for_log("Sending 200000000msat over 1 hops to deliver 200000000msat")
708717
l1.rpc.waitsendpay(inv['payment_hash'])['payment_preimage']
@@ -731,6 +740,7 @@ def test_wait_sendpay(node_factory, executor):
731740
'delay': 5,
732741
'channel': first_scid(l1, l2)
733742
}
743+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
734744
l1.rpc.sendpay([routestep], inv['payment_hash'], payment_secret=inv['payment_secret'])
735745
assert wait_created.result(TIMEOUT) == {'subsystem': 'sendpays',
736746
'created': 1,
@@ -1158,6 +1168,7 @@ def test_forward(node_factory, bitcoind):
11581168
# Unknown other peer
11591169
route = copy.deepcopy(baseroute)
11601170
route[1]['id'] = '031a8dc444e41bb989653a4501e11175a488a57439b0c4947704fd6e3de5dca607'
1171+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
11611172
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
11621173
with pytest.raises(RpcError):
11631174
l1.rpc.waitsendpay(rhash)
@@ -1560,6 +1571,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
15601571

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

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

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

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

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

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

16661682
l4.daemon.wait_for_log('permfail')
@@ -1716,6 +1732,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17161732

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

17211738
# Now increment CLTV
@@ -1724,6 +1741,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17241741

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

17291747
# Now increment CLTV
@@ -1732,6 +1750,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17321750

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

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

@@ -2515,6 +2535,7 @@ def test_channel_spendable(node_factory, bitcoind):
25152535

25162536
# Exact amount should succeed.
25172537
route = l1.rpc.getroute(l2.info['id'], amount, riskfactor=1, fuzzpercent=0)['route']
2538+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
25182539
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
25192540

25202541
# Amount should drop to 0 once HTLC is sent; we have time, thanks to
@@ -2540,6 +2561,7 @@ def test_channel_spendable(node_factory, bitcoind):
25402561

25412562
# Exact amount should succeed.
25422563
route = l2.rpc.getroute(l1.info['id'], amount, riskfactor=1, fuzzpercent=0)['route']
2564+
l2.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
25432565
l2.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
25442566

25452567
# Amount should drop to 0 once HTLC is sent; we have time, thanks to
@@ -2701,6 +2723,7 @@ def test_htlc_too_dusty_outgoing(node_factory, bitcoind, chainparams):
27012723
route = l1.rpc.getroute(l2.info['id'], non_dust_htlc_val_sat * 1000, 1)['route']
27022724
for i in range(0, 3):
27032725
inv = l2.rpc.invoice((non_dust_htlc_val_sat * 1000), str(i + 100), str(i + 100))
2726+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27042727
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27052728
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
27062729
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])
@@ -2710,20 +2733,23 @@ def test_htlc_too_dusty_outgoing(node_factory, bitcoind, chainparams):
27102733
route = l1.rpc.getroute(l2.info['id'], htlc_val_msat, 1)['route']
27112734
for i in range(0, num_dusty_htlcs):
27122735
inv = l2.rpc.invoice(htlc_val_msat, str(i), str(i))
2736+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27132737
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27142738
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
27152739
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])
27162740
assert res['status'] == 'pending'
27172741

27182742
# one more should tip it over, and return a payment failure
27192743
inv = l2.rpc.invoice(htlc_val_msat, str(num_dusty_htlcs), str(num_dusty_htlcs))
2744+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27202745
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27212746
l1.daemon.wait_for_log('CHANNEL_ERR_DUST_FAILURE')
27222747
wait_for(lambda: only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])['status'] == 'failed')
27232748

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

0 commit comments

Comments
 (0)