From e0d702e182ca35b1076a85e49d82b77b8b1982ec Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 18 Jun 2021 14:32:23 +0200 Subject: [PATCH] pytest: Add test for keysend extra-tlvs --- contrib/pyln-client/pyln/client/lightning.py | 6 ++-- tests/plugins/sphinx-receiver.py | 16 ++++++++++ tests/test_pay.py | 31 ++++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100755 tests/plugins/sphinx-receiver.py diff --git a/contrib/pyln-client/pyln/client/lightning.py b/contrib/pyln-client/pyln/client/lightning.py index 3ce3e17ba947..a2bcf4ad5764 100644 --- a/contrib/pyln-client/pyln/client/lightning.py +++ b/contrib/pyln-client/pyln/client/lightning.py @@ -1360,9 +1360,9 @@ def keysend(self, destination, msatoshi, label=None, maxfeepercent=None, """ """ - if extra_tlvs is not None and not isinstance(extra_tlvs, dict): - raise ValueErrr( - "extra_tlvs is not a dictionary with integer keys and hexadecimal values" + if extratlvs is not None and not isinstance(extratlvs, dict): + raise ValueError( + "extratlvs is not a dictionary with integer keys and hexadecimal values" ) payload = { diff --git a/tests/plugins/sphinx-receiver.py b/tests/plugins/sphinx-receiver.py new file mode 100755 index 000000000000..ff5d8a8775fb --- /dev/null +++ b/tests/plugins/sphinx-receiver.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +from pyln.client import Plugin + + +plugin = Plugin() + + +@plugin.hook('invoice_payment') +def on_invoice_payment(**kwargs): + """ + """ + plugin.log("invoice_payment kwargs {a}".format(a=kwargs)) + return {'result': 'continue'} + + +plugin.run() diff --git a/tests/test_pay.py b/tests/test_pay.py index c701c38d4110..c73b612328f1 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -3084,6 +3084,37 @@ def test_keysend(node_factory): l3.rpc.keysend(l4.info['id'], amt) +@unittest.skipIf(not EXPERIMENTAL_FEATURES, "Requires extratlvs option") +def test_keysend_extra_tlvs(node_factory): + """Use the extratlvs option to deliver a message with sphinx' TLV type. + """ + amt = 10000 + l1, l2 = node_factory.line_graph( + 2, + wait_for_announce=True, + opts=[ + {}, + { + 'experimental-accept-extra-tlv-types': '133773310', + "plugin": os.path.join(os.path.dirname(__file__), "plugins/sphinx-receiver.py"), + }, + ] + ) + + # Send an indirect one from l1 to l3 + l1.rpc.keysend(l2.info['id'], amt, extra_tlvs={133773310: 'FEEDC0DE'}) + invs = l2.rpc.listinvoices()['invoices'] + assert(len(invs) == 1) + assert(l2.daemon.is_in_log(r'plugin-sphinx-receiver.py.*extratlvs.*133773310.*feedc0de')) + + inv = invs[0] + print(inv) + assert(inv['msatoshi_received'] >= amt) + + # Now try again with the TLV type in extra_tlvs as string: + l1.rpc.keysend(l2.info['id'], amt, extra_tlvs={133773310: 'FEEDC0DE'}) + + def test_invalid_onion_channel_update(node_factory): ''' Some onion failures "should" send a `channel_update`.