18
18
"""
19
19
20
20
from decimal import Decimal
21
+ import subprocess
21
22
22
23
from test_framework .test_framework import BitcoinTestFramework
23
24
from test_framework .util import (
24
25
assert_equal ,
26
+ assert_raises ,
25
27
assert_raises_jsonrpc ,
26
28
assert_is_hex_string ,
27
29
assert_is_hash_string ,
30
+ bitcoind_processes ,
28
31
)
29
32
30
33
@@ -34,14 +37,16 @@ def __init__(self):
34
37
super ().__init__ ()
35
38
self .setup_clean_chain = False
36
39
self .num_nodes = 1
40
+ self .extra_args = [['-stopatheight=207' ]]
37
41
38
42
def run_test (self ):
39
43
self ._test_getchaintxstats ()
40
44
self ._test_gettxoutsetinfo ()
41
45
self ._test_getblockheader ()
42
46
self ._test_getdifficulty ()
43
47
self ._test_getnetworkhashps ()
44
- self .nodes [0 ].verifychain (4 , 0 )
48
+ self ._test_stopatheight ()
49
+ assert self .nodes [0 ].verifychain (4 , 0 )
45
50
46
51
def _test_getchaintxstats (self ):
47
52
chaintxstats = self .nodes [0 ].getchaintxstats (1 )
@@ -129,5 +134,18 @@ def _test_getnetworkhashps(self):
129
134
# This should be 2 hashes every 10 minutes or 1/300
130
135
assert abs (hashes_per_second * 300 - 1 ) < 0.0001
131
136
137
+ def _test_stopatheight (self ):
138
+ assert_equal (self .nodes [0 ].getblockcount (), 200 )
139
+ self .nodes [0 ].generate (6 )
140
+ assert_equal (self .nodes [0 ].getblockcount (), 206 )
141
+ self .log .debug ('Node should not stop at this height' )
142
+ assert_raises (subprocess .TimeoutExpired , lambda : bitcoind_processes [0 ].wait (timeout = 3 ))
143
+ self .nodes [0 ].generate (1 )
144
+ self .log .debug ('Node should stop at this height...' )
145
+ bitcoind_processes [0 ].wait (timeout = 3 )
146
+ self .nodes [0 ] = self .start_node (0 , self .options .tmpdir )
147
+ assert_equal (self .nodes [0 ].getblockcount (), 207 )
148
+
149
+
132
150
if __name__ == '__main__' :
133
151
BlockchainTest ().main ()
0 commit comments