aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/util.py
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-04-07 17:29:36 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-05-13 07:23:23 +0200
commitb5ad5e783d6f636d5ca5703919d05fd0119a34fc (patch)
tree2f6a26031cec7701c8517a411e502c84eb8686a1 /qa/rpc-tests/util.py
parentf923c077547ceb8492e11001d571ba27145242ef (diff)
downloadbitcoin-b5ad5e783d6f636d5ca5703919d05fd0119a34fc.tar.xz
Add Python test for -rpcbind and -rpcallowip
Add a new test, `rpcbind_test.py`, that extensively tests the new `-rpcbind` functionality.
Diffstat (limited to 'qa/rpc-tests/util.py')
-rw-r--r--qa/rpc-tests/util.py32
1 files changed, 28 insertions, 4 deletions
diff --git a/qa/rpc-tests/util.py b/qa/rpc-tests/util.py
index 1d0896a3fb..40f4a1458f 100644
--- a/qa/rpc-tests/util.py
+++ b/qa/rpc-tests/util.py
@@ -15,6 +15,7 @@ import json
import shutil
import subprocess
import time
+import re
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from util import *
@@ -112,20 +113,43 @@ def initialize_chain(test_dir):
to_dir = os.path.join(test_dir, "node"+str(i))
shutil.copytree(from_dir, to_dir)
-def start_nodes(num_nodes, dir):
+def _rpchost_to_args(rpchost):
+ '''Convert optional IP:port spec to rpcconnect/rpcport args'''
+ if rpchost is None:
+ return []
+
+ match = re.match('(\[[0-9a-fA-f:]+\]|[^:]+)(?::([0-9]+))?$', rpchost)
+ if not match:
+ raise ValueError('Invalid RPC host spec ' + rpchost)
+
+ rpcconnect = match.group(1)
+ rpcport = match.group(2)
+
+ if rpcconnect.startswith('['): # remove IPv6 [...] wrapping
+ rpcconnect = rpcconnect[1:-1]
+
+ rv = ['-rpcconnect=' + rpcconnect]
+ if rpcport:
+ rv += ['-rpcport=' + rpcport]
+ return rv
+
+def start_nodes(num_nodes, dir, extra_args=None, rpchost=None):
# Start bitcoinds, and wait for RPC interface to be up and running:
devnull = open("/dev/null", "w+")
for i in range(num_nodes):
datadir = os.path.join(dir, "node"+str(i))
args = [ "bitcoind", "-datadir="+datadir ]
+ if extra_args is not None:
+ args += extra_args[i]
bitcoind_processes.append(subprocess.Popen(args))
- subprocess.check_call([ "bitcoin-cli", "-datadir="+datadir,
- "-rpcwait", "getblockcount"], stdout=devnull)
+ subprocess.check_call([ "bitcoin-cli", "-datadir="+datadir] +
+ _rpchost_to_args(rpchost) +
+ ["-rpcwait", "getblockcount"], stdout=devnull)
devnull.close()
# Create&return JSON-RPC connections
rpc_connections = []
for i in range(num_nodes):
- url = "http://rt:rt@127.0.0.1:%d"%(START_RPC_PORT+i,)
+ url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', START_RPC_PORT+i,)
rpc_connections.append(AuthServiceProxy(url))
return rpc_connections