Skip to content

Commit

Permalink
test: add interface_ipc_mining.py test calling bitcoin-mine
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanofsky committed Nov 27, 2024
1 parent 8fab416 commit 1f18eef
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions test/config.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,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
31 changes: 31 additions & 0 deletions test/functional/interface_ipc_mining.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
# Copyright (c) 2024 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-cli"""

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
)

import subprocess

class TestBitcoinMine(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
# Always run multiprocess binaries
self.options.bitcoind = self.options.bitcoin_node
self.extra_args = [["-ipcbind=unix"]]

def skip_test_if_missing_module(self):
self.skip_if_no_multiprocess()

def run_test(self):
args = [self.options.bitcoin_mine, f"-datadir={self.nodes[0].datadir_path}"]
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()
21 changes: 16 additions & 5 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def parse_args(self, test_file):
config = configparser.ConfigParser()
config.read_file(open(self.options.configfile))
self.config = config
self.set_binary_paths()
if self.options.v1transport:
self.options.v2transport=False

Expand Down Expand Up @@ -241,13 +242,16 @@ def set_binary_paths(self):
"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"],
"src",
binary + self.config["environment"]["EXEEXT"],
)
setattr(self.options, attribute_name, os.getenv(env_variable_name, default=default_filename))
for binary, [attribute_name, env_variable_name] in binaries.items():
setattr(self.options, attribute_name, os.getenv(env_variable_name) or binary_path(binary))
self.options.bitcoin_mine = binary_path("bitcoin-mine")
self.options.bitcoin_node = binary_path("bitcoin-node")

def setup(self):
"""Call this method to start up the test framework object with options set."""
Expand All @@ -258,8 +262,6 @@ def setup(self):

config = self.config

self.set_binary_paths()

os.environ['PATH'] = os.pathsep.join([
os.path.join(config['environment']['BUILDDIR'], 'src'),
os.path.join(config['environment']['BUILDDIR'], 'src', 'qt'), os.environ['PATH']
Expand Down Expand Up @@ -984,6 +986,11 @@ def skip_if_no_cli(self):
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():
Expand Down Expand Up @@ -1046,5 +1053,9 @@ def is_bdb_compiled(self):
"""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()
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@
'rpc_getdescriptorinfo.py',
'rpc_mempool_info.py',
'rpc_help.py',
'interface_ipc_mining.py',
'mempool_ephemeral_dust.py',
'p2p_handshake.py',
'p2p_handshake.py --v2transport',
Expand Down

0 comments on commit 1f18eef

Please sign in to comment.