49
49
from test_framework .wallet import MiniWallet
50
50
51
51
52
+ HEIGHT = 200 # blocks mined
52
53
TIME_RANGE_STEP = 600 # ten-minute steps
53
- TIME_RANGE_MTP = TIME_GENESIS_BLOCK + 194 * TIME_RANGE_STEP
54
- TIME_RANGE_END = TIME_GENESIS_BLOCK + 200 * TIME_RANGE_STEP
54
+ TIME_RANGE_MTP = TIME_GENESIS_BLOCK + ( HEIGHT - 6 ) * TIME_RANGE_STEP
55
+ TIME_RANGE_END = TIME_GENESIS_BLOCK + HEIGHT * TIME_RANGE_STEP
55
56
56
57
57
58
class BlockchainTest (BitcoinTestFramework ):
@@ -76,11 +77,11 @@ def run_test(self):
76
77
assert self .nodes [0 ].verifychain (4 , 0 )
77
78
78
79
def mine_chain (self ):
79
- self .log .info ("Generate 200 blocks after the genesis block in ten-minute steps" )
80
+ self .log .info (f "Generate { HEIGHT } blocks after the genesis block in ten-minute steps" )
80
81
for t in range (TIME_GENESIS_BLOCK , TIME_RANGE_END , TIME_RANGE_STEP ):
81
82
self .nodes [0 ].setmocktime (t )
82
83
self .nodes [0 ].generatetoaddress (1 , ADDRESS_BCRT1_P2WSH_OP_TRUE )
83
- assert_equal (self .nodes [0 ].getblockchaininfo ()['blocks' ], 200 )
84
+ assert_equal (self .nodes [0 ].getblockchaininfo ()['blocks' ], HEIGHT )
84
85
85
86
def _test_getblockchaininfo (self ):
86
87
self .log .info ("Test getblockchaininfo" )
@@ -153,8 +154,8 @@ def _test_getblockchaininfo(self):
153
154
'statistics' : {
154
155
'period' : 144 ,
155
156
'threshold' : 108 ,
156
- 'elapsed' : 57 ,
157
- 'count' : 57 ,
157
+ 'elapsed' : HEIGHT - 143 ,
158
+ 'count' : HEIGHT - 143 ,
158
159
'possible' : True ,
159
160
},
160
161
'min_activation_height' : 0 ,
@@ -191,33 +192,33 @@ def _test_getchaintxstats(self):
191
192
assert_raises_rpc_error (- 8 , "blockhash must be of length 64 (not 1, for '0')" , self .nodes [0 ].getchaintxstats , blockhash = '0' )
192
193
assert_raises_rpc_error (- 8 , "blockhash must be hexadecimal string (not 'ZZZ0000000000000000000000000000000000000000000000000000000000000')" , self .nodes [0 ].getchaintxstats , blockhash = 'ZZZ0000000000000000000000000000000000000000000000000000000000000' )
193
194
assert_raises_rpc_error (- 5 , "Block not found" , self .nodes [0 ].getchaintxstats , blockhash = '0000000000000000000000000000000000000000000000000000000000000000' )
194
- blockhash = self .nodes [0 ].getblockhash (200 )
195
+ blockhash = self .nodes [0 ].getblockhash (HEIGHT )
195
196
self .nodes [0 ].invalidateblock (blockhash )
196
197
assert_raises_rpc_error (- 8 , "Block is not in main chain" , self .nodes [0 ].getchaintxstats , blockhash = blockhash )
197
198
self .nodes [0 ].reconsiderblock (blockhash )
198
199
199
200
chaintxstats = self .nodes [0 ].getchaintxstats (nblocks = 1 )
200
201
# 200 txs plus genesis tx
201
- assert_equal (chaintxstats ['txcount' ], 201 )
202
+ assert_equal (chaintxstats ['txcount' ], HEIGHT + 1 )
202
203
# tx rate should be 1 per 10 minutes, or 1/600
203
204
# we have to round because of binary math
204
- assert_equal (round (chaintxstats ['txrate' ] * 600 , 10 ), Decimal (1 ))
205
+ assert_equal (round (chaintxstats ['txrate' ] * TIME_RANGE_STEP , 10 ), Decimal (1 ))
205
206
206
207
b1_hash = self .nodes [0 ].getblockhash (1 )
207
208
b1 = self .nodes [0 ].getblock (b1_hash )
208
- b200_hash = self .nodes [0 ].getblockhash (200 )
209
+ b200_hash = self .nodes [0 ].getblockhash (HEIGHT )
209
210
b200 = self .nodes [0 ].getblock (b200_hash )
210
211
time_diff = b200 ['mediantime' ] - b1 ['mediantime' ]
211
212
212
213
chaintxstats = self .nodes [0 ].getchaintxstats ()
213
214
assert_equal (chaintxstats ['time' ], b200 ['time' ])
214
- assert_equal (chaintxstats ['txcount' ], 201 )
215
+ assert_equal (chaintxstats ['txcount' ], HEIGHT + 1 )
215
216
assert_equal (chaintxstats ['window_final_block_hash' ], b200_hash )
216
- assert_equal (chaintxstats ['window_final_block_height' ], 200 )
217
- assert_equal (chaintxstats ['window_block_count' ], 199 )
218
- assert_equal (chaintxstats ['window_tx_count' ], 199 )
217
+ assert_equal (chaintxstats ['window_final_block_height' ], HEIGHT )
218
+ assert_equal (chaintxstats ['window_block_count' ], HEIGHT - 1 )
219
+ assert_equal (chaintxstats ['window_tx_count' ], HEIGHT - 1 )
219
220
assert_equal (chaintxstats ['window_interval' ], time_diff )
220
- assert_equal (round (chaintxstats ['txrate' ] * time_diff , 10 ), Decimal (199 ))
221
+ assert_equal (round (chaintxstats ['txrate' ] * time_diff , 10 ), Decimal (HEIGHT - 1 ))
221
222
222
223
chaintxstats = self .nodes [0 ].getchaintxstats (blockhash = b1_hash )
223
224
assert_equal (chaintxstats ['time' ], b1 ['time' ])
@@ -234,11 +235,11 @@ def _test_gettxoutsetinfo(self):
234
235
res = node .gettxoutsetinfo ()
235
236
236
237
assert_equal (res ['total_amount' ], Decimal ('8725.00000000' ))
237
- assert_equal (res ['transactions' ], 200 )
238
- assert_equal (res ['height' ], 200 )
239
- assert_equal (res ['txouts' ], 200 )
238
+ assert_equal (res ['transactions' ], HEIGHT )
239
+ assert_equal (res ['height' ], HEIGHT )
240
+ assert_equal (res ['txouts' ], HEIGHT )
240
241
assert_equal (res ['bogosize' ], 16800 ),
241
- assert_equal (res ['bestblock' ], node .getblockhash (200 ))
242
+ assert_equal (res ['bestblock' ], node .getblockhash (HEIGHT ))
242
243
size = res ['disk_size' ]
243
244
assert size > 6400
244
245
assert size < 64000
@@ -298,11 +299,11 @@ def _test_getblockheader(self):
298
299
assert_raises_rpc_error (- 5 , "Block not found" , node .getblockheader , "0cf7bb8b1697ea987f3b223ba7819250cae33efacb068d23dc24859824a77844" )
299
300
300
301
besthash = node .getbestblockhash ()
301
- secondbesthash = node .getblockhash (199 )
302
+ secondbesthash = node .getblockhash (HEIGHT - 1 )
302
303
header = node .getblockheader (blockhash = besthash )
303
304
304
305
assert_equal (header ['hash' ], besthash )
305
- assert_equal (header ['height' ], 200 )
306
+ assert_equal (header ['height' ], HEIGHT )
306
307
assert_equal (header ['confirmations' ], 1 )
307
308
assert_equal (header ['previousblockhash' ], secondbesthash )
308
309
assert_is_hex_string (header ['chainwork' ])
@@ -341,9 +342,9 @@ def _test_getnetworkhashps(self):
341
342
assert abs (hashes_per_second * 300 - 1 ) < 0.0001
342
343
343
344
def _test_stopatheight (self ):
344
- assert_equal (self .nodes [0 ].getblockcount (), 200 )
345
+ assert_equal (self .nodes [0 ].getblockcount (), HEIGHT )
345
346
self .nodes [0 ].generatetoaddress (6 , ADDRESS_BCRT1_P2WSH_OP_TRUE )
346
- assert_equal (self .nodes [0 ].getblockcount (), 206 )
347
+ assert_equal (self .nodes [0 ].getblockcount (), HEIGHT + 6 )
347
348
self .log .debug ('Node should not stop at this height' )
348
349
assert_raises (subprocess .TimeoutExpired , lambda : self .nodes [0 ].process .wait (timeout = 3 ))
349
350
try :
@@ -353,7 +354,7 @@ def _test_stopatheight(self):
353
354
self .log .debug ('Node should stop at this height...' )
354
355
self .nodes [0 ].wait_until_stopped ()
355
356
self .start_node (0 )
356
- assert_equal (self .nodes [0 ].getblockcount (), 207 )
357
+ assert_equal (self .nodes [0 ].getblockcount (), HEIGHT + 7 )
357
358
358
359
def _test_waitforblockheight (self ):
359
360
self .log .info ("Test waitforblockheight" )
0 commit comments