Skip to content

Commit e76a334

Browse files
tests: add the test for fetching invoice with metadata
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 6f0dbbb commit e76a334

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/test_pay.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6702,3 +6702,34 @@ def get_local_channel_by_id(node, chanid):
67026702
receipt = only_one(l3.rpc.listinvoices("inv")["invoices"])
67036703
assert receipt["status"] == "paid"
67046704
assert receipt["amount_received_msat"] == total_msat
6705+
6706+
6707+
def test_fetchinvoice_with_payer_metadata(node_factory, bitcoind):
6708+
# We remove the conversion plugin on l3, causing it to get upset.
6709+
l1, l2 = node_factory.line_graph(2, wait_for_announce=True,
6710+
opts=[{'experimental-offers': None},
6711+
{'experimental-offers': None}])
6712+
6713+
# Simple default offer first.
6714+
offer = l2.rpc.call('offer', {'amount': 'any'})
6715+
assert offer['created'] is True
6716+
6717+
# Fetch an invoice for a monthly payroll for two different people, one is macros and the other is vincenzopalazzo.
6718+
# Now the payroll software has a bug and injects the wrong payer_node description (this often happens with wire descriptions).
6719+
inv1 = l1.rpc.call('fetchinvoice', {'offer': offer['bolt12'], 'amount_msat': '1sat', 'payer_note': 'Payment For vincenzopalazzo', 'payer_metadata': b'macros'.hex()})['invoice']
6720+
inv2 = l1.rpc.call('fetchinvoice', {'offer': offer['bolt12'], 'amount_msat': '1sat', 'payer_note': 'Payment For vincenzopalazzo', 'payer_metadata': b'vincenzopalazzo'.hex()})['invoice']
6721+
assert inv1 != inv2
6722+
# At this point, macros noticed the bug in the payroll system and reported a
6723+
# 'not paid for the current month' issue. The payroll system can verify that
6724+
# there is a bug in the fetchinvoice, but it can also prove that the payment was sent
6725+
# to macros because the payroll system can generate the `payer_id` with the `macros` metadata.
6726+
decode1 = l1.rpc.call('decode', {'string': inv1})
6727+
decode2 = l1.rpc.call('decode', {'string': inv2})
6728+
assert decode1['invreq_payer_id'] != decode2['invreq_payer_id']
6729+
6730+
# Delay to avoid sending too many onion messages per second!
6731+
time.sleep(1)
6732+
6733+
inv3 = l1.rpc.call('fetchinvoice', {'offer': offer['bolt12'], 'amount_msat': '1sat', 'payer_note': 'Payment For vincenzopalazzo', 'payer_metadata': b'macros'.hex()})['invoice']
6734+
decode3 = l1.rpc.call('decode', {'string': inv3})
6735+
assert decode1['invreq_payer_id'] == decode3['invreq_payer_id']

0 commit comments

Comments
 (0)