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.2KB

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