Merge #19350: test: Refactor tests using restart_node

20b6e959449d0c07639599b99ba917d2cac62493 test: refactor functional tests to use restart_node (Christopher Coverdale)

Pull request description:

  fixes #19345

  This PR replaces consecutive calls to `stop_node()` and `start_node()` with `restart_node()` where appropriate in the functional tests.

  The commit messages are repetitive but focused on each file changed with the intention of squashing if applicable.

ACKs for top commit:
  laanwj:
    ACK 20b6e959449d0c07639599b99ba917d2cac62493

Tree-SHA512: 1cfa1fb8c5f01a7b00fe44e80dbef072147f21e3891098817acd4275b0c5d91dc1c787594209e117edd418f2fa3a7b2dfcbafdf87efc07f740040938d641f3a9
This commit is contained in:
Wladimir J. van der Laan 2020-06-22 18:24:41 +02:00 committed by PastaPastaPasta
parent 98322e44a9
commit d90a46175b
11 changed files with 20 additions and 40 deletions

View File

@ -88,8 +88,7 @@ class LLMQChainLocksTest(DashTestFramework):
self.log.info("Keep node connected and let it try to reorg the chain") self.log.info("Keep node connected and let it try to reorg the chain")
good_tip = self.nodes[0].getbestblockhash() good_tip = self.nodes[0].getbestblockhash()
self.log.info("Restart it so that it forgets all the chainlock messages from the past") self.log.info("Restart it so that it forgets all the chainlock messages from the past")
self.stop_node(0) self.restart_node(0)
self.start_node(0)
self.connect_nodes(0, 1) self.connect_nodes(0, 1)
assert self.nodes[0].getbestblockhash() == good_tip assert self.nodes[0].getbestblockhash() == good_tip
self.nodes[0].invalidateblock(good_tip) self.nodes[0].invalidateblock(good_tip)
@ -119,11 +118,9 @@ class LLMQChainLocksTest(DashTestFramework):
self.log.info("Should switch to the best non-conflicting tip (not to the most work chain) on restart") self.log.info("Should switch to the best non-conflicting tip (not to the most work chain) on restart")
assert int(self.nodes[0].getblock(bad_tip)["chainwork"], 16) > int(self.nodes[1].getblock(good_tip)["chainwork"], 16) assert int(self.nodes[0].getblock(bad_tip)["chainwork"], 16) > int(self.nodes[1].getblock(good_tip)["chainwork"], 16)
self.stop_node(0) self.restart_node(0)
self.start_node(0)
self.nodes[0].invalidateblock(good_fork) self.nodes[0].invalidateblock(good_fork)
self.stop_node(0) self.restart_node(0)
self.start_node(0)
time.sleep(1) time.sleep(1)
assert self.nodes[0].getbestblockhash() == good_tip assert self.nodes[0].getbestblockhash() == good_tip

View File

@ -71,8 +71,7 @@ class LoadblockTest(BitcoinTestFramework):
check=True) check=True)
self.log.info("Restart second, unsynced node with bootstrap file") self.log.info("Restart second, unsynced node with bootstrap file")
self.stop_node(1) self.restart_node(1, extra_args=["-loadblock=" + bootstrap_file])
self.start_node(1, ["-loadblock=" + bootstrap_file])
assert_equal(self.nodes[1].getblockcount(), 100) # start_node is blocking on all block files being imported assert_equal(self.nodes[1].getblockcount(), 100) # start_node is blocking on all block files being imported
assert_equal(self.nodes[1].getblockchaininfo()['blocks'], 100) assert_equal(self.nodes[1].getblockchaininfo()['blocks'], 100)

View File

