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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python3
  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 BIP66 changeover logic."""
  6. from test_framework.test_framework import BitcoinTestFramework
  7. from test_framework.util import *
  8. class BIP66Test(BitcoinTestFramework):
  9. def __init__(self):
  10. super().__init__()
  11. self.num_nodes = 3
  12. self.setup_clean_chain = False
  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 range(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 AssertionError("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 range(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. This should fail
  59. assert_raises_jsonrpc(-1, "CreateNewBlock: TestBlockValidity failed: bad-version(0x00000002)", self.nodes[1].generate, 1)
  60. self.sync_all()
  61. if (self.nodes[0].getblockcount() != cnt + 1051):
  62. raise AssertionError("Accepted a version=2 block after 950 version=3 blocks")
  63. # Mine 1 new-version blocks
  64. self.nodes[2].generate(1)
  65. self.sync_all()
  66. if (self.nodes[0].getblockcount() != cnt + 1052):
  67. raise AssertionError("Failed to mine a version=3 block")
  68. if __name__ == '__main__':
  69. BIP66Test().main()