Skip to content

Commit

Permalink
[tests] Move deterministic address import to setup_nodes
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
jnewbery committed Nov 1, 2018
1 parent 08a57d5 commit 3fd7e76
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 42 deletions.
1 change: 1 addition & 0 deletions test/functional/feature_dbcrash.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def skip_test_if_missing_module(self):
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):
Expand Down
8 changes: 3 additions & 5 deletions test/functional/feature_fee_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def setup_network(self):
# (68k weight is room enough for 120 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.00001")
Expand Down Expand Up @@ -171,11 +174,6 @@ def transact_and_mine(self, numblocks, mining_node):
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")
Expand Down
2 changes: 2 additions & 0 deletions test/functional/feature_pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def setup_network(self):
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
Expand Down
1 change: 1 addition & 0 deletions test/functional/interface_zmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def setup_nodes(self):
]
self.add_nodes(self.num_nodes, self.extra_args)
self.start_nodes()
self.import_deterministic_coinbase_privkeys()

def run_test(self):
try:
Expand Down
4 changes: 2 additions & 2 deletions test/functional/p2p_node_network_limited.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def disconnect_all(self):
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())
Expand Down
7 changes: 2 additions & 5 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ def main(self):
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 as e:
Expand Down Expand Up @@ -261,19 +260,17 @@ def setup_nodes(self):
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()
except JSONRPCException as e:
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"""
Expand Down
15 changes: 0 additions & 15 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,6 @@ def wait_for_rpc_connection(self):

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):
Expand Down
7 changes: 3 additions & 4 deletions test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def setup_network(self):
self.add_nodes(4)
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_bi(self.nodes, 0, 1)
connect_nodes_bi(self.nodes, 1, 2)
connect_nodes_bi(self.nodes, 0, 2)
Expand Down
6 changes: 2 additions & 4 deletions test/functional/wallet_import_rescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,14 @@ def setup_network(self):

# 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.
Expand Down
12 changes: 5 additions & 7 deletions test/functional/wallet_listreceivedby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -31,6 +26,9 @@ def run_test(self):
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
Expand Down Expand Up @@ -76,7 +74,7 @@ def run_test(self):
assert_raises_rpc_error(-4, "address_filter parameter was invalid", self.nodes[1].listreceivedbyaddress, minconf=0, include_empty=True, include_watchonly=True, address_filter="bamboozling")
# Another address receive money
res = self.nodes[1].listreceivedbyaddress(0, 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)
Expand All @@ -93,7 +91,7 @@ def run_test(self):
assert_equal(len(res), 1)
# Should be two entries though without filter
res = self.nodes[1].listreceivedbyaddress(0, 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
Expand Down

0 comments on commit 3fd7e76

Please sign in to comment.