Skip to content

Commit 51dd34a

Browse files
committed
tests: Add explicit preapprove{invoice,keysend} calls before sendpay
1 parent 3fc4060 commit 51dd34a

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
@@ -1834,6 +1834,7 @@ def test_onchaind_replay(node_factory, bitcoind):
18341834
'delay': 101,
18351835
'channel': first_scid(l1, l2)
18361836
}
1837+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
18371838
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
18381839
l1.daemon.wait_for_log('sendrawtx exit 0')
18391840
bitcoind.generate_block(1, wait_for_mempool=1)
@@ -1979,6 +1980,7 @@ def test_onchain_timeout(node_factory, bitcoind, executor, chainparams, anchors)
19791980
'channel': first_scid(l1, l2)
19801981
}
19811982

1983+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
19821984
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'], groupid=1)
19831985
with pytest.raises(RpcError):
19841986
l1.rpc.waitsendpay(rhash)
@@ -2114,6 +2116,7 @@ def test_onchain_middleman_simple(node_factory, bitcoind, chainparams, anchors):
21142116

21152117
q = queue.Queue()
21162118

2119+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
21172120
def try_pay():
21182121
try:
21192122
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
@@ -2254,6 +2257,7 @@ def test_onchain_middleman_their_unilateral_in(node_factory, bitcoind, chainpara
22542257

22552258
q = queue.Queue()
22562259

2260+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
22572261
def try_pay():
22582262
try:
22592263
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
@@ -2365,6 +2369,8 @@ def try_pay():
23652369
try:
23662370
# rhash is fake (so is payment_secret)
23672371
rhash = 'B1' * 32
2372+
# let the signer know this payment is coming
2373+
l1.rpc.preapprovekeysend(l2.info['id'], rhash, 10**8)
23682374
l1.rpc.sendpay(route, rhash, payment_secret=rhash)
23692375
q.put(None)
23702376
except Exception as err:
@@ -2506,6 +2512,7 @@ def test_onchain_feechange(node_factory, bitcoind, executor):
25062512
'channel': first_scid(l1, l2)
25072513
}
25082514

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

25112518
# l2 will drop to chain.
@@ -2587,6 +2594,7 @@ def test_onchain_all_dust(node_factory, bitcoind, executor):
25872594
'channel': first_scid(l1, l2)
25882595
}
25892596

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

25922600
# l2 will drop to chain.

tests/test_connection.py

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

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

862863

@@ -888,6 +889,7 @@ def test_reconnect_sender_add(node_factory):
888889
route = [{'amount_msat': amt, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}]
889890

890891
# This will send commit, so will reconnect as required.
892+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
891893
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
892894
# Should have printed this for every reconnect.
893895
for i in range(0, len(disconnects)):
@@ -920,6 +922,7 @@ def test_reconnect_receiver_add(node_factory):
920922
assert only_one(l2.rpc.listinvoices('testpayment2')['invoices'])['status'] == 'unpaid'
921923

922924
route = [{'amount_msat': amt, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}]
925+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
923926
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
924927
for i in range(len(disconnects)):
925928
l1.daemon.wait_for_log('Already have funding locked in')
@@ -950,6 +953,7 @@ def test_reconnect_receiver_fulfill(node_factory):
950953
assert only_one(l2.rpc.listinvoices('testpayment2')['invoices'])['status'] == 'unpaid'
951954

952955
route = [{'amount_msat': amt, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}]
956+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
953957
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
954958
for i in range(len(disconnects)):
955959
l1.daemon.wait_for_log('Already have funding locked in')
@@ -4248,6 +4252,7 @@ def test_multichan(node_factory, executor, bitcoind):
42484252

42494253
before = l2.rpc.listpeerchannels(l3.info['id'])['channels']
42504254
inv1 = l3.rpc.invoice(100000000, "invoice", "invoice")
4255+
l1.rpc.preapproveinvoice(bolt11=inv1['bolt11']) # let the signer know this payment is coming
42514256
l1.rpc.sendpay(route, inv1['payment_hash'], payment_secret=inv1['payment_secret'])
42524257
l1.rpc.waitsendpay(inv1['payment_hash'])
42534258

