aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/test_node.py
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2018-10-05 16:51:10 +0900
committerJohn Newbery <john@johnnewbery.com>2018-10-18 17:46:48 -0400
commitaab81720de237b258ed4e15f1b1831c11abf74f0 (patch)
tree821676af4c944e0cc776f7f5e18d7de973739259 /test/functional/test_framework/test_node.py
parentc269209336dfa7e4258cfe7d5b0a3bc07b0da3b2 (diff)
downloadbitcoin-aab81720de237b258ed4e15f1b1831c11abf74f0.tar.xz
[tests] Add generate method to TestNode
Adds a generate() method to the TestNode class in the test framework. This method intercepts calls to generate, imports a dewterministic private key to the node and then calls generatetoaddress to generate the block to that address. Note that repeated calls to importprivkey for the same private keys are no-ops, so it's fine to call the generate() method many times.
Diffstat (limited to 'test/functional/test_framework/test_node.py')
-rwxr-xr-xtest/functional/test_framework/test_node.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index c05988c661..cc1bfabbfa 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -197,6 +197,25 @@ class TestNode():
time.sleep(1.0 / poll_per_s)
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:
+ 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):
if self.use_cli:
return self.cli("-rpcwallet={}".format(wallet_name))