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.
13 from test_framework
.test_framework
import BitcoinTestFramework
14 from test_framework
.util
import assert_equal
16 class GetChainTipsTest (BitcoinTestFramework
):
20 self
.setup_clean_chain
= False
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.
32 self
.nodes
[0].generate(10)
33 self
.nodes
[2].generate(20)
36 tips
= self
.nodes
[1].getchaintips ()
37 assert_equal (len (tips
), 1)
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)
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).
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 ()