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 21, 2021
1 parent 62e1e0e commit e0d702e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
6 changes: 3 additions & 3 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
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 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`.
Expand Down

0 comments on commit e0d702e

Please sign in to comment.