Skip to content

Commit 76f3387

Browse files
committed
test: cover defaultConfig / config options when creating network
1 parent 7bcbe06 commit 76f3387

File tree

3 files changed

+54
-42
lines changed

3 files changed

+54
-42
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
test:
3939
- conf_test.py
4040
- dag_connection_test.py
41+
- graph_test.py
4142
- logging_test.py
4243
- rpc_test.py
4344
- services_test.py
@@ -87,24 +88,3 @@ jobs:
8788
name: kubernetes-logs-${{ matrix.test }}
8889
path: ./k8s-logs
8990
retention-days: 5
90-
test-without-mk:
91-
runs-on: ubuntu-latest
92-
strategy:
93-
matrix:
94-
test:
95-
- graph_test.py
96-
steps:
97-
- uses: actions/checkout@v4
98-
- name: Install the latest version of uv
99-
uses: astral-sh/setup-uv@v2
100-
with:
101-
version: "latest"
102-
enable-cache: true
103-
- name: Install Python
104-
run: uv python install $PYTHON_VERSION
105-
- name: Install project
106-
run: uv sync --all-extras --dev
107-
- name: Run tests
108-
run: |
109-
source .venv/bin/activate
110-
./test/${{matrix.test}}

test/graph_test.py

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

3+
import json
34
import os
4-
import shutil
55

66
import pexpect
77
from test_base import TestBase
@@ -15,34 +15,65 @@ def __init__(self):
1515

1616
def run_test(self):
1717
try:
18+
# cwd out of the git repo for remainder of script
19+
os.chdir(self.tmpdir)
1820
self.directory_not_exist()
1921
os.mkdir(NETWORKS_DIR)
2022
self.directory_exists()
21-
23+
self.run_created_network()
2224
finally:
23-
shutil.rmtree(NETWORKS_DIR) if os.path.exists(NETWORKS_DIR) else None
25+
self.cleanup()
2426

2527
def directory_not_exist(self):
26-
self.sut = pexpect.spawn("warnet create")
27-
self.sut.expect("init", timeout=50)
28+
try:
29+
self.log.info("testing warnet create, dir doesn't exist")
30+
self.sut = pexpect.spawn("warnet create")
31+
self.sut.expect("init", timeout=10)
32+
except Exception as e:
33+
print(f"\nReceived prompt text:\n {self.sut.before.decode('utf-8')}\n")
34+
raise e
2835

2936
def directory_exists(self):
30-
self.sut = pexpect.spawn("warnet create")
31-
self.sut.expect("name", timeout=10)
32-
self.sut.sendline("ANewNetwork")
33-
self.sut.expect("many", timeout=10)
34-
self.sut.sendline("")
35-
self.sut.expect("connections", timeout=10)
36-
self.sut.sendline("")
37-
self.sut.expect("version", timeout=10)
38-
self.sut.sendline("")
39-
self.sut.expect("enable fork-observer", timeout=10)
40-
self.sut.sendline("")
41-
self.sut.expect("seconds", timeout=10)
42-
self.sut.sendline("")
43-
self.sut.expect("enable grafana", timeout=10)
44-
self.sut.sendline("")
45-
self.sut.expect("successfully", timeout=50)
37+
try:
38+
self.log.info("testing warnet create, dir does exist")
39+
self.sut = pexpect.spawn("warnet create")
40+
self.sut.expect("name", timeout=10)
41+
self.sut.sendline("ANewNetwork")
42+
self.sut.expect("many", timeout=10)
43+
self.sut.sendline("")
44+
self.sut.expect("connections", timeout=10)
45+
self.sut.sendline("")
46+
self.sut.expect("version", timeout=10)
47+
self.sut.sendline("")
48+
self.sut.expect("enable fork-observer", timeout=10)
49+
self.sut.sendline("")
50+
self.sut.expect("seconds", timeout=10)
51+
self.sut.sendline("")
52+
self.sut.expect("enable grafana", timeout=10)
53+
self.sut.sendline("")
54+
self.sut.expect("successfully", timeout=50)
55+
except Exception as e:
56+
print(f"\nReceived prompt text:\n {self.sut.before.decode('utf-8')}\n")
57+
raise e
58+
59+
def run_created_network(self):
60+
self.log.info("adding custom config to one tank")
61+
with open("networks/ANewNetwork/network.yaml") as f:
62+
s = f.read()
63+
s = s.replace(" name: tank-0000\n", " name: tank-0000\n config: debug=mempool\n")
64+
with open("networks/ANewNetwork/network.yaml", "w") as f:
65+
f.write(s)
66+
67+
self.log.info("deploying new network")
68+
self.warnet("deploy networks/ANewNetwork")
69+
self.wait_for_all_tanks_status(target="running")
70+
debugs = json.loads(self.warnet("bitcoin rpc tank-0000 logging"))
71+
# set in defaultConfig
72+
assert debugs["rpc"]
73+
# set in config just for this tank
74+
assert debugs["mempool"]
75+
# santy check
76+
assert not debugs["zmq"]
4677

4778

4879
if __name__ == "__main__":

test/test_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def setup_logging(self):
3939
logging.config.dictConfig(logging_config)
4040
self.log = logging.getLogger("test")
4141
self.log.info("Logging started")
42+
self.log.info(f"Testdir: {self.tmpdir}")
4243

4344
def cleanup(self, signum=None, frame=None):
4445
try:

0 commit comments

Comments
 (0)