Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_node.py
Show All 22 Lines | |||||
from .authproxy import JSONRPCException | from .authproxy import JSONRPCException | ||||
from .descriptors import descsum_create | from .descriptors import descsum_create | ||||
from .messages import COIN, CTransaction, FromHex | from .messages import COIN, CTransaction, FromHex | ||||
from .util import ( | from .util import ( | ||||
MAX_NODES, | MAX_NODES, | ||||
append_config, | append_config, | ||||
delete_cookie_file, | delete_cookie_file, | ||||
get_auth_cookie, | |||||
get_rpc_proxy, | get_rpc_proxy, | ||||
p2p_port, | p2p_port, | ||||
rpc_url, | rpc_url, | ||||
wait_until, | wait_until, | ||||
EncodeDecimal, | EncodeDecimal, | ||||
) | ) | ||||
BITCOIND_PROC_WAIT_TIMEOUT = 60 | BITCOIND_PROC_WAIT_TIMEOUT = 60 | ||||
▲ Show 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | def wait_for_rpc_connection(self): | ||||
raise # unknown JSON RPC exception | raise # unknown JSON RPC exception | ||||
except ConnectionResetError: | except ConnectionResetError: | ||||
# This might happen when the RPC server is in warmup, but shut down before the call to getblockcount | # This might happen when the RPC server is in warmup, but shut down before the call to getblockcount | ||||
# succeeds. Try again to properly raise the FailedToStartError | # succeeds. Try again to properly raise the FailedToStartError | ||||
pass | pass | ||||
except OSError as e: | except OSError as e: | ||||
if e.errno != errno.ECONNREFUSED: # Port not yet open? | if e.errno != errno.ECONNREFUSED: # Port not yet open? | ||||
raise # unknown OS error | raise # unknown OS error | ||||
except ValueError as e: # cookie file not found and no rpcuser or rpcassword. bitcoind still starting | except ValueError as e: # cookie file not found and no rpcuser or rpcpassword; bitcoind is still starting | ||||
if "No RPC credentials" not in str(e): | if "No RPC credentials" not in str(e): | ||||
raise | raise | ||||
time.sleep(1.0 / poll_per_s) | time.sleep(1.0 / poll_per_s) | ||||
self._raise_assertion_error("Unable to connect to bitcoind") | self._raise_assertion_error("Unable to connect to bitcoind") | ||||
def wait_for_cookie_credentials(self): | |||||
"""Ensures auth cookie credentials can be read, e.g. for testing CLI with -rpcwait before RPC connection is up.""" | |||||
self.log.debug("Waiting for cookie credentials") | |||||
# Poll at a rate of four times per second. | |||||
poll_per_s = 4 | |||||
for _ in range(poll_per_s * self.rpc_timeout): | |||||
try: | |||||
get_auth_cookie(self.datadir, self.chain) | |||||
self.log.debug("Cookie credentials successfully retrieved") | |||||
return | |||||
except ValueError: # cookie file not found and no rpcuser or rpcpassword; bitcoind is still starting | |||||
PiRK: comments on their own line | |||||
pass # so we continue polling until RPC credentials are retrieved | |||||
time.sleep(1.0 / poll_per_s) | |||||
self._raise_assertion_error( | |||||
"Unable to retrieve cookie credentials after {}s".format( | |||||
self.rpc_timeout)) | |||||
def generate(self, nblocks, maxtries=1000000): | def generate(self, nblocks, maxtries=1000000): | ||||
self.log.debug( | self.log.debug( | ||||
"TestNode.generate() dispatches `generate` call to `generatetoaddress`") | "TestNode.generate() dispatches `generate` call to `generatetoaddress`") | ||||
return self.generatetoaddress( | return self.generatetoaddress( | ||||
nblocks=nblocks, address=self.get_deterministic_priv_key().address, maxtries=maxtries) | nblocks=nblocks, address=self.get_deterministic_priv_key().address, maxtries=maxtries) | ||||
def get_wallet_rpc(self, wallet_name): | def get_wallet_rpc(self, wallet_name): | ||||
if self.use_cli: | if self.use_cli: | ||||
▲ Show 20 Lines • Show All 503 Lines • Show Last 20 Lines |
comments on their own line