From 873e93ad1b7629aa0016cbd3a8a0f84857e8bb0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kami=C5=84ski?= Date: Thu, 20 Feb 2025 16:07:32 +0000 Subject: [PATCH] test_: refactor default messaging scenario (#6351) * test_: split default messaging tests * test_: add json schema verification for sendOneToOneMessage * test_: add some assertions on the response * test_: assert all responses --- .../schemas/wakuext_sendOneToOneMessage | 412 ++++++++++++++++++ tests-functional/tests/test_cases.py | 5 + ...c.py => test_wakuext_default_messaging.py} | 27 +- tests-functional/tests/test_wakuext_rpc.py | 18 + 4 files changed, 444 insertions(+), 18 deletions(-) create mode 100644 tests-functional/schemas/wakuext_sendOneToOneMessage rename tests-functional/tests/{test_waku_rpc.py => test_wakuext_default_messaging.py} (74%) create mode 100644 tests-functional/tests/test_wakuext_rpc.py diff --git a/tests-functional/schemas/wakuext_sendOneToOneMessage b/tests-functional/schemas/wakuext_sendOneToOneMessage new file mode 100644 index 0000000000..7c94f4ee3d --- /dev/null +++ b/tests-functional/schemas/wakuext_sendOneToOneMessage @@ -0,0 +1,412 @@ +{ + "$schema": "http://json-schema.org/schema#", + "properties": { + "id": { + "type": "integer" + }, + "jsonrpc": { + "type": "string" + }, + "result": { + "properties": { + "chats": { + "items": { + "properties": { + "ReadMessagesAtClockValue": { + "type": "integer" + }, + "active": { + "type": "boolean" + }, + "alias": { + "type": "string" + }, + "chatType": { + "type": "integer" + }, + "color": { + "type": "string" + }, + "deletedAtClockValue": { + "type": "integer" + }, + "description": { + "type": "string" + }, + "emoji": { + "type": "string" + }, + "highlight": { + "type": "boolean" + }, + "id": { + "type": "string" + }, + "identicon": { + "type": "string" + }, + "joined": { + "type": "integer" + }, + "lastClockValue": { + "type": "integer" + }, + "lastMessage": { + "properties": { + "alias": { + "type": "string" + }, + "chatId": { + "type": "string" + }, + "clock": { + "type": "integer" + }, + "compressedKey": { + "type": "string" + }, + "contentType": { + "type": "integer" + }, + "displayName": { + "type": "string" + }, + "emojiHash": { + "items": { + "type": "string" + }, + "type": "array" + }, + "ensName": { + "type": "string" + }, + "from": { + "type": "string" + }, + "id": { + "type": "string" + }, + "identicon": { + "type": "string" + }, + "lineCount": { + "type": "integer" + }, + "localChatId": { + "type": "string" + }, + "messageType": { + "type": "integer" + }, + "outgoingStatus": { + "type": "string" + }, + "parsedText": { + "items": { + "properties": { + "children": { + "items": { + "properties": { + "literal": { + "type": "string" + } + }, + "required": [ + "literal" + ], + "type": "object" + }, + "type": "array" + }, + "type": { + "type": "string" + } + }, + "required": [ + "children", + "type" + ], + "type": "object" + }, + "type": "array" + }, + "quotedMessage": { + "type": "null" + }, + "replace": { + "type": "string" + }, + "responseTo": { + "type": "string" + }, + "rtl": { + "type": "boolean" + }, + "seen": { + "type": "boolean" + }, + "text": { + "type": "string" + }, + "timestamp": { + "type": "integer" + }, + "whisperTimestamp": { + "type": "integer" + } + }, + "required": [ + "alias", + "chatId", + "clock", + "compressedKey", + "contentType", + "displayName", + "emojiHash", + "ensName", + "from", + "id", + "identicon", + "lineCount", + "localChatId", + "messageType", + "outgoingStatus", + "parsedText", + "quotedMessage", + "replace", + "responseTo", + "rtl", + "seen", + "text", + "timestamp", + "whisperTimestamp" + ], + "type": "object" + }, + "members": { + "type": "null" + }, + "membershipUpdateEvents": { + "type": "null" + }, + "muteTill": { + "type": "string" + }, + "muted": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "syncedFrom": { + "type": "integer" + }, + "syncedTo": { + "type": "integer" + }, + "timestamp": { + "type": "integer" + }, + "unviewedMentionsCount": { + "type": "integer" + }, + "unviewedMessagesCount": { + "type": "integer" + }, + "viewersCanPostReactions": { + "type": "boolean" + } + }, + "required": [ + "ReadMessagesAtClockValue", + "active", + "alias", + "chatType", + "color", + "deletedAtClockValue", + "description", + "emoji", + "highlight", + "id", + "identicon", + "joined", + "lastClockValue", + "lastMessage", + "members", + "membershipUpdateEvents", + "muteTill", + "muted", + "name", + "syncedFrom", + "syncedTo", + "timestamp", + "unviewedMentionsCount", + "unviewedMessagesCount", + "viewersCanPostReactions" + ], + "type": "object" + }, + "type": "array" + }, + "discordOldestMessageTimestamp": { + "type": "integer" + }, + "messages": { + "items": { + "properties": { + "alias": { + "type": "string" + }, + "chatId": { + "type": "string" + }, + "clock": { + "type": "integer" + }, + "compressedKey": { + "type": "string" + }, + "contentType": { + "type": "integer" + }, + "displayName": { + "type": "string" + }, + "emojiHash": { + "items": { + "type": "string" + }, + "type": "array" + }, + "ensName": { + "type": "string" + }, + "from": { + "type": "string" + }, + "gapParameters": { + "type": "object" + }, + "id": { + "type": "string" + }, + "identicon": { + "type": "string" + }, + "lineCount": { + "type": "integer" + }, + "localChatId": { + "type": "string" + }, + "messageType": { + "type": "integer" + }, + "outgoingStatus": { + "type": "string" + }, + "parsedText": { + "items": { + "properties": { + "children": { + "items": { + "properties": { + "literal": { + "type": "string" + } + }, + "required": [ + "literal" + ], + "type": "object" + }, + "type": "array" + }, + "type": { + "type": "string" + } + }, + "required": [ + "children", + "type" + ], + "type": "object" + }, + "type": "array" + }, + "quotedMessage": { + "type": "null" + }, + "replace": { + "type": "string" + }, + "responseTo": { + "type": "string" + }, + "rtl": { + "type": "boolean" + }, + "seen": { + "type": "boolean" + }, + "text": { + "type": "string" + }, + "timestamp": { + "type": "integer" + }, + "whisperTimestamp": { + "type": "integer" + } + }, + "required": [ + "alias", + "chatId", + "clock", + "compressedKey", + "contentType", + "displayName", + "emojiHash", + "ensName", + "from", + "gapParameters", + "id", + "identicon", + "lineCount", + "localChatId", + "messageType", + "outgoingStatus", + "parsedText", + "quotedMessage", + "replace", + "responseTo", + "rtl", + "seen", + "text", + "timestamp", + "whisperTimestamp" + ], + "type": "object" + }, + "type": "array" + }, + "notifications": { + "type": "null" + } + }, + "required": [ + "chats", + "discordOldestMessageTimestamp", + "messages", + "notifications" + ], + "type": "object" + } + }, + "required": [ + "id", + "jsonrpc", + "result" + ], + "type": "object" +} \ No newline at end of file diff --git a/tests-functional/tests/test_cases.py b/tests-functional/tests/test_cases.py index 9881cf01b3..c873c4643b 100644 --- a/tests-functional/tests/test_cases.py +++ b/tests-functional/tests/test_cases.py @@ -355,10 +355,13 @@ def community_messages(self, message_chat_id, message_count): ) def one_to_one_message(self, message_count): + responses = [] sent_messages = [] + for i in range(message_count): message_text = f"test_message_{i+1}_{uuid4()}" response = self.sender.wakuext_service.send_message(self.receiver.public_key, message_text) + responses.append(response) expected_message = self.get_message_by_content_type(response, content_type=MessageContentType.TEXT_PLAIN.value)[0] sent_messages.append(expected_message) time.sleep(0.01) @@ -375,6 +378,8 @@ def one_to_one_message(self, message_count): expected_message=expected_message, ) + return responses + def add_contact(self, execution_number, network_condition=None, privileged=True): message_text = f"test_contact_request_{execution_number}_{uuid4()}" sender = self.initialize_backend(await_signals=self.await_signals, privileged=privileged) diff --git a/tests-functional/tests/test_waku_rpc.py b/tests-functional/tests/test_wakuext_default_messaging.py similarity index 74% rename from tests-functional/tests/test_waku_rpc.py rename to tests-functional/tests/test_wakuext_default_messaging.py index 9ec2a9ac51..ae82d1f654 100644 --- a/tests-functional/tests/test_waku_rpc.py +++ b/tests-functional/tests/test_wakuext_default_messaging.py @@ -1,21 +1,5 @@ -import random import pytest -from test_cases import StatusBackendTestCase, MessengerTestCase - - -class TestRpc(StatusBackendTestCase): - - @pytest.mark.parametrize( - "method, params", - [ - ("wakuext_peers", []), - ], - ) - def test_(self, method, params): - _id = str(random.randint(1, 8888)) - - response = self.rpc_client.rpc_valid_request(method, params, _id) - self.rpc_client.verify_json_schema(response.json(), method) +from test_cases import MessengerTestCase @pytest.mark.rpc @@ -23,7 +7,14 @@ def test_(self, method, params): class TestDefaultMessaging(MessengerTestCase): def test_one_to_one_messages(self): - self.one_to_one_message(5) + responses = self.one_to_one_message(5) + + for response in responses: + self.receiver.verify_json_schema(response, method="wakuext_sendOneToOneMessage") + + chat = response["result"]["chats"][0] + assert chat["id"] == self.receiver.public_key + assert chat["lastMessage"]["displayName"] == self.sender.display_name def test_add_contact(self): self.add_contact(execution_number=1, network_condition=None, privileged=False) diff --git a/tests-functional/tests/test_wakuext_rpc.py b/tests-functional/tests/test_wakuext_rpc.py new file mode 100644 index 0000000000..ad77813dcf --- /dev/null +++ b/tests-functional/tests/test_wakuext_rpc.py @@ -0,0 +1,18 @@ +import random +import pytest +from test_cases import StatusBackendTestCase + + +class TestRpc(StatusBackendTestCase): + + @pytest.mark.parametrize( + "method, params", + [ + ("wakuext_peers", []), + ], + ) + def test_valid_rpc_requests(self, method, params): + _id = str(random.randint(1, 8888)) + + response = self.rpc_client.rpc_valid_request(method, params, _id) + self.rpc_client.verify_json_schema(response.json(), method)