twnet_parser/tests/packet_header7_test.py
ChillerDragon 0988cff4c9 Refactor to prepare proper msg unpacking
Rename `name` -> `message_name`
Replaced `GameMessage` and `SysMessage` with duck typed `NetMessage`
Split up packet.py in multiple files
2023-03-25 14:22:45 +01:00

63 lines
2.1 KiB
Python

from twnet_parser.packet import *
def test_parse_7_close():
packet = parse7(b'\x04\x0a\x00\xcf\x2e\xde\x1d\04') # 0.7 close
assert packet.version == '0.7'
assert packet.header.size == 0
assert packet.header.ack == 10
assert packet.header.token == b'\xcf.\xde\x1d'
assert packet.header.num_chunks == 0
assert packet.header.flags.control == True
assert packet.header.flags.resend == False
assert packet.header.flags.compression == False
assert packet.header.flags.connless == False
assert packet.messages[0].message_name == 'close'
assert len(packet.messages) == 1
def test_parse_7_close_fake_resend():
packet = parse7(b'\x0c\x0a\x00\xaa\xbb\xcc\xdd\04') # 0.7 close
# ^
# resending ctrl close
# probably never happens
assert packet.version == '0.7'
assert packet.header.size == 0
assert packet.header.ack == 10
assert packet.header.token == b'\xaa\xbb\xcc\xdd'
assert packet.header.num_chunks == 0
assert packet.header.flags.control == True
assert packet.header.flags.resend == True
assert packet.header.flags.compression == False
assert packet.header.flags.connless == False
assert packet.messages[0].message_name == 'close'
assert len(packet.messages) == 1
def test_parse_7_close_fake_num_chunks():
packet = parse7(b'\x04\x0a\x01\xcf\xee\xde\x2d\04') # 0.7 close
# ^
# 1 chunk makes no sense
# because control messages should
# always have 0 chunks
assert packet.version == '0.7'
assert packet.header.size == 0
assert packet.header.ack == 10
assert packet.header.token == b'\xcf\xee\xde\x2d'
assert packet.header.num_chunks == 1
assert packet.header.flags.control == True
assert packet.header.flags.resend == False
assert packet.header.flags.compression == False
assert packet.header.flags.connless == False
assert packet.messages[0].message_name == 'close'
assert len(packet.messages) == 1