Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
Show First 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | def __init__(self): | ||||
# Should only call methods on this from the NetworkThread, c.f. | # Should only call methods on this from the NetworkThread, c.f. | ||||
# call_soon_threadsafe | # call_soon_threadsafe | ||||
self._transport = None | self._transport = None | ||||
@property | @property | ||||
def is_connected(self): | def is_connected(self): | ||||
return self._transport is not None | return self._transport is not None | ||||
def peer_connect(self, dstaddr, dstport, *, net, factor): | def peer_connect(self, dstaddr, dstport, *, net, timeout_factor): | ||||
assert not self.is_connected | assert not self.is_connected | ||||
self.factor = factor | self.timeout_factor = timeout_factor | ||||
self.dstaddr = dstaddr | self.dstaddr = dstaddr | ||||
self.dstport = dstport | self.dstport = dstport | ||||
# The initial message to send after the connection was made: | # The initial message to send after the connection was made: | ||||
self.on_connection_send_msg = None | self.on_connection_send_msg = None | ||||
self.on_connection_send_msg_is_raw = False | self.on_connection_send_msg_is_raw = False | ||||
self.recvbuf = b"" | self.recvbuf = b"" | ||||
self.magic_bytes = MAGIC_BYTES[net] | self.magic_bytes = MAGIC_BYTES[net] | ||||
logger.debug('Connecting to Bitcoin Node: {}:{}'.format( | logger.debug('Connecting to Bitcoin Node: {}:{}'.format( | ||||
▲ Show 20 Lines • Show All 299 Lines • ▼ Show 20 Lines | def on_version(self, message): | ||||
assert message.nVersion >= MIN_VERSION_SUPPORTED, "Version {} received. Test framework only supports versions greater than {}".format( | assert message.nVersion >= MIN_VERSION_SUPPORTED, "Version {} received. Test framework only supports versions greater than {}".format( | ||||
message.nVersion, MIN_VERSION_SUPPORTED) | message.nVersion, MIN_VERSION_SUPPORTED) | ||||
self.send_message(msg_verack()) | self.send_message(msg_verack()) | ||||
self.nServices = message.nServices | self.nServices = message.nServices | ||||
# Connection helper methods | # Connection helper methods | ||||
def wait_until(self, test_function, timeout): | def wait_until(self, test_function, timeout): | ||||
wait_until(test_function, timeout=timeout, | wait_until(test_function, timeout=timeout, lock=mininode_lock, | ||||
lock=mininode_lock, factor=self.factor) | timeout_factor=self.timeout_factor) | ||||
def wait_for_disconnect(self, timeout=60): | def wait_for_disconnect(self, timeout=60): | ||||
def test_function(): return not self.is_connected | def test_function(): return not self.is_connected | ||||
self.wait_until(test_function, timeout=timeout) | self.wait_until(test_function, timeout=timeout) | ||||
# Message receiving helper methods | # Message receiving helper methods | ||||
def wait_for_tx(self, txid, timeout=60): | def wait_for_tx(self, txid, timeout=60): | ||||
▲ Show 20 Lines • Show All 315 Lines • Show Last 20 Lines |