[tests] don't override __init__() in individual tests
[bitcoinplatinum.git] / test / functional / getchaintips.py
blob00fc23c6b0d3f54e761ef92b690fbc896330f0cd
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 run_test (self):
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')
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([self.nodes[:2], self.nodes[2:]])
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')
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')
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 ()
48 tips = self.nodes[0].getchaintips ()
49 assert_equal (len (tips), 2)
50 assert_equal (tips[0], longTip)
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)
58 if __name__ == '__main__':
59 GetChainTipsTest ().main ()