@ -67,8 +67,7 @@ class LoggingTest(BitcoinTestFramework):
assert not os.path.isfile(default_log_path) assert not os.path.isfile(default_log_path)
# just sanity check no crash here # just sanity check no crash here
self.stop_node(0) self.restart_node(0, ["-debuglogfile=%s" % os.devnull])
self.start_node(0, ["-debuglogfile=%s" % os.devnull])
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -257,8 +257,7 @@ class PruneTest(BitcoinTestFramework):
assert_raises_rpc_error(-1, "Cannot prune blocks because node is not in prune mode", node.pruneblockchain, 500) assert_raises_rpc_error(-1, "Cannot prune blocks because node is not in prune mode", node.pruneblockchain, 500)
# now re-start in manual pruning mode # now re-start in manual pruning mode
self.stop_node(node_number, expected_stderr='Warning: You are starting with governance validation disabled.') self.restart_node(node_number, extra_args=["-dip3params=2000:2000", "-dip8params=2000", "-disablegovernance", "-txindex=0", "-prune=1"])
self.start_node(node_number, extra_args=["-dip3params=2000:2000", "-dip8params=2000", "-disablegovernance", "-txindex=0", "-prune=1"])
node = self.nodes[node_number] node = self.nodes[node_number]
assert_equal(node.getblockcount(), 995) assert_equal(node.getblockcount(), 995)
@ -327,16 +326,14 @@ class PruneTest(BitcoinTestFramework):
assert not has_block(3), "blk00003.dat is still there, should be pruned by now" assert not has_block(3), "blk00003.dat is still there, should be pruned by now"
# stop node, start back up with auto-prune at 550 MiB, make sure still runs # stop node, start back up with auto-prune at 550 MiB, make sure still runs
self.stop_node(node_number, expected_stderr='Warning: You are starting with governance validation disabled. This is expected because you are running a pruned node.') self.restart_node(node_number, extra_args=["-dip3params=2000:2000", "-dip8params=2000", "-disablegovernance", "-txindex=0", "-prune=550"])
self.start_node(node_number, extra_args=["-dip3params=2000:2000", "-dip8params=2000", "-disablegovernance", "-txindex=0", "-prune=550"])
self.log.info("Success") self.log.info("Success")
def wallet_test(self): def wallet_test(self):
# check that the pruning node's wallet is still in good shape # check that the pruning node's wallet is still in good shape
self.log.info("Stop and start pruning node to trigger wallet rescan") self.log.info("Stop and start pruning node to trigger wallet rescan")
self.stop_node(2, expected_stderr='Warning: You are starting with governance validation disabled. This is expected because you are running a pruned node.') self.restart_node(2, extra_args=["-dip3params=2000:2000", "-dip8params=2000", "-disablegovernance", "-txindex=0", "-prune=550"])
self.start_node(2, extra_args=["-dip3params=2000:2000", "-dip8params=2000", "-disablegovernance", "-txindex=0", "-prune=550"])
self.log.info("Success") self.log.info("Success")
# check that wallet loads successfully when restarting a pruned node after IBD. # check that wallet loads successfully when restarting a pruned node after IBD.
@ -345,8 +342,7 @@ class PruneTest(BitcoinTestFramework):
self.connect_nodes(0, 5) self.connect_nodes(0, 5)
nds = [self.nodes[0], self.nodes[5]] nds = [self.nodes[0], self.nodes[5]]
self.sync_blocks(nds, wait=5, timeout=300) self.sync_blocks(nds, wait=5, timeout=300)
self.stop_node(5, expected_stderr='Warning: You are starting with governance validation disabled. This is expected because you are running a pruned node.') # stop and start to trigger rescan self.restart_node(5, extra_args=["-dip3params=2000:2000", "-dip8params=2000", "-disablegovernance", "-txindex=0", "-prune=550"]) # restart to trigger rescan
self.start_node(5, extra_args=["-dip3params=2000:2000", "-dip8params=2000", "-disablegovernance", "-txindex=0", "-prune=550"])
self.log.info("Success") self.log.info("Success")
def run_test(self): def run_test(self):

View File

