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.

bipdersig.py 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #
  6. # Test the BIP66 changeover logic
  7. #
  8. from test_framework.test_framework import BitcoinTestFramework
  9. from test_framework.util import *
  10. import os
  11. import shutil
  12. class BIP66Test(BitcoinTestFramework):
  13. def setup_network(self):
  14. self.nodes = []
  15. self.nodes.append(start_node(0, self.options.tmpdir, []))
  16. self.nodes.append(start_node(1, self.options.tmpdir, ["-blockversion=2"]))
  17. self.nodes.append(start_node(2, self.options.tmpdir, ["-blockversion=3"]))
  18. connect_nodes(self.nodes[1], 0)
  19. connect_nodes(self.nodes[2], 0)
  20. self.is_network_split = False
  21. self.sync_all()
  22. def run_test(self):
  23. cnt = self.nodes[0].getblockcount()
  24. # Mine some old-version blocks
  25. self.nodes[1].generate(100)
  26. self.sync_all()
  27. if (self.nodes[0].getblockcount() != cnt + 100):
  28. raise AssertionError("Failed to mine 100 version=2 blocks")
  29. # Mine 750 new-version blocks
  30. for i in xrange(15):
  31. self.nodes[2].generate(50)
  32. self.sync_all()
  33. if (self.nodes[0].getblockcount() != cnt + 850):
  34. raise AssertionError("Failed to mine 750 version=3 blocks")
  35. # TODO: check that new DERSIG rules are not enforced
  36. # Mine 1 new-version block
  37. self.nodes[2].generate(1)
  38. self.sync_all()
  39. if (self.nodes[0].getblockcount() != cnt + 851):
  40. raise AssertionFailure("Failed to mine a version=3 blocks")
  41. # TODO: check that new DERSIG rules are enforced
  42. # Mine 198 new-version blocks
  43. for i in xrange(2):
  44. self.nodes[2].generate(99)
  45. self.sync_all()
  46. if (self.nodes[0].getblockcount() != cnt + 1049):
  47. raise AssertionError("Failed to mine 198 version=3 blocks")
  48. # Mine 1 old-version block
  49. self.nodes[1].generate(1)
  50. self.sync_all()
  51. if (self.nodes[0].getblockcount() != cnt + 1050):
  52. raise AssertionError("Failed to mine a version=2 block after 949 version=3 blocks")
  53. # Mine 1 new-version blocks
  54. self.nodes[2].generate(1)
  55. self.sync_all()
  56. if (self.nodes[0].getblockcount() != cnt + 1051):
  57. raise AssertionError("Failed to mine a version=3 block")
  58. # Mine 1 old-version blocks
  59. try:
  60. self.nodes[1].generate(1)
  61. raise AssertionError("Succeeded to mine a version=2 block after 950 version=3 blocks")
  62. except JSONRPCException:
  63. pass
  64. self.sync_all()
  65. if (self.nodes[0].getblockcount() != cnt + 1051):
  66. raise AssertionError("Accepted a version=2 block after 950 version=3 blocks")
  67. # Mine 1 new-version blocks
  68. self.nodes[2].generate(1)
  69. self.sync_all()
  70. if (self.nodes[0].getblockcount() != cnt + 1052):
  71. raise AssertionError("Failed to mine a version=3 block")
  72. if __name__ == '__main__':
  73. BIP66Test().main()