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
This commit is contained in:
Alexander Block 2019-12-06 22:40:18 +01:00
parent 8dae12cc60
commit a8b8891a1d

View File

@ -14,6 +14,7 @@ import traceback
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from time import time, sleep from time import time, sleep
from test_framework.mininode import wait_until
from .util import ( from .util import (
assert_equal, assert_equal,
initialize_chain, initialize_chain,
@ -555,22 +556,29 @@ class DashTestFramework(BitcoinTestFramework):
return self.wait_for_instantlock(txid, sender) return self.wait_for_instantlock(txid, sender)
def wait_for_instantlock(self, txid, node): def wait_for_instantlock(self, txid, node):
# wait for instantsend locks def check_instantlock():
start = time()
locked = False
while True:
try: try:
is_tx = node.getrawtransaction(txid, True) return node.getrawtransaction(txid, True)["instantlock"]
if is_tx['instantlock']:
locked = True
break
except: except:
# TX not received yet? return False
pass return wait_until(check_instantlock, timeout=10, sleep=0.5)
if time() > start + 10:
break def wait_for_chainlocked_block(self, node, block_hash, expected=True, timeout=15):
sleep(0.5) def check_chainlocked_block():
return locked 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): def wait_for_sporks_same(self, timeout=30):
st = time() st = time()