Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_node.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2017 The Bitcoin Core developers | # Copyright (c) 2017 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Class for bitcoind node under test""" | """Class for bitcoind node under test""" | ||||
import contextlib | |||||
import decimal | import decimal | ||||
import errno | import errno | ||||
import http.client | import http.client | ||||
import json | import json | ||||
import logging | import logging | ||||
import os | import os | ||||
import re | import re | ||||
import subprocess | import subprocess | ||||
▲ Show 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | def is_node_stopped(self): | ||||
self.rpc_connected = False | self.rpc_connected = False | ||||
self.rpc = None | self.rpc = None | ||||
self.log.debug("Node stopped") | self.log.debug("Node stopped") | ||||
return True | return True | ||||
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT): | def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT): | ||||
wait_until(self.is_node_stopped, timeout=timeout) | wait_until(self.is_node_stopped, timeout=timeout) | ||||
@contextlib.contextmanager | |||||
def assert_debug_log(self, expected_msgs): | |||||
debug_log = os.path.join(self.datadir, 'regtest', 'debug.log') | |||||
with open(debug_log, encoding='utf-8') as dl: | |||||
dl.seek(0, 2) | |||||
prev_size = dl.tell() | |||||
try: | |||||
yield | |||||
finally: | |||||
with open(debug_log, encoding='utf-8') as dl: | |||||
dl.seek(prev_size) | |||||
log = dl.read() | |||||
print_log = " - " + "\n - ".join(log.splitlines()) | |||||
for expected_msg in expected_msgs: | |||||
if re.search(re.escape(expected_msg), log, flags=re.MULTILINE) is None: | |||||
self._raise_assertion_error( | |||||
'Expected message "{}" does not partially match log:\n\n{}\n\n'.format(expected_msg, print_log)) | |||||
def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, partial_match=False, *args, **kwargs): | def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, partial_match=False, *args, **kwargs): | ||||
"""Attempt to start the node and expect it to raise an error. | """Attempt to start the node and expect it to raise an error. | ||||
extra_args: extra arguments to pass through to bitcoind | extra_args: extra arguments to pass through to bitcoind | ||||
expected_msg: regex that stderr should match when bitcoind fails | expected_msg: regex that stderr should match when bitcoind fails | ||||
Will throw if bitcoind starts without an error. | Will throw if bitcoind starts without an error. | ||||
Will throw if an expected_msg is provided and it does not match bitcoind's stdout.""" | Will throw if an expected_msg is provided and it does not match bitcoind's stdout.""" | ||||
▲ Show 20 Lines • Show All 165 Lines • Show Last 20 Lines |