Skip to content

Commit 48262a0

Browse files
committed
Add functional test for block sync from inbound peers
1 parent 0569b5c commit 48262a0

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

test/functional/p2p_block_sync.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2022 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+
"""Test block download
6+
7+
Ensure that even in IBD, we'll eventually sync chain from inbound peers
8+
(whether we have only inbound peers or both inbound and outbound peers).
9+
"""
10+
11+
from test_framework.test_framework import BitcoinTestFramework
12+
13+
class BlockSyncTest(BitcoinTestFramework):
14+
15+
def set_test_params(self):
16+
self.setup_clean_chain = True
17+
self.num_nodes = 3
18+
19+
def setup_network(self):
20+
self.setup_nodes()
21+
# Construct a network:
22+
# node0 -> node1 -> node2
23+
# So node1 has both an inbound and outbound peer.
24+
# In our test, we will mine a block on node0, and ensure that it makes
25+
# to to both node1 and node2.
26+
self.connect_nodes(0, 1)
27+
self.connect_nodes(1, 2)
28+
29+
def run_test(self):
30+
self.log.info("Setup network: node0->node1->node2")
31+
self.log.info("Mining one block on node0 and verify all nodes sync")
32+
self.generate(self.nodes[0], 1)
33+
self.log.info("Success!")
34+
35+
36+
if __name__ == '__main__':
37+
BlockSyncTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
'wallet_avoidreuse.py --descriptors',
158158
'mempool_reorg.py',
159159
'mempool_persist.py',
160+
'p2p_block_sync.py',
160161
'wallet_multiwallet.py --legacy-wallet',
161162
'wallet_multiwallet.py --descriptors',
162163
'wallet_multiwallet.py --usecli',

0 commit comments

Comments
 (0)