2
2
# Copyright (c) 2020 The Bitcoin Core developers
3
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
- """Test Anchors functionality"""
5
+ """Test block-relay-only anchors functionality"""
6
6
7
7
import os
8
8
9
9
from test_framework .p2p import P2PInterface
10
10
from test_framework .test_framework import BitcoinTestFramework
11
11
from test_framework .util import assert_equal
12
12
13
+ INBOUND_CONNECTIONS = 5
14
+ BLOCK_RELAY_CONNECTIONS = 2
15
+
13
16
14
17
def check_node_connections (* , node , num_in , num_out ):
15
18
info = node .getnetworkinfo ()
@@ -25,19 +28,26 @@ def setup_network(self):
25
28
self .setup_nodes ()
26
29
27
30
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 ):
30
40
self .log .debug (f"block-relay-only: { i } " )
31
41
self .nodes [0 ].add_outbound_p2p_connection (
32
42
P2PInterface (), p2p_idx = i , connection_type = "block-relay-only"
33
43
)
34
44
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 ):
37
47
self .log .debug (f"inbound: { i } " )
38
48
self .nodes [0 ].add_p2p_connection (P2PInterface ())
39
49
40
- self .log .info ("Check node 0 connections" )
50
+ self .log .info ("Check node connections" )
41
51
check_node_connections (node = self .nodes [0 ], num_in = 5 , num_out = 2 )
42
52
43
53
# 127.0.0.1
@@ -57,14 +67,10 @@ def run_test(self):
57
67
self .log .info ("Stop node 0" )
58
68
self .stop_node (0 )
59
69
60
- node0_anchors_path = os .path .join (
61
- self .nodes [0 ].datadir , "regtest" , "anchors.dat"
62
- )
63
-
64
70
# It should contain only the block-relay-only addresses
65
71
self .log .info ("Check the addresses in anchors.dat" )
66
72
67
- with open (node0_anchors_path , "rb" ) as file_handler :
73
+ with open (node_anchors_path , "rb" ) as file_handler :
68
74
anchors = file_handler .read ().hex ()
69
75
70
76
for port in block_relay_nodes_port :
@@ -74,11 +80,11 @@ def run_test(self):
74
80
ip_port = ip + port
75
81
assert ip_port not in anchors
76
82
77
- self .log .info ("Start node 0 " )
83
+ self .log .info ("Start node" )
78
84
self .start_node (0 )
79
85
80
86
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 )
82
88
83
89
84
90
if __name__ == "__main__" :
0 commit comments