diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index cc30424653c..60641f66cfc 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -25,7 +25,6 @@ from io import BytesIO import math import random import socket -import struct import time import unittest @@ -97,24 +96,24 @@ def hash256(s): def ser_compact_size(l): r = b"" if l < 253: - r = struct.pack("B", l) + r = l.to_bytes(1, "little") elif l < 0x10000: - r = struct.pack("H", f.read(2))[0] + self.port = int.from_bytes(f.read(2), "big") def serialize(self, *, with_time=True): """Serialize in addrv1 format (pre-BIP155)""" @@ -293,20 +292,20 @@ class CAddress: r = b"" if with_time: # VERSION messages serialize CAddress objects without time - r += struct.pack("H", self.port) + r += self.port.to_bytes(2, "big") return r def deserialize_v2(self, f): """Deserialize from addrv2 format (BIP155)""" - self.time = struct.unpack("H", f.read(2))[0] + self.port = int.from_bytes(f.read(2), "big") def serialize_v2(self): """Serialize in addrv2 format (BIP155)""" assert self.net in self.ADDRV2_NET_NAME r = b"" - r += struct.pack("H", self.port) + r += self.port.to_bytes(2, "big") return r def __repr__(self): @@ -382,12 +381,12 @@ class CInv: self.hash = h def deserialize(self, f): - self.type = struct.unpack("