Skip to content

Commit 1906e3a

Browse files
authored
Merge pull request #753 from pinheadmz/ln-commander
scenarios: include pyln-proto in commander and test ln wire messages
2 parents 880400c + d1c6fbc commit 1906e3a

File tree

3 files changed

+74
-0
lines changed

3 files changed

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