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."""
9 from test_framework
.test_framework
import BitcoinTestFramework
11 class ForkNotifyTest(BitcoinTestFramework
):
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()
27 # Mine 51 up-version blocks
28 self
.nodes
[1].generate(51)
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)
36 # Give bitcoind 10 seconds to write the alert notification
39 if os
.path
.exists(self
.alert_filename
) and os
.path
.getsize(self
.alert_filename
):
44 assert False, "-alertnotify did not warn of up-version blocks"
46 with
open(self
.alert_filename
, 'r', encoding
='utf8') as f
:
49 # Mine more up-version blocks, should not get more alerts:
50 self
.nodes
[1].generate(1)
52 self
.nodes
[1].generate(1)
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()