Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/util.py
Show First 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | |||||
def str_to_b64str(string): | def str_to_b64str(string): | ||||
return b64encode(string.encode('utf-8')).decode('ascii') | return b64encode(string.encode('utf-8')).decode('ascii') | ||||
def satoshi_round(amount): | def satoshi_round(amount): | ||||
return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN) | return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN) | ||||
def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None): | |||||
if attempts == float('inf') and timeout == float('inf'): | |||||
timeout = 60 | |||||
attempt = 0 | |||||
timeout += time.time() | |||||
while attempt < attempts and time.time() < timeout: | |||||
if lock: | |||||
with lock: | |||||
if predicate(): | |||||
return | |||||
else: | |||||
if predicate(): | |||||
return | |||||
attempt += 1 | |||||
time.sleep(0.05) | |||||
# Print the cause of the timeout | |||||
assert_greater_than(attempts, attempt) | |||||
assert_greater_than(timeout, time.time()) | |||||
raise RuntimeError('Unreachable') | |||||
# RPC/P2P connection constants and functions | # RPC/P2P connection constants and functions | ||||
############################################ | ############################################ | ||||
# The maximum number of nodes a single test can spawn | # The maximum number of nodes a single test can spawn | ||||
MAX_NODES = 8 | MAX_NODES = 8 | ||||
# Don't assign rpc or p2p ports lower than this | # Don't assign rpc or p2p ports lower than this | ||||
PORT_MIN = 11000 | PORT_MIN = 11000 | ||||
▲ Show 20 Lines • Show All 463 Lines • Show Last 20 Lines |