Skip to content

Commit 6985038

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22118: test: check anchors.dat when node starts for the first time
ef99d03 test: check anchors.dat when node starts for the first time (bruno) Pull request description: See bitcoin/bitcoin#21338 (comment), bitcoin/bitcoin#21338 (comment), bitcoin/bitcoin#21338 (comment). ACKs for top commit: laanwj: Code review ACK ef99d03 Tree-SHA512: 505f1f34fbc0c72a92968883be0f1c5f169a4ba3aa8a56e1ce8bc5e514f49e3a17ce51fd40be0073dc4bc06eaeda36dfe90ace843c181170e34643226afd78ef
2 parents ce8276b + ef99d03 commit 6985038

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

test/functional/feature_anchors.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
# Copyright (c) 2020 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
"""Test Anchors functionality"""
5+
"""Test block-relay-only anchors functionality"""
66

77
import os
88

99
from test_framework.p2p import P2PInterface
1010
from test_framework.test_framework import BitcoinTestFramework
1111
from test_framework.util import assert_equal
1212

13+
INBOUND_CONNECTIONS = 5
14+
BLOCK_RELAY_CONNECTIONS = 2
15+
1316

1417
def check_node_connections(*, node, num_in, num_out):
1518
info = node.getnetworkinfo()
@@ -25,19 +28,26 @@ def setup_network(self):
2528
self.setup_nodes()
2629

2730
def run_test(self):
28-
self.log.info("Add 2 block-relay-only connections to node 0")
29-
for i in range(2):
31+
node_anchors_path = os.path.join(
32+
self.nodes[0].datadir, "regtest", "anchors.dat"
33+
)
34+
35+
self.log.info("When node starts, check if anchors.dat doesn't exist")
36+
assert not os.path.exists(node_anchors_path)
37+
38+
self.log.info(f"Add {BLOCK_RELAY_CONNECTIONS} block-relay-only connections to node")
39+
for i in range(BLOCK_RELAY_CONNECTIONS):
3040
self.log.debug(f"block-relay-only: {i}")
3141
self.nodes[0].add_outbound_p2p_connection(
3242
P2PInterface(), p2p_idx=i, connection_type="block-relay-only"
3343
)
3444

35-
self.log.info("Add 5 inbound connections to node 0")
36-
for i in range(5):
45+
self.log.info(f"Add {INBOUND_CONNECTIONS} inbound connections to node")
46+
for i in range(INBOUND_CONNECTIONS):
3747
self.log.debug(f"inbound: {i}")
3848
self.nodes[0].add_p2p_connection(P2PInterface())
3949

40-
self.log.info("Check node 0 connections")
50+
self.log.info("Check node connections")
4151
check_node_connections(node=self.nodes[0], num_in=5, num_out=2)
4252

4353
# 127.0.0.1
@@ -57,14 +67,10 @@ def run_test(self):
5767
self.log.info("Stop node 0")
5868
self.stop_node(0)
5969

60-
node0_anchors_path = os.path.join(
61-
self.nodes[0].datadir, "regtest", "anchors.dat"
62-
)
63-
6470
# It should contain only the block-relay-only addresses
6571
self.log.info("Check the addresses in anchors.dat")
6672

67-
with open(node0_anchors_path, "rb") as file_handler:
73+
with open(node_anchors_path, "rb") as file_handler:
6874
anchors = file_handler.read().hex()
6975

7076
for port in block_relay_nodes_port:
@@ -74,11 +80,11 @@ def run_test(self):
7480
ip_port = ip + port
7581
assert ip_port not in anchors
7682

77-
self.log.info("Start node 0")
83+
self.log.info("Start node")
7884
self.start_node(0)
7985

8086
self.log.info("When node starts, check if anchors.dat doesn't exist anymore")
81-
assert not os.path.exists(node0_anchors_path)
87+
assert not os.path.exists(node_anchors_path)
8288

8389

8490
if __name__ == "__main__":

0 commit comments

Comments
 (0)