(self)
| 28 | self.supports_cli = False |
| 29 | |
| 30 | def run_test(self): |
| 31 | self.nodes[1].setnetworkactive(state=False) |
| 32 | self.generate(self.nodes[0], COINBASE_MATURITY, sync_fun=self.no_op) |
| 33 | |
| 34 | # Parsing the url of our node to get settings for config file |
| 35 | data_dir = self.nodes[0].datadir |
| 36 | node_url = urllib.parse.urlparse(self.nodes[0].url) |
| 37 | cfg_file = os.path.join(data_dir, "linearize.cfg") |
| 38 | bootstrap_file = os.path.join(self.options.tmpdir, "bootstrap.dat") |
| 39 | genesis_block = self.nodes[0].getblockhash(0) |
| 40 | blocks_dir = os.path.join(data_dir, self.chain, "blocks") |
| 41 | hash_list = tempfile.NamedTemporaryFile(dir=data_dir, |
| 42 | mode='w', |
| 43 | delete=False, |
| 44 | encoding="utf-8") |
| 45 | |
| 46 | self.log.info("Create linearization config file") |
| 47 | with open(cfg_file, "a", encoding="utf-8") as cfg: |
| 48 | cfg.write(f"datadir={data_dir}\n") |
| 49 | cfg.write(f"rpcuser={node_url.username}\n") |
| 50 | cfg.write(f"rpcpassword={node_url.password}\n") |
| 51 | cfg.write(f"port={node_url.port}\n") |
| 52 | cfg.write(f"host={node_url.hostname}\n") |
| 53 | cfg.write(f"output_file={bootstrap_file}\n") |
| 54 | cfg.write(f"max_height=100\n") |
| 55 | cfg.write(f"netmagic=fabfb5da\n") |
| 56 | cfg.write(f"input={blocks_dir}\n") |
| 57 | cfg.write(f"genesis={genesis_block}\n") |
| 58 | cfg.write(f"hashlist={hash_list.name}\n") |
| 59 | |
| 60 | base_dir = self.config["environment"]["SRCDIR"] |
| 61 | linearize_dir = os.path.join(base_dir, "contrib", "linearize") |
| 62 | |
| 63 | self.log.info("Run linearization of block hashes") |
| 64 | linearize_hashes_file = os.path.join(linearize_dir, "linearize-hashes.py") |
| 65 | subprocess.run([sys.executable, linearize_hashes_file, cfg_file], |
| 66 | stdout=hash_list, |
| 67 | check=True) |
| 68 | |
| 69 | self.log.info("Run linearization of block data") |
| 70 | linearize_data_file = os.path.join(linearize_dir, "linearize-data.py") |
| 71 | subprocess.run([sys.executable, linearize_data_file, cfg_file], |
| 72 | check=True) |
| 73 | |
| 74 | self.log.info("Restart second, unsynced node with bootstrap file") |
| 75 | self.restart_node(1, extra_args=[f"-loadblock={bootstrap_file}"]) |
| 76 | assert_equal(self.nodes[1].getblockcount(), 100) # start_node is blocking on all block files being imported |
| 77 | |
| 78 | assert_equal(self.nodes[1].getblockchaininfo()['blocks'], 100) |
| 79 | assert_equal(self.nodes[0].getbestblockhash(), self.nodes[1].getbestblockhash()) |
| 80 | |
| 81 | |
| 82 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected