Skip to content

Commit fa3886b

Browse files
author
MarcoFalke
committed
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
1 parent 5fbcc8f commit fa3886b

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

test/functional/test_framework/messages.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,10 +1132,7 @@ def deserialize(self, f):
11321132

11331133
# Relay field is optional for version 70001 onwards
11341134
# But, unconditionally check it to match behaviour in bitcoind
1135-
try:
1136-
self.relay = struct.unpack("<b", f.read(1))[0]
1137-
except struct.error:
1138-
self.relay = 0
1135+
self.relay = int.from_bytes(f.read(1), "little") # f.read(1) may return an empty b''
11391136

11401137
def serialize(self):
11411138
r = b""
@@ -1147,7 +1144,7 @@ def serialize(self):
11471144
r += struct.pack("<Q", self.nNonce)
11481145
r += ser_string(self.strSubVer.encode('utf-8'))
11491146
r += struct.pack("<i", self.nStartingHeight)
1150-
r += struct.pack("<b", self.relay)
1147+
r += self.relay.to_bytes(1, "little")
11511148
return r
11521149

11531150
def __repr__(self):

0 commit comments

Comments
 (0)