Skip to content

Commit 7c5d188

Browse files
committed
tests: add explicit preapprove{invoice,keysend} calls before sendpay
1 parent ce2cb32 commit 7c5d188

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
@@ -1824,6 +1824,7 @@ def test_onchaind_replay(node_factory, bitcoind):
18241824
'delay': 101,
18251825
'channel': first_scid(l1, l2)
18261826
}
1827+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
18271828
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
18281829
l1.daemon.wait_for_log('sendrawtx exit 0')
18291830
bitcoind.generate_block(1, wait_for_mempool=1)
@@ -1967,6 +1968,7 @@ def test_onchain_timeout(node_factory, bitcoind, executor, chainparams, anchors)
19671968
'channel': first_scid(l1, l2)
19681969
}
19691970

1971+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
19701972
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'], groupid=1)
19711973
with pytest.raises(RpcError):
19721974
l1.rpc.waitsendpay(rhash)
@@ -2101,6 +2103,7 @@ def test_onchain_middleman_simple(node_factory, bitcoind, chainparams, anchors):
21012103

21022104
q = queue.Queue()
21032105

2106+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
21042107
def try_pay():
21052108
try:
21062109
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
@@ -2240,6 +2243,7 @@ def test_onchain_middleman_their_unilateral_in(node_factory, bitcoind, chainpara
22402243

22412244
q = queue.Queue()
22422245

2246+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
22432247
def try_pay():
22442248
try:
22452249
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
@@ -2352,6 +2356,8 @@ def try_pay():
23522356
try:
23532357
# rhash is fake (so is payment_secret)
23542358
rhash = 'B1' * 32
2359+
# let the signer know this payment is coming
2360+
l1.rpc.preapprovekeysend(l2.info['id'], rhash, 10**8)
23552361
l1.rpc.sendpay(route, rhash, payment_secret=rhash)
23562362
q.put(None)
23572363
except Exception as err:
@@ -2495,6 +2501,7 @@ def test_onchain_feechange(node_factory, bitcoind, executor):
24952501
'channel': first_scid(l1, l2)
24962502
}
24972503

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

25002507
# l2 will drop to chain.
@@ -2575,6 +2582,7 @@ def test_onchain_all_dust(node_factory, bitcoind, executor):
25752582
'channel': first_scid(l1, l2)
25762583
}
25772584

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

25802588
# l2 will drop to chain.
@@ -3775,6 +3783,7 @@ def test_closing_anchorspend_htlc_tx_rbf(node_factory, bitcoind):
37753783
'delay': 12,
37763784
'channel': first_scid(l1, l2)
37773785
}
3786+
l1.rpc.preapprovekeysend(routestep['id'], rhash, routestep['amount_msat'])
37783787
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
37793788
l2.daemon.wait_for_log('dev_disconnect')
37803789
l2.stop()
@@ -3842,6 +3851,7 @@ def test_htlc_no_force_close(node_factory, bitcoind, anchors):
38423851
'id': l3.info['id'],
38433852
'delay': 10,
38443853
'channel': first_scid(l2, l3)}]
3854+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
38453855
l1.rpc.sendpay(route, inv['payment_hash'],
38463856
payment_secret=inv['payment_secret'])
38473857
l3.daemon.wait_for_log('dev_disconnect')
@@ -3961,6 +3971,7 @@ def test_peer_anchor_push(node_factory, bitcoind, executor, chainparams):
39613971
amt = 100_000_000
39623972
sticky_inv = l3.rpc.invoice(amt, 'sticky', 'sticky')
39633973
route = l1.rpc.getroute(l3.info['id'], amt, 1)['route']
3974+
l1.rpc.preapproveinvoice(bolt11=sticky_inv['bolt11']) # let the signer know this payment is coming
39643975
l1.rpc.sendpay(route, sticky_inv['payment_hash'], payment_secret=sticky_inv['payment_secret'])
39653976
l3.daemon.wait_for_log('dev_disconnect: -WIRE_UPDATE_FULFILL_HTLC')
39663977

tests/test_connection.py

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

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

836837

@@ -861,6 +862,7 @@ def test_reconnect_sender_add(node_factory):
861862
route = [{'amount_msat': amt, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}]
862863

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

894896
route = [{'amount_msat': amt, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}]
897+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
895898
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
896899
for i in range(len(disconnects)):
897900
l1.daemon.wait_for_log('Already have funding locked in')
@@ -921,6 +924,7 @@ def test_reconnect_receiver_fulfill(node_factory):
921924
assert only_one(l2.rpc.listinvoices('testpayment2')['invoices'])['status'] == 'unpaid'
922925

923926
route = [{'amount_msat': amt, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}]
927+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
924928
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
925929
for i in range(len(disconnects)):
926930
l1.daemon.wait_for_log('Already have funding locked in')
@@ -4234,6 +4238,7 @@ def test_multichan(node_factory, executor, bitcoind):
42344238