@@ -4275,6 +4280,7 @@ def test_multichan(node_factory, executor, bitcoind):
42754280
before = l2.rpc.listpeerchannels(l3.info['id'])['channels']
42764281
route[1]['channel'] = scid23b
42774282
inv2 = l3.rpc.invoice(100000000, "invoice2", "invoice2")
4283+
l1.rpc.preapproveinvoice(bolt11=inv2['bolt11']) # let the signer know this payment is coming
42784284
l1.rpc.sendpay(route, inv2['payment_hash'], payment_secret=inv2['payment_secret'])
42794285
l1.rpc.waitsendpay(inv2['payment_hash'])
42804286
# Wait until HTLCs fully settled
@@ -4319,6 +4325,7 @@ def test_multichan(node_factory, executor, bitcoind):
43194325
# We can actually pay by *closed* scid (at least until it's completely forgotten)
43204326
route[1]['channel'] = scid23a
43214327
inv3 = l3.rpc.invoice(100000000, "invoice3", "invoice3")
4328+
l1.rpc.preapproveinvoice(bolt11=inv3['bolt11']) # let the signer know this payment is coming
43224329
l1.rpc.sendpay(route, inv3['payment_hash'], payment_secret=inv3['payment_secret'])
43234330
l1.rpc.waitsendpay(inv3['payment_hash'])
43244331

tests/test_pay.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ def invoice_unpaid(dst, label):
584584
with pytest.raises(RpcError):
585585
rs = copy.deepcopy(routestep)
586586
rs['amount_msat'] = rs['amount_msat'] - 1
587+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
587588
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
588589
l1.rpc.waitsendpay(rhash)
589590
assert invoice_unpaid(l2, 'testpayment2')
@@ -592,6 +593,7 @@ def invoice_unpaid(dst, label):
592593
with pytest.raises(RpcError):
593594
rs = copy.deepcopy(routestep)
594595
rs['amount_msat'] = rs['amount_msat'] * 2 + 1
596+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
595597
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
596598
l1.rpc.waitsendpay(rhash)
597599
assert invoice_unpaid(l2, 'testpayment2')
@@ -600,6 +602,7 @@ def invoice_unpaid(dst, label):
600602
with pytest.raises(RpcError):
601603
rs = copy.deepcopy(routestep)
602604
rs['delay'] = rs['delay'] - 2
605+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
603606
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
604607
l1.rpc.waitsendpay(rhash)
605608
assert invoice_unpaid(l2, 'testpayment2')
@@ -609,17 +612,20 @@ def invoice_unpaid(dst, label):
609612
with pytest.raises(RpcError):
610613
rs = copy.deepcopy(routestep)
611614
rs['id'] = '00000000000000000000000000000000'
615+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
612616
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
613617
assert invoice_unpaid(l2, 'testpayment2')
614618
l1.rpc.check_request_schemas = True
615619

616620
# Bad payment_secret
621+
l1.rpc.preapprovekeysend(l2.info['id'], rhash, routestep['amount_msat'])
617622
l1.rpc.sendpay([routestep], rhash, payment_secret="00" * 32)
618623
with pytest.raises(RpcError):
619624
l1.rpc.waitsendpay(rhash)
620625
assert invoice_unpaid(l2, 'testpayment2')
621626

622627
# Missing payment_secret
628+
l1.rpc.preapprovekeysend(l2.info['id'], rhash, routestep['amount_msat'])
623629
l1.rpc.sendpay([routestep], rhash)
624630
with pytest.raises(RpcError):
625631
l1.rpc.waitsendpay(rhash)
@@ -635,6 +641,7 @@ def invoice_unpaid(dst, label):
635641

636642
# This works.
637643
before = int(time.time())
644+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
638645
details = l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
639646
after = int(time.time())
640647
preimage = l1.rpc.waitsendpay(rhash)['payment_preimage']
@@ -677,6 +684,7 @@ def check_balances():
677684
rhash = inv['payment_hash']
678685
assert only_one(l2.rpc.listinvoices('testpayment3')['invoices'])['status'] == 'unpaid'
679686
routestep = {'amount_msat': amt * 2, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}
687+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
680688
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
681689
preimage3 = l1.rpc.waitsendpay(rhash)['payment_preimage']
682690
assert only_one(l2.rpc.listinvoices('testpayment3')['invoices'])['status'] == 'paid'
@@ -1112,6 +1120,7 @@ def test_forward(node_factory, bitcoind):
11121120
# Unknown other peer
11131121
route = copy.deepcopy(baseroute)
11141122
route[1]['id'] = '031a8dc444e41bb989653a4501e11175a488a57439b0c4947704fd6e3de5dca607'
1123+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
11151124
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
11161125
with pytest.raises(RpcError):
11171126
l1.rpc.waitsendpay(rhash)
@@ -1518,6 +1527,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
15181527

