Work towards getting RPC tests working again
So much has changed since I originally got the RPC tests working many years ago, most notably modern Linux distros don't even have a way to install python2 via packages, you have to install from source. Continuing with python2 does not seem like a good idea, so we begin migrating thigns to Python 3. Currently running ./test.sh will successfully spin up a test chain but then the test suite crashes when attempting to send an RPC request, which looks to be caused by the test suite internals still expecting python2.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2016-2024 The Hush developers
|
||||
# Copyright (c) 2018 SuperNET developers
|
||||
# Distributed under the GPLv3 software license, see the accompanying
|
||||
@@ -39,13 +39,10 @@ class AssetChainPrivateTest (BitcoinTestFramework):
|
||||
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
|
||||
extra_args=[[
|
||||
# always give -ac_name as first extra_arg and port as third
|
||||
'-ac_name=REGTEST',
|
||||
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
|
||||
'-ac_name=ZZZ',
|
||||
'-conf='+self.options.tmpdir+'/node0/ZZZ.conf',
|
||||
'-port=64367',
|
||||
'-rpcport=64368',
|
||||
'-regtest',
|
||||
'-addressindex=1',
|
||||
'-spentindex=1',
|
||||
'-ac_supply=0',
|
||||
'-ac_reward=25600000000',
|
||||
'-ac_private=1',
|
||||
@@ -78,7 +75,7 @@ class AssetChainPrivateTest (BitcoinTestFramework):
|
||||
rpc.getwalletinfo()
|
||||
|
||||
taddr = rpc.getnewaddress()
|
||||
print "Sending to " + taddr
|
||||
print("Sending to " + taddr)
|
||||
# sending to arbitrary non-notary transparent address is not allowed
|
||||
assert_raises(JSONRPCException, rpc.sendtoaddress, taddr,1)
|
||||
|
||||
|
||||
@@ -142,6 +142,7 @@ class AuthServiceProxy(object):
|
||||
'method': self.__service_name,
|
||||
'params': args,
|
||||
'id': AuthServiceProxy.__id_count}, default=EncodeDecimal)
|
||||
print("self.__url.path=" + self.__url.path)
|
||||
response = self._request('POST', self.__url.path, postdata)
|
||||
if response['error'] is not None:
|
||||
raise JSONRPCException(response['error'])
|
||||
|
||||
@@ -169,7 +169,7 @@ class ComparisonTestFramework(BitcoinTestFramework):
|
||||
help="bitcoind binary to use for reference nodes (if any)")
|
||||
|
||||
def setup_chain(self):
|
||||
print "Initializing test directory "+self.options.tmpdir
|
||||
print("Initializing test directory "+self.options.tmpdir)
|
||||
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
|
||||
|
||||
def setup_network(self):
|
||||
|
||||
@@ -107,7 +107,7 @@ def initialize_datadir(dirname, n):
|
||||
f.write("port="+str(p2p_port(n))+"\n");
|
||||
rpcport = str(rpc_port(n))
|
||||
f.write("rpcport="+rpcport+"\n");
|
||||
print "RPC port=" + rpcport
|
||||
print("RPC port=" + rpcport)
|
||||
f.write("listenonion=0\n");
|
||||
# TODO: maybe make these optional, via arg to initialize_datadir, defaulted to on for now
|
||||
f.write("addressindex=1\n");
|
||||
@@ -136,14 +136,14 @@ def initialize_chain(test_dir):
|
||||
cmd = os.getenv("BITCOINCLI", "hush-cli")
|
||||
cmd_args = cmd + " -datadir="+datadir + " -rpcwait getblockcount"
|
||||
if os.getenv("PYTHON_DEBUG", ""):
|
||||
print "initialize_chain: hushd started, calling: " + cmd_args
|
||||
print("initialize_chain: hushd started, calling: " + cmd_args)
|
||||
strcmd = cmd + " " + "-datadir="+datadir + " -rpcwait getblockcount"
|
||||
|
||||
print("Running " + strcmd)
|
||||
subprocess.check_call(strcmd, shell=True);
|
||||
#subprocess.check_call([ cmd, "-rpcwait", "getblockcount"], stdout=devnull)
|
||||
if os.getenv("PYTHON_DEBUG", ""):
|
||||
print "initialize_chain: hush-cli -rpcwait getblockcount completed"
|
||||
print("initialize_chain: hush-cli -rpcwait getblockcount completed")
|
||||
devnull.close()
|
||||
rpcs = []
|
||||
for i in range(4):
|
||||
@@ -175,7 +175,7 @@ def initialize_chain(test_dir):
|
||||
stop_nodes(rpcs)
|
||||
wait_bitcoinds()
|
||||
for i in range(4):
|
||||
print "Cleaning up cache dir files"
|
||||
print("Cleaning up cache dir files")
|
||||
os.remove(log_filename("cache", i, "debug.log"))
|
||||
os.remove(log_filename("cache", i, "db.log"))
|
||||
os.remove(log_filename("cache", i, "peers.dat"))
|
||||
@@ -221,13 +221,12 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
|
||||
"""
|
||||
Start a hushd and return RPC connection to it
|
||||
"""
|
||||
print("Starting node " + str(i))
|
||||
print("Starting node " + str(i) + "in dir " + dirname)
|
||||
datadir = os.path.join(dirname, "node"+str(i))
|
||||
# creating special config in case of cryptocondition asset chain test
|
||||
if len(extra_args) > 0 and extra_args[0] == '-ac_name=REGTEST':
|
||||
configpath = datadir + "/REGTEST.conf"
|
||||
if len(extra_args) > 0 and extra_args[0] == '-ac_name=ZZZ':
|
||||
configpath = datadir + "/ZZZ.conf"
|
||||
with open(configpath, "w+") as config:
|
||||
config.write("regtest=1\n")
|
||||
config.write("rpcuser=rt\n")
|
||||
config.write("rpcpassword=rt\n")
|
||||
port = extra_args[3]
|
||||
@@ -239,18 +238,18 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
|
||||
config.write("bind=127.0.0.1\n")
|
||||
config.write("rpcbind=127.0.0.1")
|
||||
if binary is None:
|
||||
binary = os.getenv("BITCOIND", "hushd")
|
||||
binary = os.getenv("BITCOIND", "src/hushd")
|
||||
args = [ binary, "-datadir="+datadir, "-keypool=1", "-discover=0", "-rest" ]
|
||||
if extra_args is not None: args.extend(extra_args)
|
||||
#print("args=" + ' '.join(args))
|
||||
bitcoind_processes[i] = subprocess.Popen(args)
|
||||
devnull = open("/dev/null", "w+")
|
||||
|
||||
cmd = os.getenv("BITCOINCLI", "hush-cli")
|
||||
cmd = os.getenv("BITCOINCLI", "src/hush-cli")
|
||||
print("cmd=" + cmd)
|
||||
cmd_args = ' '.join(extra_args) + " -rpcwait getblockcount "
|
||||
if os.getenv("PYTHON_DEBUG", ""):
|
||||
print "start_node: hushd started, calling : " + cmd + " " + cmd_args
|
||||
print("start_node: hushd started, calling : " + cmd + " " + cmd_args)
|
||||
strcmd = cmd + " " + cmd_args
|
||||
|
||||
print("Running " + strcmd)
|
||||
@@ -261,13 +260,14 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
|
||||
# _rpchost_to_args(rpchost) +
|
||||
# ["-rpcwait", "-rpcport=6438", "getblockcount"], stdout=devnull)
|
||||
if os.getenv("PYTHON_DEBUG", ""):
|
||||
print "start_node: calling hush-cli -rpcwait getblockcount returned"
|
||||
print("start_node: calling hush-cli -rpcwait getblockcount returned")
|
||||
devnull.close()
|
||||
#port = extra_args[3]
|
||||
port = rpc_port(i)
|
||||
print("port=%s" % port)
|
||||
username = rpc_username()
|
||||
password = rpc_password()
|
||||
url = "http://%s:%s@%s:%d" % (username, password, rpchost or '127.0.0.1', int(port[9:]))
|
||||
url = "http://%s:%s@%s:%s" % (username, password, rpchost or '127.0.0.1', port)
|
||||
print("connecting to " + url)
|
||||
if timewait is not None:
|
||||
proxy = AuthServiceProxy(url, timeout=timewait)
|
||||
|
||||
Reference in New Issue
Block a user