From 807332b587ec85edc103b35af6ca23447d34c3c3 Mon Sep 17 00:00:00 2001 From: thegamecracks <61257169+thegamecracks@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:56:00 -0400 Subject: [PATCH] test: write test for incompatible protocol versions --- tests/test_protocol.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_protocol.py b/tests/test_protocol.py index 2ebd041..c4f1ae7 100644 --- a/tests/test_protocol.py +++ b/tests/test_protocol.py @@ -7,12 +7,14 @@ Client, ClientEventAuthentication, ClientEventChannelsListed, + ClientEventIncompatibleVersion, ClientState, HighCommand, InvalidStateError, Protocol, Server, ServerEventAuthentication, + ServerEventIncompatibleVersion, ServerEventMessageReceived, ServerState, ) @@ -71,6 +73,33 @@ def test_authenticate(): assert server_events == [ServerEventAuthentication(success=True, nick=nick)] +def test_authenticate_incompatible_version(): + hc = HighCommand() + + nick = "thegamecracks" + client = Client(nick=nick) + server = Server(hc) + + client.PROTOCOL_VERSION = server.PROTOCOL_VERSION + 1 # type: ignore + if client.PROTOCOL_VERSION > 255: + client.PROTOCOL_VERSION = server.PROTOCOL_VERSION - 1 # type: ignore + + assert client.PROTOCOL_VERSION != server.PROTOCOL_VERSION + + client_events, server_events = communicate(client, client.authenticate(), server) + assert client_events == [ + ClientEventIncompatibleVersion( + client_version=client.PROTOCOL_VERSION, + server_version=server.PROTOCOL_VERSION, + ) + ] + assert server_events == [ + ServerEventIncompatibleVersion( + version=client.PROTOCOL_VERSION, + ) + ] + + def test_send_message(): nick = "thegamecracks" content = "Hello world!"