From a8b8891a1d8d3ebe18ba89e9977d5d6cd00b318c Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 6 Dec 2019 22:40:18 +0100 Subject: [PATCH] Add wait_for_xxx methods as found in develop But slightly modified so that they work with wait_until which does not assert in v0.14.0.x --- qa/rpc-tests/test_framework/test_framework.py | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py index 7effeb8119c09..4e80a8c669aec 100755 --- a/qa/rpc-tests/test_framework/test_framework.py +++ b/qa/rpc-tests/test_framework/test_framework.py @@ -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, @@ -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()