2024-08-13 12:46:48 +00:00
|
|
|
import random
|
|
|
|
import time
|
2024-10-11 08:08:39 +00:00
|
|
|
from dataclasses import dataclass
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
import pytest
|
2024-08-13 12:46:48 +00:00
|
|
|
|
2024-10-11 08:08:39 +00:00
|
|
|
from conftest import option
|
2024-10-23 19:48:33 +00:00
|
|
|
from test_cases import StatusBackendTestCase
|
2024-08-13 12:46:48 +00:00
|
|
|
|
2024-10-07 15:40:18 +00:00
|
|
|
|
2024-10-23 19:48:33 +00:00
|
|
|
class TestRpc(StatusBackendTestCase):
|
2024-08-13 12:46:48 +00:00
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"method, params",
|
|
|
|
[
|
|
|
|
("wakuext_peers", []),
|
2024-11-12 13:30:13 +00:00
|
|
|
("wakuext_activityCenterNotifications", [{"cursor": "", "limit": 20, "activityTypes": [5], "readType": 2}])
|
2024-08-13 12:46:48 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_(self, method, params):
|
|
|
|
_id = str(random.randint(1, 8888))
|
|
|
|
|
2024-10-23 19:48:33 +00:00
|
|
|
response = self.rpc_client.rpc_valid_request(method, params, _id)
|
2024-10-29 12:10:48 +00:00
|
|
|
self.rpc_client.verify_json_schema(response.json(), method)
|
2024-08-13 12:46:48 +00:00
|
|
|
|
|
|
|
|
2024-10-07 15:40:18 +00:00
|
|
|
@pytest.mark.skip("to be reworked via status-backend")
|
2024-10-23 19:48:33 +00:00
|
|
|
class TestRpcMessaging(StatusBackendTestCase):
|
2024-08-13 12:46:48 +00:00
|
|
|
@dataclass
|
|
|
|
class User:
|
|
|
|
rpc_url: str
|
|
|
|
chat_public_key: Optional[str] = None
|
|
|
|
chat_id: Optional[str] = None
|
|
|
|
|
|
|
|
def test_add_contact(self):
|
|
|
|
_id = str(random.randint(1, 8888))
|
|
|
|
|
|
|
|
self.user_1 = self.User(rpc_url=option.rpc_url)
|
|
|
|
self.user_2 = self.User(rpc_url=option.rpc_url_2)
|
|
|
|
|
|
|
|
# get chat public key
|
|
|
|
for user in self.user_1, self.user_2:
|
2024-10-07 15:40:18 +00:00
|
|
|
response = self.rpc_client.rpc_request(
|
2024-08-13 12:46:48 +00:00
|
|
|
"accounts_getAccounts", [], _id, url=user.rpc_url
|
|
|
|
)
|
2024-10-07 15:40:18 +00:00
|
|
|
self.rpc_client.verify_is_valid_json_rpc_response(response)
|
2024-08-13 12:46:48 +00:00
|
|
|
|
|
|
|
user.chat_public_key = next(
|
|
|
|
(
|
|
|
|
item["public-key"]
|
|
|
|
for item in response.json()["result"]
|
|
|
|
if item["chat"]
|
|
|
|
),
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
|
|
|
|
# send contact requests
|
|
|
|
for sender in self.user_1, self.user_2:
|
|
|
|
for receiver in self.user_1, self.user_2:
|
|
|
|
if sender != receiver:
|
2024-10-07 15:40:18 +00:00
|
|
|
response = self.rpc_client.rpc_request(
|
2024-08-13 12:46:48 +00:00
|
|
|
method="wakuext_sendContactRequest",
|
|
|
|
params=[
|
|
|
|
{
|
|
|
|
"id": receiver.chat_public_key,
|
|
|
|
"message": f"contact request from {sender.chat_public_key}: sent at {time.time()}",
|
|
|
|
}
|
|
|
|
],
|
2024-10-11 08:08:39 +00:00
|
|
|
request_id=99,
|
2024-08-13 12:46:48 +00:00
|
|
|
url=sender.rpc_url,
|
|
|
|
)
|
|
|
|
|
2024-10-07 15:40:18 +00:00
|
|
|
self.rpc_client.verify_is_valid_json_rpc_response(response)
|
2024-08-13 12:46:48 +00:00
|
|
|
sender.chat_id = response.json()["result"]["chats"][0]["lastMessage"]["id"]
|
|
|
|
|
|
|
|
# accept contact requests
|
|
|
|
for user in self.user_1, self.user_2:
|
2024-10-07 15:40:18 +00:00
|
|
|
response = self.rpc_client.rpc_request(
|
2024-08-13 12:46:48 +00:00
|
|
|
method="wakuext_acceptContactRequest",
|
|
|
|
params=[
|
|
|
|
{
|
|
|
|
"id": user.chat_id,
|
|
|
|
}
|
|
|
|
],
|
2024-10-11 08:08:39 +00:00
|
|
|
request_id=99,
|
2024-08-13 12:46:48 +00:00
|
|
|
url=user.rpc_url,
|
|
|
|
)
|
2024-10-07 15:40:18 +00:00
|
|
|
self.rpc_client.verify_is_valid_json_rpc_response(response)
|
2024-08-13 12:46:48 +00:00
|
|
|
|
|
|
|
# verify contacts
|
|
|
|
for user in (self.user_1, self.user_2), (self.user_2, self.user_1):
|
2024-10-07 15:40:18 +00:00
|
|
|
response = self.rpc_client.rpc_request(
|
2024-08-13 12:46:48 +00:00
|
|
|
method="wakuext_contacts",
|
|
|
|
params=[],
|
2024-10-11 08:08:39 +00:00
|
|
|
request_id=99,
|
2024-08-13 12:46:48 +00:00
|
|
|
url=user[0].rpc_url,
|
|
|
|
)
|
2024-10-07 15:40:18 +00:00
|
|
|
self.rpc_client.verify_is_valid_json_rpc_response(response)
|
2024-08-13 12:46:48 +00:00
|
|
|
|
|
|
|
response = response.json()
|
2024-10-23 19:48:33 +00:00
|
|
|
assert response["result"][0]["added"] is True
|
2024-08-13 12:46:48 +00:00
|
|
|
assert response["result"][0]["id"] == user[1].chat_public_key
|