From dfea6c69d2eca66b8c4572f76a3c82796a4c50b6 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Sun, 27 Mar 2022 00:39:41 +0000 Subject: [PATCH] Repair `feature_zip239` RPC test by checking the debug log of node 0 rather than its stderr. Since we no longer redirect stderr, this will correctly fail if stderr has unexpected output. Signed-off-by: Daira Hopwood --- qa/rpc-tests/feature_zip239.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/qa/rpc-tests/feature_zip239.py b/qa/rpc-tests/feature_zip239.py index 19ec1550f..6824d9ff1 100755 --- a/qa/rpc-tests/feature_zip239.py +++ b/qa/rpc-tests/feature_zip239.py @@ -32,7 +32,7 @@ from test_framework.util import ( ) from tx_expiry_helper import TestNode -import tempfile +import os.path import time # Test ZIP 239 behaviour before and after NU5. @@ -46,14 +46,8 @@ class Zip239Test(BitcoinTestFramework): nuparams(NU5_BRANCH_ID, 210), ] - # We log the stderr of node 0, which the test nodes connect to. This - # enables us to check that we see the expected error logged, and also - # ensures that the test itself passes (as otherwise the stderr output - # would be interpreted as an error from the test itself). - self.log_stderr = tempfile.SpooledTemporaryFile(max_size=2**16) - nodes = [] - nodes.append(start_node(0, self.options.tmpdir, extra_args, stderr=self.log_stderr)) + nodes.append(start_node(0, self.options.tmpdir, extra_args)) nodes.append(start_node(1, self.options.tmpdir, extra_args)) nodes.append(start_node(2, self.options.tmpdir, extra_args)) nodes.append(start_node(3, self.options.tmpdir, extra_args)) @@ -138,12 +132,13 @@ class Zip239Test(BitcoinTestFramework): expected.reason = b"error parsing message" assert_equal(conn.rejectMessage, expected) - # Verify that we see the expected error on stderr - self.log_stderr.seek(0) - stderr = self.log_stderr.read().decode('utf-8') - self.log_stderr.truncate(0) - if expected_msg not in stderr: - raise AssertionError("Expected error \"" + expected_msg + "\" not found in:\n" + stderr) + # Verify that we see the expected error in the debug log of node 0 + log_path = os.path.join(self.options.tmpdir, 'node0', 'regtest', 'debug.log') + with open(log_path, 'r', encoding='utf-8') as log_file: + log_content = log_file.read() + + if expected_msg not in log_content: + raise AssertionError("Expected error \"" + expected_msg + "\" not found in:\n" + log_content) def verify_disconnected(self, testnode, timeout=30): sleep_time = 0.05 @@ -266,7 +261,6 @@ class Zip239Test(BitcoinTestFramework): test_nodes[0], connections[0], 0xffff, "Unknown CInv message type") [c.disconnect_node() for c in connections] - self.log_stderr.close() if __name__ == '__main__': Zip239Test().main()