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."""
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
):
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()
22 # Mine 51 up-version blocks. -alertnotify should trigger on the 51st.
23 self
.nodes
[1].generate(51)
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
:
32 # Mine more up-version blocks, should not get more alerts:
33 self
.nodes
[1].generate(2)
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()