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.

bip65-cltv.py 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2015-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 CHECKLOCKTIMEVERIFY (BIP65) soft-fork logic."""
  6. from test_framework.test_framework import BitcoinTestFramework
  7. from test_framework.util import *
  8. class BIP65Test(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=3"]))
  17. self.nodes.append(start_node(2, self.options.tmpdir, ["-blockversion=4"]))
  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(200)
  26. cnt += 100
  27. self.sync_all()
  28. if (self.nodes[0].getblockcount() != cnt + 100):
  29. raise AssertionError("Failed to mine 100 version=3 blocks")
  30. # Mine 750 new-version blocks
  31. for i in range(15):
  32. self.nodes[2].generate(50)
  33. self.sync_all()
  34. if (self.nodes[0].getblockcount() != cnt + 850):
  35. raise AssertionError("Failed to mine 750 version=4 blocks")
  36. # TODO: check that new CHECKLOCKTIMEVERIFY rules are not enforced
  37. # Mine 1 new-version block
  38. self.nodes[2].generate(1)
  39. self.sync_all()
  40. if (self.nodes[0].getblockcount() != cnt + 851):
  41. raise AssertionError("Failed to mine a version=4 blocks")
  42. # TODO: check that new CHECKLOCKTIMEVERIFY rules are enforced
  43. # Mine 198 new-version blocks
  44. for i in range(2):
  45. self.nodes[2].generate(99)
  46. self.sync_all()
  47. if (self.nodes[0].getblockcount() != cnt + 1049):
  48. raise AssertionError("Failed to mine 198 version=4 blocks")
  49. # Mine 1 old-version block
  50. self.nodes[1].generate(1)
  51. self.sync_all()
  52. if (self.nodes[0].getblockcount() != cnt + 1050):
  53. raise AssertionError("Failed to mine a version=3 block after 949 version=4 blocks")
  54. # Mine 1 new-version blocks
  55. self.nodes[2].generate(1)
  56. self.sync_all()
  57. if (self.nodes[0].getblockcount() != cnt + 1051):
  58. raise AssertionError("Failed to mine a version=4 block")
  59. # Mine 1 old-version blocks. This should fail
  60. assert_raises_jsonrpc(-1,"CreateNewBlock: TestBlockValidity failed: bad-version(0x00000003)", self.nodes[1].generate, 1)
  61. self.sync_all()
  62. if (self.nodes[0].getblockcount() != cnt + 1051):
  63. raise AssertionError("Accepted a version=3 block after 950 version=4 blocks")
  64. # Mine 1 new-version blocks
  65. self.nodes[2].generate(1)
  66. self.sync_all()
  67. if (self.nodes[0].getblockcount() != cnt + 1052):
  68. raise AssertionError("Failed to mine a version=4 block")
  69. if __name__ == '__main__':
  70. BIP65Test().main()