Skip to content

Commit 07acd0c

Browse files
committed
tests: Add explicit preapprove{invoice,keysend} calls before sendpay
1 parent 7511716 commit 07acd0c

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
@@ -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: 24 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'
@@ -1158,6 +1166,7 @@ def test_forward(node_factory, bitcoind):
11581166
# Unknown other peer
11591167
route = copy.deepcopy(baseroute)
11601168
route[1]['id'] = '031a8dc444e41bb989653a4501e11175a488a57439b0c4947704fd6e3de5dca607'
1169+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
11611170
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
11621171
with pytest.raises(RpcError):
11631172
l1.rpc.waitsendpay(rhash)
@@ -1560,6 +1569,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
15601569

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

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

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

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

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

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

16661680
l4.daemon.wait_for_log('permfail')
@@ -1716,6 +1730,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17161730

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

17211736
# Now increment CLTV
@@ -1724,6 +1739,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17241739

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

17291745
# Now increment CLTV
@@ -1732,6 +1748,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17321748

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

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

@@ -2515,6 +2533,7 @@ def test_channel_spendable(node_factory, bitcoind):
25152533

25162534
# Exact amount should succeed.
25172535
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
25182537
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
25192538

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

25412560
# Exact amount should succeed.
25422561
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
25432563
l2.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
25442564

25452565
# Amount should drop to 0 once HTLC is sent; we have time, thanks to
@@ -2701,6 +2721,7 @@ def test_htlc_too_dusty_outgoing(node_factory, bitcoind, chainparams):
27012721
route = l1.rpc.getroute(l2.info['id'], non_dust_htlc_val_sat * 1000, 1)['route']
27022722
for i in range(0, 3):
27032723
inv = l2.rpc.invoice((non_dust_htlc_val_sat * 1000), str(i + 100), str(i + 100))
2724+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27042725
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27052726
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
27062727
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])
@@ -2710,20 +2731,23 @@ def test_htlc_too_dusty_outgoing(node_factory, bitcoind, chainparams):
27102731
route = l1.rpc.getroute(l2.info['id'], htlc_val_msat, 1)['route']
27112732
for i in range(0, num_dusty_htlcs):
27122733
inv = l2.rpc.invoice(htlc_val_msat, str(i), str(i))
2734+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27132735
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27142736
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
27152737
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])
27162738
assert res['status'] == 'pending'
27172739

27182740
# one more should tip it over, and return a payment failure
27192741
inv = l2.rpc.invoice(htlc_val_msat, str(num_dusty_htlcs), str(num_dusty_htlcs))
2742+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27202743
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27212744
l1.daemon.wait_for_log('CHANNEL_ERR_DUST_FAILURE')
27222745
wait_for(lambda: only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])['status'] == 'failed')
27232746

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

0 commit comments

Comments
 (0)