diff --git a/test/functional/abc-finalize-block.py b/test/functional/abc-finalize-block.py --- a/test/functional/abc-finalize-block.py +++ b/test/functional/abc-finalize-block.py @@ -26,16 +26,13 @@ ["-finalizationdelay=0"], []] self.finalization_delay = 2 * 60 * 60 - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def run_test(self): node = self.nodes[0] self.mocktime = int(time.time()) self.log.info("Test block finalization...") - node.generate(10) + node.generatetoaddress(10, node.get_deterministic_priv_key().address) tip = node.getbestblockhash() node.finalizeblock(tip) assert_equal(node.getbestblockhash(), tip) @@ -84,17 +81,20 @@ wait_until(check_block) # First block header is accepted as valid-header - alt_node.generate(1) + alt_node.generatetoaddress( + 1, alt_node.get_deterministic_priv_key().address) wait_for_block(node, alt_node.getbestblockhash(), "valid-headers") # Second block header is accepted but set invalid - alt_node.generate(1) + alt_node.generatetoaddress( + 1, alt_node.get_deterministic_priv_key().address) invalid_block = alt_node.getbestblockhash() wait_for_block(node, invalid_block) # Later block headers are rejected for i in range(2, 9): - alt_node.generate(1) + alt_node.generatetoaddress( + 1, alt_node.get_deterministic_priv_key().address) assert_raises_rpc_error(-5, RPC_BLOCK_NOT_FOUND_ERROR, node.getblockheader, alt_node.getbestblockhash()) @@ -148,7 +148,8 @@ # (200)->(201)-> // ->(209 finalized)->(210) node.reconsiderblock(invalid_block) - alt_node_tip = alt_node.generate(1)[-1] + alt_node_tip = alt_node.generatetoaddress( + 1, alt_node.get_deterministic_priv_key().address)[-1] wait_for_tip(node, alt_node_tip) assert_equal(node.getbestblockhash(), alt_node.getbestblockhash()) @@ -194,8 +195,10 @@ # / # (200)->(201)-> // ->(209)->(210 invalid) node.reconsiderblock(alt_node.getbestblockhash()) - block_to_autofinalize = alt_node.generate(1)[-1] - alt_node_new_tip = alt_node.generate(9)[-1] + block_to_autofinalize = alt_node.generatetoaddress( + 1, alt_node.get_deterministic_priv_key().address)[-1] + alt_node_new_tip = alt_node.generatetoaddress( + 9, alt_node.get_deterministic_priv_key().address)[-1] wait_for_tip(node, alt_node_new_tip) assert_equal(node.getbestblockhash(), alt_node.getbestblockhash()) @@ -271,7 +274,8 @@ # (200)->(201)-> // ->(209)->(210) self.mocktime += self.finalization_delay set_node_times([delay_node], self.mocktime) - new_tip = alt_node.generate(1)[-1] + new_tip = alt_node.generatetoaddress( + 1, alt_node.get_deterministic_priv_key().address)[-1] wait_for_tip(delay_node, new_tip) assert_equal(alt_node.getbestblockhash(), new_tip) @@ -295,7 +299,8 @@ # >(220)-> // ->(250 tip) # / # (200)->(201)-> // ->(209)->(210) - blocks = delay_node.generate(20) + blocks = delay_node.generatetoaddress( + 20, alt_node.get_deterministic_priv_key().address) reboot_autofinalized_block = blocks[10] new_tip = blocks[-1] wait_for_tip(delay_node, new_tip) @@ -313,7 +318,8 @@ # (200)->(201)-> // ->(209)->(210) self.mocktime += self.finalization_delay set_node_times([delay_node], self.mocktime) - new_tip = delay_node.generate(1)[-1] + new_tip = delay_node.generatetoaddress( + 1, delay_node.get_deterministic_priv_key().address)[-1] wait_for_tip(delay_node, new_tip) assert_equal(delay_node.getfinalizedblockhash(), diff --git a/test/functional/abc-get-invalid-block.py b/test/functional/abc-get-invalid-block.py --- a/test/functional/abc-get-invalid-block.py +++ b/test/functional/abc-get-invalid-block.py @@ -21,16 +21,14 @@ def set_test_params(self): self.num_nodes = 1 - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def run_test(self): node = self.nodes[0] node.add_p2p_connection(P2PInterface()) chaintip = node.getbestblockhash() # Mine some blocks and invalidate them - blocks = node.generate(nblocks=3) + blocks = node.generatetoaddress( + 3, node.get_deterministic_priv_key().address) assert_equal(blocks[-1], node.getbestblockhash()) node.invalidateblock(blocks[0]) assert_equal(chaintip, node.getbestblockhash()) diff --git a/test/functional/abc-minimaldata.py b/test/functional/abc-minimaldata.py --- a/test/functional/abc-minimaldata.py +++ b/test/functional/abc-minimaldata.py @@ -52,9 +52,6 @@ self.num_nodes = 1 self.block_heights = {} - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def bootstrap_p2p(self, *, num_connections=1): """Add a P2P connection to the node. @@ -128,7 +125,7 @@ spendable_outputs = [block.vtx[0] for block in blocks] self.log.info("Mature the blocks and get out of IBD.") - node.generate(100) + node.generatetoaddress(100, node.get_deterministic_priv_key().address) tip = self.getbestblock(node) diff --git a/test/functional/abc-schnorr.py b/test/functional/abc-schnorr.py --- a/test/functional/abc-schnorr.py +++ b/test/functional/abc-schnorr.py @@ -67,9 +67,6 @@ self.num_nodes = 1 self.block_heights = {} - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def bootstrap_p2p(self, *, num_connections=1): """Add a P2P connection to the node. @@ -143,7 +140,7 @@ spendable_outputs = [block.vtx[0] for block in blocks] self.log.info("Mature the blocks and get out of IBD.") - node.generate(100) + node.generatetoaddress(100, node.get_deterministic_priv_key().address) tip = self.getbestblock(node) @@ -210,7 +207,7 @@ self.log.info("Typical ECDSA and Schnorr CHECKSIG are valid.") node.p2p.send_txs_and_test([schnorrchecksigtx, ecdsachecksigtx], node) # They get mined as usual. - node.generate(1) + node.generatetoaddress(1, node.get_deterministic_priv_key().address) tip = self.getbestblock(node) # Make sure they are in the block, and mempool is now empty. txhashes = set([schnorrchecksigtx.hash, ecdsachecksigtx.hash]) diff --git a/test/functional/abc-schnorrmultisig.py b/test/functional/abc-schnorrmultisig.py --- a/test/functional/abc-schnorrmultisig.py +++ b/test/functional/abc-schnorrmultisig.py @@ -71,9 +71,6 @@ self.num_nodes = 1 self.block_heights = {} - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def bootstrap_p2p(self, *, num_connections=1): """Add a P2P connection to the node. @@ -147,7 +144,7 @@ spendable_outputs = [block.vtx[0] for block in blocks] self.log.info("Mature the blocks and get out of IBD.") - node.generate(100) + node.generatetoaddress(100, node.get_deterministic_priv_key().address) tip = self.getbestblock(node) diff --git a/test/functional/example_test.py b/test/functional/example_test.py --- a/test/functional/example_test.py +++ b/test/functional/example_test.py @@ -88,6 +88,8 @@ # self.log.info("I've finished set_test_params") # Oops! Can't run # self.log before run_test() + # Use skip_test_if_missing_module() to skip the test if your test requires certain modules to be present. + # This test uses generate which requires wallet to be compiled def skip_test_if_missing_module(self): self.skip_if_no_wallet() diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py --- a/test/functional/feature_block.py +++ b/test/functional/feature_block.py @@ -72,9 +72,6 @@ self.setup_clean_chain = True self.extra_args = [['-noparkdeepreorg', '-maxreorgdepth=-1']] - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def run_test(self): node = self.nodes[0] # convenience reference to the node diff --git a/test/functional/feature_blocksdir.py b/test/functional/feature_blocksdir.py --- a/test/functional/feature_blocksdir.py +++ b/test/functional/feature_blocksdir.py @@ -16,9 +16,6 @@ self.setup_clean_chain = True self.num_nodes = 1 - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def run_test(self): self.stop_node(0) assert os.path.isdir(os.path.join( @@ -34,7 +31,8 @@ self.log.info("Starting with existing blocksdir ...") self.start_node(0, ["-blocksdir=" + blocksdir_path]) self.log.info("mining blocks..") - self.nodes[0].generate(10) + self.nodes[0].generatetoaddress( + 10, self.nodes[0].get_deterministic_priv_key().address) assert os.path.isfile(os.path.join( blocksdir_path, "regtest", "blocks", "blk00000.dat")) assert os.path.isdir(os.path.join( diff --git a/test/functional/feature_logging.py b/test/functional/feature_logging.py --- a/test/functional/feature_logging.py +++ b/test/functional/feature_logging.py @@ -15,9 +15,6 @@ self.num_nodes = 1 self.setup_clean_chain = True - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def relative_log_path(self, name): return os.path.join(self.nodes[0].datadir, "regtest", name) diff --git a/test/functional/feature_minchainwork.py b/test/functional/feature_minchainwork.py --- a/test/functional/feature_minchainwork.py +++ b/test/functional/feature_minchainwork.py @@ -32,9 +32,6 @@ ["-minimumchainwork=0x65"]] self.node_min_work = [0, 101, 101] - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def setup_network(self): # This test relies on the chain setup being: # node0 <- node1 <- node2 @@ -59,7 +56,8 @@ (self.node_min_work[1] - starting_chain_work) / REGTEST_WORK_PER_BLOCK) self.log.info("Generating {} blocks on node0".format( num_blocks_to_generate)) - hashes = self.nodes[0].generate(num_blocks_to_generate) + hashes = self.nodes[0].generatetoaddress(num_blocks_to_generate, + self.nodes[0].get_deterministic_priv_key().address) self.log.info("Node0 current chain work: {}".format( self.nodes[0].getblockheader(hashes[-1])['chainwork'])) @@ -83,7 +81,8 @@ assert_equal(self.nodes[2].getblockcount(), starting_blockcount) self.log.info("Generating one more block") - self.nodes[0].generate(1) + self.nodes[0].generatetoaddress( + 1, self.nodes[0].get_deterministic_priv_key().address) self.log.info("Verifying nodes are all synced") diff --git a/test/functional/feature_reindex.py b/test/functional/feature_reindex.py --- a/test/functional/feature_reindex.py +++ b/test/functional/feature_reindex.py @@ -19,11 +19,9 @@ self.setup_clean_chain = True self.num_nodes = 1 - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def reindex(self, justchainstate=False): - self.nodes[0].generate(3) + self.nodes[0].generatetoaddress( + 3, self.nodes[0].get_deterministic_priv_key().address) blockcount = self.nodes[0].getblockcount() self.stop_nodes() extra_args = [ diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py --- a/test/functional/mining_basic.py +++ b/test/functional/mining_basic.py @@ -39,9 +39,6 @@ self.num_nodes = 2 self.setup_clean_chain = False - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def run_test(self): node = self.nodes[0] @@ -66,7 +63,7 @@ assert_equal(mining_info['pooledtx'], 0) # Mine a block to leave initial block download - node.generate(1) + node.generatetoaddress(1, node.get_deterministic_priv_key().address) tmpl = node.getblocktemplate() self.log.info("getblocktemplate: Test capability advertised") assert 'proposal' in tmpl['capabilities'] @@ -241,7 +238,7 @@ branchlen=0) in node.getchaintips() # Building a few blocks should give the same results - node.generate(10) + node.generatetoaddress(10, node.get_deterministic_priv_key().address) assert_raises_rpc_error(-25, 'time-too-old', lambda: node.submitheader( hexdata=CBlockHeader(bad_block_time).serialize().hex())) assert_raises_rpc_error(-25, 'bad-prevblk', lambda: node.submitheader( diff --git a/test/functional/p2p_fingerprint.py b/test/functional/p2p_fingerprint.py --- a/test/functional/p2p_fingerprint.py +++ b/test/functional/p2p_fingerprint.py @@ -28,9 +28,6 @@ self.setup_clean_chain = True self.num_nodes = 1 - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - # Build a chain of blocks on top of given one def build_chain(self, nblocks, prev_hash, prev_height, prev_median_time): blocks = [] @@ -82,7 +79,8 @@ self.nodes[0].setmocktime(int(time.time()) - 60 * 24 * 60 * 60) # Generating a chain of 10 blocks - block_hashes = self.nodes[0].generate(nblocks=10) + block_hashes = self.nodes[0].generatetoaddress( + 10, self.nodes[0].get_deterministic_priv_key().address) # Create longer chain starting 2 blocks before current tip height = len(block_hashes) - 2 @@ -115,7 +113,8 @@ # Longest chain is extended so stale is much older than chain tip self.nodes[0].setmocktime(0) - tip = self.nodes[0].generate(nblocks=1)[0] + tip = self.nodes[0].generatetoaddress( + 1, self.nodes[0].get_deterministic_priv_key().address)[0] assert_equal(self.nodes[0].getblockcount(), 14) # Send getdata & getheaders to refresh last received getheader message diff --git a/test/functional/p2p_invalid_block.py b/test/functional/p2p_invalid_block.py --- a/test/functional/p2p_invalid_block.py +++ b/test/functional/p2p_invalid_block.py @@ -30,9 +30,6 @@ self.setup_clean_chain = True self.extra_args = [["-whitelist=127.0.0.1"]] - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def run_test(self): # Add p2p connection to node0 node = self.nodes[0] # convenience reference to the node @@ -54,7 +51,7 @@ node.p2p.send_blocks_and_test([block1], node, success=True) self.log.info("Mature the block.") - node.generate(100) + node.generatetoaddress(100, node.get_deterministic_priv_key().address) best_block = node.getblock(node.getbestblockhash()) tip = int(node.getbestblockhash(), 16) diff --git a/test/functional/p2p_invalid_locator.py b/test/functional/p2p_invalid_locator.py --- a/test/functional/p2p_invalid_locator.py +++ b/test/functional/p2p_invalid_locator.py @@ -19,14 +19,11 @@ self.num_nodes = 1 self.setup_clean_chain = False - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def run_test(self): # Convenience reference to the node node = self.nodes[0] # Get node out of IBD - node.generate(1) + node.generatetoaddress(1, node.get_deterministic_priv_key().address) self.log.info('Test max locator size') block_count = node.getblockcount() diff --git a/test/functional/p2p_invalid_tx.py b/test/functional/p2p_invalid_tx.py --- a/test/functional/p2p_invalid_tx.py +++ b/test/functional/p2p_invalid_tx.py @@ -34,9 +34,6 @@ self.num_nodes = 1 self.setup_clean_chain = True - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def bootstrap_p2p(self, *, num_connections=1): """Add a P2P connection to the node. @@ -72,7 +69,8 @@ node.p2p.send_blocks_and_test([block], node, success=True) self.log.info("Mature the block.") - self.nodes[0].generate(100) + self.nodes[0].generatetoaddress( + 100, self.nodes[0].get_deterministic_priv_key().address) # b'\x64' is OP_NOTIF # Transaction will be rejected with code 16 (REJECT_INVALID) diff --git a/test/functional/p2p_leak.py b/test/functional/p2p_leak.py --- a/test/functional/p2p_leak.py +++ b/test/functional/p2p_leak.py @@ -133,9 +133,6 @@ self.num_nodes = 1 self.extra_args = [['-banscore=' + str(banscore)]] - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def run_test(self): no_version_bannode = self.nodes[0].add_p2p_connection( CNodeNoVersionBan(), send_version=False, wait_for_verack=False) @@ -152,7 +149,8 @@ timeout=10, lock=mininode_lock) # Mine a block and make sure that it's not sent to the connected nodes - self.nodes[0].generate(1) + self.nodes[0].generatetoaddress( + 1, self.nodes[0].get_deterministic_priv_key().address) # Give the node enough time to possibly leak out a message time.sleep(5) diff --git a/test/functional/p2p_node_network_limited.py b/test/functional/p2p_node_network_limited.py --- a/test/functional/p2p_node_network_limited.py +++ b/test/functional/p2p_node_network_limited.py @@ -56,9 +56,6 @@ self.num_nodes = 3 self.extra_args = [['-prune=550', '-addrmantest'], [], []] - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def disconnect_all(self): disconnect_nodes(self.nodes[0], self.nodes[1]) disconnect_nodes(self.nodes[1], self.nodes[0]) @@ -86,7 +83,8 @@ self.log.info( "Mine enough blocks to reach the NODE_NETWORK_LIMITED range.") connect_nodes_bi(self.nodes[0], self.nodes[1]) - blocks = self.nodes[1].generate(292) + blocks = self.nodes[1].generatetoaddress( + 292, self.nodes[1].get_deterministic_priv_key().address) sync_blocks([self.nodes[0], self.nodes[1]]) self.log.info("Make sure we can max retrieve block at tip-288.") @@ -134,7 +132,8 @@ self.disconnect_all() # mine 10 blocks on node 0 (pruned node) - self.nodes[0].generate(10) + self.nodes[0].generatetoaddress( + 10, self.nodes[0].get_deterministic_priv_key().address) # connect node1 (non pruned) with node0 (pruned) and check if the can # sync diff --git a/test/functional/p2p_sendheaders.py b/test/functional/p2p_sendheaders.py --- a/test/functional/p2p_sendheaders.py +++ b/test/functional/p2p_sendheaders.py @@ -210,15 +210,13 @@ self.num_nodes = 2 self.extra_args = [["-noparkdeepreorg"], ["-noparkdeepreorg"]] - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def mine_blocks(self, count): """Mine count blocks and return the new tip.""" # Clear out block announcements from each p2p listener [x.clear_block_announcements() for x in self.nodes[0].p2ps] - self.nodes[0].generate(count) + self.nodes[0].generatetoaddress( + count, self.nodes[0].get_deterministic_priv_key().address) return int(self.nodes[0].getbestblockhash(), 16) def mine_reorg(self, length): @@ -229,7 +227,8 @@ return the list of block hashes newly mined.""" # make sure all invalidated blocks are node0's - self.nodes[0].generate(length) + self.nodes[0].generatetoaddress( + length, self.nodes[0].get_deterministic_priv_key().address) sync_blocks(self.nodes, wait=0.1) for x in self.nodes[0].p2ps: x.wait_for_block_announcement( @@ -241,7 +240,8 @@ tip_height - (length - 1)) self.nodes[1].invalidateblock(hash_to_invalidate) # Must be longer than the orig chain - all_hashes = self.nodes[1].generate(length + 1) + all_hashes = self.nodes[1].generatetoaddress( + length + 1, self.nodes[1].get_deterministic_priv_key().address) sync_blocks(self.nodes, wait=0.1) return [int(x, 16) for x in all_hashes] @@ -260,7 +260,8 @@ self.test_nonnull_locators(test_node, inv_node) def test_null_locators(self, test_node, inv_node): - tip = self.nodes[0].getblockheader(self.nodes[0].generate(1)[0]) + tip = self.nodes[0].getblockheader(self.nodes[0].generatetoaddress( + 1, self.nodes[0].get_deterministic_priv_key().address)[0]) tip_hash = int(tip["hash"], 16) inv_node.check_last_inv_announcement(inv=[tip_hash]) diff --git a/test/functional/p2p_unrequested_blocks.py b/test/functional/p2p_unrequested_blocks.py --- a/test/functional/p2p_unrequested_blocks.py +++ b/test/functional/p2p_unrequested_blocks.py @@ -86,9 +86,6 @@ self.extra_args = [["-noparkdeepreorg"], ["-minimumchainwork=0x10"]] - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def setup_network(self): # Node0 will be used to test behavior of processing unrequested blocks # from peers which are not whitelisted, while Node1 will be used for @@ -105,7 +102,8 @@ min_work_node = self.nodes[1].add_p2p_connection(P2PInterface()) # 1. Have nodes mine a block (leave IBD) - [n.generate(1) for n in self.nodes] + [n.generatetoaddress(1, n.get_deterministic_priv_key().address) + for n in self.nodes] tips = [int("0x" + n.getbestblockhash(), 0) for n in self.nodes] # 2. Send one block that builds on each tip. diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -50,9 +50,6 @@ def set_test_params(self): self.num_nodes = 1 - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def run_test(self): # Set extra args with pruning after rescan is complete self.restart_node(0, extra_args=['-stopatheight=207', '-prune=1']) @@ -64,8 +61,9 @@ self._test_getdifficulty() self._test_getnetworkhashps() self._test_stopatheight() - self._test_getblock() self._test_waitforblockheight() + if self.is_wallet_compiled(): + self._test_getblock() assert self.nodes[0].verifychain(4, 0) def _test_getblockchaininfo(self): @@ -284,13 +282,15 @@ def _test_stopatheight(self): assert_equal(self.nodes[0].getblockcount(), 200) - self.nodes[0].generate(6) + self.nodes[0].generatetoaddress( + 6, self.nodes[0].get_deterministic_priv_key().address) assert_equal(self.nodes[0].getblockcount(), 206) self.log.debug('Node should not stop at this height') assert_raises(subprocess.TimeoutExpired, lambda: self.nodes[0].process.wait(timeout=3)) try: - self.nodes[0].generate(1) + self.nodes[0].generatetoaddress( + 1, self.nodes[0].get_deterministic_priv_key().address) except (ConnectionError, http.client.BadStatusLine): pass # The node already shut down before response self.log.debug('Node should stop at this height...') diff --git a/test/functional/rpc_getchaintips.py b/test/functional/rpc_getchaintips.py --- a/test/functional/rpc_getchaintips.py +++ b/test/functional/rpc_getchaintips.py @@ -19,9 +19,6 @@ self.num_nodes = 4 self.extra_args = [["-noparkdeepreorg"], ["-noparkdeepreorg"], [], []] - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def run_test(self): tips = self.nodes[0].getchaintips() assert_equal(len(tips), 1) @@ -31,8 +28,10 @@ # Split the network and build two chains of different lengths. self.split_network() - self.nodes[0].generate(10) - self.nodes[2].generate(20) + self.nodes[0].generatetoaddress( + 10, self.nodes[0].get_deterministic_priv_key().address) + self.nodes[2].generatetoaddress( + 20, self.nodes[2].get_deterministic_priv_key().address) self.sync_all([self.nodes[:2], self.nodes[2:]]) tips = self.nodes[1].getchaintips() diff --git a/test/functional/rpc_invalidateblock.py b/test/functional/rpc_invalidateblock.py --- a/test/functional/rpc_invalidateblock.py +++ b/test/functional/rpc_invalidateblock.py @@ -16,9 +16,6 @@ self.num_nodes = 3 self.extra_args = [["-noparkdeepreorg"], [], []] - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def setup_network(self): self.setup_nodes() @@ -26,12 +23,14 @@ self.log.info( "Make sure we repopulate setBlockIndexCandidates after InvalidateBlock:") self.log.info("Mine 4 blocks on Node 0") - self.nodes[0].generate(4) + self.nodes[0].generatetoaddress( + 4, self.nodes[0].get_deterministic_priv_key().address) assert self.nodes[0].getblockcount() == 4 besthash = self.nodes[0].getbestblockhash() self.log.info("Mine competing 6 blocks on Node 1") - self.nodes[1].generate(6) + self.nodes[1].generatetoaddress( + 6, self.nodes[1].get_deterministic_priv_key().address) assert self.nodes[1].getblockcount() == 6 self.log.info("Connect nodes to force a reorg") @@ -61,7 +60,8 @@ self.nodes[2].invalidateblock(self.nodes[2].getblockhash(3)) assert self.nodes[2].getblockcount() == 2 self.log.info("..and then mine a block") - self.nodes[2].generate(1) + self.nodes[2].generatetoaddress( + 1, self.nodes[2].get_deterministic_priv_key().address) self.log.info("Verify all nodes are at the right height") time.sleep(5) assert_equal(self.nodes[2].getblockcount(), 3) diff --git a/test/functional/rpc_preciousblock.py b/test/functional/rpc_preciousblock.py --- a/test/functional/rpc_preciousblock.py +++ b/test/functional/rpc_preciousblock.py @@ -44,27 +44,27 @@ self.extra_args = [["-noparkdeepreorg"], ["-noparkdeepreorg"], ["-noparkdeepreorg"]] - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - def setup_network(self): self.setup_nodes() def run_test(self): self.log.info( "Ensure submitblock can in principle reorg to a competing chain") - self.nodes[0].generate(1) + # A non-wallet address to mine to + def gen_address( + i): return self.nodes[i].get_deterministic_priv_key().address + self.nodes[0].generatetoaddress(1, gen_address(0)) assert_equal(self.nodes[0].getblockcount(), 1) - hashZ = self.nodes[1].generate(2)[-1] + hashZ = self.nodes[1].generatetoaddress(2, gen_address(1))[-1] assert_equal(self.nodes[1].getblockcount(), 2) node_sync_via_rpc(self.nodes[0:3]) assert_equal(self.nodes[0].getbestblockhash(), hashZ) self.log.info("Mine blocks A-B-C on Node 0") - hashC = self.nodes[0].generate(3)[-1] + hashC = self.nodes[0].generatetoaddress(3, gen_address(0))[-1] assert_equal(self.nodes[0].getblockcount(), 5) self.log.info("Mine competing blocks E-F-G on Node 1") - hashG = self.nodes[1].generate(3)[-1] + hashG = self.nodes[1].generatetoaddress(3, gen_address(1))[-1] assert_equal(self.nodes[1].getblockcount(), 5) assert hashC != hashG self.log.info("Connect nodes and check no reorg occurs") @@ -96,7 +96,7 @@ assert_equal(self.nodes[1].getbestblockhash(), hashC) self.log.info( "Mine another block (E-F-G-)H on Node 0 and reorg Node 1") - self.nodes[0].generate(1) + self.nodes[0].generatetoaddress(1, gen_address(0)) assert_equal(self.nodes[0].getblockcount(), 6) sync_blocks(self.nodes[0:2]) hashH = self.nodes[0].getbestblockhash() @@ -105,7 +105,7 @@ self.nodes[1].preciousblock(hashC) assert_equal(self.nodes[1].getbestblockhash(), hashH) self.log.info("Mine competing blocks I-J-K-L on Node 2") - self.nodes[2].generate(4) + self.nodes[2].generatetoaddress(4, gen_address(2)) assert_equal(self.nodes[2].getblockcount(), 6) hashL = self.nodes[2].getbestblockhash() self.log.info("Connect nodes and check no reorg occurs") diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -266,7 +266,7 @@ assert str(e).startswith('Method not found') continue - n.importprivkey(n.get_deterministic_priv_key()[1]) + n.importprivkey(n.get_deterministic_priv_key().key) def run_test(self): """Tests must override this method to define test logic""" @@ -498,7 +498,7 @@ for j in range(25): set_node_times(self.nodes, block_time) self.nodes[peer].generatetoaddress( - 1, self.nodes[peer].get_deterministic_priv_key()[0]) + 1, self.nodes[peer].get_deterministic_priv_key().address) block_time += 10 * 60 # Must sync before next peer starts generating blocks sync_blocks(self.nodes) diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -18,6 +18,7 @@ import tempfile import time import urllib.parse +import collections from .authproxy import JSONRPCException from .messages import COIN, CTransaction, FromHex @@ -111,26 +112,28 @@ def get_deterministic_priv_key(self): """Return a deterministic priv key in base58, that only depends on the node's index""" + AddressKeyPair = collections.namedtuple( + 'AddressKeyPair', ['address', 'key']) PRIV_KEYS = [ # address , privkey - ('mjTkW3DjgyZck4KbiRusZsqTgaYTxdSz6z', - 'cVpF924EspNh8KjYsfhgY96mmxvT6DgdWiTYMtMjuM74hJaU5psW'), - ('msX6jQXvxiNhx3Q62PKeLPrhrqZQdSimTg', - 'cUxsWyKyZ9MAQTaAhUQWJmBbSvHMwSmuv59KgxQV7oZQU3PXN3KE'), - ('mnonCMyH9TmAsSj3M59DsbH8H63U3RKoFP', - 'cTrh7dkEAeJd6b3MRX9bZK8eRmNqVCMH3LSUkE3dSFDyzjU38QxK'), - ('mqJupas8Dt2uestQDvV2NH3RU8uZh2dqQR', - 'cVuKKa7gbehEQvVq717hYcbE9Dqmq7KEBKqWgWrYBa2CKKrhtRim'), - ('msYac7Rvd5ywm6pEmkjyxhbCDKqWsVeYws', - 'cQDCBuKcjanpXDpCqacNSjYfxeQj8G6CAtH1Dsk3cXyqLNC4RPuh'), - ('n2rnuUnwLgXqf9kk2kjvVm8R5BZK1yxQBi', - 'cQakmfPSLSqKHyMFGwAqKHgWUiofJCagVGhiB4KCainaeCSxeyYq'), - ('myzuPxRwsf3vvGzEuzPfK9Nf2RfwauwYe6', - 'cQMpDLJwA8DBe9NcQbdoSb1BhmFxVjWD5gRyrLZCtpuF9Zi3a9RK'), - ('mumwTaMtbxEPUswmLBBN3vM9oGRtGBrys8', - 'cSXmRKXVcoouhNNVpcNKFfxsTsToY5pvB9DVsFksF1ENunTzRKsy'), - ('mpV7aGShMkJCZgbW7F6iZgrvuPHjZjH9qg', - 'cSoXt6tm3pqy43UMabY6eUTmR3eSUYFtB2iNQDGgb3VUnRsQys2k'), + AddressKeyPair('mjTkW3DjgyZck4KbiRusZsqTgaYTxdSz6z', + 'cVpF924EspNh8KjYsfhgY96mmxvT6DgdWiTYMtMjuM74hJaU5psW'), + AddressKeyPair('msX6jQXvxiNhx3Q62PKeLPrhrqZQdSimTg', + 'cUxsWyKyZ9MAQTaAhUQWJmBbSvHMwSmuv59KgxQV7oZQU3PXN3KE'), + AddressKeyPair('mnonCMyH9TmAsSj3M59DsbH8H63U3RKoFP', + 'cTrh7dkEAeJd6b3MRX9bZK8eRmNqVCMH3LSUkE3dSFDyzjU38QxK'), + AddressKeyPair('mqJupas8Dt2uestQDvV2NH3RU8uZh2dqQR', + 'cVuKKa7gbehEQvVq717hYcbE9Dqmq7KEBKqWgWrYBa2CKKrhtRim'), + AddressKeyPair('msYac7Rvd5ywm6pEmkjyxhbCDKqWsVeYws', + 'cQDCBuKcjanpXDpCqacNSjYfxeQj8G6CAtH1Dsk3cXyqLNC4RPuh'), + AddressKeyPair('n2rnuUnwLgXqf9kk2kjvVm8R5BZK1yxQBi', + 'cQakmfPSLSqKHyMFGwAqKHgWUiofJCagVGhiB4KCainaeCSxeyYq'), + AddressKeyPair('myzuPxRwsf3vvGzEuzPfK9Nf2RfwauwYe6', + 'cQMpDLJwA8DBe9NcQbdoSb1BhmFxVjWD5gRyrLZCtpuF9Zi3a9RK'), + AddressKeyPair('mumwTaMtbxEPUswmLBBN3vM9oGRtGBrys8', + 'cSXmRKXVcoouhNNVpcNKFfxsTsToY5pvB9DVsFksF1ENunTzRKsy'), + AddressKeyPair('mpV7aGShMkJCZgbW7F6iZgrvuPHjZjH9qg', + 'cSoXt6tm3pqy43UMabY6eUTmR3eSUYFtB2iNQDGgb3VUnRsQys2k'), ] return PRIV_KEYS[self.index]