diff --git a/test/functional/abc_p2p_compactblocks.py b/test/functional/abc_p2p_compactblocks.py --- a/test/functional/abc_p2p_compactblocks.py +++ b/test/functional/abc_p2p_compactblocks.py @@ -269,10 +269,7 @@ return (test_p2p.last_sendcmpct is not None) self.wait_until(received_sendcmpct, timeout=30) - sendcmpct = msg_sendcmpct() - sendcmpct.version = 1 - sendcmpct.announce = True - test_p2p.send_and_ping(sendcmpct) + test_p2p.send_and_ping(msg_sendcmpct(announce=True, version=1)) # Exchange headers def received_getheaders(): diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py --- a/test/functional/p2p_compactblocks.py +++ b/test/functional/p2p_compactblocks.py @@ -223,10 +223,7 @@ test_node.request_headers_and_sync(locator=[tip]) # Now try a SENDCMPCT message with too-high version - sendcmpct = msg_sendcmpct() - sendcmpct.version = 999 # was: preferred_version+1 - sendcmpct.announce = True - test_node.send_and_ping(sendcmpct) + test_node.send_and_ping(msg_sendcmpct(announce=True, version=999)) check_announcement_of_new_block( node, test_node, lambda p: "cmpctblock" not in p.last_message) @@ -234,9 +231,8 @@ test_node.request_headers_and_sync(locator=[tip]) # Now try a SENDCMPCT message with valid version, but announce=False - sendcmpct.version = preferred_version - sendcmpct.announce = False - test_node.send_and_ping(sendcmpct) + test_node.send_and_ping(msg_sendcmpct(announce=False, + version=preferred_version)) check_announcement_of_new_block( node, test_node, lambda p: "cmpctblock" not in p.last_message) @@ -244,9 +240,8 @@ test_node.request_headers_and_sync(locator=[tip]) # Finally, try a SENDCMPCT message with announce=True - sendcmpct.version = preferred_version - sendcmpct.announce = True - test_node.send_and_ping(sendcmpct) + test_node.send_and_ping(msg_sendcmpct(announce=True, + version=preferred_version)) check_announcement_of_new_block( node, test_node, lambda p: "cmpctblock" in p.last_message) @@ -260,25 +255,21 @@ node, test_node, lambda p: "cmpctblock" in p.last_message) # Try one more time, after sending a version-1, announce=false message. - sendcmpct.version = preferred_version - 1 - sendcmpct.announce = False - test_node.send_and_ping(sendcmpct) + test_node.send_and_ping(msg_sendcmpct(announce=False, + version=preferred_version - 1)) check_announcement_of_new_block( node, test_node, lambda p: "cmpctblock" in p.last_message) # Now turn off announcements - sendcmpct.version = preferred_version - sendcmpct.announce = False - test_node.send_and_ping(sendcmpct) + test_node.send_and_ping(msg_sendcmpct(announce=False, + version=preferred_version)) check_announcement_of_new_block( node, test_node, lambda p: "cmpctblock" not in p.last_message and "headers" in p.last_message) if old_node is not None: # Verify that a peer using an older protocol version can receive # announcements from this node. - sendcmpct.version = 1 # preferred_version-1 - sendcmpct.announce = True - old_node.send_and_ping(sendcmpct) + old_node.send_and_ping(msg_sendcmpct(announce=True, version=1)) # Header sync old_node.request_headers_and_sync(locator=[tip]) check_announcement_of_new_block( @@ -772,11 +763,7 @@ def request_cb_announcements(self, peer, node, version=1): tip = node.getbestblockhash() peer.get_headers(locator=[int(tip, 16)], hashstop=0) - - msg = msg_sendcmpct() - msg.version = version - msg.announce = True - peer.send_and_ping(msg) + peer.send_and_ping(msg_sendcmpct(announce=True, version=version)) def test_compactblock_reconstruction_multiple_peers( self, node, stalling_peer, delivery_peer): diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -1710,9 +1710,9 @@ __slots__ = ("announce", "version") msgtype = b"sendcmpct" - def __init__(self): - self.announce = False - self.version = 1 + def __init__(self, announce=False, version=1): + self.announce = announce + self.version = version def deserialize(self, f): self.announce = struct.unpack("