Skip to content

Commit

Permalink
plugin: fetchinvoice: assign the quantity to the invrequest field
Browse files Browse the repository at this point in the history
assign the quantity field receive as RPC parameter inside the
invrequest field.

Changelog-Fixed: fetchinvoice: assign the quantity to the invrequest field

Reported-by: @aaronbarnardsound
Link: #6089
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Mar 15, 2023
1 parent be8ed8c commit 78cb683
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/fetchinvoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 78cb683

Please sign in to comment.