Dash Core  0.12.2.1
P2P Digital Currency
timestampindex.py
Go to the documentation of this file.
1 #!/usr/bin/env python2
2 # Copyright (c) 2014-2015 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 timestampindex generation and fetching
8 #
9 
10 import time
11 
12 from test_framework.test_framework import BitcoinTestFramework
13 from test_framework.util import *
14 
15 
17 
18  def setup_chain(self):
19  print("Initializing test directory "+self.options.tmpdir)
20  initialize_chain_clean(self.options.tmpdir, 4)
21 
22  def setup_network(self):
23  self.nodes = []
24  # Nodes 0/1 are "wallet" nodes
25  self.nodes.append(start_node(0, self.options.tmpdir, ["-debug"]))
26  self.nodes.append(start_node(1, self.options.tmpdir, ["-debug", "-timestampindex"]))
27  # Nodes 2/3 are used for testing
28  self.nodes.append(start_node(2, self.options.tmpdir, ["-debug"]))
29  self.nodes.append(start_node(3, self.options.tmpdir, ["-debug", "-timestampindex"]))
30  connect_nodes(self.nodes[0], 1)
31  connect_nodes(self.nodes[0], 2)
32  connect_nodes(self.nodes[0], 3)
33 
34  self.is_network_split = False
35  self.sync_all()
36 
37  def run_test(self):
38  print "Mining 5 blocks..."
39  blockhashes = self.nodes[0].generate(5)
40  low = self.nodes[0].getblock(blockhashes[0])["time"]
41  high = self.nodes[0].getblock(blockhashes[4])["time"]
42  self.sync_all()
43  print "Checking timestamp index..."
44  hashes = self.nodes[1].getblockhashes(high, low)
45  assert_equal(len(hashes), 5)
46  assert_equal(sorted(blockhashes), sorted(hashes))
47  print "Passed\n"
48 
49 
50 if __name__ == '__main__':
UniValue getblock(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:483
UniValue getblockhashes(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:277
def connect_nodes(from_connection, node_num)
Definition: util.py:343
def initialize_chain_clean(test_dir, num_nodes)
Definition: util.py:252
def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None)
Definition: util.py:281
UniValue generate(const UniValue &params, bool fHelp)
Definition: mining.cpp:122
def assert_equal(thing1, thing2)
Definition: util.py:461