message: test: add wait_for_cookie_credentials() to test framework
  to be able to ensure the cookie file is written and auth credentials available
  when testing CLI/RPC commands before the RPC connection is up.
diff: @@ -26,6 +26,7 @@ from .util import (
  MAX_NODES,
  append_config,
  delete_cookie_file,
  + get_auth_cookie,
  get_rpc_proxy,
  rpc_url,
  wait_until,
  @@ -240,12 +241,27 @@ class TestNode():
  except OSError as e:
  if e.errno != errno.ECONNREFUSED: # Port not yet open?
  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):
  raise
  time.sleep(1.0 / poll_per_s)
  self._raise_assertion_error("Unable to connect to bitcoind after {}s".format(self.rpc_timeout))
  + 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
  + 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):
  self.log.debug("TestNode.generate() dispatches `generate` call to `generatetoaddress`")
  return self.generatetoaddress(nblocks=nblocks, address=self.get_deterministic_priv_key().address, maxtries=maxtries)
  