Skip to content

Commit 8563954

Browse files
committed
run dag connection test
1 parent 7d1d54f commit 8563954

File tree

12 files changed

+50
-103
lines changed

12 files changed

+50
-103
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
strategy:
3131
matrix:
3232
# test: [scenarios_test.py, rpc_test.py, graph_test.py, ln_test.py, dag_connection_test.py, logging_test.py]
33-
test: [scenarios_test.py, rpc_test.py, graph_test.py, logging_test.py]
33+
test: [scenarios_test.py, rpc_test.py, graph_test.py, dag_connection_test.py, logging_test.py]
3434
steps:
3535
- uses: actions/checkout@v4
3636
- uses: azure/[email protected]

resources/images/commander/src/commander.py

+22-42
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import argparse
22
import configparser
3-
import ipaddress
43
import json
54
import logging
65
import os
@@ -93,6 +92,7 @@ def setup(self):
9392
cwd=self.options.tmpdir,
9493
coverage_dir=self.options.coveragedir,
9594
)
95+
node.tank = tank["tank"]
9696
node.rpc = get_rpc_proxy(
9797
f"http://{tank['rpc_user']}:{tank['rpc_password']}@{tank['rpc_host']}:{tank['rpc_port']}",
9898
i,
@@ -302,83 +302,63 @@ def connect_nodes(self, a, b, *, peer_advertises_v2=None, wait_for_connect: bool
302302
"""
303303
from_connection = self.nodes[a]
304304
to_connection = self.nodes[b]
305-
306-
to_ip_port = self.warnet.tanks[b].get_dns_addr()
307-
from_ip_port = self.warnet.tanks[a].get_ip_addr()
305+
from_num_peers = 1 + len(from_connection.getpeerinfo())
306+
to_num_peers = 1 + len(to_connection.getpeerinfo())
307+
ip_port = self.nodes[b].rpchost + ":18444"
308308

309309
if peer_advertises_v2 is None:
310310
peer_advertises_v2 = self.options.v2transport
311311

312312
if peer_advertises_v2:
313-
from_connection.addnode(node=to_ip_port, command="onetry", v2transport=True)
313+
from_connection.addnode(node=ip_port, command="onetry", v2transport=True)
314314
else:
315315
# skip the optional third argument (default false) for
316316
# compatibility with older clients
317-
from_connection.addnode(to_ip_port, "onetry")
317+
from_connection.addnode(ip_port, "onetry")
318318

319319
if not wait_for_connect:
320320
return
321321

322-
def get_peer_ip(peer):
323-
try: # we encounter a regular ip address
324-
ip_addr = str(ipaddress.ip_address(peer["addr"].split(":")[0]))
325-
return ip_addr
326-
except ValueError as err: # or we encounter a service name
327-
try:
328-
# NETWORK-tank-TANK_INDEX-service
329-
# NETWORK-test-TEST-tank-TANK_INDEX-service
330-
tank_index = int(peer["addr"].split("-")[-2])
331-
except (ValueError, IndexError) as inner_err:
332-
raise ValueError(
333-
"could not derive tank index from service name: {} {}".format(
334-
peer["addr"], inner_err
335-
)
336-
) from err
337-
338-
ip_addr = self.warnet.tanks[tank_index].get_ip_addr()
339-
return ip_addr
340-
341322
# poll until version handshake complete to avoid race conditions
342323
# with transaction relaying
343324
# See comments in net_processing:
344325
# * Must have a version message before anything else
345326
# * Must have a verack message before anything else
346327
self.wait_until(
347-
lambda: any(
348-
peer["addr"] == to_ip_port and peer["version"] != 0
349-
for peer in from_connection.getpeerinfo()
350-
)
328+
lambda: sum(peer["version"] != 0 for peer in from_connection.getpeerinfo())
329+
== from_num_peers
351330
)
352331
self.wait_until(
353-
lambda: any(
354-
get_peer_ip(peer) == from_ip_port and peer["version"] != 0
355-
for peer in to_connection.getpeerinfo()
356-
)
332+
lambda: sum(peer["version"] != 0 for peer in to_connection.getpeerinfo())
333+
== to_num_peers
357334
)
358335
self.wait_until(
359-
lambda: any(
360-
peer["addr"] == to_ip_port and peer["bytesrecv_per_msg"].pop("verack", 0) >= 21
336+
lambda: sum(
337+
peer["bytesrecv_per_msg"].pop("verack", 0) >= 21
361338
for peer in from_connection.getpeerinfo()
362339
)
340+
== from_num_peers
363341
)
364342
self.wait_until(
365-
lambda: any(
366-
get_peer_ip(peer) == from_ip_port
367-
and peer["bytesrecv_per_msg"].pop("verack", 0) >= 21
343+
lambda: sum(
344+
peer["bytesrecv_per_msg"].pop("verack", 0) >= 21
368345
for peer in to_connection.getpeerinfo()
369346
)
347+
== to_num_peers
370348
)
371349
# The message bytes are counted before processing the message, so make
372350
# sure it was fully processed by waiting for a ping.
373351
self.wait_until(
374-
lambda: any(
375-
peer["addr"] == to_ip_port and peer["bytesrecv_per_msg"].pop("pong", 0) >= 29
352+
lambda: sum(
353+
peer["bytesrecv_per_msg"].pop("pong", 0) >= 29
376354
for peer in from_connection.getpeerinfo()
377355
)
356+
== from_num_peers
378357
)
379358
self.wait_until(
380-
lambda: any(
381-
get_peer_ip(peer) == from_ip_port and peer["bytesrecv_per_msg"].pop("pong", 0) >= 29
359+
lambda: sum(
360+
peer["bytesrecv_per_msg"].pop("pong", 0) >= 29
382361
for peer in to_connection.getpeerinfo()
383362
)
363+
== to_num_peers
384364
)

resources/scripts/apidocs.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from click import Context
88
from tabulate import tabulate
9-
109
from warnet.cli.main import cli
1110

1211
file_path = Path(os.path.dirname(os.path.abspath(__file__))) / ".." / ".." / "docs" / "warcli.md"

resources/scripts/graphdocs.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from pathlib import Path
66

77
from tabulate import tabulate
8-
98
from warnet.cli.util import load_schema
109

1110
graph_schema = load_schema()

src/warnet/cli/bitcoin.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from io import BytesIO
66

77
import click
8-
98
from test_framework.messages import ser_uint256
109
from test_framework.p2p import MESSAGEMAP
1110

src/warnet/cli/namespaces.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import click
66
import yaml
77

8-
from .process import stream_command, run_command
8+
from .process import run_command, stream_command
99

1010
NAMESPACES_DIR = Path("namespaces")
1111
DEFAULT_NAMESPACES = "two_namespaces_two_users"
@@ -14,6 +14,7 @@
1414
HELM_COMMAND = "helm upgrade --install"
1515
BITCOIN_CHART_LOCATION = "./resources/charts/namespaces"
1616

17+
1718
@click.group(name="namespaces")
1819
def namespaces():
1920
"""Namespaces commands"""
@@ -35,7 +36,9 @@ def deploy(namespaces: str):
3536
names = [n.get("name") for n in namespaces_file["namespaces"]]
3637
for n in names:
3738
if not n.startswith("warnet-"):
38-
print(f"Failled to create namespace: {n}. Namespaces must start with a 'warnet-' prefix.")
39+
print(
40+
f"Failled to create namespace: {n}. Namespaces must start with a 'warnet-' prefix."
41+
)
3942

4043
# deploy namespaces
4144
for namespace in namespaces_file["namespaces"]:
@@ -46,7 +49,9 @@ def deploy(namespaces: str):
4649
# all the keys apart from name
4750
namespace_config_override = {k: v for k, v in namespace.items() if k != "name"}
4851

49-
cmd = f"{HELM_COMMAND} {namespace_name} {BITCOIN_CHART_LOCATION} -f {defaults_file_path}"
52+
cmd = (
53+
f"{HELM_COMMAND} {namespace_name} {BITCOIN_CHART_LOCATION} -f {defaults_file_path}"
54+
)
5055

5156
if namespace_config_override:
5257
with tempfile.NamedTemporaryFile(
@@ -63,6 +68,7 @@ def deploy(namespaces: str):
6368
print(f"Error: {e}")
6469
return
6570

71+
6672
@namespaces.command()
6773
def list():
6874
"""List all namespaces with 'warnet-' prefix"""
@@ -78,6 +84,7 @@ def list():
7884
else:
7985
print("No warnet namespaces found.")
8086

87+
8188
@namespaces.command()
8289
@click.option("--all", "destroy_all", is_flag=True, help="Destroy all warnet- prefixed namespaces")
8390
@click.argument("namespace", required=False)

src/warnet/cli/scenarios.py

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from rich import print
1212
from rich.console import Console
1313
from rich.table import Table
14-
1514
from warnet import scenarios as SCENARIOS
1615

1716
from .k8s import apply_kubernetes_yaml, create_namespace, get_mission

test/dag_connection_test.py

-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def run_test(self):
1717
try:
1818
self.setup_network()
1919
self.run_connect_dag_scenario()
20-
self.run_connect_dag_scenario_post_connection()
2120
finally:
2221
self.stop_server()
2322

@@ -29,21 +28,8 @@ def setup_network(self):
2928

3029
def run_connect_dag_scenario(self):
3130
self.log.info("Running connect_dag scenario")
32-
self.log_expected_msgs = [
33-
"Successfully ran the connect_dag.py scenario using a temporary file"
34-
]
35-
self.log_unexpected_msgs = ["Test failed."]
3631
self.warcli("scenarios run-file test/data/scenario_connect_dag.py")
3732
self.wait_for_all_scenarios()
38-
self.assert_log_msgs()
39-
40-
def run_connect_dag_scenario_post_connection(self):
41-
self.log.info("Running connect_dag scenario")
42-
self.log_expected_msgs = ["Successfully ran the connect_dag.py scenario"]
43-
self.log_unexpected_msgs = ["Test failed"]
44-
self.warcli("scenarios run-file test/data/scenario_connect_dag.py")
45-
self.wait_for_all_scenarios()
46-
self.assert_log_msgs()
4733

4834

4935
if __name__ == "__main__":

test/data/scenario_connect_dag.py

+17-36
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import os
44
from enum import Enum, auto, unique
5-
from time import sleep
65

76
# The base class exists inside the commander container
87
from commander import Commander
@@ -23,18 +22,7 @@ def set_test_params(self):
2322
# This is just a minimum
2423
self.num_nodes = 10
2524

26-
def add_options(self, parser):
27-
parser.add_argument(
28-
"--network_name",
29-
dest="network_name",
30-
default="warnet",
31-
help="",
32-
)
33-
3425
def run_test(self):
35-
while not self.warnet.network_connected():
36-
sleep(1)
37-
3826
# All permutations of a directed acyclic graph with zero, one, or two inputs/outputs
3927
#
4028
# │ Node │ In │ Out │ Con In │ Con Out │
@@ -66,12 +54,6 @@ def run_test(self):
6654
self.connect_nodes(5, 4)
6755
self.connect_nodes(5, 6)
6856
self.connect_nodes(6, 7)
69-
70-
# Nodes 8 & 9 shall come pre-connected. Attempt to connect them anyway to test the handling
71-
# of dns node addresses
72-
self.connect_nodes(8, 9)
73-
self.connect_nodes(9, 8)
74-
7557
self.sync_all()
7658

7759
zero_peers = self.nodes[0].getpeerinfo()
@@ -85,31 +67,29 @@ def run_test(self):
8567
eight_peers = self.nodes[8].getpeerinfo()
8668
nine_peers = self.nodes[9].getpeerinfo()
8769

88-
for tank in self.warnet.tanks:
89-
self.log.info(
90-
f"Tank {tank.index}: {tank.warnet.tanks[tank.index].get_dns_addr()} pod:"
91-
f" {tank.warnet.tanks[tank.index].get_ip_addr()}"
92-
)
70+
for node in self.nodes:
71+
self.log.info(f"Node {node.index}: tank={node.tank} ip={node.rpchost}")
9372

94-
self.assert_connection(zero_peers, 2, ConnectionType.DNS)
95-
self.assert_connection(one_peers, 2, ConnectionType.DNS)
96-
self.assert_connection(one_peers, 3, ConnectionType.DNS)
73+
self.assert_connection(zero_peers, 2, ConnectionType.IP)
74+
self.assert_connection(one_peers, 2, ConnectionType.IP)
75+
self.assert_connection(one_peers, 3, ConnectionType.IP)
9776
self.assert_connection(two_peers, 0, ConnectionType.IP)
9877
self.assert_connection(two_peers, 1, ConnectionType.IP)
99-
self.assert_connection(two_peers, 3, ConnectionType.DNS)
100-
self.assert_connection(two_peers, 4, ConnectionType.DNS)
78+
self.assert_connection(two_peers, 3, ConnectionType.IP)
79+
self.assert_connection(two_peers, 4, ConnectionType.IP)
10180
self.assert_connection(three_peers, 1, ConnectionType.IP)
10281
self.assert_connection(three_peers, 2, ConnectionType.IP)
103-
self.assert_connection(three_peers, 5, ConnectionType.DNS)
82+
self.assert_connection(three_peers, 5, ConnectionType.IP)
10483
self.assert_connection(four_peers, 2, ConnectionType.IP)
10584
self.assert_connection(four_peers, 5, ConnectionType.IP)
10685
self.assert_connection(five_peers, 3, ConnectionType.IP)
107-
self.assert_connection(five_peers, 4, ConnectionType.DNS)
108-
self.assert_connection(five_peers, 6, ConnectionType.DNS)
86+
self.assert_connection(five_peers, 4, ConnectionType.IP)
87+
self.assert_connection(five_peers, 6, ConnectionType.IP)
10988
self.assert_connection(six_peers, 5, ConnectionType.IP)
110-
self.assert_connection(six_peers, 7, ConnectionType.DNS)
89+
self.assert_connection(six_peers, 7, ConnectionType.IP)
11190
self.assert_connection(seven_peers, 6, ConnectionType.IP)
11291
# Check the pre-connected nodes
92+
# The only connection made by DNS name would be from the initial graph edges
11393
self.assert_connection(eight_peers, 9, ConnectionType.DNS)
11494
self.assert_connection(nine_peers, 8, ConnectionType.IP)
11595

@@ -121,14 +101,15 @@ def run_test(self):
121101
def assert_connection(self, connector, connectee_index, connection_type: ConnectionType):
122102
if connection_type == ConnectionType.DNS:
123103
assert any(
124-
d.get("addr") == self.warnet.tanks[connectee_index].get_dns_addr()
104+
# ignore the ...-service suffix
105+
self.nodes[connectee_index].tank in d.get("addr")
125106
for d in connector
126-
), f"Could not find {self.options.network_name}-tank-00000{connectee_index}-service"
107+
), "Could not find conectee hostname"
127108
elif connection_type == ConnectionType.IP:
128109
assert any(
129-
d.get("addr").split(":")[0] == self.warnet.tanks[connectee_index].get_ip_addr()
110+
d.get("addr").split(":")[0] == self.nodes[connectee_index].rpchost
130111
for d in connector
131-
), f"Could not find Tank {connectee_index}'s ip addr"
112+
), "Could not find connectee ip addr"
132113
else:
133114
raise ValueError("ConnectionType must be of type DNS or IP")
134115

test/data/scenario_p2p_interface.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
# The base class exists inside the commander container
55
from commander import Commander
6-
76
from test_framework.messages import CInv, msg_getdata
87
from test_framework.p2p import P2PInterface
98

test/ln_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from pathlib import Path
66

77
from test_base import TestBase
8-
98
from warnet.services import ServiceType
109

1110

test/scenarios_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from pathlib import Path
55

66
from test_base import TestBase
7-
87
from warnet.cli.k8s import delete_pod
98
from warnet.cli.scenarios import _active as scenarios_active
109
from warnet.cli.scenarios import _available as scenarios_available

0 commit comments

Comments
 (0)