diff --git a/test/functional/feature_addressindex.py b/test/functional/feature_addressindex.py index 5643e8005b..7f71e6c9d3 100755 --- a/test/functional/feature_addressindex.py +++ b/test/functional/feature_addressindex.py @@ -35,8 +35,8 @@ class AddressIndexTest(BitcoinTestFramework): connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 2) connect_nodes(self.nodes[0], 3) - self.sync_all() + self.import_deterministic_coinbase_privkeys() def run_test(self): self.log.info("Test that settings can't be changed without -reindex...") diff --git a/test/functional/feature_dbcrash.py b/test/functional/feature_dbcrash.py index b7cc776fa2..3a18d74c74 100755 --- a/test/functional/feature_dbcrash.py +++ b/test/functional/feature_dbcrash.py @@ -74,6 +74,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework): def setup_network(self): self.add_nodes(self.num_nodes, extra_args=self.extra_args) self.start_nodes() + self.import_deterministic_coinbase_privkeys() # Leave them unconnected, we'll use submitblock directly in this test def restart_node(self, node_index, expected_tip): diff --git a/test/functional/feature_dip3_deterministicmns.py b/test/functional/feature_dip3_deterministicmns.py index 7019b10028..3d53d3ff1f 100755 --- a/test/functional/feature_dip3_deterministicmns.py +++ b/test/functional/feature_dip3_deterministicmns.py @@ -35,6 +35,7 @@ class DIP3Test(BitcoinTestFramework): self.disable_mocktime() self.add_nodes(1) self.start_controller_node() + self.import_deterministic_coinbase_privkeys() def start_controller_node(self): self.log.info("starting controller node") diff --git a/test/functional/feature_fee_estimation.py b/test/functional/feature_fee_estimation.py index 692c71a2f6..0007447947 100755 --- a/test/functional/feature_fee_estimation.py +++ b/test/functional/feature_fee_estimation.py @@ -147,6 +147,9 @@ class EstimateFeeTest(BitcoinTestFramework): # (17k is room enough for 110 or so transactions) # Node2 is a stingy miner, that # produces too small blocks (room for only 55 or so transactions) + self.start_nodes() + self.import_deterministic_coinbase_privkeys() + self.stop_nodes() def transact_and_mine(self, numblocks, mining_node): min_fee = Decimal("0.0001") @@ -174,11 +177,6 @@ class EstimateFeeTest(BitcoinTestFramework): newmem.append(utx) self.memutxo = newmem - def import_deterministic_coinbase_privkeys(self): - self.start_nodes() - super().import_deterministic_coinbase_privkeys() - self.stop_nodes() - def run_test(self): self.log.info("This test is time consuming, please be patient") self.log.info("Splitting inputs so we can generate tx's") diff --git a/test/functional/feature_pruning.py b/test/functional/feature_pruning.py index 507249f605..7c9c3af38f 100755 --- a/test/functional/feature_pruning.py +++ b/test/functional/feature_pruning.py @@ -105,6 +105,8 @@ class PruneTest(BitcoinTestFramework): def setup_nodes(self): self.add_nodes(self.num_nodes, self.extra_args) self.start_nodes() + for n in self.nodes: + n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase', rescan=False) def create_big_chain(self): # Start by creating some coinbases we can spend later diff --git a/test/functional/feature_spentindex.py b/test/functional/feature_spentindex.py index 9fcc853dcf..0015e8708b 100755 --- a/test/functional/feature_spentindex.py +++ b/test/functional/feature_spentindex.py @@ -37,8 +37,8 @@ class SpentIndexTest(BitcoinTestFramework): connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 2) connect_nodes(self.nodes[0], 3) - self.sync_all() + self.import_deterministic_coinbase_privkeys() def run_test(self): self.log.info("Test that settings can't be changed without -reindex...") diff --git a/test/functional/feature_txindex.py b/test/functional/feature_txindex.py index 449cc9f725..05f0907636 100755 --- a/test/functional/feature_txindex.py +++ b/test/functional/feature_txindex.py @@ -35,8 +35,8 @@ class TxIndexTest(BitcoinTestFramework): connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 2) connect_nodes(self.nodes[0], 3) - self.sync_all() + self.import_deterministic_coinbase_privkeys() def run_test(self): self.log.info("Mining blocks...") diff --git a/test/functional/interface_zmq.py b/test/functional/interface_zmq.py index b6b45ffe78..b6301b4729 100755 --- a/test/functional/interface_zmq.py +++ b/test/functional/interface_zmq.py @@ -73,6 +73,7 @@ class ZMQTest (BitcoinTestFramework): ] self.add_nodes(self.num_nodes, self.extra_args) self.start_nodes() + self.import_deterministic_coinbase_privkeys() def run_test(self): try: diff --git a/test/functional/p2p_node_network_limited.py b/test/functional/p2p_node_network_limited.py index 0cb4c371f0..a4b5f85de3 100755 --- a/test/functional/p2p_node_network_limited.py +++ b/test/functional/p2p_node_network_limited.py @@ -43,8 +43,8 @@ class NodeNetworkLimitedTest(BitcoinTestFramework): disconnect_nodes(self.nodes[1], 2) def setup_network(self): - super(NodeNetworkLimitedTest, self).setup_network() - self.disconnect_all() + self.add_nodes(self.num_nodes, self.extra_args) + self.start_nodes() def run_test(self): node = self.nodes[0].add_p2p_connection(P2PIgnoreInv()) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index bf0091d8c9..9fbd70030c 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -230,7 +230,6 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): self.skip_test_if_missing_module() self.setup_chain() self.setup_network() - self.import_deterministic_coinbase_privkeys() self.run_test() success = TestStatus.PASSED except JSONRPCException: @@ -353,11 +352,9 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): extra_args = self.extra_args self.add_nodes(self.num_nodes, extra_args) self.start_nodes() + self.import_deterministic_coinbase_privkeys() def import_deterministic_coinbase_privkeys(self): - if self.setup_clean_chain: - return - for n in self.nodes: try: n.getwalletinfo() @@ -365,7 +362,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): assert str(e).startswith('Method not found') continue - n.importprivkey(n.get_deterministic_priv_key().key) + n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase') def run_test(self): """Tests must override this method to define test logic""" @@ -925,6 +922,7 @@ class DashTestFramework(BitcoinTestFramework): self.log.info("Creating and starting controller node") self.add_nodes(1, extra_args=[self.extra_args[0]]) self.start_node(0) + self.import_deterministic_coinbase_privkeys() required_balance = MASTERNODE_COLLATERAL * self.mn_count + 1 self.log.info("Generating %d coins" % required_balance) while self.nodes[0].getbalance() < required_balance: @@ -945,6 +943,7 @@ class DashTestFramework(BitcoinTestFramework): self.prepare_masternodes() self.prepare_datadirs() self.start_masternodes() + self.import_deterministic_coinbase_privkeys() # non-masternodes where disconnected from the control node during prepare_datadirs, # let's reconnect them back to make sure they receive updates diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 431c23a3dd..04546edc3a 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -266,21 +266,6 @@ class TestNode(): 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): diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py index 2a0243f32f..fb58e67631 100755 --- a/test/functional/wallet_basic.py +++ b/test/functional/wallet_basic.py @@ -31,10 +31,9 @@ class WalletTest(BitcoinTestFramework): self.skip_if_no_wallet() def setup_network(self): - self.add_nodes(4, self.extra_args) - self.start_node(0) - self.start_node(1) - self.start_node(2) + self.setup_nodes() + # Only need nodes 0-2 running at start of test + self.stop_node(3) connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[1], 2) connect_nodes(self.nodes[0], 2) diff --git a/test/functional/wallet_hd.py b/test/functional/wallet_hd.py index 2c1915a747..18453c2b40 100755 --- a/test/functional/wallet_hd.py +++ b/test/functional/wallet_hd.py @@ -22,6 +22,7 @@ class WalletHDTest(BitcoinTestFramework): def setup_network(self): self.add_nodes(self.num_nodes, self.extra_args) self.start_nodes() + self.import_deterministic_coinbase_privkeys() def skip_test_if_missing_module(self): self.skip_if_no_wallet() diff --git a/test/functional/wallet_import_rescan.py b/test/functional/wallet_import_rescan.py index 823551bfa7..fcc3ae86b8 100755 --- a/test/functional/wallet_import_rescan.py +++ b/test/functional/wallet_import_rescan.py @@ -135,16 +135,14 @@ class ImportRescanTest(BitcoinTestFramework): # Import keys with pruning disabled self.start_nodes(extra_args=[[]] * self.num_nodes) - super().import_deterministic_coinbase_privkeys() + for n in self.nodes: + n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase') self.stop_nodes() self.start_nodes() for i in range(1, self.num_nodes): connect_nodes(self.nodes[i], 0) - def import_deterministic_coinbase_privkeys(self): - pass - def run_test(self): # Create one transaction on node 0 with a unique amount for # each possible type of wallet import RPC. diff --git a/test/functional/wallet_listreceivedby.py b/test/functional/wallet_listreceivedby.py index 21f13035e5..5e8a48832a 100755 --- a/test/functional/wallet_listreceivedby.py +++ b/test/functional/wallet_listreceivedby.py @@ -18,11 +18,6 @@ class ReceivedByTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 2 - def import_deterministic_coinbase_privkeys(self): - assert_equal(0, len(self.nodes[1].listreceivedbyaddress(minconf=0, include_empty=True, include_watchonly=True))) - super().import_deterministic_coinbase_privkeys() - self.num_cb_reward_addresses = len(self.nodes[1].listreceivedbyaddress(minconf=0, include_empty=True, include_watchonly=True)) - def skip_test_if_missing_module(self): self.skip_if_no_wallet() self.skip_if_no_cli() @@ -32,6 +27,9 @@ class ReceivedByTest(BitcoinTestFramework): self.nodes[0].generate(1) sync_blocks(self.nodes) + # save the number of coinbase reward addresses so far + num_cb_reward_addresses = len(self.nodes[1].listreceivedbyaddress(minconf=0, include_empty=True, include_watchonly=True)) + self.log.info("listreceivedbyaddress Test") # Send from node 0 to 1 @@ -77,7 +75,7 @@ class ReceivedByTest(BitcoinTestFramework): assert_raises_rpc_error(-4, "address_filter parameter was invalid", self.nodes[1].listreceivedbyaddress, minconf=0, addlocked=True, include_empty=True, include_watchonly=True, address_filter="bamboozling") # Another address receive money res = self.nodes[1].listreceivedbyaddress(0, True, True, True) - assert_equal(len(res), 2 + self.num_cb_reward_addresses) # Right now 2 entries + assert_equal(len(res), 2 + num_cb_reward_addresses) # Right now 2 entries other_addr = self.nodes[1].getnewaddress() txid2 = self.nodes[0].sendtoaddress(other_addr, 0.1) self.nodes[0].generate(1) @@ -94,7 +92,7 @@ class ReceivedByTest(BitcoinTestFramework): assert_equal(len(res), 1) # Should be two entries though without filter res = self.nodes[1].listreceivedbyaddress(0, True, True, True) - assert_equal(len(res), 3 + self.num_cb_reward_addresses) # Became 3 entries + assert_equal(len(res), 3 + num_cb_reward_addresses) # Became 3 entries # Not on random addr other_addr = self.nodes[0].getnewaddress() # note on node[0]! just a random addr diff --git a/test/functional/wallet_upgradetohd.py b/test/functional/wallet_upgradetohd.py index 4b21434a3a..7f798365cd 100755 --- a/test/functional/wallet_upgradetohd.py +++ b/test/functional/wallet_upgradetohd.py @@ -28,6 +28,7 @@ class WalletUpgradeToHDTest(BitcoinTestFramework): def setup_network(self): self.add_nodes(self.num_nodes) self.start_nodes() + self.import_deterministic_coinbase_privkeys() def recover_non_hd(self): self.log.info("Recover non-HD wallet to check different upgrade paths")