@@ -363,18 +363,23 @@ def wait_for_disconnect(self, timeout=60):
363
363
364
364
def wait_for_tx (self , txid , timeout = 60 ):
365
365
def test_function ():
366
+ assert self .is_connected
366
367
if not self .last_message .get ('tx' ):
367
368
return False
368
369
return self .last_message ['tx' ].tx .rehash () == txid
369
370
370
371
wait_until (test_function , timeout = timeout , lock = mininode_lock )
371
372
372
373
def wait_for_block (self , blockhash , timeout = 60 ):
373
- test_function = lambda : self .last_message .get ("block" ) and self .last_message ["block" ].block .rehash () == blockhash
374
+ def test_function ():
375
+ assert self .is_connected
376
+ return self .last_message .get ("block" ) and self .last_message ["block" ].block .rehash () == blockhash
377
+
374
378
wait_until (test_function , timeout = timeout , lock = mininode_lock )
375
379
376
380
def wait_for_header (self , blockhash , timeout = 60 ):
377
381
def test_function ():
382
+ assert self .is_connected
378
383
last_headers = self .last_message .get ('headers' )
379
384
if not last_headers :
380
385
return False
@@ -389,7 +394,11 @@ def wait_for_getdata(self, timeout=60):
389
394
value must be explicitly cleared before calling this method, or this will return
390
395
immediately with success. TODO: change this method to take a hash value and only
391
396
return true if the correct block/tx has been requested."""
392
- test_function = lambda : self .last_message .get ("getdata" )
397
+
398
+ def test_function ():
399
+ assert self .is_connected
400
+ return self .last_message .get ("getdata" )
401
+
393
402
wait_until (test_function , timeout = timeout , lock = mininode_lock )
394
403
395
404
def wait_for_getheaders (self , timeout = 60 ):
@@ -399,20 +408,30 @@ def wait_for_getheaders(self, timeout=60):
399
408
value must be explicitly cleared before calling this method, or this will return
400
409
immediately with success. TODO: change this method to take a hash value and only
401
410
return true if the correct block header has been requested."""
402
- test_function = lambda : self .last_message .get ("getheaders" )
411
+
412
+ def test_function ():
413
+ assert self .is_connected
414
+ return self .last_message .get ("getheaders" )
415
+
403
416
wait_until (test_function , timeout = timeout , lock = mininode_lock )
404
417
405
418
def wait_for_inv (self , expected_inv , timeout = 60 ):
406
419
"""Waits for an INV message and checks that the first inv object in the message was as expected."""
407
420
if len (expected_inv ) > 1 :
408
421
raise NotImplementedError ("wait_for_inv() will only verify the first inv object" )
409
- test_function = lambda : self .last_message .get ("inv" ) and \
422
+
423
+ def test_function ():
424
+ assert self .is_connected
425
+ return self .last_message .get ("inv" ) and \
410
426
self .last_message ["inv" ].inv [0 ].type == expected_inv [0 ].type and \
411
427
self .last_message ["inv" ].inv [0 ].hash == expected_inv [0 ].hash
428
+
412
429
wait_until (test_function , timeout = timeout , lock = mininode_lock )
413
430
414
431
def wait_for_verack (self , timeout = 60 ):
415
- test_function = lambda : self .message_count ["verack" ]
432
+ def test_function ():
433
+ return self .message_count ["verack" ]
434
+
416
435
wait_until (test_function , timeout = timeout , lock = mininode_lock )
417
436
418
437
# Message sending helper functions
@@ -424,7 +443,11 @@ def send_and_ping(self, message, timeout=60):
424
443
# Sync up with the node
425
444
def sync_with_ping (self , timeout = 60 ):
426
445
self .send_message (msg_ping (nonce = self .ping_counter ))
427
- test_function = lambda : self .last_message .get ("pong" ) and self .last_message ["pong" ].nonce == self .ping_counter
446
+
447
+ def test_function ():
448
+ assert self .is_connected
449
+ return self .last_message .get ("pong" ) and self .last_message ["pong" ].nonce == self .ping_counter
450
+
428
451
wait_until (test_function , timeout = timeout , lock = mininode_lock )
429
452
self .ping_counter += 1
430
453
0 commit comments