scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal instead...
[bitcoinplatinum.git] / test / functional / getchaintips.py
blob15f96c565fe60353c4a20ff105953f5b21e8a922
1 #!/usr/bin/env python3
2 # Copyright (c) 2014-2016 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 the getchaintips RPC.
7 - introduce a network split
8 - work on chains of different lengths
9 - join the network together again
10 - verify that getchaintips now returns two chain tips.
11 """
13 from test_framework.test_framework import BitcoinTestFramework
14 from test_framework.util import assert_equal
16 class GetChainTipsTest (BitcoinTestFramework):
17 def __init__(self):
18 super().__init__()
19 self.num_nodes = 4
20 self.setup_clean_chain = False
22 def run_test (self):
24 tips = self.nodes[0].getchaintips ()
25 assert_equal (len (tips), 1)
26 assert_equal (tips[0]['branchlen'], 0)
27 assert_equal (tips[0]['height'], 200)
28 assert_equal (tips[0]['status'], 'active')
30 # Split the network and build two chains of different lengths.
31 self.split_network ()
32 self.nodes[0].generate(10)
33 self.nodes[2].generate(20)
34 self.sync_all([self.nodes[:2], self.nodes[2:]])
36 tips = self.nodes[1].getchaintips ()
37 assert_equal (len (tips), 1)
38 shortTip = tips[0]
39 assert_equal (shortTip['branchlen'], 0)
40 assert_equal (shortTip['height'], 210)
41 assert_equal (tips[0]['status'], 'active')
43 tips = self.nodes[3].getchaintips ()
44 assert_equal (len (tips), 1)
45 longTip = tips[0]
46 assert_equal (longTip['branchlen'], 0)
47 assert_equal (longTip['height'], 220)
48 assert_equal (tips[0]['status'], 'active')
50 # Join the network halves and check that we now have two tips
51 # (at least at the nodes that previously had the short chain).
52 self.join_network ()
54 tips = self.nodes[0].getchaintips ()
55 assert_equal (len (tips), 2)
56 assert_equal (tips[0], longTip)
58 assert_equal (tips[1]['branchlen'], 10)
59 assert_equal (tips[1]['status'], 'valid-fork')
60 tips[1]['branchlen'] = 0
61 tips[1]['status'] = 'active'
62 assert_equal (tips[1], shortTip)
64 if __name__ == '__main__':
65 GetChainTipsTest ().main ()