mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 14:34:49 +01:00
test: refactor functional tests to use restart_node
This commit is contained in:
parent
8ef15e8a86
commit
20b6e95944
13 changed files with 25 additions and 48 deletions
|
@ -311,15 +311,13 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
|
||||||
self.start_node(4)
|
self.start_node(4)
|
||||||
|
|
||||||
# Open most recent wallet in v0.16 (no loadwallet RPC)
|
# Open most recent wallet in v0.16 (no loadwallet RPC)
|
||||||
self.stop_node(5)
|
self.restart_node(5, extra_args=["-wallet=w2"])
|
||||||
self.start_node(5, extra_args=["-wallet=w2"])
|
|
||||||
wallet = node_v16.get_wallet_rpc("w2")
|
wallet = node_v16.get_wallet_rpc("w2")
|
||||||
info = wallet.getwalletinfo()
|
info = wallet.getwalletinfo()
|
||||||
assert info['keypoolsize'] == 1
|
assert info['keypoolsize'] == 1
|
||||||
|
|
||||||
# Create upgrade wallet in v0.16
|
# Create upgrade wallet in v0.16
|
||||||
self.stop_node(-1)
|
self.restart_node(-1, extra_args=["-wallet=u1_v16"])
|
||||||
self.start_node(-1, extra_args=["-wallet=u1_v16"])
|
|
||||||
wallet = node_v16.get_wallet_rpc("u1_v16")
|
wallet = node_v16.get_wallet_rpc("u1_v16")
|
||||||
v16_addr = wallet.getnewaddress('', "bech32")
|
v16_addr = wallet.getnewaddress('', "bech32")
|
||||||
v16_info = wallet.validateaddress(v16_addr)
|
v16_info = wallet.validateaddress(v16_addr)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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__':
|
||||||
|
|
|
@ -263,8 +263,7 @@ class PruneTest(BitcoinTestFramework):
|
||||||
assert_raises_rpc_error(-1, "not in prune mode", node.pruneblockchain, 500)
|
assert_raises_rpc_error(-1, "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)
|
self.restart_node(node_number, extra_args=["-prune=1"])
|
||||||
self.start_node(node_number, extra_args=["-prune=1"])
|
|
||||||
node = self.nodes[node_number]
|
node = self.nodes[node_number]
|
||||||
assert_equal(node.getblockcount(), 995)
|
assert_equal(node.getblockcount(), 995)
|
||||||
|
|
||||||
|
@ -326,16 +325,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)
|
self.restart_node(node_number, extra_args=["-prune=550"])
|
||||||
self.start_node(node_number, extra_args=["-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)
|
self.restart_node(2, extra_args=["-prune=550"])
|
||||||
self.start_node(2, extra_args=["-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.
|
||||||
|
@ -344,8 +341,7 @@ class PruneTest(BitcoinTestFramework):
|
||||||
connect_nodes(self.nodes[0], 5)
|
connect_nodes(self.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) # stop and start to trigger rescan
|
self.restart_node(5, extra_args=["-prune=550"]) # restart to trigger rescan
|
||||||
self.start_node(5, extra_args=["-prune=550"])
|
|
||||||
self.log.info("Success")
|
self.log.info("Success")
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
|
|
|
@ -559,8 +559,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
assert_equal(self.nodes[1].listtransactions("*", 1, 0, True)[0]["txid"], txid)
|
assert_equal(self.nodes[1].listtransactions("*", 1, 0, True)[0]["txid"], txid)
|
||||||
|
|
||||||
# Assert it is properly saved
|
# Assert it is properly saved
|
||||||
self.stop_node(1)
|
self.restart_node(1)
|
||||||
self.start_node(1)
|
|
||||||
assert_equal(self.nodes[1].gettransaction(txid, True)["txid"], txid)
|
assert_equal(self.nodes[1].gettransaction(txid, True)["txid"], txid)
|
||||||
assert_equal(self.nodes[1].listtransactions("*", 1, 0, True)[0]["txid"], txid)
|
assert_equal(self.nodes[1].listtransactions("*", 1, 0, True)[0]["txid"], txid)
|
||||||
|
|
||||||
|
|
|
@ -69,8 +69,7 @@ class DisconnectBanTest(BitcoinTestFramework):
|
||||||
self.nodes[1].setmocktime(old_time + 3)
|
self.nodes[1].setmocktime(old_time + 3)
|
||||||
assert_equal(len(self.nodes[1].listbanned()), 3)
|
assert_equal(len(self.nodes[1].listbanned()), 3)
|
||||||
|
|
||||||
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'])
|
||||||
|
|
|
@ -1898,8 +1898,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
def test_upgrade_after_activation(self):
|
def test_upgrade_after_activation(self):
|
||||||
"""Test the behavior of starting up a segwit-aware node after the softfork has activated."""
|
"""Test the behavior of starting up a segwit-aware node after the softfork has activated."""
|
||||||
|
|
||||||
self.stop_node(2)
|
self.restart_node(2, extra_args=["-segwitheight={}".format(SEGWIT_HEIGHT)])
|
||||||
self.start_node(2, extra_args=["-segwitheight={}".format(SEGWIT_HEIGHT)])
|
|
||||||
connect_nodes(self.nodes[0], 2)
|
connect_nodes(self.nodes[0], 2)
|
||||||
|
|
||||||
# We reconnect more than 100 blocks, give it plenty of time
|
# We reconnect more than 100 blocks, give it plenty of time
|
||||||
|
|
|
@ -95,8 +95,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
|
||||||
|
@ -123,8 +122,7 @@ class AbandonConflictTest(BitcoinTestFramework):
|
||||||
balance = newbalance
|
balance = newbalance
|
||||||
|
|
||||||
# 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)
|
||||||
|
@ -145,8 +143,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()
|
||||||
|
|
|
@ -110,9 +110,7 @@ class AvoidReuseTest(BitcoinTestFramework):
|
||||||
assert_equal(self.nodes[0].getwalletinfo()["avoid_reuse"], False)
|
assert_equal(self.nodes[0].getwalletinfo()["avoid_reuse"], False)
|
||||||
assert_equal(self.nodes[1].getwalletinfo()["avoid_reuse"], True)
|
assert_equal(self.nodes[1].getwalletinfo()["avoid_reuse"], True)
|
||||||
|
|
||||||
# Stop and restart node 1
|
self.restart_node(1)
|
||||||
self.stop_node(1)
|
|
||||||
self.start_node(1)
|
|
||||||
connect_nodes(self.nodes[0], 1)
|
connect_nodes(self.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
|
||||||
|
|
|
@ -190,8 +190,7 @@ class WalletDumpTest(BitcoinTestFramework):
|
||||||
assert_raises_rpc_error(-8, "already exists", lambda: self.nodes[0].dumpwallet(wallet_enc_dump))
|
assert_raises_rpc_error(-8, "already exists", lambda: self.nodes[0].dumpwallet(wallet_enc_dump))
|
||||||
|
|
||||||
# Restart node with new wallet, and test importwallet
|
# Restart node with new wallet, and test importwallet
|
||||||
self.stop_node(0)
|
self.restart_node(0, ['-wallet=w2'])
|
||||||
self.start_node(0, ['-wallet=w2'])
|
|
||||||
|
|
||||||
# Make sure the address is not IsMine before import
|
# Make sure the address is not IsMine before import
|
||||||
result = self.nodes[0].getaddressinfo(multisig_addr)
|
result = self.nodes[0].getaddressinfo(multisig_addr)
|
||||||
|
|
|
@ -103,8 +103,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
|
||||||
|
@ -183,8 +182,7 @@ class WalletHDTest(BitcoinTestFramework):
|
||||||
self.nodes[0].generate(10)
|
self.nodes[0].generate(10)
|
||||||
# Restart node 1 with keypool of 3 and a different wallet
|
# Restart node 1 with keypool of 3 and a different wallet
|
||||||
self.nodes[1].createwallet(wallet_name='origin', blank=True)
|
self.nodes[1].createwallet(wallet_name='origin', blank=True)
|
||||||
self.stop_node(1)
|
self.restart_node(1, extra_args=['-keypool=3', '-wallet=origin'])
|
||||||
self.start_node(1, extra_args=['-keypool=3', '-wallet=origin'])
|
|
||||||
connect_nodes(self.nodes[0], 1)
|
connect_nodes(self.nodes[0], 1)
|
||||||
|
|
||||||
# sethdseed restoring and seeing txs to addresses out of the keypool
|
# sethdseed restoring and seeing txs to addresses out of the keypool
|
||||||
|
|
|
@ -77,8 +77,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)
|
||||||
|
|
|
@ -49,17 +49,15 @@ class ZapWalletTXesTest (BitcoinTestFramework):
|
||||||
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
||||||
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
||||||
|
|
||||||
# Stop-start node0. Both confirmed and unconfirmed transactions remain in the wallet.
|
# Restart node0. Both confirmed and unconfirmed transactions remain in the wallet.
|
||||||
self.stop_node(0)
|
self.restart_node(0)
|
||||||
self.start_node(0)
|
|
||||||
|
|
||||||
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
||||||
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
||||||
|
|
||||||
# Stop node0 and restart with zapwallettxes and persistmempool. The unconfirmed
|
# Restart node0 with zapwallettxes and persistmempool. The unconfirmed
|
||||||
# transaction is zapped from the wallet, but is re-added when the mempool is reloaded.
|
# transaction is zapped from the wallet, but is re-added when the mempool is reloaded.
|
||||||
self.stop_node(0)
|
self.restart_node(0, ["-persistmempool=1", "-zapwallettxes=2"])
|
||||||
self.start_node(0, ["-persistmempool=1", "-zapwallettxes=2"])
|
|
||||||
|
|
||||||
wait_until(lambda: self.nodes[0].getmempoolinfo()['size'] == 1, timeout=3)
|
wait_until(lambda: self.nodes[0].getmempoolinfo()['size'] == 1, timeout=3)
|
||||||
self.nodes[0].syncwithvalidationinterfacequeue() # Flush mempool to wallet
|
self.nodes[0].syncwithvalidationinterfacequeue() # Flush mempool to wallet
|
||||||
|
@ -67,10 +65,9 @@ class ZapWalletTXesTest (BitcoinTestFramework):
|
||||||
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
||||||
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
assert_equal(self.nodes[0].gettransaction(txid2)['txid'], txid2)
|
||||||
|
|
||||||
# Stop node0 and restart with zapwallettxes, but not persistmempool.
|
# Restart node0 with zapwallettxes, but not persistmempool.
|
||||||
# The unconfirmed transaction is zapped and is no longer in the wallet.
|
# The unconfirmed transaction is zapped and is no longer in the wallet.
|
||||||
self.stop_node(0)
|
self.restart_node(0, ["-zapwallettxes=2"])
|
||||||
self.start_node(0, ["-zapwallettxes=2"])
|
|
||||||
|
|
||||||
# tx1 is still be available because it was confirmed
|
# tx1 is still be available because it was confirmed
|
||||||
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
assert_equal(self.nodes[0].gettransaction(txid1)['txid'], txid1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue