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.

getchaintips.py 2.1KB

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