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:
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):
def run_test(self):
lp = addr_to_hex("127.0.0.1")
test_cases = [
lambda p, _: ([[f"-bind=127.0.0.1:{p}=onion"], # onion-only
[(lp, p)], "no normal -bind with -bind=...=onion"]),
lambda p, q: ([[f"-bind=127.0.0.1:{p}", f"-bind=127.0.0.1:{q}=onion"], # bind + onion
[(lp, p), (lp, q)], "both -bind and -bind=...=onion"]),
lambda p, _: ([[f"-bind=127.0.0.1:{p}"], # bind only
[(lp, p)], "no -bind=...=onion"]),
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
[(lp, p), (lp, p), (lp, q)], "duplicated -bind=... and -bind=..."]),
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
[(lp, p), (lp, p), (lp, q)], "duplicated -bind=...=onion and -bind=...=onion"]),
]
ports = itertools.count(p2p_port(self.num_nodes))
for i, make in enumerate(test_cases):
args, expected_services, description = make(next(ports), next(ports))
self.log.info(f"Test case {i + 1}: {description}")
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