Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Broken by reorg and switch to shortest encoding for a value. It is
needed to match encoding used in other implementations for
cryptography inputs.
  • Loading branch information
tannewt committed Oct 8, 2024
1 parent 3d67377 commit edb2996
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
3 changes: 2 additions & 1 deletion circuitmatter/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def decode(self, buffer):
)
self.general_code = GeneralCode(self.general_code)
self.protocol_data = buffer[8:]
self.protocol_id = protocol.ProtocolId(self.protocol_id)
if self.protocol_id in protocol.ProtocolId:
self.protocol_id = protocol.ProtocolId(self.protocol_id)

if self.protocol_id == protocol.ProtocolId.SECURE_CHANNEL:
self.protocol_code = SecureChannelProtocolCode(self.protocol_code)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_message_reception_state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from circuitmatter import MessageReceptionState
from circuitmatter.session import MessageReceptionState


def test_basics():
Expand Down
3 changes: 2 additions & 1 deletion tests/test_status_report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from circuitmatter import StatusReport, GeneralCode, ProtocolId
from circuitmatter.session import StatusReport, GeneralCode
from circuitmatter.protocol import ProtocolId


def test_example1():
Expand Down
18 changes: 6 additions & 12 deletions tests/test_tlv.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_signed_int_negative_17_encode(self):
def test_signed_int_42_two_octet_encode(self):
s = SignedIntTwoOctet()
s.i = 42
assert s.encode().tobytes() == b"\x15\x21\x00\x2a\x00\x18"
assert s.encode().tobytes() == b"\x15\x20\x00\x2a\x18"

def test_signed_int_negative_170000_encode(self):
s = SignedIntFourOctet()
Expand Down Expand Up @@ -547,10 +547,7 @@ def test_inner_struct_encode(self):
inner.a = 42
inner.b = -17
s.s = inner
assert (
s.encode().tobytes()
== b"\x15\x35\x00\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x18"
)
assert s.encode().tobytes() == b"\x15\x35\x00\x20\x00\x2a\x20\x01\xef\x18\x18"

def test_inner_struct_encode_empty(self):
s = OuterStruct()
Expand Down Expand Up @@ -581,7 +578,7 @@ def test_encode(self):
s.b = -17
assert (
s.encode().tobytes()
== b"\x15\xc2\xda\x0a\x00\x0f\x23\x01\x2a\x00\x00\x00\xe2\xda\x0a\x00\x0f\x45\x23\x01\x00\xef\xff\xff\xff\x18"
== b"\x15\xc0\xda\x0a\x00\x0f\x23\x01\x2a\xe0\xda\x0a\x00\x0f\x45\x23\x01\x00\xef\x18"
)


Expand All @@ -601,10 +598,7 @@ def test_encode(self):
inner.a = 42
inner.b = -17
s.sublist = inner
assert (
s.encode().tobytes()
== b"\x15\x37\x00\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x18"
)
assert s.encode().tobytes() == b"\x15\x37\x00\x20\x00\x2a\x20\x01\xef\x18\x18"


class OuterStructArray(tlv.Structure):
Expand All @@ -620,7 +614,7 @@ def test_encode(self):
s.a = [inner]
assert (
s.encode().tobytes()
== b"\x15\x36\x00\x17\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x18\x18"
== b"\x15\x36\x00\x17\x20\x00\x2a\x20\x01\xef\x18\x18\x18"
)

def test_encode2(self):
Expand All @@ -631,5 +625,5 @@ def test_encode2(self):
s.a = [inner, inner]
assert (
s.encode().tobytes()
== b"\x15\x36\x00\x17\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x17\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x18\x18"
== b"\x15\x36\x00\x17\x20\x00\x2a\x20\x01\xef\x18\x17\x20\x00\x2a\x20\x01\xef\x18\x18\x18"
)

0 comments on commit edb2996

Please sign in to comment.