Skip to content

Commit d854469

Browse files
committed
scenarios: include lnpy-proto in commander and test ln wire messages
1 parent 880400c commit d854469

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

resources/images/commander/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ FROM python:3.12-slim
33

44
# Python dependencies
55
RUN pip install --no-cache-dir kubernetes
6+
RUN pip install --no-cache-dir pyln-proto
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
3+
from io import BytesIO
4+
from pyln.proto.wire import connect, PrivateKey, PublicKey
5+
from pyln.proto.message import Message, MessageNamespace
6+
from commander import Commander
7+
8+
9+
class PyLNConnect(Commander):
10+
def set_test_params(self):
11+
self.num_nodes = 0
12+
13+
def run_test(self):
14+
ln = self.lns["tank-0000-ln"]
15+
ln.createrune()
16+
uri = ln.uri()
17+
pk, host = uri.split("@")
18+
host, port = host.split(":")
19+
20+
ls_privkey = PrivateKey(bytes.fromhex(
21+
'1111111111111111111111111111111111111111111111111111111111111111'
22+
))
23+
remote_pubkey = PublicKey(bytes.fromhex(pk))
24+
25+
lc = connect(ls_privkey, remote_pubkey, host, port)
26+
27+
# Send an init message, with no global features, and 0b10101010 as local
28+
# features.
29+
# From BOLT1:
30+
# type: 16 (init)
31+
# data:
32+
# [u16:gflen]
33+
# [gflen*byte:globalfeatures]
34+
# [u16:flen]
35+
# [flen*byte:features]
36+
# [init_tlvs:tlvs]
37+
lc.send_message(b'\x00\x10\x00\x00\x00\x01\xaa')
38+
39+
# Import the BOLT#1 init message namesapce
40+
ns = MessageNamespace([
41+
"msgtype,init,16",
42+
"msgdata,init,gflen,u16,",
43+
"msgdata,init,globalfeatures,byte,gflen",
44+
"msgdata,init,flen,u16,",
45+
"msgdata,init,features,byte,flen",
46+
])
47+
# read reply from peer
48+
msg = lc.read_message()
49+
self.log.info(f"Got message bytes: {msg.hex()}")
50+
# interpret reply from peer
51+
stream = BytesIO(msg)
52+
msg = Message.read(ns, stream)
53+
self.log.info(f"Decoded message type: {msg.messagetype} content: {msg.to_py()}")
54+
55+
56+
def main():
57+
PyLNConnect().main()
58+
59+
60+
if __name__ == "__main__":
61+
main()

test/ln_basic_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def run_test(self):
3434
# Wait for all nodes to wake up. ln_init will start automatically
3535
self.setup_network()
3636

37+
# Test pyln-proto package in scenario
38+
self.test_pyln_scenario()
39+
3740
# Test manually configured macroons
3841
self.test_admin_macaroons()
3942

@@ -56,6 +59,12 @@ def setup_network(self):
5659
self.log.info("Setting up network")
5760
stream_command(f"warnet deploy {self.network_dir}")
5861

62+
def test_pyln_scenario(self):
63+
self.log.info("Running pyln_connect scenario")
64+
scenario_file = self.scen_dir / "test_scenarios" / "pyln_connect.py"
65+
self.log.info(f"Running scenario from: {scenario_file}")
66+
stream_command(f"warnet run {scenario_file} --source_dir={self.scen_dir} --debug")
67+
5968
def test_admin_macaroons(self):
6069
self.log.info("Testing lnd nodes with same macaroon root key can query each other")
6170
# These tanks all use the same default macaroon root key, meaning the macaroons

0 commit comments

Comments
 (0)