mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-11 12:03:04 +02:00
[Tests] Move assert_start_raises_init_error method to TestNode
This commit is contained in:
@@ -12,6 +12,7 @@ import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from .authproxy import JSONRPCException
|
||||
@@ -165,6 +166,33 @@ class TestNode():
|
||||
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):
|
||||
wait_until(self.is_node_stopped, timeout=timeout)
|
||||
|
||||
def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, *args, **kwargs):
|
||||
"""Attempt to start the node and expect it to raise an error.
|
||||
|
||||
Will throw if bitcoind starts without an error.
|
||||
Will throw if an expected_msg is provided and it does not appear in bitcoind's stdout."""
|
||||
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
|
||||
try:
|
||||
self.start(extra_args, stderr=log_stderr, *args, **kwargs)
|
||||
self.wait_for_rpc_connection()
|
||||
self.stop_node()
|
||||
self.wait_util_stopped()
|
||||
except Exception as e:
|
||||
assert 'bitcoind exited' in str(e) # node must have shutdown
|
||||
self.running = False
|
||||
self.process = None
|
||||
if expected_msg is not None:
|
||||
log_stderr.seek(0)
|
||||
stderr = log_stderr.read().decode('utf-8')
|
||||
if expected_msg not in stderr:
|
||||
raise AssertionError("Expected error \"" + expected_msg + "\" not found in:\n" + stderr)
|
||||
else:
|
||||
if expected_msg is None:
|
||||
assert_msg = "bitcoind should have exited with an error"
|
||||
else:
|
||||
assert_msg = "bitcoind should have exited with expected error " + expected_msg
|
||||
raise AssertionError(assert_msg)
|
||||
|
||||
def node_encrypt_wallet(self, passphrase):
|
||||
""""Encrypts the wallet.
|
||||
|
||||
|
Reference in New Issue
Block a user