From fca62113f5f166a1877907f870620c5df6680e5d Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Mon, 13 Mar 2023 12:53:14 +0100 Subject: [PATCH] plugin: fetchinvoice: set the quantity in invreq While the user trying to fetch an invoice by specifing the quantity we do not work as expected. Running the command ``` lightning-cli fetchinvoice -k offer='lno1qgsqvgnwgcg35z6ee2h3yczraddm72xrfua9uve2rlrm9deu7xyfzrcgqffqszsk2p6hycmgv9ek2grpyphxjcm9ypmkjer8v46pyzmhd9jxwet5wvhxxmmdzsqs593pq0ylsvakdua5h976f4g3eautgjt3udvtyga47eaw7339sjrhpwpwz' quantity=2 ``` and we answer back with ```json { "code": -32602, "message": "quantity parameter required" } ``` This is caused because we forget to bind the `quanity` field from the RPC into the `invrequest`. Reported-by: @aaronbarnardsound Link: https://github.com/ElementsProject/lightning/issues/6089 Signed-off-by: Vincenzo Palazzo Changelog-EXPERIMENTAL: fetchinvoice: fix: do not ignore the `quantity` field into the invreq field. --- plugins/fetchinvoice.c | 1 + tests/test_pay.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index 98b8e4587..ad267351f 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -1029,6 +1029,7 @@ static struct command_result *json_fetchinvoice(struct command *cmd, invreq = invoice_request_for_offer(sent, sent->offer); invreq->invreq_recurrence_counter = tal_steal(invreq, recurrence_counter); invreq->invreq_recurrence_start = tal_steal(invreq, recurrence_start); + invreq->invreq_quantity = tal_steal(invreq, quantity); /* BOLT-offers-recurrence #12: * - if `offer_amount` is not present: diff --git a/tests/test_pay.py b/tests/test_pay.py index f999a196f..6cca937b8 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -5395,3 +5395,29 @@ def test_delpay_works(node_factory, bitcoind): status=failed['status'], groupid=failed['groupid'], partid=failed['partid']) + + +def test_fetchinvoice_with_no_quantity(node_factory): + """ + Reproducer for https://github.com/ElementsProject/lightning/issues/6089 + + The issue is when the offer has the quantity_max and the parameter. + + In particular, in the fetchinvoice we forget to map the + quantity parameter with the invoice request quantity field. + """ + l1, l2 = node_factory.line_graph(2, wait_for_announce=True, + opts={'experimental-offers': None}) + offer1 = l2.rpc.call('offer', {'amount': '2msat', + 'description': 'simple test', + 'quantity_max': 10}) + + assert offer1['created'] is True, f"offer created is {offer1['created']}" + + with pytest.raises(RpcError, match="quantity parameter required"): + l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12']}) + + inv = l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12'], 'quantity': 2}) + inv = inv['invoice'] + decode_inv = l2.rpc.decode(inv) + assert decode_inv['invreq_quantity'] == 2, f'`invreq_quantity` in the invoice did not match, received {decode_inv["quantity"]}, expected 2'