Skip to content

Commit f5c54a3

Browse files
committed
test: import graph
1 parent 677e68f commit f5c54a3

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/warnet/server.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,14 @@ def graph_import(
573573
srcp += f" --base_fee_msat={channel['node1_policy']['fee_base_msat']}"
574574
srcp += f" --fee_rate_ppm={channel['node1_policy']['fee_rate_milli_msat']}"
575575
srcp += f" --time_lock_delta={channel['node1_policy']['time_lock_delta']}"
576-
srcp += f" --max_htlc_msat={channel['node1_policy']['max_htlc_msat']}"
577576
srcp += f" --min_htlc_msat={channel['node1_policy']['min_htlc']}"
577+
srcp += f" --max_htlc_msat={push * 1000}"
578578
if channel["node2_policy"]:
579579
tgtp += f" --base_fee_msat={channel['node2_policy']['fee_base_msat']}"
580580
tgtp += f" --fee_rate_ppm={channel['node2_policy']['fee_rate_milli_msat']}"
581581
tgtp += f" --time_lock_delta={channel['node2_policy']['time_lock_delta']}"
582-
tgtp += f" --max_htlc_msat={channel['node2_policy']['max_htlc_msat']}"
583582
tgtp += f" --min_htlc_msat={channel['node2_policy']['min_htlc']}"
583+
tgtp += f" --max_htlc_msat={push * 1000}"
584584

585585
graph.add_edge(
586586
src,

src/warnet/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,10 @@ def policy_match(pol1, pol2):
489489
return (
490490
pol1["time_lock_delta"] == pol2["time_lock_delta"]
491491
and pol1["min_htlc"] == pol2["min_htlc"]
492-
and pol1["max_htlc_msat"] == pol2["max_htlc_msat"]
493492
and pol1["fee_base_msat"] == pol2["fee_base_msat"]
494493
and pol1["fee_rate_milli_msat"] == pol2["fee_rate_milli_msat"]
494+
# Ignoring this for now since we use capacity/2
495+
# and pol1["max_htlc_msat"] == pol2["max_htlc_msat"]
495496
)
496497

497498

test/graph_test.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#!/usr/bin/env python3
22

3+
import json
34
import os
45
import tempfile
56
import uuid
67
from pathlib import Path
7-
8+
from warnet.utils import channel_match, DEFAULT_TAG
89
from test_base import TestBase
9-
from warnet.utils import DEFAULT_TAG
1010

11-
json_file_path = Path(os.path.dirname(__file__)) / "data" / "LN_10.json"
1211

1312
base = TestBase()
1413
base.start_server()
@@ -41,6 +40,10 @@
4140
base.wait_for_all_tanks_status(target="stopped")
4241

4342
print("Import graph")
43+
44+
json_file_path = Path(os.path.dirname(__file__)) / "data" / "LN_10.json"
45+
NUM_NODES = 10
46+
4447
with tempfile.TemporaryDirectory() as dir:
4548
tf = f"{dir}/{str(uuid.uuid4())}.graphml"
4649
if base.backend == "compose":
@@ -66,6 +69,18 @@
6669
base.warcli("scenarios run ln_init")
6770
base.wait_for_all_scenarios()
6871

69-
print(base.warcli("lncli 0 describegraph"))
72+
print("Ensuring warnet LN channel policies match imported JSON description")
73+
with open(json_file_path, "r") as file:
74+
actual = json.loads(base.warcli(f"lncli 0 describegraph"))["edges"]
75+
expected = json.loads(file.read())["edges"]
76+
expected = sorted(expected, key=lambda chan: int(chan['channel_id']))
77+
for chan_index, actual_chan in enumerate(actual):
78+
expected_chan = expected[chan_index]
79+
if not channel_match(actual_chan, expected_chan, allow_flip=True):
80+
raise Exception(
81+
f"Channel policy doesn't match source: {actual_chan['channel_id']}\n" +
82+
"Actual:\n" + json.dumps(actual_chan, indent=2) +
83+
"Expected:\n" + json.dumps(expected_chan, indent=2)
84+
)
7085

7186
base.stop_server()

0 commit comments

Comments
 (0)