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

Function test_sendinvoice

tests/test_pay.py:5046–5105  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

5044
5045
5046def test_sendinvoice(node_factory, bitcoind):
5047 l1, l2 = node_factory.line_graph(2, wait_for_announce=True)
5048
5049 # Simple offer to send money (balances channel a little)
5050 invreq = l1.rpc.call('invoicerequest', {'amount': '100000sat',
5051 'description': 'simple test'})
5052
5053 # Fetchinvoice will refuse, since it's not an offer.
5054 with pytest.raises(RpcError, match='unexpected prefix lnr'):
5055 l2.rpc.call('fetchinvoice', {'offer': invreq['bolt12']})
5056
5057 # Pay will refuse, since it's not an invoice.
5058 with pytest.raises(RpcError, match='unexpected prefix lnr'):
5059 l2.rpc.call('fetchinvoice', {'offer': invreq['bolt12']})
5060
5061 # used will be false
5062 assert only_one(l1.rpc.call('listinvoicerequests', [invreq['invreq_id']])['invoicerequests'])['used'] is False
5063
5064 # sendinvoice should work.
5065 out = l2.rpc.call('sendinvoice', {'invreq': invreq['bolt12'],
5066 'label': 'test sendinvoice 1'})
5067 assert out['label'] == 'test sendinvoice 1'
5068 assert out['description'] == 'simple test'
5069 assert 'bolt12' in out
5070 assert 'payment_hash' in out
5071 assert out['status'] == 'paid'
5072 assert 'payment_preimage' in out
5073 assert 'expires_at' in out
5074 assert out['amount_msat'] == Millisatoshi(100000000)
5075 assert 'pay_index' in out
5076 assert out['amount_received_msat'] == Millisatoshi(100000000)
5077
5078 # Note, if we're slow, this fails with "Offer no longer available",
5079 # *but* if it hasn't heard about payment success yet, l2 will fail
5080 # simply because payments are already pending.
5081 with pytest.raises(RpcError, match='no longer available|pay attempt failed'):
5082 l2.rpc.call('sendinvoice', {'invreq': invreq['bolt12'],
5083 'label': 'test sendinvoice 2'})
5084
5085 # Technically, l1 may not have gotten payment success, so we need to wait.
5086 wait_for(lambda: only_one(l1.rpc.call('listinvoicerequests', [invreq['invreq_id']])['invoicerequests'])['used'] is True)
5087
5088 # Offer with issuer: we must copy issuer into our invoice!
5089 invreq = l1.rpc.call('invoicerequest', {'amount': '10000sat',
5090 'description': 'simple test',
5091 'issuer': "clightning test suite"})
5092
5093 out = l2.rpc.call('sendinvoice', {'invreq': invreq['bolt12'],
5094 'label': 'test sendinvoice 3'})
5095 assert out['label'] == 'test sendinvoice 3'
5096 assert out['description'] == 'simple test'
5097 assert 'issuer' not in out
5098 assert 'bolt12' in out
5099 assert 'payment_hash' in out
5100 assert out['status'] == 'paid'
5101 assert 'payment_preimage' in out
5102 assert 'expires_at' in out
5103 assert out['amount_msat'] == Millisatoshi(10000000)

Callers

nothing calls this directly

Calls 5

only_oneFunction · 0.90
MillisatoshiClass · 0.90
wait_forFunction · 0.90
line_graphMethod · 0.80
callMethod · 0.45

Tested by

no test coverage detected