Skip to content

Commit 75656ad

Browse files
committed
test: add functional test for -maxtipage parameter
1 parent 792d0d8 commit 75656ad

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

test/functional/feature_maxtipage.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 logic for setting nMaxTipAge on command line.
6+
7+
Nodes don't consider themselves out of "initial block download" as long as
8+
their best known block header time is more than nMaxTipAge in the past.
9+
"""
10+
11+
import time
12+
13+
from test_framework.test_framework import BitcoinTestFramework
14+
from test_framework.util import assert_equal
15+
16+
17+
DEFAULT_MAX_TIP_AGE = 24 * 60 * 60
18+
19+
20+
class MaxTipAgeTest(BitcoinTestFramework):
21+
def set_test_params(self):
22+
self.setup_clean_chain = True
23+
self.num_nodes = 2
24+
25+
def test_maxtipage(self, maxtipage, set_parameter=True):
26+
node_miner = self.nodes[0]
27+
node_ibd = self.nodes[1]
28+
29+
self.restart_node(1, [f'-maxtipage={maxtipage}'] if set_parameter else None)
30+
self.connect_nodes(0, 1)
31+
32+
# tips older than maximum age -> stay in IBD
33+
cur_time = int(time.time())
34+
node_ibd.setmocktime(cur_time)
35+
for delta in [5, 4, 3, 2, 1]:
36+
node_miner.setmocktime(cur_time - maxtipage - delta)
37+
self.generate(node_miner, 1)
38+
assert_equal(node_ibd.getblockchaininfo()['initialblockdownload'], True)
39+
40+
# tip within maximum age -> leave IBD
41+
node_miner.setmocktime(cur_time - maxtipage)
42+
self.generate(node_miner, 1)
43+
assert_equal(node_ibd.getblockchaininfo()['initialblockdownload'], False)
44+
45+
def run_test(self):
46+
self.log.info("Test IBD with maximum tip age of 24 hours (default).")
47+
self.test_maxtipage(DEFAULT_MAX_TIP_AGE, set_parameter=False)
48+
49+
for hours in [20, 10, 5, 2, 1]:
50+
maxtipage = hours * 60 * 60
51+
self.log.info(f"Test IBD with maximum tip age of {hours} hours (-maxtipage={maxtipage}).")
52+
self.test_maxtipage(maxtipage)
53+
54+
55+
if __name__ == '__main__':
56+
MaxTipAgeTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
'wallet_keypool.py --legacy-wallet',
199199
'wallet_keypool.py --descriptors',
200200
'wallet_descriptor.py --descriptors',
201+
'feature_maxtipage.py',
201202
'p2p_nobloomfilter_messages.py',
202203
'p2p_filter.py',
203204
'rpc_setban.py',

0 commit comments

Comments
 (0)