aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2023-03-21 13:14:53 -0400
committerRyan Ofsky <ryan@ofsky.org>2023-04-21 06:53:23 -0400
commit3746f00be1b732a04976fc70cbb0661f97bbbd99 (patch)
tree80756a50e6ac4ea56e6eacd933966f8543d418e2 /test/functional/test_framework
parent398c3719b02197ad92fded20f6ff83b364747297 (diff)
downloadbitcoin-3746f00be1b732a04976fc70cbb0661f97bbbd99.tar.xz
init: Error if ignored bitcoin.conf file is found
Show an error on startup if a bitcoin datadir that is being used contains a `bitcoin.conf` file that is ignored. There are two cases where this could happen: - One case reported in https://github.com/bitcoin/bitcoin/issues/27246#issuecomment-1470006043 happens when a bitcoin.conf file in the default datadir (e.g. $HOME/.bitcoin/bitcoin.conf) has a "datadir=/path" line that sets different datadir containing a second bitcoin.conf file. Currently the second bitcoin.conf file is ignored with no warning. - Another way this could happen is if a -conf= command line argument points to a configuration file with a "datadir=/path" line and that specified path contains a bitcoin.conf file, which is currently ignored. This change only adds an error message and doesn't change anything about way settings are applied. It also doesn't trigger errors if there are redundant -datadir or -conf settings pointing at the same configuration file, only if they are pointing at different files and one file is being ignored.
Diffstat (limited to 'test/functional/test_framework')
-rwxr-xr-xtest/functional/test_framework/test_node.py4
-rw-r--r--test/functional/test_framework/util.py20
2 files changed, 22 insertions, 2 deletions
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index 56abe5f26a..51bd697e81 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -190,7 +190,7 @@ class TestNode():
assert self.rpc_connected and self.rpc is not None, self._node_msg("Error: no RPC connection")
return getattr(RPCOverloadWrapper(self.rpc, descriptors=self.descriptors), name)
- def start(self, extra_args=None, *, cwd=None, stdout=None, stderr=None, **kwargs):
+ def start(self, extra_args=None, *, cwd=None, stdout=None, stderr=None, env=None, **kwargs):
"""Start the node."""
if extra_args is None:
extra_args = self.extra_args
@@ -213,6 +213,8 @@ class TestNode():
# add environment variable LIBC_FATAL_STDERR_=1 so that libc errors are written to stderr and not the terminal
subp_env = dict(os.environ, LIBC_FATAL_STDERR_="1")
+ if env is not None:
+ subp_env.update(env)
self.process = subprocess.Popen(self.args + extra_args, env=subp_env, stdout=stdout, stderr=stderr, cwd=cwd, **kwargs)
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index a1b90860f6..c75db60afe 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -12,14 +12,16 @@ import inspect
import json
import logging
import os
+import pathlib
import random
import re
+import sys
import time
import unittest
from . import coverage
from .authproxy import AuthServiceProxy, JSONRPCException
-from typing import Callable, Optional
+from typing import Callable, Optional, Tuple
logger = logging.getLogger("TestFramework.utils")
@@ -420,6 +422,22 @@ def get_datadir_path(dirname, n):
return os.path.join(dirname, "node" + str(n))
+def get_temp_default_datadir(temp_dir: pathlib.Path) -> Tuple[dict, pathlib.Path]:
+ """Return os-specific environment variables that can be set to make the
+ GetDefaultDataDir() function return a datadir path under the provided
+ temp_dir, as well as the complete path it would return."""
+ if sys.platform == "win32":
+ env = dict(APPDATA=str(temp_dir))
+ datadir = temp_dir / "Bitcoin"
+ else:
+ env = dict(HOME=str(temp_dir))
+ if sys.platform == "darwin":
+ datadir = temp_dir / "Library/Application Support/Bitcoin"
+ else:
+ datadir = temp_dir / ".bitcoin"
+ return env, datadir
+
+
def append_config(datadir, options):
with open(os.path.join(datadir, "bitcoin.conf"), 'a', encoding='utf8') as f:
for option in options: