2
2
# Copyright (c) 2014-2016 The Bitcoin Core developers
3
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
- """Test the -alertnotify option ."""
5
+ """Test the -alertnotify and -blocknotify options ."""
6
6
import os
7
7
8
8
from test_framework .test_framework import BitcoinTestFramework
9
9
from test_framework .util import assert_equal , wait_until
10
10
11
- class ForkNotifyTest (BitcoinTestFramework ):
11
+ class NotificationsTest (BitcoinTestFramework ):
12
12
def set_test_params (self ):
13
13
self .num_nodes = 2
14
14
15
15
def setup_network (self ):
16
16
self .alert_filename = os .path .join (self .options .tmpdir , "alert.txt" )
17
- self .extra_args = [["-alertnotify=echo %%s >> %s" % self .alert_filename ],
17
+ self .block_filename = os .path .join (self .options .tmpdir , 'blocks.txt' )
18
+ self .extra_args = [["-blockversion=2" ,
19
+ "-alertnotify=echo %%s >> %s" % self .alert_filename ,
20
+ "-blocknotify=echo %%s >> %s" % self .block_filename ],
18
21
["-blockversion=211" ]]
19
22
super ().setup_network ()
20
23
21
24
def run_test (self ):
22
- # Mine 51 up-version blocks. -alertnotify should trigger on the 51st.
23
- self .nodes [1 ].generate (51 )
25
+ self .log .info ("test -blocknotify" )
26
+ block_count = 10
27
+ blocks = self .nodes [1 ].generate (block_count )
28
+
29
+ # wait at most 10 seconds for expected file size before reading the content
30
+ wait_until (lambda : os .path .isfile (self .block_filename ) and os .stat (self .block_filename ).st_size >= (block_count * 65 ), timeout = 10 )
31
+
32
+ # file content should equal the generated blocks hashes
33
+ with open (self .block_filename , 'r' ) as f :
34
+ assert_equal (sorted (blocks ), sorted (f .read ().splitlines ()))
35
+
36
+ # Mine another 41 up-version blocks. -alertnotify should trigger on the 51st.
37
+ self .log .info ("test -alertnotify" )
38
+ self .nodes [1 ].generate (41 )
24
39
self .sync_all ()
25
40
26
41
# Give bitcoind 10 seconds to write the alert notification
@@ -40,4 +55,4 @@ def run_test(self):
40
55
assert_equal (alert_text , alert_text2 )
41
56
42
57
if __name__ == '__main__' :
43
- ForkNotifyTest ().main ()
58
+ NotificationsTest ().main ()
0 commit comments