mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
test: add interface_ipc_mining.py test calling bitcoin-mine
Co-authored-by: Sjors Provoost <sjors@sprovoost.nl>
This commit is contained in:
parent
8e31982d5a
commit
fae300f159
5 changed files with 64 additions and 3 deletions
|
@ -25,6 +25,7 @@ function(create_test_config)
|
|||
set_configure_variable(WITH_ZMQ ENABLE_ZMQ)
|
||||
set_configure_variable(ENABLE_EXTERNAL_SIGNER ENABLE_EXTERNAL_SIGNER)
|
||||
set_configure_variable(WITH_USDT ENABLE_USDT_TRACEPOINTS)
|
||||
set_configure_variable(WITH_MULTIPROCESS WITH_MULTIPROCESS)
|
||||
|
||||
configure_file(config.ini.in config.ini USE_SOURCE_PERMISSIONS @ONLY)
|
||||
endfunction()
|
||||
|
|
|
@ -25,3 +25,4 @@ RPCAUTH=@abs_top_srcdir@/share/rpcauth/rpcauth.py
|
|||
@ENABLE_ZMQ_TRUE@ENABLE_ZMQ=true
|
||||
@ENABLE_EXTERNAL_SIGNER_TRUE@ENABLE_EXTERNAL_SIGNER=true
|
||||
@ENABLE_USDT_TRACEPOINTS_TRUE@ENABLE_USDT_TRACEPOINTS=true
|
||||
@WITH_MULTIPROCESS_TRUE@WITH_MULTIPROCESS=true
|
||||
|
|
46
test/functional/interface_ipc_mining.py
Executable file
46
test/functional/interface_ipc_mining.py
Executable file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2025 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
"""Test bitcoin-mine"""
|
||||
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
)
|
||||
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
class TestBitcoinMine(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_multiprocess()
|
||||
|
||||
def setup_nodes(self):
|
||||
# Always run multiprocess binaries
|
||||
self.binary_paths.bitcoind = self.binary_paths.bitcoin_node
|
||||
|
||||
# Work around default CI path exceeding maximum socket path length.
|
||||
# On Linux sun_path is 108 bytes, on macOS it's only 104. Includes
|
||||
# null terminator.
|
||||
socket_path = self.options.tmpdir + "/node0/regtest/node.sock"
|
||||
if len(socket_path.encode('utf-8')) < 104:
|
||||
self.extra_args = [["-ipcbind=unix"]]
|
||||
self.mine_args = []
|
||||
else:
|
||||
sock_path = tempfile.mktemp()
|
||||
self.extra_args = [[f"-ipcbind=unix:{sock_path}"]]
|
||||
self.mine_args = [f"-ipcconnect=unix:{sock_path}"]
|
||||
super().setup_nodes()
|
||||
|
||||
def run_test(self):
|
||||
args = [self.binary_paths.bitcoin_mine, f"-datadir={self.nodes[0].datadir_path}"] + self.mine_args
|
||||
result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, check=True)
|
||||
assert_equal(result.stdout, "Connected to bitcoin-node\nTip hash is 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206.\n")
|
||||
|
||||
if __name__ == '__main__':
|
||||
TestBitcoinMine(__file__).main()
|
|
@ -293,13 +293,16 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
|||
"bitcoin-util": ("bitcoinutil", "BITCOINUTIL"),
|
||||
"bitcoin-wallet": ("bitcoinwallet", "BITCOINWALLET"),
|
||||
}
|
||||
for binary, [attribute_name, env_variable_name] in binaries.items():
|
||||
default_filename = os.path.join(
|
||||
def binary_path(binary):
|
||||
return os.path.join(
|
||||
self.config["environment"]["BUILDDIR"],
|
||||
"bin",
|
||||
binary + self.config["environment"]["EXEEXT"],
|
||||
)
|
||||
setattr(paths, attribute_name, os.getenv(env_variable_name, default=default_filename))
|
||||
for binary, [attribute_name, env_variable_name] in binaries.items():
|
||||
setattr(paths, attribute_name, os.getenv(env_variable_name) or binary_path(binary))
|
||||
paths.bitcoin_mine = binary_path("bitcoin-mine")
|
||||
paths.bitcoin_node = binary_path("bitcoin-node")
|
||||
return paths
|
||||
|
||||
def get_binaries(self, bin_dir=None):
|
||||
|
@ -1027,6 +1030,11 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
|||
if not self.is_cli_compiled():
|
||||
raise SkipTest("bitcoin-cli has not been compiled.")
|
||||
|
||||
def skip_if_no_multiprocess(self):
|
||||
"""Skip the running test if multiprocess binaries are not compiled."""
|
||||
if not self.is_multiprocess_compiled():
|
||||
raise SkipTest("multiprocess binaries have not been compiled.")
|
||||
|
||||
def skip_if_no_previous_releases(self):
|
||||
"""Skip the running test if previous releases are not available."""
|
||||
if not self.has_previous_releases():
|
||||
|
@ -1085,5 +1093,9 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
|||
"""Checks whether the wallet module was compiled with BDB support."""
|
||||
return self.config["components"].getboolean("USE_BDB")
|
||||
|
||||
def is_multiprocess_compiled(self):
|
||||
"""Checks whether multiprocess binaries are compiled."""
|
||||
return self.config["components"].getboolean("WITH_MULTIPROCESS")
|
||||
|
||||
def has_blockfile(self, node, filenum: str):
|
||||
return (node.blocks_path/ f"blk{filenum}.dat").is_file()
|
||||
|
|
|
@ -407,6 +407,7 @@ BASE_SCRIPTS = [
|
|||
'rpc_help.py',
|
||||
'p2p_handshake.py',
|
||||
'p2p_handshake.py --v2transport',
|
||||
'interface_ipc_mining.py',
|
||||
'feature_dirsymlinks.py',
|
||||
'feature_help.py',
|
||||
'feature_shutdown.py',
|
||||
|
|
Loading…
Add table
Reference in a new issue