5
5
"""Test the -alertnotify, -blocknotify and -walletnotify options."""
6
6
import os
7
7
8
+ from test_framework .address import ADDRESS_BCRT1_UNSPENDABLE
8
9
from test_framework .test_framework import BitcoinTestFramework
9
10
from test_framework .util import assert_equal , wait_until , connect_nodes_bi
10
11
12
+
11
13
class NotificationsTest (BitcoinTestFramework ):
12
14
def set_test_params (self ):
13
15
self .num_nodes = 2
14
16
self .setup_clean_chain = True
15
17
16
- def skip_test_if_missing_module (self ):
17
- self .skip_if_no_wallet ()
18
-
19
18
def setup_network (self ):
20
19
self .alertnotify_dir = os .path .join (self .options .tmpdir , "alertnotify" )
21
20
self .blocknotify_dir = os .path .join (self .options .tmpdir , "blocknotify" )
@@ -25,7 +24,7 @@ def setup_network(self):
25
24
os .mkdir (self .walletnotify_dir )
26
25
27
26
# -alertnotify and -blocknotify on node0, walletnotify on node1
28
- self .extra_args = [["-blockversion=2" ,
27
+ self .extra_args = [[
29
28
"-alertnotify=echo > {}" .format (os .path .join (self .alertnotify_dir , '%s' )),
30
29
"-blocknotify=echo > {}" .format (os .path .join (self .blocknotify_dir , '%s' ))],
31
30
["-blockversion=211" ,
@@ -36,38 +35,39 @@ def setup_network(self):
36
35
def run_test (self ):
37
36
self .log .info ("test -blocknotify" )
38
37
block_count = 10
39
- blocks = self .nodes [1 ].generate (block_count )
38
+ blocks = self .nodes [1 ].generatetoaddress (block_count , self . nodes [ 1 ]. getnewaddress () if self . is_wallet_compiled () else ADDRESS_BCRT1_UNSPENDABLE )
40
39
41
40
# wait at most 10 seconds for expected number of files before reading the content
42
41
wait_until (lambda : len (os .listdir (self .blocknotify_dir )) == block_count , timeout = 10 )
43
42
44
43
# directory content should equal the generated blocks hashes
45
44
assert_equal (sorted (blocks ), sorted (os .listdir (self .blocknotify_dir )))
46
45
47
- self .log .info ("test -walletnotify" )
48
- # wait at most 10 seconds for expected number of files before reading the content
49
- wait_until (lambda : len (os .listdir (self .walletnotify_dir )) == block_count , timeout = 10 )
46
+ if self .is_wallet_compiled ():
47
+ self .log .info ("test -walletnotify" )
48
+ # wait at most 10 seconds for expected number of files before reading the content
49
+ wait_until (lambda : len (os .listdir (self .walletnotify_dir )) == block_count , timeout = 10 )
50
50
51
- # directory content should equal the generated transaction hashes
52
- txids_rpc = list (map (lambda t : t ['txid' ], self .nodes [1 ].listtransactions ("*" , block_count )))
53
- assert_equal (sorted (txids_rpc ), sorted (os .listdir (self .walletnotify_dir )))
54
- for tx_file in os .listdir (self .walletnotify_dir ):
55
- os .remove (os .path .join (self .walletnotify_dir , tx_file ))
51
+ # directory content should equal the generated transaction hashes
52
+ txids_rpc = list (map (lambda t : t ['txid' ], self .nodes [1 ].listtransactions ("*" , block_count )))
53
+ assert_equal (sorted (txids_rpc ), sorted (os .listdir (self .walletnotify_dir )))
54
+ for tx_file in os .listdir (self .walletnotify_dir ):
55
+ os .remove (os .path .join (self .walletnotify_dir , tx_file ))
56
56
57
- self .log .info ("test -walletnotify after rescan" )
58
- # restart node to rescan to force wallet notifications
59
- self .restart_node (1 )
60
- connect_nodes_bi (self .nodes , 0 , 1 )
57
+ self .log .info ("test -walletnotify after rescan" )
58
+ # restart node to rescan to force wallet notifications
59
+ self .restart_node (1 )
60
+ connect_nodes_bi (self .nodes , 0 , 1 )
61
61
62
- wait_until (lambda : len (os .listdir (self .walletnotify_dir )) == block_count , timeout = 10 )
62
+ wait_until (lambda : len (os .listdir (self .walletnotify_dir )) == block_count , timeout = 10 )
63
63
64
- # directory content should equal the generated transaction hashes
65
- txids_rpc = list (map (lambda t : t ['txid' ], self .nodes [1 ].listtransactions ("*" , block_count )))
66
- assert_equal (sorted (txids_rpc ), sorted (os .listdir (self .walletnotify_dir )))
64
+ # directory content should equal the generated transaction hashes
65
+ txids_rpc = list (map (lambda t : t ['txid' ], self .nodes [1 ].listtransactions ("*" , block_count )))
66
+ assert_equal (sorted (txids_rpc ), sorted (os .listdir (self .walletnotify_dir )))
67
67
68
68
# Mine another 41 up-version blocks. -alertnotify should trigger on the 51st.
69
69
self .log .info ("test -alertnotify" )
70
- self .nodes [1 ].generate (41 )
70
+ self .nodes [1 ].generatetoaddress (41 , ADDRESS_BCRT1_UNSPENDABLE )
71
71
self .sync_all ()
72
72
73
73
# Give bitcoind 10 seconds to write the alert notification
@@ -77,7 +77,7 @@ def run_test(self):
77
77
os .remove (os .path .join (self .alertnotify_dir , notify_file ))
78
78
79
79
# Mine more up-version blocks, should not get more alerts:
80
- self .nodes [1 ].generate ( 2 )
80
+ self .nodes [1 ].generatetoaddress ( 2 , ADDRESS_BCRT1_UNSPENDABLE )
81
81
self .sync_all ()
82
82
83
83
self .log .info ("-alertnotify should not continue notifying for more unknown version blocks" )
0 commit comments