test: Treat msg_version.relay as unsigned

The C++ code treats bool as uint8_t, so the python tests should as well.

This also allows to simplify the code, because converting an empty byte
array to int gives int(0).

>>> int.from_bytes(b'')
0
This commit is contained in:
MarcoFalke 2023-12-12 17:57:00 +01:00
parent 5fbcc8f056
commit fa3886b7c6
No known key found for this signature in database

View File

@ -1132,10 +1132,7 @@ class msg_version:
# Relay field is optional for version 70001 onwards
# But, unconditionally check it to match behaviour in bitcoind
try:
self.relay = struct.unpack("<b", f.read(1))[0]
except struct.error:
self.relay = 0
self.relay = int.from_bytes(f.read(1), "little") # f.read(1) may return an empty b''
def serialize(self):
r = b""
@ -1147,7 +1144,7 @@ class msg_version:
r += struct.pack("<Q", self.nNonce)
r += ser_string(self.strSubVer.encode('utf-8'))
r += struct.pack("<i", self.nStartingHeight)
r += struct.pack("<b", self.relay)
r += self.relay.to_bytes(1, "little")
return r
def __repr__(self):