aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/test_framework/util.py')
-rw-r--r--test/functional/test_framework/util.py39
1 files changed, 23 insertions, 16 deletions
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index 35dbfbba8d..54f2fdee21 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -5,7 +5,6 @@
"""Helpful routines for regression testing."""
from base64 import b64encode
-from binascii import unhexlify
from decimal import Decimal, ROUND_DOWN
from subprocess import CalledProcessError
import hashlib
@@ -214,10 +213,6 @@ def count_bytes(hex_string):
return len(bytearray.fromhex(hex_string))
-def hex_str_to_bytes(hex_str):
- return unhexlify(hex_str.encode('ascii'))
-
-
def str_to_b64str(string):
return b64encode(string.encode('utf-8')).decode('ascii')
@@ -286,15 +281,15 @@ class PortSeed:
n = None
-def get_rpc_proxy(url, node_number, *, timeout=None, coveragedir=None):
+def get_rpc_proxy(url: str, node_number: int, *, timeout: int=None, coveragedir: str=None) -> coverage.AuthServiceProxyWrapper:
"""
Args:
- url (str): URL of the RPC server to call
- node_number (int): the node number (or id) that this calls to
+ url: URL of the RPC server to call
+ node_number: the node number (or id) that this calls to
Kwargs:
- timeout (int): HTTP timeout in seconds
- coveragedir (str): Directory
+ timeout: HTTP timeout in seconds
+ coveragedir: Directory
Returns:
AuthServiceProxy. convenience object for making RPC calls.
@@ -305,11 +300,10 @@ def get_rpc_proxy(url, node_number, *, timeout=None, coveragedir=None):
proxy_kwargs['timeout'] = int(timeout)
proxy = AuthServiceProxy(url, **proxy_kwargs)
- proxy.url = url # store URL on proxy for info
coverage_logfile = coverage.get_filename(coveragedir, node_number) if coveragedir else None
- return coverage.AuthServiceProxyWrapper(proxy, coverage_logfile)
+ return coverage.AuthServiceProxyWrapper(proxy, url, coverage_logfile)
def p2p_port(n):
@@ -338,17 +332,17 @@ def rpc_url(datadir, i, chain, rpchost):
################
-def initialize_datadir(dirname, n, chain):
+def initialize_datadir(dirname, n, chain, disable_autoconnect=True):
datadir = get_datadir_path(dirname, n)
if not os.path.isdir(datadir):
os.makedirs(datadir)
- write_config(os.path.join(datadir, "bitcoin.conf"), n=n, chain=chain)
+ write_config(os.path.join(datadir, "bitcoin.conf"), n=n, chain=chain, disable_autoconnect=disable_autoconnect)
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
return datadir
-def write_config(config_path, *, n, chain, extra_config=""):
+def write_config(config_path, *, n, chain, extra_config="", disable_autoconnect=True):
# Translate chain subdirectory name to config name
if chain == 'testnet3':
chain_name_conf_arg = 'testnet'
@@ -376,6 +370,8 @@ def write_config(config_path, *, n, chain, extra_config=""):
f.write("shrinkdebugfile=0\n")
# To improve SQLite wallet performance so that the tests don't timeout, use -unsafesqlitesync
f.write("unsafesqlitesync=1\n")
+ if disable_autoconnect:
+ f.write("connect=0\n")
f.write(extra_config)
@@ -516,7 +512,7 @@ def gen_return_txouts():
from .messages import CTxOut
txout = CTxOut()
txout.nValue = 0
- txout.scriptPubKey = hex_str_to_bytes(script_pubkey)
+ txout.scriptPubKey = bytes.fromhex(script_pubkey)
for _ in range(128):
txouts.append(txout)
return txouts
@@ -559,6 +555,17 @@ def mine_large_block(node, utxos=None):
node.generate(1)
+def generate_to_height(node, target_height):
+ """Generates blocks until a given target block height has been reached.
+ To prevent timeouts, only up to 200 blocks are generated per RPC call.
+ Can be used to activate certain soft-forks (e.g. CSV, CLTV)."""
+ current_height = node.getblockcount()
+ while current_height < target_height:
+ nblocks = min(200, target_height - current_height)
+ current_height += len(node.generate(nblocks))
+ assert_equal(node.getblockcount(), target_height)
+
+
def find_vout_for_address(node, txid, addr):
"""
Locate the vout index of the given transaction sending to the