MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_channel_receivable

Function test_channel_receivable

tests/test_pay.py:2690–2764  ·  view source on GitHub ↗

Test that receivable_msat is accurate

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

2688
2689
2690def test_channel_receivable(node_factory, bitcoind):
2691 """Test that receivable_msat is accurate"""
2692 sats = 10**6
2693 l1, l2 = node_factory.line_graph(2, fundamount=sats, wait_for_announce=True,
2694 opts={'plugin': os.path.join(os.getcwd(), 'tests/plugins/hold_invoice.py')})
2695
2696 inv = l2.rpc.invoice('any', 'inv', 'for testing')
2697 payment_hash = inv['payment_hash']
2698
2699 # We should be able to receive this much, and not one msat more!
2700 amount = l2.rpc.listpeerchannels()['channels'][0]['receivable_msat']
2701 # If we get askrene to use the auto.localchans layer, it will know!
2702 # So use getroutes without that
2703 route = only_one(l1.rpc.getroutes(source=l1.info['id'],
2704 destination=l2.info['id'],
2705 amount_msat=amount + 1,
2706 layers=["auto.sourcefree"],
2707 maxfee_msat=10000000,
2708 final_cltv=9,
2709 maxparts=1)['routes'])['path']
2710 l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
2711
2712 # This should fail locally with "capacity exceeded"
2713 with pytest.raises(RpcError, match=r"Capacity exceeded.*'erring_index': 0"):
2714 l1.rpc.waitsendpay(payment_hash, TIMEOUT)
2715
2716 # Exact amount should succeed.
2717 route = only_one(l1.rpc.getroutes(source=l1.info['id'],
2718 destination=l2.info['id'],
2719 amount_msat=amount,
2720 layers=["auto.sourcefree"],
2721 maxfee_msat=10000000,
2722 final_cltv=9,
2723 maxparts=1)['routes'])['path']
2724 l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
2725
2726 # Amount should drop to 0 once HTLC is sent; we have time, thanks to
2727 # hold_invoice.py plugin.
2728 wait_for(lambda: len(l2.rpc.listpeerchannels()['channels'][0]['htlcs']) == 1)
2729 assert l2.rpc.listpeerchannels()['channels'][0]['receivable_msat'] == Millisatoshi(0)
2730 open(os.path.join(l2.daemon.lightning_dir, TEST_NETWORK, "unhold"), "w").close()
2731 l1.rpc.waitsendpay(payment_hash, TIMEOUT)
2732
2733 # Make sure both think it's all over.
2734 wait_for(lambda: len(l1.rpc.listpeerchannels()['channels'][0]['htlcs']) == 0)
2735 wait_for(lambda: len(l2.rpc.listpeerchannels()['channels'][0]['htlcs']) == 0)
2736 # Now, reverse should work similarly.
2737 inv = l1.rpc.invoice('any', 'inv', 'for testing')
2738 payment_hash = inv['payment_hash']
2739 amount = l1.rpc.listpeerchannels()['channels'][0]['receivable_msat']
2740
2741 # Turns out we won't route this, as it's over max - reserve:
2742 route = only_one(l2.rpc.getroutes(source=l2.info['id'],
2743 destination=l1.info['id'],
2744 amount_msat=amount + 1,
2745 layers=["auto.sourcefree"],
2746 maxfee_msat=10000000,
2747 final_cltv=9,

Callers

nothing calls this directly

Calls 12

only_oneFunction · 0.90
wait_forFunction · 0.90
MillisatoshiClass · 0.90
line_graphMethod · 0.80
joinMethod · 0.80
listpeerchannelsMethod · 0.80
getroutesMethod · 0.80
sendpayMethod · 0.80
waitsendpayMethod · 0.80
single_routeMethod · 0.80
invoiceMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected