@@ -171,30 +171,27 @@ def check_last_announcement(self, headers=None, inv=None):
171
171
"""Test whether the last announcement received had the right header or the right inv.
172
172
173
173
inv and headers should be lists of block hashes."""
174
- expect_headers = headers if headers is not None else []
175
- expect_inv = inv if inv is not None else []
174
+
176
175
test_function = lambda : self .block_announced
177
176
wait_until (test_function , timeout = 60 , lock = mininode_lock )
177
+
178
178
with mininode_lock :
179
179
self .block_announced = False
180
180
181
- success = True
182
181
compare_inv = []
183
182
if "inv" in self .last_message :
184
183
compare_inv = [x .hash for x in self .last_message ["inv" ].inv ]
185
- if compare_inv != expect_inv :
186
- success = False
184
+ if inv is not None :
185
+ assert_equal ( compare_inv , inv )
187
186
188
- hash_headers = []
187
+ compare_headers = []
189
188
if "headers" in self .last_message :
190
- # treat headers as a list of block hashes
191
- hash_headers = [x .sha256 for x in self .last_message ["headers" ].headers ]
192
- if hash_headers != expect_headers :
193
- success = False
189
+ compare_headers = [x .sha256 for x in self .last_message ["headers" ].headers ]
190
+ if headers is not None :
191
+ assert_equal (compare_headers , headers )
194
192
195
193
self .last_message .pop ("inv" , None )
196
194
self .last_message .pop ("headers" , None )
197
- return success
198
195
199
196
class SendHeadersTest (BitcoinTestFramework ):
200
197
def set_test_params (self ):
@@ -256,7 +253,7 @@ def test_null_locators(self, test_node):
256
253
self .log .info ("Verify getheaders with null locator and valid hashstop returns headers." )
257
254
test_node .clear_last_announcement ()
258
255
test_node .send_get_headers (locator = [], hashstop = tip_hash )
259
- assert_equal ( test_node .check_last_announcement (headers = [tip_hash ]), True )
256
+ test_node .check_last_announcement (headers = [tip_hash ])
260
257
261
258
self .log .info ("Verify getheaders with null locator and invalid hashstop does not return headers." )
262
259
block = create_block (int (tip ["hash" ], 16 ), create_coinbase (tip ["height" ] + 1 ), tip ["mediantime" ] + 1 )
@@ -277,8 +274,8 @@ def test_nonnull_locators(self, test_node, inv_node):
277
274
for i in range (4 ):
278
275
old_tip = tip
279
276
tip = self .mine_blocks (1 )
280
- assert_equal ( inv_node .check_last_announcement (inv = [tip ]), True )
281
- assert_equal ( test_node .check_last_announcement (inv = [tip ]), True )
277
+ inv_node .check_last_announcement (inv = [tip ], headers = [] )
278
+ test_node .check_last_announcement (inv = [tip ], headers = [] )
282
279
# Try a few different responses; none should affect next announcement
283
280
if i == 0 :
284
281
# first request the block
@@ -316,8 +313,8 @@ def test_nonnull_locators(self, test_node, inv_node):
316
313
317
314
# Now that we've synced headers, headers announcements should work
318
315
tip = self .mine_blocks (1 )
319
- assert_equal ( inv_node .check_last_announcement (inv = [tip ]), True )
320
- assert_equal ( test_node .check_last_announcement (headers = [tip ]), True )
316
+ inv_node .check_last_announcement (inv = [tip ], headers = [] )
317
+ test_node .check_last_announcement (headers = [tip ])
321
318
322
319
height = self .nodes [0 ].getblockcount () + 1
323
320
block_time += 10 # Advance far enough ahead
@@ -361,8 +358,8 @@ def test_nonnull_locators(self, test_node, inv_node):
361
358
assert "inv" not in inv_node .last_message
362
359
assert "headers" not in inv_node .last_message
363
360
tip = self .mine_blocks (1 )
364
- assert_equal ( inv_node .check_last_announcement (inv = [tip ]), True )
365
- assert_equal ( test_node .check_last_announcement (headers = [tip ]), True )
361
+ inv_node .check_last_announcement (inv = [tip ], headers = [] )
362
+ test_node .check_last_announcement (headers = [tip ])
366
363
height += 1
367
364
block_time += 1
368
365
@@ -376,16 +373,16 @@ def test_nonnull_locators(self, test_node, inv_node):
376
373
# First try mining a reorg that can propagate with header announcement
377
374
new_block_hashes = self .mine_reorg (length = 7 )
378
375
tip = new_block_hashes [- 1 ]
379
- assert_equal ( inv_node .check_last_announcement (inv = [tip ]), True )
380
- assert_equal ( test_node .check_last_announcement (headers = new_block_hashes ), True )
376
+ inv_node .check_last_announcement (inv = [tip ], headers = [] )
377
+ test_node .check_last_announcement (headers = new_block_hashes )
381
378
382
379
block_time += 8
383
380
384
381
# Mine a too-large reorg, which should be announced with a single inv
385
382
new_block_hashes = self .mine_reorg (length = 8 )
386
383
tip = new_block_hashes [- 1 ]
387
- assert_equal ( inv_node .check_last_announcement (inv = [tip ]), True )
388
- assert_equal ( test_node .check_last_announcement (inv = [tip ]), True )
384
+ inv_node .check_last_announcement (inv = [tip ], headers = [] )
385
+ test_node .check_last_announcement (inv = [tip ], headers = [] )
389
386
390
387
block_time += 9
391
388
@@ -394,15 +391,15 @@ def test_nonnull_locators(self, test_node, inv_node):
394
391
395
392
# Use getblocks/getdata
396
393
test_node .send_getblocks (locator = [fork_point ])
397
- assert_equal ( test_node .check_last_announcement (inv = new_block_hashes ), True )
394
+ test_node .check_last_announcement (inv = new_block_hashes , headers = [] )
398
395
test_node .send_get_data (new_block_hashes )
399
396
test_node .wait_for_block (new_block_hashes [- 1 ])
400
397
401
398
for i in range (3 ):
402
399
# Mine another block, still should get only an inv
403
400
tip = self .mine_blocks (1 )
404
- assert_equal ( inv_node .check_last_announcement (inv = [tip ]), True )
405
- assert_equal ( test_node .check_last_announcement (inv = [tip ]), True )
401
+ inv_node .check_last_announcement (inv = [tip ], headers = [] )
402
+ test_node .check_last_announcement (inv = [tip ], headers = [] )
406
403
if i == 0 :
407
404
# Just get the data -- shouldn't cause headers announcements to resume
408
405
test_node .send_get_data ([tip ])
@@ -427,8 +424,8 @@ def test_nonnull_locators(self, test_node, inv_node):
427
424
test_node .sync_with_ping ()
428
425
# New blocks should now be announced with header
429
426
tip = self .mine_blocks (1 )
430
- assert_equal ( inv_node .check_last_announcement (inv = [tip ]), True )
431
- assert_equal ( test_node .check_last_announcement (headers = [tip ]), True )
427
+ inv_node .check_last_announcement (inv = [tip ], headers = [] )
428
+ test_node .check_last_announcement (headers = [tip ])
432
429
433
430
self .log .info ("Part 3: success!" )
434
431
0 commit comments