refactor: torcontrol add connection checks to restart_with_mock
What changed, and why it matters
This commit is a minor cleanup of a Bitcoin Core functional test file. It moves some connection-checking code into a helper method so it is reused by multiple tests, rather than being duplicated in each test. There is no change to the actual Bitcoin Core software that users run, and no security issue is introduced or fixed.
No action needed. This is a non-security test refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors test/functional/feature_torcontrol.py. The restart_with_mock helper now waits for the mock Tor control server connection and verifies the first received command is ‘PROTOCOLINFO 1’. Previously this wait/assert block was duplicated in test_basic and test_max_line_length. The change is purely test-code deduplication; production code is untouched.
Changed components
test/functional/feature_torcontrol.pyInspect captured patch +5 / −10
diff --git a/test/functional/feature_torcontrol.py b/test/functional/feature_torcontrol.py
index 2148fc10..5f8cf9f6 100755
--- a/test/functional/feature_torcontrol.py
+++ b/test/functional/feature_torcontrol.py
@@ -119,6 +119,11 @@ class TorControlTest(BitcoinTestFramework):
"-debug=tor",
])
+ # Wait for connection and PROTOCOLINFO command
+ mock_tor.conn_ready.wait(timeout=10)
+ self.wait_until(lambda: len(mock_tor.received_commands) >= 1, timeout=10)
+ assert_equal(mock_tor.received_commands[0], "PROTOCOLINFO 1")
+
def test_basic(self):
self.log.info("Test Tor control basic functionality")
@@ -144,11 +149,6 @@ class TorControlTest(BitcoinTestFramework):
mock_tor = MockTorControlServer(self.next_port(), manual_mode=True)
self.restart_with_mock(mock_tor)
- # Wait for connection and PROTOCOLINFO command
- mock_tor.conn_ready.wait(timeout=10)
- self.wait_until(lambda: len(mock_tor.received_commands) >= 1, timeout=10)
- assert_equal(mock_tor.received_commands[0], "PROTOCOLINFO 1")
-
# Send partial response (no \r\n on last line)
mock_tor.send_raw(
"250-PROTOCOLINFO 1\r\n"
@@ -207,11 +207,6 @@ class TorControlTest(BitcoinTestFramework):
mock_tor = MockTorControlServer(self.next_port(), manual_mode=True)
self.restart_with_mock(mock_tor)
- # Wait for connection and PROTOCOLINFO command.
- mock_tor.conn_ready.wait(timeout=10)
- self.wait_until(lambda: len(mock_tor.received_commands) >= 1, timeout=10)
- assert_equal(mock_tor.received_commands[0], "PROTOCOLINFO 1")
-
# Send a single line longer than MAX_LINE_LENGTH. The node should disconnect.
MAX_LINE_LENGTH = 100000
mock_tor.send_raw("250-" + ("A" * (MAX_LINE_LENGTH + 1)) + "\r\n")
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.