Skip to content

Commit

Permalink
Partial merge bitcoin#16681: Tests: Use self.chain instead of 'regtes…
Browse files Browse the repository at this point in the history
…t' in almost all current tests, revert one TODO while at it
  • Loading branch information
jtimon authored and KolbyML committed Jan 21, 2021
1 parent 0f6f62e commit ef37c2f
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 50 deletions.
8 changes: 2 additions & 6 deletions test/functional/feature_assumevalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ def send_blocks_until_disconnected(self, p2p_conn):
break
try:
p2p_conn.send_message(msg_block(self.blocks[i]))
# TODO There is a race condition between send_message and on_close which causes an AttributError on Travis
# We can reenable the correct exception handling and the assert when Bitcoin 0.16 mininode.py changes have been
# backported
#except IOError as e:
except:
#assert not p2p_conn.is_connected
except IOError:
assert not p2p_conn.is_connected
break

def assert_blockchain_height(self, node, height):
Expand Down
6 changes: 3 additions & 3 deletions test/functional/feature_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ def set_test_params(self):

def run_test(self):
# test default log file name
assert os.path.isfile(os.path.join(self.nodes[0].datadir, "regtest", "debug.log"))
assert os.path.isfile(os.path.join(self.nodes[0].datadir, self.chain, "debug.log"))

# test alternative log file name in datadir
self.restart_node(0, ["-debuglogfile=foo.log"])
assert os.path.isfile(os.path.join(self.nodes[0].datadir, "regtest", "foo.log"))
assert os.path.isfile(os.path.join(self.nodes[0].datadir, self.chain, "foo.log"))

# test alternative log file name outside datadir
tempname = os.path.join(self.options.tmpdir, "foo.log")
self.restart_node(0, ["-debuglogfile=%s" % tempname])
assert os.path.isfile(tempname)

# check that invalid log (relative) will cause error
invdir = os.path.join(self.nodes[0].datadir, "regtest", "foo")
invdir = os.path.join(self.nodes[0].datadir, self.chain, "foo")
invalidname = os.path.join("foo", "foo.log")
self.stop_node(0)
exp_stderr = "Error: Could not open debug log file \S+$"
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def set_test_params(self):
def setup_network(self):
self.setup_nodes()

self.prunedir = os.path.join(self.nodes[2].datadir, 'regtest', 'blocks', '')
self.prunedir = os.path.join(self.nodes[2].datadir, self.chain, 'blocks', '')

connect_nodes(self.nodes[0], 1)
connect_nodes(self.nodes[1], 2)
Expand Down Expand Up @@ -256,7 +256,7 @@ def prune(index, expected_ret=None):
assert_equal(ret, expected_ret)

def has_block(index):
return os.path.isfile(os.path.join(self.nodes[node_number].datadir, "regtest", "blocks", "blk{:05}.dat".format(index)))
return os.path.isfile(os.path.join(self.nodes[node_number].datadir, self.chain, "blocks", "blk{:05}.dat".format(index)))

# should not prune because chain tip of node 3 (995) < PruneAfterHeight (1000)
assert_raises_rpc_error(-1, "Blockchain is too short for pruning", node.pruneblockchain, height(500))
Expand Down
4 changes: 2 additions & 2 deletions test/functional/mempool_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def run_test(self):
self.start_node(0)
wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)

mempooldat0 = os.path.join(self.nodes[0].datadir, 'regtest', 'mempool.dat')
mempooldat1 = os.path.join(self.nodes[1].datadir, 'regtest', 'mempool.dat')
mempooldat0 = os.path.join(self.nodes[0].datadir, self.chain, 'mempool.dat')
mempooldat1 = os.path.join(self.nodes[1].datadir, self.chain, 'mempool.dat')
self.log.debug("Remove the mempool.dat file. Verify that savemempool to disk via RPC re-creates it")
os.remove(mempooldat0)
self.nodes[0].savemempool()
Expand Down
2 changes: 1 addition & 1 deletion test/functional/mining_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def run_test(self):
self.log.info('getmininginfo')
mining_info = node.getmininginfo()
assert_equal(mining_info['blocks'], 200)
assert_equal(mining_info['chain'], 'regtest')
assert_equal(mining_info['chain'], self.chain)
assert_equal(mining_info['currentblocksize'], 0)
assert_equal(mining_info['currentblocktx'], 0)
assert_equal(mining_info['difficulty'], Decimal('4.656542373906925E-10'))
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ def prepare_datadirs(self):

start_idx = len(self.nodes)
for idx in range(0, self.mn_count):
copy_datadir(0, idx + start_idx, self.options.tmpdir)
copy_datadir(0, idx + start_idx, self.options.tmpdir, self.chain)

# restart faucet node
self.start_node(0)
Expand Down
6 changes: 3 additions & 3 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ def get_auth_cookie(datadir, chain):
raise ValueError("No RPC credentials")
return user, password