42354239
before = l2.rpc.listpeerchannels(l3.info['id'])['channels']
42364240
inv1 = l3.rpc.invoice(100000000, "invoice", "invoice")
4241+
l1.rpc.preapproveinvoice(bolt11=inv1['bolt11']) # let the signer know this payment is coming
42374242
l1.rpc.sendpay(route, inv1['payment_hash'], payment_secret=inv1['payment_secret'])
42384243
l1.rpc.waitsendpay(inv1['payment_hash'])
42394244

@@ -4261,6 +4266,7 @@ def test_multichan(node_factory, executor, bitcoind):
42614266
before = l2.rpc.listpeerchannels(l3.info['id'])['channels']
42624267
route[1]['channel'] = scid23b
42634268
inv2 = l3.rpc.invoice(100000000, "invoice2", "invoice2")
4269+
l1.rpc.preapproveinvoice(bolt11=inv2['bolt11']) # let the signer know this payment is coming
42644270
l1.rpc.sendpay(route, inv2['payment_hash'], payment_secret=inv2['payment_secret'])
42654271
l1.rpc.waitsendpay(inv2['payment_hash'])
42664272
# Wait until HTLCs fully settled
@@ -4305,6 +4311,7 @@ def test_multichan(node_factory, executor, bitcoind):
43054311
# We can actually pay by *closed* scid (at least until it's completely forgotten)
43064312
route[1]['channel'] = scid23a
43074313
inv3 = l3.rpc.invoice(100000000, "invoice3", "invoice3")
4314+
l1.rpc.preapproveinvoice(bolt11=inv3['bolt11']) # let the signer know this payment is coming
43084315
l1.rpc.sendpay(route, inv3['payment_hash'], payment_secret=inv3['payment_secret'])
43094316
l1.rpc.waitsendpay(inv3['payment_hash'])
43104317

tests/test_pay.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ def invoice_unpaid(dst, label):
577577
with pytest.raises(RpcError):
578578
rs = copy.deepcopy(routestep)
579579
rs['amount_msat'] = rs['amount_msat'] - 1
580+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
580581
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
581582
l1.rpc.waitsendpay(rhash)
582583
assert invoice_unpaid(l2, 'testpayment2')
@@ -585,6 +586,7 @@ def invoice_unpaid(dst, label):
585586
with pytest.raises(RpcError):
586587
rs = copy.deepcopy(routestep)
587588
rs['amount_msat'] = rs['amount_msat'] * 2 + 1
589+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
588590
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
589591
l1.rpc.waitsendpay(rhash)
590592
assert invoice_unpaid(l2, 'testpayment2')
@@ -593,6 +595,7 @@ def invoice_unpaid(dst, label):
593595
with pytest.raises(RpcError):
594596
rs = copy.deepcopy(routestep)
595597
rs['delay'] = rs['delay'] - 2
598+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
596599
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
597600
l1.rpc.waitsendpay(rhash)
598601
assert invoice_unpaid(l2, 'testpayment2')
@@ -602,17 +605,20 @@ def invoice_unpaid(dst, label):
602605
with pytest.raises(RpcError):
603606
rs = copy.deepcopy(routestep)
604607
rs['id'] = '00000000000000000000000000000000'
608+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
605609
l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
606610
assert invoice_unpaid(l2, 'testpayment2')
607611
l1.rpc.check_request_schemas = True
608612

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

615620
# Missing payment_secret
621+
l1.rpc.preapprovekeysend(l2.info['id'], rhash, routestep['amount_msat'])
616622
l1.rpc.sendpay([routestep], rhash)
617623
with pytest.raises(RpcError):
618624
l1.rpc.waitsendpay(rhash)
@@ -628,6 +634,7 @@ def invoice_unpaid(dst, label):
628634

629635
# This works.
630636
before = int(time.time())
637+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
631638
details = l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
632639
after = int(time.time())
633640
preimage = l1.rpc.waitsendpay(rhash)['payment_preimage']
@@ -670,6 +677,7 @@ def check_balances():
670677
rhash = inv['payment_hash']
671678
assert only_one(l2.rpc.listinvoices('testpayment3')['invoices'])['status'] == 'unpaid'
672679
routestep = {'amount_msat': amt * 2, 'id': l2.info['id'], 'delay': 5, 'channel': first_scid(l1, l2)}
680+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
673681
l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
674682
preimage3 = l1.rpc.waitsendpay(rhash)['payment_preimage']
675683
assert only_one(l2.rpc.listinvoices('testpayment3')['invoices'])['status'] == 'paid'
@@ -705,6 +713,7 @@ def test_repay(node_factory):
705713
'delay': 5,
706714
'channel': first_scid(l1, l2)
707715
}
716+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
708717
l1.rpc.sendpay([routestep], inv['payment_hash'], payment_secret=inv['payment_secret'])
709718
l1.daemon.wait_for_log("Sending 200000000msat over 1 hops to deliver 200000000msat")
710719
l1.rpc.waitsendpay(inv['payment_hash'])['payment_preimage']
@@ -733,6 +742,7 @@ def test_wait_sendpay(node_factory, executor):
733742
'delay': 5,
734743
'channel': first_scid(l1, l2)
735744
}
745+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
736746
l1.rpc.sendpay([routestep], inv['payment_hash'], payment_secret=inv['payment_secret'])
737747
assert wait_created.result(TIMEOUT) == {'subsystem': 'sendpays',
738748
'created': 1,
@@ -1160,6 +1170,7 @@ def test_forward(node_factory, bitcoind):
11601170
# Unknown other peer
11611171
route = copy.deepcopy(baseroute)
11621172
route[1]['id'] = '031a8dc444e41bb989653a4501e11175a488a57439b0c4947704fd6e3de5dca607'
1173+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
11631174
l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
11641175
with pytest.raises(RpcError):
11651176
l1.rpc.waitsendpay(rhash)
@@ -1563,6 +1574,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
15631574

15641575
l2.rpc.close(c23, 1)
15651576

1577+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
15661578
with pytest.raises(RpcError):
15671579
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
15681580
l1.rpc.waitsendpay(payment_hash)
@@ -1588,6 +1600,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
15881600
'delay': 6,
15891601
'channel': c24}]
15901602

