Skip to content

Commit 6eeb188

Browse files
committed
test: adds seednode functional tests
Adds functional tests to test the interaction between seednode and the AddrMan
1 parent 3270f0a commit 6eeb188

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

test/functional/p2p_seednode.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2019-2021 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
"""
7+
Test seednode interaction with the AddrMan
8+
"""
9+
import random
10+
import time
11+
12+
from test_framework.test_framework import BitcoinTestFramework
13+
14+
ADD_NEXT_SEEDNODE = 10
15+
16+
17+
class P2PSeedNodes(BitcoinTestFramework):
18+
def set_test_params(self):
19+
self.num_nodes = 1
20+
self.disable_autoconnect = False
21+
22+
def test_no_seednode(self):
23+
# Check that if no seednode is provided, the node proceeds as usual (without waiting)
24+
with self.nodes[0].assert_debug_log(expected_msgs=[], unexpected_msgs=["Empty addrman, adding seednode", f"Couldn't connect to peers from addrman after {ADD_NEXT_SEEDNODE} seconds. Adding seednode"], timeout=ADD_NEXT_SEEDNODE):
25+
self.restart_node(0)
26+
27+
def test_seednode_empty_addrman(self):
28+
seed_node = "0.0.0.1"
29+
# Check that the seednode is added to m_addr_fetches on bootstrap on an empty addrman
30+
with self.nodes[0].assert_debug_log(expected_msgs=[f"Empty addrman, adding seednode ({seed_node}) to addrfetch"], timeout=ADD_NEXT_SEEDNODE):
31+
self.restart_node(0, extra_args=[f'-seednode={seed_node}'])
32+
33+
def test_seednode_addrman_unreachable_peers(self):
34+
seed_node = "0.0.0.2"
35+
node = self.nodes[0]
36+
# Fill the addrman with unreachable nodes
37+
for i in range(10):
38+
ip = f"{random.randrange(128,169)}.{random.randrange(1,255)}.{random.randrange(1,255)}.{random.randrange(1,255)}"
39+
port = 8333 + i
40+
node.addpeeraddress(ip, port)
41+
42+
# Restart the node so seednode is processed again
43+
with node.assert_debug_log(expected_msgs=[f"Couldn't connect to peers from addrman after {ADD_NEXT_SEEDNODE} seconds. Adding seednode ({seed_node}) to addrfetch"], unexpected_msgs=["Empty addrman, adding seednode"], timeout=ADD_NEXT_SEEDNODE * 1.5):
44+
self.restart_node(0, extra_args=[f'-seednode={seed_node}'])
45+
node.setmocktime(int(time.time()) + ADD_NEXT_SEEDNODE + 1)
46+
47+
def run_test(self):
48+
self.test_no_seednode()
49+
self.test_seednode_empty_addrman()
50+
self.test_seednode_addrman_unreachable_peers()
51+
52+
53+
if __name__ == '__main__':
54+
P2PSeedNodes(__file__).main()
55+

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@
405405
'feature_shutdown.py',
406406
'wallet_migration.py',
407407
'p2p_ibd_txrelay.py',
408+
'p2p_seednode.py',
408409
# Don't append tests at the end to avoid merge conflicts
409410
# Put them in a random line within the section that fits their approximate run-time
410411
]

0 commit comments

Comments
 (0)