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.
10 from test_framework
.test_framework
import BitcoinTestFramework
11 from test_framework
.util
import *
13 class ForkNotifyTest(BitcoinTestFramework
):
18 self
.setup_clean_chain
= False
20 alert_filename
= None # Set by setup_network
22 def setup_network(self
):
24 self
.alert_filename
= os
.path
.join(self
.options
.tmpdir
, "alert.txt")
25 with
open(self
.alert_filename
, 'w', encoding
='utf8') as f
:
26 pass # Just open then close to create zero-length file
27 self
.nodes
.append(start_node(0, self
.options
.tmpdir
,
28 ["-blockversion=2", "-alertnotify=echo %s >> \"" + self
.alert_filename
+ "\""]))
29 # Node1 mines block.version=211 blocks
30 self
.nodes
.append(start_node(1, self
.options
.tmpdir
,
31 ["-blockversion=211"]))
32 connect_nodes(self
.nodes
[1], 0)
34 self
.is_network_split
= False
38 # Mine 51 up-version blocks
39 self
.nodes
[1].generate(51)
41 # -alertnotify should trigger on the 51'st,
42 # but mine and sync another to give
43 # -alertnotify time to write
44 self
.nodes
[1].generate(1)
47 with
open(self
.alert_filename
, 'r', encoding
='utf8') as f
:
50 if len(alert_text
) == 0:
51 raise AssertionError("-alertnotify did not warn of up-version blocks")
53 # Mine more up-version blocks, should not get more alerts:
54 self
.nodes
[1].generate(1)
56 self
.nodes
[1].generate(1)
59 with
open(self
.alert_filename
, 'r', encoding
='utf8') as f
:
60 alert_text2
= f
.read()
62 if alert_text
!= alert_text2
:
63 raise AssertionError("-alertnotify excessive warning of up-version blocks")
65 if __name__
== '__main__':
66 ForkNotifyTest().main()