You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.2 KiB
66 lines
2.2 KiB
![]()
9 years ago
|
#!/usr/bin/env python3
|
||
|
# Copyright (c) 2014-2016 The Bitcoin Core developers
|
||
![]()
10 years ago
|
# Distributed under the MIT software license, see the accompanying
|
||
![]()
10 years ago
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||
![]()
8 years ago
|
"""Test the getchaintips RPC.
|
||
![]()
10 years ago
|
|
||
![]()
8 years ago
|
- introduce a network split
|
||
|
- work on chains of different lengths
|
||
|
- join the network together again
|
||
|
- verify that getchaintips now returns two chain tips.
|
||
|
"""
|
||
![]()
10 years ago
|
|
||
![]()
9 years ago
|
from test_framework.test_framework import BitcoinTestFramework
|
||
|
from test_framework.util import assert_equal
|
||
![]()
10 years ago
|
|
||
|
class GetChainTipsTest (BitcoinTestFramework):
|
||
![]()
8 years ago
|
def __init__(self):
|
||
|
super().__init__()
|
||
|
self.num_nodes = 4
|
||
|
self.setup_clean_chain = False
|
||
![]()
10 years ago
|
|
||
![]()
10 years ago
|
def run_test (self):
|
||
|
|
||
|
tips = self.nodes[0].getchaintips ()
|
||
|
assert_equal (len (tips), 1)
|
||
|
assert_equal (tips[0]['branchlen'], 0)
|
||
|
assert_equal (tips[0]['height'], 200)
|
||
![]()
10 years ago
|
assert_equal (tips[0]['status'], 'active')
|
||
![]()
10 years ago
|
|
||
|
# Split the network and build two chains of different lengths.
|
||
|
self.split_network ()
|
||
![]()
9 years ago
|
self.nodes[0].generate(10)
|
||
|
self.nodes[2].generate(20)
|
||
![]()
10 years ago
|
self.sync_all ()
|
||
|
|
||
|
tips = self.nodes[1].getchaintips ()
|
||
|
assert_equal (len (tips), 1)
|
||
|
shortTip = tips[0]
|
||
|
assert_equal (shortTip['branchlen'], 0)
|
||
|
assert_equal (shortTip['height'], 210)
|
||
![]()
10 years ago
|
assert_equal (tips[0]['status'], 'active')
|
||
![]()
10 years ago
|
|
||
|
tips = self.nodes[3].getchaintips ()
|
||
|
assert_equal (len (tips), 1)
|
||
|
longTip = tips[0]
|
||
|
assert_equal (longTip['branchlen'], 0)
|
||
|
assert_equal (longTip['height'], 220)
|
||
![]()
10 years ago
|
assert_equal (tips[0]['status'], 'active')
|
||
![]()
10 years ago
|
|
||
|
# Join the network halves and check that we now have two tips
|
||
|
# (at least at the nodes that previously had the short chain).
|
||
|
self.join_network ()
|
||
|
|
||
|
tips = self.nodes[0].getchaintips ()
|
||
|
assert_equal (len (tips), 2)
|
||
|
assert_equal (tips[0], longTip)
|
||
|
|
||
|
assert_equal (tips[1]['branchlen'], 10)
|
||
![]()
10 years ago
|
assert_equal (tips[1]['status'], 'valid-fork')
|
||
|
tips[1]['branchlen'] = 0
|
||
|
tips[1]['status'] = 'active'
|
||
![]()
10 years ago
|
assert_equal (tips[1], shortTip)
|
||
![]()
10 years ago
|
|
||
|
if __name__ == '__main__':
|
||
|
GetChainTipsTest ().main ()
|