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.

forknotify.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #
  6. # Test -alertnotify
  7. #
  8. from test_framework import BitcoinTestFramework
  9. from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
  10. from util import *
  11. import os
  12. import shutil
  13. class ForkNotifyTest(BitcoinTestFramework):
  14. alert_filename = None # Set by setup_network
  15. def setup_network(self):
  16. self.nodes = []
  17. self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
  18. with open(self.alert_filename, 'w') as f:
  19. pass # Just open then close to create zero-length file
  20. self.nodes.append(start_node(0, self.options.tmpdir,
  21. ["-blockversion=2", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]))
  22. # Node1 mines block.version=211 blocks
  23. self.nodes.append(start_node(1, self.options.tmpdir,
  24. ["-blockversion=211"]))
  25. connect_nodes(self.nodes[1], 0)
  26. self.is_network_split = False
  27. self.sync_all()
  28. def run_test(self):
  29. # Mine 51 up-version blocks
  30. self.nodes[1].setgenerate(True, 51)
  31. self.sync_all()
  32. # -alertnotify should trigger on the 51'st,
  33. # but mine and sync another to give
  34. # -alertnotify time to write
  35. self.nodes[1].setgenerate(True, 1)
  36. self.sync_all()
  37. with open(self.alert_filename, 'r') as f:
  38. alert_text = f.read()
  39. if len(alert_text) == 0:
  40. raise AssertionError("-alertnotify did not warn of up-version blocks")
  41. # Mine more up-version blocks, should not get more alerts:
  42. self.nodes[1].setgenerate(True, 1)
  43. self.sync_all()
  44. self.nodes[1].setgenerate(True, 1)
  45. self.sync_all()
  46. with open(self.alert_filename, 'r') as f:
  47. alert_text2 = f.read()
  48. if alert_text != alert_text2:
  49. raise AssertionError("-alertnotify excessive warning of up-version blocks")
  50. if __name__ == '__main__':
  51. ForkNotifyTest().main()