Skip to content

Commit 904a987

Browse files
committed
Merge bitcoin/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
2 parents 03cb2fc + 33fdfc7 commit 904a987

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
@@ -63,17 +63,25 @@ def run_test(self):
6363
self.log.info("Check the addresses in anchors.dat")
6464

6565
with open(node_anchors_path, "rb") as file_handler:
66-
anchors = file_handler.read().hex()
66+
anchors = file_handler.read()
6767

68+
anchors_hex = anchors.hex()
6869
for port in block_relay_nodes_port:
6970
ip_port = ip + port
70-
assert ip_port in anchors
71+
assert ip_port in anchors_hex
7172
for port in inbound_nodes_port:
7273
ip_port = ip + port
73-
assert ip_port not in anchors
74+
assert ip_port not in anchors_hex
7475

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

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

0 commit comments

Comments
 (0)