Skip to content

Commit 341b2d0

Browse files
committed
test: cover simln service in both compose and k8s
1 parent bbd81bc commit 341b2d0

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

src/cli/network.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ def connected(network: str):
143143

144144
@network.command()
145145
@click.option("--network", default="warnet", show_default=True)
146-
def export(network: str):
146+
@click.option("--activity", type=str)
147+
def export(network: str, activity: str):
147148
"""
148149
Export all [network] data for a "simln" service running in a container
149-
on the network. Returns True on success.
150+
on the network. Optionally add JSON string [activity] to simln config.
151+
Returns True on success.
150152
"""
151-
print(rpc_call("network_export", {"network": network}))
153+
print(rpc_call("network_export", {"network": network, "activity": activity}))

src/warnet/server.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def tank_messages(self, network: str, node_a: int, node_b: int) -> str:
270270
self.logger.error(msg)
271271
raise ServerError(message=msg) from e
272272

273-
def network_export(self, network: str) -> bool:
273+
def network_export(self, network: str, activity: str) -> bool:
274274
"""
275275
Export all data for a simln container running on the network
276276
"""
@@ -280,6 +280,8 @@ def network_export(self, network: str) -> bool:
280280

281281
# JSON object that will eventually be written to simln config file
282282
config = {"nodes": []}
283+
if activity:
284+
config["activity"] = json.loads(activity)
283285
# In-memory file to build tar archive
284286
tar_buffer = io.BytesIO()
285287
with tarfile.open(fileobj=tar_buffer, mode="w") as tar_file:

test/data/services.graphml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key id="source_policy" attr.name="source_policy" attr.type="string" for="edge" />
1616
<key id="target_policy" attr.name="target_policy" attr.type="string" for="edge" />
1717
<graph edgedefault="directed">
18-
<data key="services">cadvisor forkobserver grafana nodeexporter prometheus simln</data>
18+
<data key="services">cadvisor forkobserver grafana nodeexporter prometheus</data>
1919
<node id="0">
2020
<data key="version">26.0</data>
2121
<data key="bitcoin_config">-uacomment=w0 -debug=validation</data>

test/ln_test.py

+18-22
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@ def get_cb_forwards(index):
2525
base.wait_for_all_tanks_status(target="running")
2626
base.wait_for_all_edges()
2727

28-
if base.backend != "compose":
29-
print("\nSkipping network export test, only supported with compose backend")
30-
else:
31-
print("\nTesting warcli network export")
32-
path = Path(base.warcli("network export")) / "sim.json"
33-
with open(path) as file:
34-
data = json.load(file)
35-
print(json.dumps(data, indent=4))
36-
assert len(data["nodes"]) == 3
37-
for node in data["nodes"]:
38-
assert os.path.exists(node["macaroon"])
39-
assert os.path.exists(node["cert"])
40-
41-
4228
print("\nRunning LN Init scenario")
4329
base.warcli("rpc 0 getblockcount")
4430
base.warcli("scenarios run ln_init")
@@ -86,17 +72,27 @@ def check_invoices():
8672
print(base.warcli(f"lncli 2 payinvoice -f {inv}"))
8773

8874
print("Waiting for payment success")
89-
def check_invoices():
90-
invs = json.loads(base.warcli("lncli 0 listinvoices"))["invoices"]
91-
if len(invs) > 0 and invs[0]["state"] == "SETTLED":
92-
print("\nSettled!")
93-
return True
94-
else:
95-
return False
96-
base.wait_for_predicate(check_invoices)
75+
def check_invoices(index):
76+
invs = json.loads(base.warcli(f"lncli {index} listinvoices"))["invoices"]
77+
settled = 0
78+
for inv in invs:
79+
if inv["state"] == "SETTLED":
80+
settled += 1
81+
return settled
82+
base.wait_for_predicate(lambda: check_invoices(0) == 1)
9783

9884
print("\nEnsuring channel-level channel policy settings: target")
9985
payment = json.loads(base.warcli("lncli 2 listpayments"))["payments"][0]
10086
assert payment["fee_msat"] == "2213"
10187

88+
print("\nEngaging simln")
89+
activity = [{
90+
"source": "ln-0",
91+
"destination": chan["node1_pub"],
92+
"interval_secs": 1,
93+
"amount_msat": 2000
94+
}]
95+
base.warcli(f"network export --activity={json.dumps(activity).replace(' ', '')}")
96+
base.wait_for_predicate(lambda: check_invoices(0) > 1 or check_invoices(1) > 1 or check_invoices(2) > 1)
97+
10298
base.stop_server()

0 commit comments

Comments
 (0)