[tests] TestNode: separate add_node from start_node
[bitcoinplatinum.git] / test / functional / forknotify.py
blob3a2a927098e0fb0c486a9647e61a2a4f7d4316bf
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
7 import time
9 from test_framework.test_framework import BitcoinTestFramework
11 class ForkNotifyTest(BitcoinTestFramework):
13 def __init__(self):
14 super().__init__()
15 self.num_nodes = 2
16 self.setup_clean_chain = False
18 def setup_network(self):
19 self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
20 with open(self.alert_filename, 'w', encoding='utf8'):
21 pass # Just open then close to create zero-length file
22 self.extra_args = [["-blockversion=2", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""],
23 ["-blockversion=211"]]
24 super().setup_network()
26 def run_test(self):
27 # Mine 51 up-version blocks
28 self.nodes[1].generate(51)
29 self.sync_all()
30 # -alertnotify should trigger on the 51'st,
31 # but mine and sync another to give
32 # -alertnotify time to write
33 self.nodes[1].generate(1)
34 self.sync_all()
36 # Give bitcoind 10 seconds to write the alert notification
37 timeout = 10.0
38 while timeout > 0:
39 if os.path.exists(self.alert_filename) and os.path.getsize(self.alert_filename):
40 break
41 time.sleep(0.1)
42 timeout -= 0.1
43 else:
44 assert False, "-alertnotify did not warn of up-version blocks"
46 with open(self.alert_filename, 'r', encoding='utf8') as f:
47 alert_text = f.read()
49 # Mine more up-version blocks, should not get more alerts:
50 self.nodes[1].generate(1)
51 self.sync_all()
52 self.nodes[1].generate(1)
53 self.sync_all()
55 with open(self.alert_filename, 'r', encoding='utf8') as f:
56 alert_text2 = f.read()
58 if alert_text != alert_text2:
59 raise AssertionError("-alertnotify excessive warning of up-version blocks")
61 if __name__ == '__main__':
62 ForkNotifyTest().main()