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

Function test_fetchinvoice

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

Source from the content-addressed store, hash-verified

4613
4614
4615def test_fetchinvoice(node_factory, bitcoind):
4616 # We remove the conversion plugin on l3, causing it to get upset.
4617 l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True,
4618 opts=[{},
4619 {'dev-allow-localhost': None},
4620 {'broken_log': "plugin-offers: Failed invreq.*Unknown command 'currencyconvert'",
4621 'dev-allow-localhost': None,
4622 'disable-plugin': 'cln-currencyrate'}])
4623
4624 # Simple offer first.
4625 offer1 = l3.rpc.call('offer', {'amount': '2msat',
4626 'description': 'simple test'})
4627 assert offer1['created'] is True
4628
4629 inv1 = l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12']})
4630 inv2 = l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12'],
4631 'payer_note': 'Thanks for the fish!'})
4632 assert inv1 != inv2
4633 assert 'next_period' not in inv1
4634 assert 'next_period' not in inv2
4635 assert only_one(l3.rpc.call('listoffers', [offer1['offer_id']])['offers'])['used'] is False
4636 l1.rpc.pay(inv1['invoice'])
4637 assert only_one(l3.rpc.call('listoffers', [offer1['offer_id']])['offers'])['used'] is True
4638 l1.rpc.pay(inv2['invoice'])
4639 assert only_one(l3.rpc.call('listoffers', [offer1['offer_id']])['offers'])['used'] is True
4640
4641 # listinvoices will show these on l3
4642 assert [x['local_offer_id'] for x in l3.rpc.listinvoices()['invoices']] == [offer1['offer_id'], offer1['offer_id']]
4643
4644 assert 'invreq_payer_note' not in only_one(l3.rpc.call('listinvoices', {'invstring': inv1['invoice']})['invoices'])
4645 assert only_one(l3.rpc.call('listinvoices', {'invstring': inv2['invoice']})['invoices'])['invreq_payer_note'] == 'Thanks for the fish!'
4646
4647 # BTW, test listinvoices-by-offer_id:
4648 assert len(l3.rpc.listinvoices(offer_id=offer1['offer_id'])['invoices']) == 2
4649
4650 # We can also set the amount explicitly, to tip.
4651 inv1 = l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12'], 'amount_msat': 3})
4652 assert l1.rpc.call('decode', [inv1['invoice']])['invoice_amount_msat'] == 3
4653 l1.rpc.pay(inv1['invoice'])
4654
4655 # We've done 4 onion calls: sleep now to avoid hitting ratelimit!
4656 time.sleep(1)
4657
4658 # More than ~5x expected is rejected as absurd (it's actually a divide test,
4659 # which means we need 15 here, not 11).
4660 with pytest.raises(RpcError, match="Remote node sent failure message.*Amount vastly exceeds 2msat"):
4661 l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12'], 'amount_msat': 15})
4662
4663 # Underpay is rejected.
4664 with pytest.raises(RpcError, match="Remote node sent failure message.*Amount must be at least 2msat"):
4665 l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12'], 'amount_msat': 1})
4666
4667 # If no amount is specified in offer, one must be in invoice.
4668 offer_noamount = l3.rpc.call('offer', {'amount': 'any',
4669 'description': 'any amount test'})
4670 with pytest.raises(RpcError, match="amount_msat parameter required"):
4671 l1.rpc.call('fetchinvoice', {'offer': offer_noamount['bolt12']})
4672 inv1 = l1.rpc.call('fetchinvoice', {'offer': offer_noamount['bolt12'], 'amount_msat': 100})

Callers

nothing calls this directly

Calls 15

only_oneFunction · 0.90
MillisatoshiClass · 0.90
wait_forFunction · 0.90
line_graphMethod · 0.80
enableofferMethod · 0.80
joinMethod · 0.80
plugin_startMethod · 0.80
plugin_stopMethod · 0.80
wait_for_logMethod · 0.80
callMethod · 0.45
payMethod · 0.45
listinvoicesMethod · 0.45

Tested by

no test coverage detected