Skip to content

Commit

Permalink
pytest: Add test for keysend extra-tlvs
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker committed Jun 18, 2021
1 parent 6db2fa9 commit 722c9a7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ def keysend(self, destination, msatoshi, label=None, maxfeepercent=None,
"""

if extra_tlvs is not None and not isinstance(extra_tlvs, dict):
raise ValueErrr(
raise ValueError(
"extra_tlvs is not a dictionary with integer keys and hexadecimal values"
)

Expand Down
16 changes: 16 additions & 0 deletions tests/plugins/sphinx-receiver.py
Original file line number Diff line number Diff line change
@@ -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()
31 changes: 31 additions & 0 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3084,6 +3084,37 @@ def test_keysend(node_factory):
l3.rpc.keysend(l4.info['id'], amt)


@unittest.skipIf(not EXPERIMENTAL_FEATURES, "Requires extra-tlvs option")
def test_keysend_extra_tlvs(node_factory):
"""Use the extra-tlvs 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.*extra_tlvs.*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`.
Expand Down

0 comments on commit 722c9a7

Please sign in to comment.