Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_node.py
Show First 20 Lines • Show All 264 Lines • ▼ Show 20 Lines | def wait_for_rpc_connection(self): | ||||
if e.error['code'] != -28 and e.error['code'] != -342: | if e.error['code'] != -28 and e.error['code'] != -342: | ||||
raise # unknown JSON RPC exception | raise # unknown JSON RPC exception | ||||
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 rpcassword. bitcoind 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 generate(self, nblocks, maxtries=1000000): | |||||
self.log.debug( | |||||
"TestNode.generate() dispatches `generate` call to `generatetoaddress`") | |||||
# Try to import the node's deterministic private key. This is a no-op if the private key | |||||
# has already been imported. | |||||
try: | |||||
if self.rpc is not None: | |||||
self.rpc.importprivkey( | |||||
privkey=self.get_deterministic_priv_key().key, | |||||
label='coinbase', | |||||
rescan=False) | |||||
except JSONRPCException as e: | |||||
# This may fail if: | |||||
# - wallet is disabled ('Method not found') | |||||
# - there are multiple wallets to import to ('Wallet file not specified') | |||||
# - wallet is locked ('Error: Please enter the wallet passphrase with walletpassphrase first') | |||||
# Just ignore those errors. We can make this tidier by importing the privkey during TestFramework.setup_nodes | |||||
# TODO: tidy up deterministic privkey import. | |||||
assert str(e).startswith('Method not found') or \ | |||||
str(e).startswith('Wallet file not specified') or \ | |||||
str(e).startswith( | |||||
'Error: Please enter the wallet passphrase with walletpassphrase first') | |||||
return self.generatetoaddress( | |||||
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: | ||||
return self.cli("-rpcwallet={}".format(wallet_name)) | return self.cli("-rpcwallet={}".format(wallet_name)) | ||||
else: | else: | ||||
assert self.rpc is not None, self._node_msg( | assert self.rpc is not None, self._node_msg( | ||||
"Error: RPC not initialized") | "Error: RPC not initialized") | ||||
assert self.rpc_connected, self._node_msg( | assert self.rpc_connected, self._node_msg( | ||||
"Error: RPC not connected") | "Error: RPC not connected") | ||||
▲ Show 20 Lines • Show All 272 Lines • Show Last 20 Lines |