13
13
connect_nodes ,
14
14
)
15
15
16
+ # Linux allow all characters other than \x00
17
+ # Windows disallow control characters (0-31) and /\?%:|"<>
18
+ FILE_CHAR_START = 32 if os .name == 'nt' else 1
19
+ FILE_CHAR_END = 128
20
+ FILE_CHAR_BLACKLIST = '/\\ ?%*:|"<>' if os .name == 'nt' else '/'
21
+
22
+
23
+ def notify_outputname (walletname , txid ):
24
+ return txid if os .name == 'nt' else '{}_{}' .format (walletname , txid )
25
+
16
26
17
27
class NotificationsTest (BitcoinTestFramework ):
18
28
def set_test_params (self ):
19
29
self .num_nodes = 2
20
30
self .setup_clean_chain = True
21
31
22
32
def setup_network (self ):
33
+ self .wallet = '' .join (chr (i ) for i in range (FILE_CHAR_START , FILE_CHAR_END ) if chr (i ) not in FILE_CHAR_BLACKLIST )
23
34
self .alertnotify_dir = os .path .join (self .options .tmpdir , "alertnotify" )
24
35
self .blocknotify_dir = os .path .join (self .options .tmpdir , "blocknotify" )
25
36
self .walletnotify_dir = os .path .join (self .options .tmpdir , "walletnotify" )
@@ -33,7 +44,8 @@ def setup_network(self):
33
44
"-blocknotify=echo > {}" .format (os .path .join (self .blocknotify_dir , '%s' ))],
34
45
["-blockversion=211" ,
35
46
"-rescan" ,
36
- "-walletnotify=echo > {}" .format (os .path .join (self .walletnotify_dir , '%s' ))]]
47
+ "-wallet={}" .format (self .wallet ),
48
+ "-walletnotify=echo > {}" .format (os .path .join (self .walletnotify_dir , notify_outputname ('%w' , '%s' )))]]
37
49
super ().setup_network ()
38
50
39
51
def run_test (self ):
@@ -53,7 +65,7 @@ def run_test(self):
53
65
wait_until (lambda : len (os .listdir (self .walletnotify_dir )) == block_count , timeout = 10 )
54
66
55
67
# directory content should equal the generated transaction hashes
56
- txids_rpc = list (map (lambda t : t ['txid' ], self .nodes [1 ].listtransactions ("*" , block_count )))
68
+ txids_rpc = list (map (lambda t : notify_outputname ( self . wallet , t ['txid' ]) , self .nodes [1 ].listtransactions ("*" , block_count )))
57
69
assert_equal (sorted (txids_rpc ), sorted (os .listdir (self .walletnotify_dir )))
58
70
self .stop_node (1 )
59
71
for tx_file in os .listdir (self .walletnotify_dir ):
@@ -67,7 +79,7 @@ def run_test(self):
67
79
wait_until (lambda : len (os .listdir (self .walletnotify_dir )) == block_count , timeout = 10 )
68
80
69
81
# directory content should equal the generated transaction hashes
70
- txids_rpc = list (map (lambda t : t ['txid' ], self .nodes [1 ].listtransactions ("*" , block_count )))
82
+ txids_rpc = list (map (lambda t : notify_outputname ( self . wallet , t ['txid' ]) , self .nodes [1 ].listtransactions ("*" , block_count )))
71
83
assert_equal (sorted (txids_rpc ), sorted (os .listdir (self .walletnotify_dir )))
72
84
73
85
# TODO: add test for `-alertnotify` large fork notifications
0 commit comments