1
0
mirror of https://github.com/kvazar-network/kevacoin.git synced 2025-01-16 10:00:13 +00:00

Check for rpcuser/rpcpassword first then for cookie

Better to check that rpcuser and rpcpassword exist then to check for
the cookie in the test framework.

Name an argument for consistency in p2p-segwit.py
This commit is contained in:
Andrew Chow 2017-06-18 10:05:33 -07:00
parent 3ec5ad88e6
commit 279fde58e3
2 changed files with 13 additions and 12 deletions
test/functional
p2p-segwit.py
test_framework

@ -1944,7 +1944,7 @@ class SegWitTest(BitcoinTestFramework):
self.test_signature_version_1() self.test_signature_version_1()
self.test_non_standard_witness() self.test_non_standard_witness()
sync_blocks(self.nodes) sync_blocks(self.nodes)
self.test_upgrade_after_activation(2) self.test_upgrade_after_activation(node_id=2)
self.test_witness_sigops() self.test_witness_sigops()

@ -192,15 +192,10 @@ def get_datadir_path(dirname, n):
return os.path.join(dirname, "node"+str(n)) return os.path.join(dirname, "node"+str(n))
def get_auth_cookie(datadir, n): def get_auth_cookie(datadir, n):
if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")): user = None
with open(os.path.join(datadir, "regtest", ".cookie"), 'r') as f: password = None
userpass = f.read() if os.path.isfile(os.path.join(datadir, "bitcoin.conf")):
split_userpass = userpass.split(':')
return split_userpass[0], split_userpass[1]
else:
with open(os.path.join(datadir, "bitcoin.conf"), 'r') as f: with open(os.path.join(datadir, "bitcoin.conf"), 'r') as f:
user = None
password = None
for line in f: for line in f:
if line.startswith("rpcuser="): if line.startswith("rpcuser="):
assert user is None # Ensure that there is only one rpcuser line assert user is None # Ensure that there is only one rpcuser line
@ -208,9 +203,15 @@ def get_auth_cookie(datadir, n):
if line.startswith("rpcpassword="): if line.startswith("rpcpassword="):
assert password is None # Ensure that there is only one rpcpassword line assert password is None # Ensure that there is only one rpcpassword line
password = line.split("=")[1].strip("\n") password = line.split("=")[1].strip("\n")
if user is None and password is None: if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")):
raise ValueError("No RPC credentials") with open(os.path.join(datadir, "regtest", ".cookie"), 'r') as f:
return user, password userpass = f.read()
split_userpass = userpass.split(':')
user = split_userpass[0]
password = split_userpass[1]
if user is None or password is None:
raise ValueError("No RPC credentials")
return user, password
def rpc_url(datadir, i, rpchost=None): def rpc_url(datadir, i, rpchost=None):
rpc_u, rpc_p = get_auth_cookie(datadir, i) rpc_u, rpc_p = get_auth_cookie(datadir, i)