Dash Core  0.12.2.1
P2P Digital Currency
getchaintips.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 # Exercise the getchaintips API. We introduce a network split, work
7 # on chains of different lengths, and join the network together again.
8 # This gives us two tips, verify that it works.
9 
10 from test_framework.test_framework import BitcoinTestFramework
11 from test_framework.util import assert_equal
12 
14 
15  def run_test (self):
16  BitcoinTestFramework.run_test (self)
17 
18  tips = self.nodes[0].getchaintips ()
19  assert_equal (len (tips), 1)
20  assert_equal (tips[0]['branchlen'], 0)
21  assert_equal (tips[0]['height'], 200)
22  assert_equal (tips[0]['status'], 'active')
23 
24  # Split the network and build two chains of different lengths.
25  self.split_network ()
26  self.nodes[0].generate(10)
27  self.nodes[2].generate(20)
28  self.sync_all ()
29 
30  tips = self.nodes[1].getchaintips ()
31  assert_equal (len (tips), 1)
32  shortTip = tips[0]
33  assert_equal (shortTip['branchlen'], 0)
34  assert_equal (shortTip['height'], 210)
35  assert_equal (tips[0]['status'], 'active')
36 
37  tips = self.nodes[3].getchaintips ()
38  assert_equal (len (tips), 1)
39  longTip = tips[0]
40  assert_equal (longTip['branchlen'], 0)
41  assert_equal (longTip['height'], 220)
42  assert_equal (tips[0]['status'], 'active')
43 
44  # Join the network halves and check that we now have two tips
45  # (at least at the nodes that previously had the short chain).
46  self.join_network ()
47 
48  tips = self.nodes[0].getchaintips ()
49  assert_equal (len (tips), 2)
50  assert_equal (tips[0], longTip)
51 
52  assert_equal (tips[1]['branchlen'], 10)
53  assert_equal (tips[1]['status'], 'valid-fork')
54  tips[1]['branchlen'] = 0
55  tips[1]['status'] = 'active'
56  assert_equal (tips[1], shortTip)
57 
58 if __name__ == '__main__':
59  GetChainTipsTest ().main ()
UniValue generate(const UniValue &params, bool fHelp)
Definition: mining.cpp:122