Skip to content

Commit f725ed5

Browse files
fanquakePastaPastaPasta
authored andcommitted
Merge bitcoin#26314: test: perturb anchors.dat to test error during initialization
33fdfc7 test: perturb anchors.dat to test it doesn't throw an error during initialization (brunoerg) Pull request description: Got some inspiration from `feature_init`. This PR tests whether perturbing `anchors.dat` doesn't throw any error during initialization. https://github.com/bitcoin/bitcoin/blob/3f1f5f6f1ec49d0fb2acfddec4021b3582ba0553/src/addrdb.cpp#L223-L235 ACKs for top commit: MarcoFalke: lgtm ACK 33fdfc7 Tree-SHA512: e6584debb37647677581fda08366b45b42803022cc4c4f1d5a7bd5e9e04d64da77656dad2b804855337487bdcfc891f300a2e03668d6122de769dd14f39af9ed
1 parent 3306f96 commit f725ed5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

test/functional/feature_anchors.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,25 @@ def run_test(self):
6262
self.log.info("Check the addresses in anchors.dat")
6363

6464
with open(node_anchors_path, "rb") as file_handler:
65-
anchors = file_handler.read().hex()
65+
anchors = file_handler.read()
6666

67+
anchors_hex = anchors.hex()
6768
for port in block_relay_nodes_port:
6869
ip_port = ip + port
69-
assert ip_port in anchors
70+
assert ip_port in anchors_hex
7071
for port in inbound_nodes_port:
7172
ip_port = ip + port
72-
assert ip_port not in anchors
73+
assert ip_port not in anchors_hex
7374

74-
self.log.info("Start node")
75-
self.start_node(0)
75+
self.log.info("Perturb anchors.dat to test it doesn't throw an error during initialization")
76+
with self.nodes[0].assert_debug_log(["0 block-relay-only anchors will be tried for connections."]):
77+
with open(node_anchors_path, "wb") as out_file_handler:
78+
tweaked_contents = bytearray(anchors)
79+
tweaked_contents[20:20] = b'1'
80+
out_file_handler.write(bytes(tweaked_contents))
81+
82+
self.log.info("Start node")
83+
self.start_node(0)
7684

7785
self.log.info("When node starts, check if anchors.dat doesn't exist anymore")
7886
assert not os.path.exists(node_anchors_path)

0 commit comments

Comments
 (0)