Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_loadblock.py
Show All 31 Lines | def run_test(self): | ||||
# Parsing the url of our node to get settings for config file | # Parsing the url of our node to get settings for config file | ||||
data_dir = self.nodes[0].datadir | data_dir = self.nodes[0].datadir | ||||
node_url = urllib.parse.urlparse(self.nodes[0].url) | node_url = urllib.parse.urlparse(self.nodes[0].url) | ||||
cfg_file = os.path.join(data_dir, "linearize.cfg") | cfg_file = os.path.join(data_dir, "linearize.cfg") | ||||
bootstrap_file = os.path.join(self.options.tmpdir, "bootstrap.dat") | bootstrap_file = os.path.join(self.options.tmpdir, "bootstrap.dat") | ||||
genesis_block = self.nodes[0].getblockhash(0) | genesis_block = self.nodes[0].getblockhash(0) | ||||
blocks_dir = os.path.join(data_dir, self.chain, "blocks") | blocks_dir = os.path.join(data_dir, self.chain, "blocks") | ||||
hash_list = tempfile.NamedTemporaryFile(dir=data_dir, | hash_list = tempfile.NamedTemporaryFile( | ||||
mode='w', | dir=data_dir, mode="w", delete=False, encoding="utf-8" | ||||
delete=False, | ) | ||||
encoding="utf-8") | |||||
self.log.info("Create linearization config file") | self.log.info("Create linearization config file") | ||||
with open(cfg_file, "a", encoding="utf-8") as cfg: | with open(cfg_file, "a", encoding="utf-8") as cfg: | ||||
cfg.write(f"datadir={data_dir}\n") | cfg.write(f"datadir={data_dir}\n") | ||||
cfg.write(f"rpcuser={node_url.username}\n") | cfg.write(f"rpcuser={node_url.username}\n") | ||||
cfg.write(f"rpcpassword={node_url.password}\n") | cfg.write(f"rpcpassword={node_url.password}\n") | ||||
cfg.write(f"port={node_url.port}\n") | cfg.write(f"port={node_url.port}\n") | ||||
cfg.write(f"host={node_url.hostname}\n") | cfg.write(f"host={node_url.hostname}\n") | ||||
cfg.write(f"output_file={bootstrap_file}\n") | cfg.write(f"output_file={bootstrap_file}\n") | ||||
cfg.write("max_height=100\n") | cfg.write("max_height=100\n") | ||||
cfg.write("netmagic=fabfb5da\n") | cfg.write("netmagic=fabfb5da\n") | ||||
cfg.write(f"input={blocks_dir}\n") | cfg.write(f"input={blocks_dir}\n") | ||||
cfg.write(f"genesis={genesis_block}\n") | cfg.write(f"genesis={genesis_block}\n") | ||||
cfg.write(f"hashlist={hash_list.name}\n") | cfg.write(f"hashlist={hash_list.name}\n") | ||||
base_dir = self.config["environment"]["SRCDIR"] | base_dir = self.config["environment"]["SRCDIR"] | ||||
linearize_dir = os.path.join(base_dir, "contrib", "linearize") | linearize_dir = os.path.join(base_dir, "contrib", "linearize") | ||||
self.log.info("Run linearization of block hashes") | self.log.info("Run linearization of block hashes") | ||||
linearize_hashes_file = os.path.join( | linearize_hashes_file = os.path.join(linearize_dir, "linearize-hashes.py") | ||||
linearize_dir, "linearize-hashes.py") | subprocess.run( | ||||
subprocess.run([sys.executable, linearize_hashes_file, cfg_file], | [sys.executable, linearize_hashes_file, cfg_file], | ||||
stdout=hash_list, | stdout=hash_list, | ||||
check=True) | check=True, | ||||
) | |||||
self.log.info("Run linearization of block data") | self.log.info("Run linearization of block data") | ||||
linearize_data_file = os.path.join(linearize_dir, "linearize-data.py") | linearize_data_file = os.path.join(linearize_dir, "linearize-data.py") | ||||
subprocess.run([sys.executable, linearize_data_file, cfg_file], | subprocess.run([sys.executable, linearize_data_file, cfg_file], 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.restart_node(1, extra_args=[f"-loadblock={bootstrap_file}"]) | self.restart_node(1, extra_args=[f"-loadblock={bootstrap_file}"]) | ||||
# start_node is blocking on all block files being imported | # start_node is blocking on all block files being imported | ||||
assert_equal(self.nodes[1].getblockcount(), 100) | assert_equal(self.nodes[1].getblockcount(), 100) | ||||
assert_equal(self.nodes[1].getblockchaininfo()['blocks'], 100) | assert_equal(self.nodes[1].getblockchaininfo()["blocks"], 100) | ||||
assert_equal( | assert_equal(self.nodes[0].getbestblockhash(), self.nodes[1].getbestblockhash()) | ||||
self.nodes[0].getbestblockhash(), | |||||
self.nodes[1].getbestblockhash()) | |||||
if __name__ == '__main__': | if __name__ == "__main__": | ||||
LoadblockTest().main() | LoadblockTest().main() |