aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorstratospher <44024636+stratospher@users.noreply.github.com>2022-02-05 23:28:02 +0530
committerstratospher <44024636+stratospher@users.noreply.github.com>2024-01-25 11:09:52 +0530
commita94e350ac0e5b65ef23a84b05fb10d1204c98c97 (patch)
tree851ca8d114b78bc1a64e19e33add3c48fa11a731 /test
parentbb7bffed799dc5ad8b606768164fce46d4cbf9d0 (diff)
[test] Build v2 P2P messages
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/test_framework/p2p.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py
index dcb93e9acc..4ababe01dc 100755
--- a/test/functional/test_framework/p2p.py
+++ b/test/functional/test_framework/p2p.py
@@ -82,6 +82,7 @@ from test_framework.util import (
)
from test_framework.v2_p2p import (
EncryptedP2PState,
+ MSGTYPE_TO_SHORTID,
SHORTID,
)
@@ -386,15 +387,25 @@ class P2PConnection(asyncio.Protocol):
"""Build a serialized P2P message"""
msgtype = message.msgtype
data = message.serialize()
- tmsg = self.magic_bytes
- tmsg += msgtype
- tmsg += b"\x00" * (12 - len(msgtype))
- tmsg += struct.pack("<I", len(data))
- th = sha256(data)
- h = sha256(th)
- tmsg += h[:4]
- tmsg += data
- return tmsg
+ if self.supports_v2_p2p:
+ if msgtype in SHORTID.values():
+ tmsg = MSGTYPE_TO_SHORTID.get(msgtype).to_bytes(1, 'big')
+ else:
+ tmsg = b"\x00"
+ tmsg += msgtype
+ tmsg += b"\x00" * (12 - len(msgtype))
+ tmsg += data
+ return self.v2_state.v2_enc_packet(tmsg)
+ else:
+ tmsg = self.magic_bytes
+ tmsg += msgtype
+ tmsg += b"\x00" * (12 - len(msgtype))
+ tmsg += struct.pack("<I", len(data))
+ th = sha256(data)
+ h = sha256(th)
+ tmsg += h[:4]
+ tmsg += data
+ return tmsg
def _log_message(self, direction, msg):
"""Logs a message being sent or received over the connection."""