@ -63,8 +63,7 @@ class DisconnectBanTest(BitcoinTestFramework):
self.bump_mocktime(2) self.bump_mocktime(2)
wait_until(lambda: len(self.nodes[1].listbanned()) == 3, timeout=10) wait_until(lambda: len(self.nodes[1].listbanned()) == 3, timeout=10)
self.stop_node(1) self.restart_node(1)
self.start_node(1)
listAfterShutdown = self.nodes[1].listbanned() listAfterShutdown = self.nodes[1].listbanned()
assert_equal("127.0.0.0/24", listAfterShutdown[0]['address']) assert_equal("127.0.0.0/24", listAfterShutdown[0]['address'])

View File

@ -93,8 +93,7 @@ class AbandonConflictTest(BitcoinTestFramework):
# Restart the node with a higher min relay fee so the parent tx is no longer in mempool # Restart the node with a higher min relay fee so the parent tx is no longer in mempool
# TODO: redo with eviction # TODO: redo with eviction
self.stop_node(0) self.restart_node(0, extra_args=["-minrelaytxfee=0.0001"])
self.start_node(0, extra_args=["-minrelaytxfee=0.0001"])
assert self.nodes[0].getmempoolinfo()['loaded'] assert self.nodes[0].getmempoolinfo()['loaded']
# Verify txs no longer in either node's mempool # Verify txs no longer in either node's mempool
@ -129,8 +128,7 @@ class AbandonConflictTest(BitcoinTestFramework):
assert_equal(tx['trusted'], False) assert_equal(tx['trusted'], False)
# Verify that even with a low min relay fee, the tx is not reaccepted from wallet on startup once abandoned # Verify that even with a low min relay fee, the tx is not reaccepted from wallet on startup once abandoned
self.stop_node(0) self.restart_node(0, extra_args=["-minrelaytxfee=0.00001"])
self.start_node(0, extra_args=["-minrelaytxfee=0.00001"])
assert self.nodes[0].getmempoolinfo()['loaded'] assert self.nodes[0].getmempoolinfo()['loaded']
assert_equal(len(self.nodes[0].getrawmempool()), 0) assert_equal(len(self.nodes[0].getrawmempool()), 0)
@ -151,8 +149,7 @@ class AbandonConflictTest(BitcoinTestFramework):
balance = newbalance balance = newbalance
# Remove using high relay fee again # Remove using high relay fee again
self.stop_node(0) self.restart_node(0, extra_args=["-minrelaytxfee=0.0001"])
self.start_node(0, extra_args=["-minrelaytxfee=0.0001"])
assert self.nodes[0].getmempoolinfo()['loaded'] assert self.nodes[0].getmempoolinfo()['loaded']
assert_equal(len(self.nodes[0].getrawmempool()), 0) assert_equal(len(self.nodes[0].getrawmempool()), 0)
newbalance = self.nodes[0].getbalance() newbalance = self.nodes[0].getbalance()

View File

@ -107,8 +107,7 @@ class AvoidReuseTest(BitcoinTestFramework):
assert_equal(self.nodes[1].getwalletinfo()["avoid_reuse"], True) assert_equal(self.nodes[1].getwalletinfo()["avoid_reuse"], True)
# Stop and restart node 1 # Stop and restart node 1
self.stop_node(1) self.restart_node(1)
self.start_node(1)
self.connect_nodes(0, 1) self.connect_nodes(0, 1)
# Flags should still be node1.avoid_reuse=false, node2.avoid_reuse=true # Flags should still be node1.avoid_reuse=false, node2.avoid_reuse=true

View File

@ -450,8 +450,7 @@ class WalletTest(BitcoinTestFramework):
# Try with walletrejectlongchains # Try with walletrejectlongchains
# Double chain limit but require combining inputs, so we pass SelectCoinsMinConf # Double chain limit but require combining inputs, so we pass SelectCoinsMinConf
self.stop_node(0) self.restart_node(0, extra_args=["-walletrejectlongchains", "-limitancestorcount=" + str(2 * chainlimit)])
self.start_node(0, extra_args=["-walletrejectlongchains", "-limitancestorcount=" + str(2 * chainlimit)])
# wait until the wallet has submitted all transactions to the mempool # wait until the wallet has submitted all transactions to the mempool
wait_until(lambda: len(self.nodes[0].getrawmempool()) == chainlimit * 2) wait_until(lambda: len(self.nodes[0].getrawmempool()) == chainlimit * 2)