15191528
l2.rpc.close(c23, 1)
15201529

1530+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
15211531
with pytest.raises(RpcError):
15221532
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
15231533
l1.rpc.waitsendpay(payment_hash)
@@ -1543,6 +1553,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
15431553
'delay': 6,
15441554
'channel': c24}]
15451555

1556+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
15461557
with pytest.raises(RpcError):
15471558
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
15481559
l1.rpc.waitsendpay(payment_hash)
@@ -1569,6 +1580,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
15691580
'delay': 6,
15701581
'channel': c25}]
15711582

1583+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
15721584
with pytest.raises(RpcError):
15731585
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
15741586
l1.rpc.waitsendpay(payment_hash)
@@ -1592,6 +1604,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
15921604
# Replace id with a different pubkey, so onion encoded badly at l2 hop.
15931605
route[1]['id'] = mangled_nodeid
15941606

1607+
l6.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
15951608
with pytest.raises(RpcError):
15961609
l6.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
15971610
l6.rpc.waitsendpay(payment_hash)
@@ -1619,6 +1632,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
16191632
'delay': 5,
16201633
'channel': c24}]
16211634

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

16241638
l4.daemon.wait_for_log('permfail')
@@ -1675,6 +1689,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
16751689

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

16801695
# Now increment CLTV
@@ -1683,6 +1698,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
16831698

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

16881704
# Now increment CLTV
@@ -1691,6 +1707,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
16911707

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

16961713
# Give them time to go through.
@@ -1757,6 +1774,7 @@ def exhaust_channel(opener, peer, scid, already_spent=0):
17571774
'delay': 10,
17581775
'channel': scid
17591776
}
1777+
opener.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
17601778
opener.rpc.sendpay([routestep], inv['payment_hash'], payment_secret=inv['payment_secret'])
17611779
opener.rpc.waitsendpay(inv['payment_hash'])
17621780

@@ -2484,6 +2502,7 @@ def test_channel_spendable(node_factory, bitcoind):
24842502

24852503
# Exact amount should succeed.
24862504
route = l1.rpc.getroute(l2.info['id'], amount, riskfactor=1, fuzzpercent=0)['route']
2505+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
24872506
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
24882507

24892508
# Amount should drop to 0 once HTLC is sent; we have time, thanks to
@@ -2509,6 +2528,7 @@ def test_channel_spendable(node_factory, bitcoind):
25092528

25102529
# Exact amount should succeed.
25112530
route = l2.rpc.getroute(l1.info['id'], amount, riskfactor=1, fuzzpercent=0)['route']
2531+
l2.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
25122532
l2.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
25132533

25142534
# Amount should drop to 0 once HTLC is sent; we have time, thanks to
@@ -2671,6 +2691,7 @@ def test_htlc_too_dusty_outgoing(node_factory, bitcoind, chainparams):
26712691
route = l1.rpc.getroute(l2.info['id'], non_dust_htlc_val_sat * 1000, 1)['route']
26722692
for i in range(0, 3):
26732693
inv = l2.rpc.invoice((non_dust_htlc_val_sat * 1000), str(i + 100), str(i + 100))
2694+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
26742695
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
26752696
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
26762697
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])
@@ -2680,20 +2701,23 @@ def test_htlc_too_dusty_outgoing(node_factory, bitcoind, chainparams):
26802701
route = l1.rpc.getroute(l2.info['id'], htlc_val_msat, 1)['route']
26812702
for i in range(0, num_dusty_htlcs):
26822703
inv = l2.rpc.invoice(htlc_val_msat, str(i), str(i))
2704+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
26832705
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
26842706
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
26852707
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])
26862708
assert res['status'] == 'pending'
26872709

26882710
# one more should tip it over, and return a payment failure
26892711
inv = l2.rpc.invoice(htlc_val_msat, str(num_dusty_htlcs), str(num_dusty_htlcs))
2712+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
26902713
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
26912714
l1.daemon.wait_for_log('CHANNEL_ERR_DUST_FAILURE')
26922715
wait_for(lambda: only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])['status'] == 'failed')
26932716

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

0 commit comments

Comments
 (0)