(self)
| 53 | self.num_nodes = 1 |
| 54 | |
| 55 | def run_test(self): |
| 56 | peers_dat = os.path.join(self.nodes[0].datadir, self.chain, "peers.dat") |
| 57 | init_error = lambda reason: ( |
| 58 | f"Error: Invalid or corrupt peers.dat \\({reason}\\). If you believe this " |
| 59 | f"is a bug, please report it to {self.config['environment']['PACKAGE_BUGREPORT']}. " |
| 60 | f'As a workaround, you can move the file \\("{re.escape(peers_dat)}"\\) out of the way \\(rename, ' |
| 61 | "move, or delete\\) to have a new one created on the next start." |
| 62 | ) |
| 63 | |
| 64 | self.log.info("Check that mocked addrman is valid") |
| 65 | self.stop_node(0) |
| 66 | write_addrman(peers_dat) |
| 67 | with self.nodes[0].assert_debug_log(["Loaded 0 addresses from peers.dat"]): |
| 68 | self.start_node(0, extra_args=["-checkaddrman=1"]) |
| 69 | assert_equal(self.nodes[0].getnodeaddresses(), []) |
| 70 | |
| 71 | self.log.info("Check that addrman from future is overwritten with new addrman") |
| 72 | self.stop_node(0) |
| 73 | write_addrman(peers_dat, lowest_compatible=111) |
| 74 | assert_equal(os.path.exists(peers_dat + ".bak"), False) |
| 75 | with self.nodes[0].assert_debug_log([ |
| 76 | f'Creating new peers.dat because the file version was not compatible ("{peers_dat}"). Original backed up to peers.dat.bak', |
| 77 | ]): |
| 78 | self.start_node(0) |
| 79 | assert_equal(self.nodes[0].getnodeaddresses(), []) |
| 80 | assert_equal(os.path.exists(peers_dat + ".bak"), True) |
| 81 | |
| 82 | self.log.info("Check that corrupt addrman cannot be read (EOF)") |
| 83 | self.stop_node(0) |
| 84 | with open(peers_dat, "wb") as f: |
| 85 | f.write(serialize_addrman()[:-1]) |
| 86 | self.nodes[0].assert_start_raises_init_error( |
| 87 | expected_msg=init_error("CAutoFile::read: end of file.*"), |
| 88 | match=ErrorMatch.FULL_REGEX, |
| 89 | ) |
| 90 | |
| 91 | self.log.info("Check that corrupt addrman cannot be read (magic)") |
| 92 | self.stop_node(0) |
| 93 | write_addrman(peers_dat, net_magic="signet") |
| 94 | self.nodes[0].assert_start_raises_init_error( |
| 95 | expected_msg=init_error("Invalid network magic number"), |
| 96 | match=ErrorMatch.FULL_REGEX, |
| 97 | ) |
| 98 | |
| 99 | self.log.info("Check that corrupt addrman cannot be read (checksum)") |
| 100 | self.stop_node(0) |
| 101 | write_addrman(peers_dat, mock_checksum=b"ab" * 32) |
| 102 | self.nodes[0].assert_start_raises_init_error( |
| 103 | expected_msg=init_error("Checksum mismatch, data corrupted"), |
| 104 | match=ErrorMatch.FULL_REGEX, |
| 105 | ) |
| 106 | |
| 107 | self.log.info("Check that corrupt addrman cannot be read (len_tried)") |
| 108 | self.stop_node(0) |
| 109 | write_addrman(peers_dat, len_tried=-1) |
| 110 | self.nodes[0].assert_start_raises_init_error( |
| 111 | expected_msg=init_error("Corrupt AddrMan serialization: nTried=-1, should be in \\[0, 16384\\]:.*"), |
| 112 | match=ErrorMatch.FULL_REGEX, |
nothing calls this directly
no test coverage detected