mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
Merge #14631: [tests] Move deterministic address import to setup_nodes
3fd7e76f6d [tests] Move deterministic address import to setup_nodes (John Newbery) Pull request description: This requires a small changes to a few tests, but means that deterministic addresses will always be imported (unless setup_nodes behaviour is explicitly overridden). Tidies up the way we import deterministic addresses, requested in review comment here: https://github.com/bitcoin/bitcoin/pull/14468#discussion_r225594586. Tree-SHA512: 2b32edf500e286c463398487ab1153116a1dc90f64a53614716373311abdc83d8a251fdd8f42d1146b56e308664deaf62952113f66e98bc37f23968096d1a961
This commit is contained in:
parent
8cac4ed930
commit
0bbd8bfab6
@ -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...")
|
||||
|
@ -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):
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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...")
|
||||
|
@ -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...")
|
||||
|
@ -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:
|
||||
|
@ -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())
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user