Skip to content

Commit 5f9e5d5

Browse files
cdeckerrustyrussell
authored andcommitted
pytest: Add test for keysend extra-tlvs
1 parent a4e3773 commit 5f9e5d5

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

contrib/pyln-client/pyln/client/lightning.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,9 +1360,9 @@ def keysend(self, destination, msatoshi, label=None, maxfeepercent=None,
13601360
"""
13611361
"""
13621362

1363-
if extra_tlvs is not None and not isinstance(extra_tlvs, dict):
1364-
raise ValueErrr(
1365-
"extra_tlvs is not a dictionary with integer keys and hexadecimal values"
1363+
if extratlvs is not None and not isinstance(extratlvs, dict):
1364+
raise ValueError(
1365+
"extratlvs is not a dictionary with integer keys and hexadecimal values"
13661366
)
13671367

13681368
payload = {

tests/plugins/sphinx-receiver.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python3
2+
from pyln.client import Plugin
3+
4+
5+
plugin = Plugin()
6+
7+
8+
@plugin.hook('invoice_payment')
9+
def on_invoice_payment(**kwargs):
10+
"""
11+
"""
12+
plugin.log("invoice_payment kwargs {a}".format(a=kwargs))
13+
return {'result': 'continue'}
14+
15+
16+
plugin.run()

tests/test_pay.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,6 +3084,37 @@ def test_keysend(node_factory):
30843084
l3.rpc.keysend(l4.info['id'], amt)
30853085

30863086

3087+
@unittest.skipIf(not EXPERIMENTAL_FEATURES, "Requires extratlvs option")
3088+
def test_keysend_extra_tlvs(node_factory):
3089+
"""Use the extratlvs option to deliver a message with sphinx' TLV type.
3090+
"""
3091+
amt = 10000
3092+
l1, l2 = node_factory.line_graph(
3093+
2,
3094+
wait_for_announce=True,
3095+
opts=[
3096+
{},
3097+
{
3098+
'experimental-accept-extra-tlv-types': '133773310',
3099+
"plugin": os.path.join(os.path.dirname(__file__), "plugins/sphinx-receiver.py"),
3100+
},
3101+
]
3102+
)
3103+
3104+
# Send an indirect one from l1 to l3
3105+
l1.rpc.keysend(l2.info['id'], amt, extratlvs={133773310: 'FEEDC0DE'})
3106+
invs = l2.rpc.listinvoices()['invoices']
3107+
assert(len(invs) == 1)
3108+
assert(l2.daemon.is_in_log(r'plugin-sphinx-receiver.py.*extratlvs.*133773310.*feedc0de'))
3109+
3110+
inv = invs[0]
3111+
print(inv)
3112+
assert(inv['msatoshi_received'] >= amt)
3113+
3114+
# Now try again with the TLV type in extra_tlvs as string:
3115+
l1.rpc.keysend(l2.info['id'], amt, extratlvs={133773310: 'FEEDC0DE'})
3116+
3117+
30873118
def test_invalid_onion_channel_update(node_factory):
30883119
'''
30893120
Some onion failures "should" send a `channel_update`.

0 commit comments

Comments
 (0)