[tests] Tidy up forknotify.py
[bitcoinplatinum.git] / test / functional / forknotify.py
blobd74b3181dad028ddb76b52317e64dbe38ca441dd
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 import os
8 from test_framework.test_framework import BitcoinTestFramework
9 from test_framework.util import assert_equal, wait_until
11 class ForkNotifyTest(BitcoinTestFramework):
12 def set_test_params(self):
13 self.num_nodes = 2
15 def setup_network(self):
16 self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
17 self.extra_args = [["-alertnotify=echo %%s >> %s" % self.alert_filename],
18 ["-blockversion=211"]]
19 super().setup_network()
21 def run_test(self):
22 # Mine 51 up-version blocks. -alertnotify should trigger on the 51st.
23 self.nodes[1].generate(51)
24 self.sync_all()
26 # Give bitcoind 10 seconds to write the alert notification
27 wait_until(lambda: os.path.isfile(self.alert_filename) and os.path.getsize(self.alert_filename), timeout=10)
29 with open(self.alert_filename, 'r', encoding='utf8') as f:
30 alert_text = f.read()
32 # Mine more up-version blocks, should not get more alerts:
33 self.nodes[1].generate(2)
34 self.sync_all()
36 with open(self.alert_filename, 'r', encoding='utf8') as f:
37 alert_text2 = f.read()
39 self.log.info("-alertnotify should not continue notifying for more unknown version blocks")
40 assert_equal(alert_text, alert_text2)
42 if __name__ == '__main__':
43 ForkNotifyTest().main()