View File

@ -99,8 +99,7 @@ class WalletHDTest(BitcoinTestFramework):
self.sync_all() self.sync_all()
# Needs rescan # Needs rescan
self.stop_node(1) self.restart_node(1, extra_args=self.extra_args[1] + ['-rescan'])
self.start_node(1, extra_args=self.extra_args[1] + ['-rescan'])
assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1) assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1)
# Try a RPC based rescan # Try a RPC based rescan

View File

@ -75,8 +75,7 @@ class ReorgsRestoreTest(BitcoinTestFramework):
assert_equal(conflicted["walletconflicts"][0], conflicting["txid"]) assert_equal(conflicted["walletconflicts"][0], conflicting["txid"])
# Node0 wallet is shutdown # Node0 wallet is shutdown
self.stop_node(0) self.restart_node(0)
self.start_node(0)
# The block chain re-orgs and the tx is included in a different block # The block chain re-orgs and the tx is included in a different block
self.nodes[1].generate(9) self.nodes[1].generate(9)

View File

@ -91,8 +91,7 @@ class WalletUpgradeToHDTest(BitcoinTestFramework):
self.recover_non_hd() self.recover_non_hd()
self.log.info("No mnemonic, no mnemonic passphrase, no wallet passphrase, should result in completely different keys") self.log.info("No mnemonic, no mnemonic passphrase, no wallet passphrase, should result in completely different keys")
self.stop_node(0) self.restart_node(0, extra_args=['-keypool=10'])
self.start_node(0, extra_args=['-keypool=10'])
assert node.upgradetohd("", "", "", True) assert node.upgradetohd("", "", "", True)
# Completely different keys, no HD coins should be recovered # Completely different keys, no HD coins should be recovered
assert mnemonic != node.dumphdinfo()['mnemonic'] assert mnemonic != node.dumphdinfo()['mnemonic']
@ -141,8 +140,7 @@ class WalletUpgradeToHDTest(BitcoinTestFramework):
self.recover_non_hd() self.recover_non_hd()
self.log.info("Same mnemonic, no mnemonic passphrase, no wallet passphrase, large enough keepool, should recover all coins with no extra rescan") self.log.info("Same mnemonic, no mnemonic passphrase, no wallet passphrase, large enough keepool, should recover all coins with no extra rescan")
self.stop_node(0) self.restart_node(0, extra_args=['-keypool=10'])
self.start_node(0, extra_args=['-keypool=10'])
assert node.upgradetohd(mnemonic) assert node.upgradetohd(mnemonic)
assert_equal(mnemonic, node.dumphdinfo()['mnemonic']) assert_equal(mnemonic, node.dumphdinfo()['mnemonic'])
assert_equal(chainid, node.getwalletinfo()['hdchainid']) assert_equal(chainid, node.getwalletinfo()['hdchainid'])
@ -152,8 +150,7 @@ class WalletUpgradeToHDTest(BitcoinTestFramework):
self.recover_non_hd() self.recover_non_hd()
self.log.info("Same mnemonic, no mnemonic passphrase, no wallet passphrase, large enough keepool, rescan is skipped initially, should recover all coins after rescanblockchain") self.log.info("Same mnemonic, no mnemonic passphrase, no wallet passphrase, large enough keepool, rescan is skipped initially, should recover all coins after rescanblockchain")
self.stop_node(0) self.restart_node(0, extra_args=['-keypool=10'])
self.start_node(0, extra_args=['-keypool=10'])
assert node.upgradetohd(mnemonic, "", "", False) assert node.upgradetohd(mnemonic, "", "", False)
assert_equal(mnemonic, node.dumphdinfo()['mnemonic']) assert_equal(mnemonic, node.dumphdinfo()['mnemonic'])
assert_equal(chainid, node.getwalletinfo()['hdchainid']) assert_equal(chainid, node.getwalletinfo()['hdchainid'])