nit: in first case increment
means +1, here it’s +1
- but more generally, the code is already, it’s enough if we just document the intent:
0 port += 2 # avoid conflicts since we've used two ports before
or even better, why are we even reusing the same variable, why not create a port iterator and instead of the list a lambda accepting two ports something like (untested, since this test is skipped on a Mac):
0def run_test(self):
1 lp = addr_to_hex("127.0.0.1")
2 test_cases = [
3 lambda p, _: ([[f"-bind=127.0.0.1:{p}=onion"], # onion-only
4 [(lp, p)], "no normal -bind with -bind=...=onion"]),
5 lambda p, q: ([[f"-bind=127.0.0.1:{p}", f"-bind=127.0.0.1:{q}=onion"], # bind + onion
6 [(lp, p), (lp, q)], "both -bind and -bind=...=onion"]),
7 lambda p, _: ([[f"-bind=127.0.0.1:{p}"], # bind only
8 [(lp, p)], "no -bind=...=onion"]),
9 lambda p, q: ([[f"-bind=127.0.0.1:{p}", f"-bind=127.0.0.1:{p}", f"-bind=127.0.0.1:{q}"], # duplicated bind
10 [(lp, p), (lp, p), (lp, q)], "duplicated -bind=... and -bind=..."]),
11 lambda p, q: ([[f"-bind=127.0.0.1:{p}=onion", f"-bind=127.0.0.1:{p}=onion", f"-bind=127.0.0.1:{q}=onion"], # duplicated onion bind
12 [(lp, p), (lp, p), (lp, q)], "duplicated -bind=...=onion and -bind=...=onion"]),
13 ]
14
15 ports = itertools.count(p2p_port(self.num_nodes))
16 for i, make in enumerate(test_cases):
17 args, expected_services, description = make(next(ports), next(ports))
18 self.log.info(f"Test case {i + 1}: {description}")
19 self.log.info(f"Restarting node 0 with args: {args}")
It’s also a bit inconsistent that at the end we just hardcode -bind=127.0.0.1:11012
, maybe we could extract that port as well