Update unit tests to use serialize

This commit is contained in:
Sergi Delgado Segura
2019-12-17 15:11:00 +01:00
parent 5c585a7a02
commit 680de0b7ac
6 changed files with 62 additions and 29 deletions

View File

@@ -1,4 +1,6 @@
import json
import struct
import binascii
from pytest import fixture
from pisa import c_logger
@@ -110,3 +112,27 @@ def test_from_dict(appointment_data):
except ValueError:
appointment_data[key] = prev_val
assert True
def test_serialize(appointment_data):
# From the tower end, appointments are only created if they pass the inspector tests, so not covering weird formats.
# Serialize may fail if, from the user end, the user tries to do it with an weird appointment. Not critical.
appointment = Appointment.from_dict(appointment_data)
serialized_appointment = appointment.serialize()
# Size must be 16 + 4 + 4 + 4 + len(encrypted_blob)
assert len(serialized_appointment) >= 28
assert isinstance(serialized_appointment, bytes)
locator = serialized_appointment[:16]
start_time = serialized_appointment[16:20]
end_time = serialized_appointment[20:24]
to_self_delay = serialized_appointment[24:28]
encrypted_blob = serialized_appointment[28:]
assert binascii.hexlify(locator).decode() == appointment.locator
assert struct.unpack(">I", start_time)[0] == appointment.start_time
assert struct.unpack(">I", end_time)[0] == appointment.end_time
assert struct.unpack(">I", to_self_delay)[0] == appointment.to_self_delay
assert binascii.hexlify(encrypted_blob).decode() == appointment.encrypted_blob.data