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 and -blocknotify options."""
5
+ """Test the -alertnotify, -blocknotify and -walletnotify options."""
6
6
import os
7
7
8
8
from test_framework .test_framework import BitcoinTestFramework
9
- from test_framework .util import assert_equal , wait_until
9
+ from test_framework .util import assert_equal , wait_until , connect_nodes_bi
10
10
11
11
class NotificationsTest (BitcoinTestFramework ):
12
12
def set_test_params (self ):
13
13
self .num_nodes = 2
14
+ self .setup_clean_chain = True
14
15
15
16
def setup_network (self ):
16
17
self .alert_filename = os .path .join (self .options .tmpdir , "alert.txt" )
17
- self .block_filename = os .path .join (self .options .tmpdir , 'blocks.txt' )
18
+ self .block_filename = os .path .join (self .options .tmpdir , "blocks.txt" )
19
+ self .tx_filename = os .path .join (self .options .tmpdir , "transactions.txt" )
20
+
21
+ # -alertnotify and -blocknotify on node0, walletnotify on node1
18
22
self .extra_args = [["-blockversion=2" ,
19
23
"-alertnotify=echo %%s >> %s" % self .alert_filename ,
20
24
"-blocknotify=echo %%s >> %s" % self .block_filename ],
21
- ["-blockversion=211" ]]
25
+ ["-blockversion=211" ,
26
+ "-rescan" ,
27
+ "-walletnotify=echo %%s >> %s" % self .tx_filename ]]
22
28
super ().setup_network ()
23
29
24
30
def run_test (self ):
@@ -33,6 +39,28 @@ def run_test(self):
33
39
with open (self .block_filename , 'r' ) as f :
34
40
assert_equal (sorted (blocks ), sorted (f .read ().splitlines ()))
35
41
42
+ self .log .info ("test -walletnotify" )
43
+ # wait at most 10 seconds for expected file size before reading the content
44
+ wait_until (lambda : os .path .isfile (self .tx_filename ) and os .stat (self .tx_filename ).st_size >= (block_count * 65 ), timeout = 10 )
45
+
46
+ # file content should equal the generated transaction hashes
47
+ txids_rpc = list (map (lambda t : t ['txid' ], self .nodes [1 ].listtransactions ("*" , block_count )))
48
+ with open (self .tx_filename , 'r' ) as f :
49
+ assert_equal (sorted (txids_rpc ), sorted (f .read ().splitlines ()))
50
+ os .remove (self .tx_filename )
51
+
52
+ self .log .info ("test -walletnotify after rescan" )
53
+ # restart node to rescan to force wallet notifications
54
+ self .restart_node (1 )
55
+ connect_nodes_bi (self .nodes , 0 , 1 )
56
+
57
+ wait_until (lambda : os .path .isfile (self .tx_filename ) and os .stat (self .tx_filename ).st_size >= (block_count * 65 ), timeout = 10 )
58
+
59
+ # file content should equal the generated transaction hashes
60
+ txids_rpc = list (map (lambda t : t ['txid' ], self .nodes [1 ].listtransactions ("*" , block_count )))
61
+ with open (self .tx_filename , 'r' ) as f :
62
+ assert_equal (sorted (txids_rpc ), sorted (f .read ().splitlines ()))
63
+
36
64
# Mine another 41 up-version blocks. -alertnotify should trigger on the 51st.
37
65
self .log .info ("test -alertnotify" )
38
66
self .nodes [1 ].generate (41 )
0 commit comments