Skip to content

Commit

Permalink
Check for rpcuser/rpcpassword first then for cookie
Browse files Browse the repository at this point in the history
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
  • Loading branch information
achow101 committed Jun 18, 2017
1 parent 3ec5ad8 commit 279fde5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion test/functional/p2p-segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,7 @@ def run_test(self):
self.test_signature_version_1()
self.test_non_standard_witness()
sync_blocks(self.nodes)
self.test_upgrade_after_activation(2)
self.test_upgrade_after_activation(node_id=2)
self.test_witness_sigops()


Expand Down
23 changes: 12 additions & 11 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,26 @@ def get_datadir_path(dirname, n):
return os.path.join(dirname, "node"+str(n))

def get_auth_cookie(datadir, n):
if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")):
with open(os.path.join(datadir, "regtest", ".cookie"), 'r') as f:
userpass = f.read()
split_userpass = userpass.split(':')
return split_userpass[0], split_userpass[1]
else:
user = None
password = None
if os.path.isfile(os.path.join(datadir, "bitcoin.conf")):
with open(os.path.join(datadir, "bitcoin.conf"), 'r') as f:
user = None
password = None
for line in f:
if line.startswith("rpcuser="):
assert user is None # Ensure that there is only one rpcuser line
user = line.split("=")[1].strip("\n")
if line.startswith("rpcpassword="):
assert password is None # Ensure that there is only one rpcpassword line
password = line.split("=")[1].strip("\n")
if user is None and password is None:
raise ValueError("No RPC credentials")
return user, password
if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")):
with open(os.path.join(datadir, "regtest", ".cookie"), 'r') as f:
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):
rpc_u, rpc_p = get_auth_cookie(datadir, i)
Expand Down

0 comments on commit 279fde5

Please sign in to comment.