Repository navigation
Expand file tree
/
Copy pathfeature_timestampindex.py
More file actions
executable file
·79 lines (64 loc) · 3.01 KB
/
Copy pathfeature_timestampindex.py
File metadata and controls
executable file
·79 lines (64 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
# Copyright (c) 2014-2015 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Test timestampindex generation and fetching
#
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
class TimestampIndexTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2
def setup_network(self):
self.add_nodes(self.num_nodes)
self.start_node(0)
self.start_node(1, ["-timestampindex"])
self.connect_nodes(0, 1)
def run_test(self):
self.log.info("Test that settings can be disabled without -reindex...")
self.generate(self.nodes[0], 1)
self.stop_node(1)
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.start_node(1, ["-timestampindex=0"])
self.connect_nodes(0, 1)
self.sync_all()
self.log.info("Test that settings can be enabled without -reindex...")
self.stop_node(1)
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.start_node(1, ["-timestampindex"])
self.connect_nodes(0, 1)
self.sync_all()
self.log.info("Check timestamp index via getblockhashes rpc")
blockhashes = []
for _ in range(5):
self.bump_mocktime(1)
blockhashes += self.generate(self.nodes[0], 1)
low = self.nodes[0].getblock(blockhashes[0])["time"]
high = self.nodes[0].getblock(blockhashes[4])["time"]
self.bump_mocktime(1)
hashes = self.nodes[1].getblockhashes(high, low)
assert_equal(len(hashes), 5)
assert_equal(sorted(blockhashes), sorted(hashes))
self.log.info("Testing reorg handling...")
# Invalidate the last 2 blocks on both nodes
self.nodes[0].invalidateblock(blockhashes[3])
self.nodes[1].invalidateblock(blockhashes[3])
# The index removes the blocks in its BlockDisconnected callbacks. getblockhashes only waits for an index
# that is behind the tip, not for one that is ahead of it, so wait for the callbacks here.
self.nodes[1].syncwithvalidationinterfacequeue()
# Verify that invalidated blocks are no longer in the index
hashes_after_invalidate = self.nodes[1].getblockhashes(high, low)
assert_equal(len(hashes_after_invalidate), 3)
assert_equal(sorted(hashes_after_invalidate), sorted(blockhashes[:3]))
# Reconsider the blocks on both nodes
self.nodes[0].reconsiderblock(blockhashes[3])
self.nodes[1].reconsiderblock(blockhashes[3])
self.sync_all()
# Verify all blocks are back in the index
hashes_after_reconsider = self.nodes[1].getblockhashes(high, low)
assert_equal(len(hashes_after_reconsider), 5)
assert_equal(sorted(hashes_after_reconsider), sorted(blockhashes))
if __name__ == '__main__':
TimestampIndexTest().main()