Skip to content

Commit

Permalink
test: write test for incompatible protocol versions
Browse files Browse the repository at this point in the history
  • Loading branch information
thegamecracks committed Mar 12, 2024
1 parent 60c2e61 commit 807332b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
Client,
ClientEventAuthentication,
ClientEventChannelsListed,
ClientEventIncompatibleVersion,
ClientState,
HighCommand,
InvalidStateError,
Protocol,
Server,
ServerEventAuthentication,
ServerEventIncompatibleVersion,
ServerEventMessageReceived,
ServerState,
)
Expand Down Expand Up @@ -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!"
Expand Down

0 comments on commit 807332b

Please sign in to comment.