1603+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
15911604
with pytest.raises(RpcError):
15921605
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
15931606
l1.rpc.waitsendpay(payment_hash)
@@ -1614,6 +1627,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
16141627
'delay': 6,
16151628
'channel': c25}]
16161629

1630+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
16171631
with pytest.raises(RpcError):
16181632
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
16191633
l1.rpc.waitsendpay(payment_hash)
@@ -1637,6 +1651,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
16371651
# Replace id with a different pubkey, so onion encoded badly at l2 hop.
16381652
route[1]['id'] = mangled_nodeid
16391653

1654+
l6.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
16401655
with pytest.raises(RpcError):
16411656
l6.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
16421657
l6.rpc.waitsendpay(payment_hash)
@@ -1664,6 +1679,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
16641679
'delay': 5,
16651680
'channel': c24}]
16661681

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

16691685
l4.daemon.wait_for_log('permfail')
@@ -1719,6 +1735,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17191735

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

17241741
# Now increment CLTV
@@ -1727,6 +1744,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17271744

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

17321750
# Now increment CLTV
@@ -1735,6 +1753,7 @@ def test_htlcs_cltv_only_difference(node_factory, bitcoind):
17351753

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

17401759
# Give them time to go through.
@@ -1800,6 +1819,7 @@ def exhaust_channel(opener, peer, scid, already_spent=0):
18001819
'delay': 10,
18011820
'channel': scid
18021821
}
1822+
opener.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
18031823
opener.rpc.sendpay([routestep], inv['payment_hash'], payment_secret=inv['payment_secret'])
18041824
opener.rpc.waitsendpay(inv['payment_hash'])
18051825

@@ -2527,6 +2547,7 @@ def test_channel_spendable(node_factory, bitcoind):
25272547

25282548
# Exact amount should succeed.
25292549
route = l1.rpc.getroute(l2.info['id'], amount, riskfactor=1, fuzzpercent=0)['route']
2550+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
25302551
l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
25312552

25322553
# Amount should drop to 0 once HTLC is sent; we have time, thanks to
@@ -2552,6 +2573,7 @@ def test_channel_spendable(node_factory, bitcoind):
25522573

25532574
# Exact amount should succeed.
25542575
route = l2.rpc.getroute(l1.info['id'], amount, riskfactor=1, fuzzpercent=0)['route']
2576+
l2.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
25552577
l2.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
25562578

25572579
# Amount should drop to 0 once HTLC is sent; we have time, thanks to
@@ -2710,6 +2732,7 @@ def test_htlc_too_dusty_outgoing(node_factory, bitcoind, chainparams):
27102732
route = l1.rpc.getroute(l2.info['id'], non_dust_htlc_val_sat * 1000, 1)['route']
27112733
for i in range(0, 3):
27122734
inv = l2.rpc.invoice((non_dust_htlc_val_sat * 1000), str(i + 100), str(i + 100))
2735+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27132736
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27142737
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
27152738
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])
@@ -2719,20 +2742,23 @@ def test_htlc_too_dusty_outgoing(node_factory, bitcoind, chainparams):
27192742
route = l1.rpc.getroute(l2.info['id'], htlc_val_msat, 1)['route']
27202743
for i in range(0, num_dusty_htlcs):
27212744
inv = l2.rpc.invoice(htlc_val_msat, str(i), str(i))
2745+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27222746
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27232747
l2.daemon.wait_for_log(r'their htlc .* dev_ignore_htlcs')
27242748
res = only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])
27252749
assert res['status'] == 'pending'
27262750

27272751
# one more should tip it over, and return a payment failure
27282752
inv = l2.rpc.invoice(htlc_val_msat, str(num_dusty_htlcs), str(num_dusty_htlcs))
2753+
l1.rpc.preapproveinvoice(bolt11=inv['bolt11']) # let the signer know this payment is coming
27292754
l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
27302755
l1.daemon.wait_for_log('CHANNEL_ERR_DUST_FAILURE')
27312756
wait_for(lambda: only_one(l1.rpc.listsendpays(payment_hash=inv['payment_hash'])['payments'])['status'] == 'failed')
27322757

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

0 commit comments

Comments
 (0)