|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 |
|
| 3 | +import json |
3 | 4 | import os
|
4 | 5 | import tempfile
|
5 | 6 | import uuid
|
6 | 7 | from pathlib import Path
|
7 |
| - |
| 8 | +from warnet.utils import channel_match, DEFAULT_TAG |
8 | 9 | from test_base import TestBase
|
9 |
| -from warnet.utils import DEFAULT_TAG |
10 | 10 |
|
11 |
| -json_file_path = Path(os.path.dirname(__file__)) / "data" / "LN_10.json" |
12 | 11 |
|
13 | 12 | base = TestBase()
|
14 | 13 | base.start_server()
|
|
41 | 40 | base.wait_for_all_tanks_status(target="stopped")
|
42 | 41 |
|
43 | 42 | print("Import graph")
|
| 43 | + |
| 44 | +json_file_path = Path(os.path.dirname(__file__)) / "data" / "LN_10.json" |
| 45 | +NUM_NODES = 10 |
| 46 | + |
44 | 47 | with tempfile.TemporaryDirectory() as dir:
|
45 | 48 | tf = f"{dir}/{str(uuid.uuid4())}.graphml"
|
46 | 49 | if base.backend == "compose":
|
|
66 | 69 | base.warcli("scenarios run ln_init")
|
67 | 70 | base.wait_for_all_scenarios()
|
68 | 71 |
|
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 | + ) |
70 | 85 |
|
71 | 86 | base.stop_server()
|
0 commit comments