Skip to content

Commit 0cb1163

Browse files
committed
update simln test
1 parent 1dc7e8d commit 0cb1163

File tree

5 files changed

+42
-32
lines changed

5 files changed

+42
-32
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
- signet_test.py
5151
- scenarios_test.py
5252
- namespace_admin_test.py
53+
- simln_test.py
5354
steps:
5455
- uses: actions/checkout@v4
5556
- uses: azure/[email protected]

resources/plugins/simln/simln.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,38 @@ def deploy_helm():
3434
def run_simln():
3535
init_network()
3636
fund_wallets()
37-
wait_for_predicate(everyone_has_a_host)
37+
wait_for_everyone_to_have_a_host()
3838
log.info(warnet("bitcoin rpc tank-0000 -generate 7"))
3939
# warnet("ln open-all-channels")
4040
manual_open_channels()
4141
log.info(warnet("bitcoin rpc tank-0000 -generate 7"))
4242
wait_for_gossip_sync(2)
4343
log.info("done waiting")
44+
pod_name = prepare_and_launch_activity()
45+
log.info(pod_name)
46+
47+
48+
def prepare_and_launch_activity() -> str:
4449
pods = get_pods_with_label(lightning_selector)
4550
pod_a = pods[0].metadata.name
4651
pod_b = pods[1].metadata.name
4752
sample_activity = [
4853
{"source": pod_a, "destination": pod_b, "interval_secs": 1, "amount_msat": 2000}
4954
]
5055
log.info(f"Activity: {sample_activity}")
51-
generate_activity(sample_activity)
56+
pod_name = launch_activity(sample_activity)
5257
log.info("Sent command. Done.")
58+
return pod_name
5359

5460

55-
def generate_activity(activity: list[dict]):
61+
def launch_activity(activity: list[dict]) -> str:
5662
random_digits = "".join(random.choices("0123456789", k=10))
5763
plugin_dir = get_plugin_directory()
5864
generate_nodes_file(activity, plugin_dir / Path("simln/charts/simln/files/sim.json"))
5965
command = f"helm upgrade --install simln-{random_digits} {plugin_dir}/simln/charts/simln"
6066
log.info(f"generate activity: {command}")
6167
run_command(command)
68+
return f"pod/simln-simln-{random_digits}"
6269

6370

6471
def init_network():
@@ -108,6 +115,10 @@ def everyone_has_a_host() -> bool:
108115
return host_havers == len(pods)
109116

110117

118+
def wait_for_everyone_to_have_a_host():
119+
wait_for_predicate(everyone_has_a_host)
120+
121+
111122
def wait_for_predicate(predicate, timeout=5 * 60, interval=5):
112123
log.info(
113124
f"Waiting for predicate ({predicate.__name__}) with timeout {timeout}s and interval {interval}s"
@@ -148,7 +159,7 @@ def check_status():
148159
wait_for_predicate(check_status, timeout, interval)
149160

150161

151-
def wait_for_gossip_sync(expected):
162+
def wait_for_gossip_sync(expected: int):
152163
log.info(f"Waiting for sync (expecting {expected})...")
153164
current = 0
154165
while current < expected:
@@ -163,7 +174,7 @@ def wait_for_gossip_sync(expected):
163174
log.info("Synced")
164175

165176

166-
def warnet(cmd):
177+
def warnet(cmd: str = "--help"):
167178
log.info(f"Executing warnet command: {cmd}")
168179
command = ["warnet"] + cmd.split()
169180
proc = run(command, capture_output=True)
@@ -172,7 +183,7 @@ def warnet(cmd):
172183
return proc.stdout.decode()
173184

174185

175-
def generate_nodes_file(activity, output_file: Path = Path("nodes.json")):
186+
def generate_nodes_file(activity: dict, output_file: Path = Path("nodes.json")):
176187
nodes = []
177188

178189
for i in get_pods_with_label(lightning_selector):

src/warnet/hooks.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,16 @@ def run(plugin: str, function: str, args: tuple[str, ...], json_dict: str):
176176
params[name] = user_input
177177
else:
178178
params[name] = cast_to_hint(user_input, hint)
179-
click.secho(
180-
f"\nwarnet plugin run {plugin} {function} --json-dict '{json.dumps(params)}'\n",
181-
fg="green",
182-
)
179+
if not params:
180+
click.secho(
181+
f"\nwarnet plugin run {plugin} {function}\n",
182+
fg="green",
183+
)
184+
else:
185+
click.secho(
186+
f"\nwarnet plugin run {plugin} {function} --json-dict '{json.dumps(params)}'\n",
187+
fg="green",
188+
)
183189
else:
184190
params = json.loads(json_dict)
185191

src/warnet/status.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
from rich.text import Text
99
from urllib3.exceptions import MaxRetryError
1010

11-
from .hooks import api
1211
from .k8s import get_mission
1312
from .network import _connected
1413

1514

1615
@click.command()
17-
@api
1816
def status():
1917
"""Display the unified status of the Warnet network and active scenarios"""
2018
console = Console()

test/simln_test.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import os
44
from pathlib import Path
5+
from subprocess import run
56
from time import sleep
67

78
import pexpect
89
from test_base import TestBase
910

1011
from warnet.k8s import download, get_pods_with_label
11-
from warnet.process import run_command
1212

1313

1414
class LNTest(TestBase):
@@ -21,7 +21,6 @@ def run_test(self):
2121
os.chdir(self.tmpdir)
2222
self.setup_network()
2323
self.run_plugin()
24-
self.check_simln_logs()
2524
result = self.copy_results()
2625
assert result
2726
finally:
@@ -36,32 +35,27 @@ def run_plugin(self):
3635
self.sut = pexpect.spawn("warnet init")
3736
self.sut.expect("network", timeout=10)
3837
self.sut.sendline("n")
38+
self.sut.close()
3939

40-
self.warnet("plugin run simln run_simln")
41-
42-
def check_simln_logs(self):
43-
pod = get_pods_with_label("mission=plugin")
44-
self.log.info(run_command(f"kubectl logs pod/{pod.metadata.name}"))
40+
self.log.info(run(["warnet", "plugin", "run", "simln", "run_simln"]))
41+
sleep(10)
4542

4643
def copy_results(self) -> bool:
4744
self.log.info("Copying results")
4845
sleep(20)
4946
pod = get_pods_with_label("mission=plugin")[0]
5047

51-
download(
52-
pod.metadata.name,
53-
pod.metadata.namespace,
54-
)
48+
download(pod.metadata.name, pod.metadata.namespace, Path("/working/results"), Path("."))
49+
50+
for root, _dirs, files in os.walk(Path("results")):
51+
for file_name in files:
52+
file_path = os.path.join(root, file_name)
5553

56-
# for root, _dirs, files in os.walk(destination_path):
57-
# for file_name in files:
58-
# file_path = os.path.join(root, file_name)
59-
#
60-
# with open(file_path) as file:
61-
# content = file.read()
62-
# if "Success" in content:
63-
# return True
64-
# return False
54+
with open(file_path) as file:
55+
content = file.read()
56+
if "Success" in content:
57+
return True
58+
return False
6559

6660

6761
if __name__ == "__main__":

0 commit comments

Comments
 (0)