def copy_datadir(from_node, to_node, dirname):
from_datadir = os.path.join(dirname, "node"+str(from_node), "regtest")
to_datadir = os.path.join(dirname, "node"+str(to_node), "regtest")
def copy_datadir(from_node, to_node, dirname, chain):
from_datadir = os.path.join(dirname, "node"+str(from_node), chain)
to_datadir = os.path.join(dirname, "node"+str(to_node), chain)

dirs = ["blocks", "chainstate", "evodb", "llmq"]
for d in dirs:
Expand Down
36 changes: 18 additions & 18 deletions test/functional/wallet_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def stop_three(self):
self.stop_node(2)

def erase_three(self):
os.remove(os.path.join(self.nodes[0].datadir, 'regtest', 'wallets', 'wallet.dat'))
os.remove(os.path.join(self.nodes[1].datadir, 'regtest', 'wallets', 'wallet.dat'))
os.remove(os.path.join(self.nodes[2].datadir, 'regtest', 'wallets', 'wallet.dat'))
os.remove(os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'))
os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat'))
os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat'))

def run_test(self):
self.log.info("Generating initial blockchain")
Expand Down Expand Up @@ -150,15 +150,15 @@ def run_test(self):
self.erase_three()

# Start node2 with no chain
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'blocks'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'chainstate'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'evodb'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'llmq'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'evodb'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'llmq'))

# Restore wallets from backup
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[0].datadir, 'regtest', 'wallets', 'wallet.dat'))
shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, 'regtest', 'wallets', 'wallet.dat'))
shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join(self.nodes[2].datadir, 'regtest', 'wallets', 'wallet.dat'))
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'))
shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat'))
shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join(self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat'))

self.log.info("Re-starting nodes")
self.start_three()
Expand All @@ -173,10 +173,10 @@ def run_test(self):
self.erase_three()

#start node2 with no chain
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'blocks'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'chainstate'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'evodb'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, 'regtest', 'llmq'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'evodb'))
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'llmq'))

self.start_three()

Expand All @@ -196,10 +196,10 @@ def run_test(self):

# Backup to source wallet file must fail
sourcePaths = [
os.path.join(self.nodes[0].datadir, 'regtest', 'wallets', 'wallet.dat'),
os.path.join(self.nodes[0].datadir, 'regtest', '.', 'wallets', 'wallet.dat'),
os.path.join(self.nodes[0].datadir, 'regtest', 'wallets', ''),
os.path.join(self.nodes[0].datadir, 'regtest', 'wallets')]
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'),
os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', 'wallet.dat'),
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', ''),
os.path.join(self.nodes[0].datadir, self.chain, 'wallets')]

for sourcePath in sourcePaths:
assert_raises_rpc_error(-4, "backup failed", self.nodes[0].backupwallet, sourcePath)
Expand Down
22 changes: 11 additions & 11 deletions test/functional/wallet_hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def run_test(self):

self.log.info("Restore backup ...")
self.stop_node(1)
# we need to delete the complete regtest directory
# we need to delete the complete chain directory
# otherwise node1 would auto-recover all funds in flag the keypool keys as used
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "blocks"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "chainstate"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "evodb"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "llmq"))
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(self.nodes[1].datadir, "regtest", "wallets", "wallet.dat"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "evodb"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "llmq"))
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat"))
self.start_node(1)

# Assert that derivation is deterministic
Expand All @@ -100,11 +100,11 @@ def run_test(self):

# Try a RPC based rescan
self.stop_node(1)
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "blocks"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "chainstate"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "evodb"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, "regtest", "llmq"))
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(self.nodes[1].datadir, "regtest", "wallets", "wallet.dat"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "evodb"))
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "llmq"))
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat"))
self.start_node(1, extra_args=self.extra_args[1])
connect_nodes_bi(self.nodes, 0, 1)
self.sync_all()
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_keypool_topup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def set_test_params(self):
self.stderr = sys.stdout

def run_test(self):
wallet_path = os.path.join(self.nodes[1].datadir, "regtest", "wallets", "wallet.dat")
wallet_path = os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat")
wallet_backup_path = os.path.join(self.nodes[1].datadir, "wallet.bak")
self.nodes[0].generate(101)

Expand Down
4 changes: 2 additions & 2 deletions test/functional/wallet_multiwallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def set_test_params(self):
def run_test(self):
node = self.nodes[0]

data_dir = lambda *p: os.path.join(node.datadir, 'regtest', *p)
data_dir = lambda *p: os.path.join(node.datadir, self.chain, *p)
wallet_dir = lambda *p: data_dir('wallets', *p)
wallet = lambda name: node.get_wallet_rpc(name)

Expand Down Expand Up @@ -160,7 +160,7 @@ def run_test(self):
assert_equal(w4.getbalance(), 3)

batch = w1.batch([w1.getblockchaininfo.get_request(), w1.getwalletinfo.get_request()])
assert_equal(batch[0]["result"]["chain"], "regtest")
assert_equal(batch[0]["result"]["chain"], self.chain)
assert_equal(batch[1]["result"]["walletname"], "w1")


Expand Down

0 comments on commit ef37c2f

Please sign in to comment.