forked from bitcoin-dev-project/warnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconf_test.py
executable file
·78 lines (64 loc) · 2.61 KB
/
conf_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
import json
import os
import re
from pathlib import Path
from test_base import TestBase
from warnet.control import stop_scenario
from warnet.k8s import get_mission
from warnet.status import _get_deployed_scenarios as scenarios_deployed
class ConfTest(TestBase):
def __init__(self):
super().__init__()
self.network_dir = Path(os.path.dirname(__file__)) / "data" / "bitcoin_conf"
self.scen_dir = Path(os.path.dirname(__file__)).parent / "resources" / "scenarios"
def run_test(self):
try:
self.setup_network()
self.check_uacomment()
self.check_single_miner()
finally:
self.cleanup()
def setup_network(self):
self.log.info("Setting up network")
self.log.info(self.warnet(f"deploy {self.network_dir}"))
self.wait_for_all_tanks_status(target="running")
def check_uacomment(self):
tanks = get_mission("tank")
def get_uacomment():
for tank in tanks[::-1]:
try:
name = tank.metadata.name
info = json.loads(self.warnet(f"bitcoin rpc {name} getnetworkinfo"))
subver = info["subversion"]
# Regex pattern to match the uacomment inside parentheses
# e.g. /Satoshi:27.0.0(tank-0027)/
pattern = r"\(([^)]+)\)"
match = re.search(pattern, subver)
if match:
uacomment = match.group(1)
assert uacomment == name
else:
return False
except Exception:
return False
return True
self.wait_for_predicate(get_uacomment)
def check_single_miner(self):
scenario_file = self.scen_dir / "miner_std.py"
self.log.info(f"Running scenario from: {scenario_file}")
# Mine from a tank that is not first or last and
# is one of the only few in the network that even
# has rpc reatewallet method!
self.warnet(f"run {scenario_file} --tank=tank-0026 --interval=1")
self.wait_for_predicate(
lambda: int(self.warnet("bitcoin rpc tank-0026 getblockcount")) >= 10
)
running = scenarios_deployed()
assert len(running) == 1, f"Expected one running scenario, got {len(running)}"
assert running[0]["status"] == "running", "Scenario should be running"
stop_scenario(running[0]["name"])
self.wait_for_all_scenarios()
if __name__ == "__main__":
test = ConfTest()
test.run_test()