Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/p2p.py
Show First 20 Lines • Show All 322 Lines • ▼ Show 20 Lines | class P2PInterface(P2PConnection): | ||||
node over P2P. | node over P2P. | ||||
Individual testcases should subclass this and override the on_* methods | Individual testcases should subclass this and override the on_* methods | ||||
if they want to alter message handling behaviour.""" | if they want to alter message handling behaviour.""" | ||||
def __init__(self, support_addrv2=False): | def __init__(self, support_addrv2=False): | ||||
super().__init__() | super().__init__() | ||||
# Track number of messages of each type received and the most recent | # Track number of messages of each type received. | ||||
# message of each type | # Should be read-only in a test. | ||||
self.message_count = defaultdict(int) | self.message_count = defaultdict(int) | ||||
# Track the most recent message of each type. | |||||
# To wait for a message to be received, pop that message from | |||||
# this and use wait_until. | |||||
self.last_message = {} | self.last_message = {} | ||||
# A count of the number of ping messages we've sent to the node | # A count of the number of ping messages we've sent to the node | ||||
self.ping_counter = 1 | self.ping_counter = 1 | ||||
# The network services received from the peer | # The network services received from the peer | ||||
self.nServices = 0 | self.nServices = 0 | ||||
▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Lines | def wait_for_inv(self, expected_inv, timeout=60): | ||||
return self.last_message.get("inv") and \ | return self.last_message.get("inv") and \ | ||||
self.last_message["inv"].inv[0].type == expected_inv[0].type and \ | self.last_message["inv"].inv[0].type == expected_inv[0].type and \ | ||||
self.last_message["inv"].inv[0].hash == expected_inv[0].hash | self.last_message["inv"].inv[0].hash == expected_inv[0].hash | ||||
self.wait_until(test_function, timeout=timeout) | self.wait_until(test_function, timeout=timeout) | ||||
def wait_for_verack(self, timeout=60): | def wait_for_verack(self, timeout=60): | ||||
def test_function(): | def test_function(): | ||||
return self.message_count["verack"] | return "verack" in self.last_message | ||||
self.wait_until(test_function, timeout=timeout, check_connected=False) | self.wait_until(test_function, timeout=timeout, check_connected=False) | ||||
# Message sending helper functions | # Message sending helper functions | ||||
def send_and_ping(self, message, timeout=60): | def send_and_ping(self, message, timeout=60): | ||||
self.send_message(message) | self.send_message(message) | ||||
self.sync_with_ping(timeout=timeout) | self.sync_with_ping(timeout=timeout) | ||||
▲ Show 20 Lines • Show All 227 Lines • Show Last 20 Lines |