mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-25 13:28:35 +01:00
test: Adapt test framework for chains other than "regtest"
Co-Authored-By: Jorge Timón <jtimon@jtimon.cc>
This commit is contained in:
@@ -271,8 +271,8 @@ def p2p_port(n):
|
||||
def rpc_port(n):
|
||||
return PORT_MIN + PORT_RANGE + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES)
|
||||
|
||||
def rpc_url(datadir, i, rpchost=None):
|
||||
rpc_u, rpc_p = get_auth_cookie(datadir)
|
||||
def rpc_url(datadir, i, chain, rpchost):
|
||||
rpc_u, rpc_p = get_auth_cookie(datadir, chain)
|
||||
host = '127.0.0.1'
|
||||
port = rpc_port(i)
|
||||
if rpchost:
|
||||
@@ -286,13 +286,13 @@ def rpc_url(datadir, i, rpchost=None):
|
||||
# Node functions
|
||||
################
|
||||
|
||||
def initialize_datadir(dirname, n):
|
||||
def initialize_datadir(dirname, n, chain):
|
||||
datadir = get_datadir_path(dirname, n)
|
||||
if not os.path.isdir(datadir):
|
||||
os.makedirs(datadir)
|
||||
with open(os.path.join(datadir, "bitcoin.conf"), 'w', encoding='utf8') as f:
|
||||
f.write("regtest=1\n")
|
||||
f.write("[regtest]\n")
|
||||
f.write("{}=1\n".format(chain))
|
||||
f.write("[{}]\n".format(chain))
|
||||
f.write("port=" + str(p2p_port(n)) + "\n")
|
||||
f.write("rpcport=" + str(rpc_port(n)) + "\n")
|
||||
f.write("server=1\n")
|
||||
@@ -312,7 +312,7 @@ def append_config(datadir, options):
|
||||
for option in options:
|
||||
f.write(option + "\n")
|
||||
|
||||
def get_auth_cookie(datadir):
|
||||
def get_auth_cookie(datadir, chain):
|
||||
user = None
|
||||
password = None
|
||||
if os.path.isfile(os.path.join(datadir, "bitcoin.conf")):
|
||||
@@ -325,7 +325,7 @@ def get_auth_cookie(datadir):
|
||||
assert password is None # Ensure that there is only one rpcpassword line
|
||||
password = line.split("=")[1].strip("\n")
|
||||
try:
|
||||
with open(os.path.join(datadir, "regtest", ".cookie"), 'r', encoding="ascii") as f:
|
||||
with open(os.path.join(datadir, chain, ".cookie"), 'r', encoding="ascii") as f:
|
||||
userpass = f.read()
|
||||
split_userpass = userpass.split(':')
|
||||
user = split_userpass[0]
|
||||
@@ -337,10 +337,10 @@ def get_auth_cookie(datadir):
|
||||
return user, password
|
||||
|
||||
# If a cookie file exists in the given datadir, delete it.
|
||||
def delete_cookie_file(datadir):
|
||||
if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")):
|
||||
def delete_cookie_file(datadir, chain):
|
||||
if os.path.isfile(os.path.join(datadir, chain, ".cookie")):
|
||||
logger.debug("Deleting leftover cookie file")
|
||||
os.remove(os.path.join(datadir, "regtest", ".cookie"))
|
||||
os.remove(os.path.join(datadir, chain, ".cookie"))
|
||||
|
||||
def get_bip9_status(node, key):
|
||||
info = node.getblockchaininfo()
|
||||
|
||||
Reference in New Issue
Block a user