Skip to content

Commit 53c990a

Browse files
committed
test: fix feature_addrman.py on big-endian systems
The test `feature_addrman.py` currently serializes the addrdb without specifying endianness for `int`s, so the machine's native byte order is used (see https://docs.python.org/3/library/struct.html#byte-order-size-and-alignment) and the generated `peers.dat` would be invalid on big-endian systems. Fix this by explicitly specifying little-endian serialization via the `<` character in `struct.pack(...)`.
1 parent 397ed22 commit 53c990a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

test/functional/feature_addrman.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ def serialize_addrman(
3232
r += struct.pack("B", format)
3333
r += struct.pack("B", INCOMPATIBILITY_BASE + lowest_compatible)
3434
r += ser_uint256(bucket_key)
35-
r += struct.pack("i", len_new or len(new))
36-
r += struct.pack("i", len_tried or len(tried))
35+
r += struct.pack("<i", len_new or len(new))
36+
r += struct.pack("<i", len_tried or len(tried))
3737
ADDRMAN_NEW_BUCKET_COUNT = 1 << 10
38-
r += struct.pack("i", ADDRMAN_NEW_BUCKET_COUNT ^ (1 << 30))
38+
r += struct.pack("<i", ADDRMAN_NEW_BUCKET_COUNT ^ (1 << 30))
3939
for _ in range(ADDRMAN_NEW_BUCKET_COUNT):
40-
r += struct.pack("i", 0)
40+
r += struct.pack("<i", 0)
4141
checksum = hash256(r)
4242
r += mock_checksum or checksum
4343
return r

0 commit comments

Comments
 (0)