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 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python2
  2. # Copyright (c) 2014 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 import BitcoinTestFramework
  9. from 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. # Split the network and build two chains of different lengths.
  18. self.split_network ()
  19. self.nodes[0].setgenerate (True, 10);
  20. self.nodes[2].setgenerate (True, 20);
  21. self.sync_all ()
  22. tips = self.nodes[1].getchaintips ()
  23. assert_equal (len (tips), 1)
  24. shortTip = tips[0]
  25. assert_equal (shortTip['branchlen'], 0)
  26. assert_equal (shortTip['height'], 210)
  27. tips = self.nodes[3].getchaintips ()
  28. assert_equal (len (tips), 1)
  29. longTip = tips[0]
  30. assert_equal (longTip['branchlen'], 0)
  31. assert_equal (longTip['height'], 220)
  32. # Join the network halves and check that we now have two tips
  33. # (at least at the nodes that previously had the short chain).
  34. self.join_network ()
  35. tips = self.nodes[0].getchaintips ()
  36. assert_equal (len (tips), 2)
  37. assert_equal (tips[0], longTip)
  38. assert_equal (tips[1]['branchlen'], 10)
  39. tips[1]['branchlen'] = 0;
  40. assert_equal (tips[1], shortTip)
  41. if __name__ == '__main__':
  42. GetChainTipsTest ().main ()