aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-04-27 10:20:12 +0100
committerfanquake <fanquake@gmail.com>2023-04-27 10:33:35 +0100
commit904a98702e7372ed186e3faa81ef64f1ce49c945 (patch)
tree686022419ba31de6748f81da2f741cce24c03b8a
parent03cb2fce4a2dc5454e61f648046b9bcd24d66186 (diff)
parent33fdfc7986455191df8ce339261bc0561115cf7f (diff)
Merge bitcoin/bitcoin#26314: test: perturb anchors.dat to test error during initialization
33fdfc7986455191df8ce339261bc0561115cf7f 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 33fdfc7986455191df8ce339261bc0561115cf7f Tree-SHA512: e6584debb37647677581fda08366b45b42803022cc4c4f1d5a7bd5e9e04d64da77656dad2b804855337487bdcfc891f300a2e03668d6122de769dd14f39af9ed
-rwxr-xr-xtest/functional/feature_anchors.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/test/functional/feature_anchors.py b/test/functional/feature_anchors.py
index 713c0826d3..468ad1eafa 100755
--- a/test/functional/feature_anchors.py
+++ b/test/functional/feature_anchors.py
@@ -63,17 +63,25 @@ class AnchorsTest(BitcoinTestFramework):
self.log.info("Check the addresses in anchors.dat")
with open(node_anchors_path, "rb") as file_handler:
- anchors = file_handler.read().hex()
+ anchors = file_handler.read()
+ anchors_hex = anchors.hex()
for port in block_relay_nodes_port:
ip_port = ip + port
- assert ip_port in anchors
+ assert ip_port in anchors_hex
for port in inbound_nodes_port:
ip_port = ip + port
- assert ip_port not in anchors
+ assert ip_port not in anchors_hex
- self.log.info("Start node")
- self.start_node(0)
+ self.log.info("Perturb anchors.dat to test it doesn't throw an error during initialization")
+ with self.nodes[0].assert_debug_log(["0 block-relay-only anchors will be tried for connections."]):
+ with open(node_anchors_path, "wb") as out_file_handler:
+ tweaked_contents = bytearray(anchors)
+ tweaked_contents[20:20] = b'1'
+ out_file_handler.write(bytes(tweaked_contents))
+
+ self.log.info("Start node")
+ self.start_node(0)
self.log.info("When node starts, check if anchors.dat doesn't exist anymore")
assert not os.path.exists(node_anchors_path)