Skip to content

Commit

Permalink
Add wait_for_xxx methods as found in develop
Browse files Browse the repository at this point in the history
But slightly modified so that they work with wait_until which does not
assert in v0.14.0.x
  • Loading branch information
codablock committed Dec 6, 2019
1 parent 8dae12c commit a8b8891
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions qa/rpc-tests/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from concurrent.futures import ThreadPoolExecutor
from time import time, sleep

from test_framework.mininode import wait_until
from .util import (
assert_equal,
initialize_chain,
Expand Down Expand Up @@ -555,22 +556,29 @@ def send_complex_tx(self, sender, receiver):
return self.wait_for_instantlock(txid, sender)

def wait_for_instantlock(self, txid, node):
# wait for instantsend locks
start = time()
locked = False
while True:
def check_instantlock():
try:
is_tx = node.getrawtransaction(txid, True)
if is_tx['instantlock']:
locked = True
break
return node.getrawtransaction(txid, True)["instantlock"]
except:
# TX not received yet?
pass
if time() > start + 10:
break
sleep(0.5)
return locked
return False
return wait_until(check_instantlock, timeout=10, sleep=0.5)

def wait_for_chainlocked_block(self, node, block_hash, expected=True, timeout=15):
def check_chainlocked_block():
try:
block = node.getblock(block_hash)
return block["confirmations"] > 0 and block["chainlock"]
except:
return False
w = wait_until(check_chainlocked_block, timeout=timeout, sleep=0.1)
if not w and expected:
raise AssertionError("wait_for_chainlocked_block failed")
elif w and not expected:
raise AssertionError("waiting unexpectedly succeeded")

def wait_for_chainlocked_block_all_nodes(self, block_hash, timeout=15):
for node in self.nodes:
self.wait_for_chainlocked_block(node, block_hash, timeout=timeout)

def wait_for_sporks_same(self, timeout=30):
st = time()
Expand Down

0 comments on commit a8b8891

Please sign in to comment.