Skip to content

Commit

Permalink
test_: merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarbu15 committed Feb 11, 2025
2 parents 084c67e + cd1c084 commit 0f6bc65
Show file tree
Hide file tree
Showing 12 changed files with 461 additions and 191 deletions.
33 changes: 21 additions & 12 deletions tests-functional/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ Functional tests for status-go
* In `./tests-functional/tests` directory run `pytest -m rpc`
* To run tests against binary run `pytest -m <your mark> --url=http:<binary_url>:<binary_port> --user_dir=/<path>`

### Prerequisites for Mac OSx users
If you see errors at attempt to run tests, try to run in terminal:
```shell
sock.connect(self.unix_socket)
```
If you see
```
PermissionError: [Errno 13] Permission denied
```
Please follow this fix: https://github.com/docker/compose/issues/10299#issuecomment-1438247730
If you're on MacOS and `/var/run/docker.sock` doesn't exist, you need to create a symlink to the docker socket:
```shell
sudo ln -s $HOME/.docker/run/docker.sock /var/run/docker.sock
```

## Implementation details

- Functional tests are implemented in `./tests-functional/tests` based on [pytest](https://docs.pytest.org/en/8.2.x/)
Expand All @@ -51,17 +68,9 @@ Functional tests for status-go

# Known issues

## Docker permission denied
## Import issues

When running tests with auto-creating status-backend containers, you might face this:
```shell
sock.connect(self.unix_socket)
PermissionError: [Errno 13] Permission denied
```
If you see some import issues, make sure that you have all requirements installed from `requirements.txt`

Please follow this fix: https://github.com/docker/compose/issues/10299#issuecomment-1438247730

If you're on MacOS and `/var/run/docker.sock` doesn't exist, you need to create a symlink to the docker socket:
```shell
sudo ln -s $HOME/.docker/run/docker.sock /var/run/docker.sock
```
### For PyCharm users
Make sure that you made `test-functional` source folder (Right click > Mark directory as > Source folder)
5 changes: 5 additions & 0 deletions tests-functional/clients/services/wakuext.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ def send_community_chat_message(self, chat_id, message, content_type=MessageCont
params = [{"chatId": chat_id, "text": message, "contentType": content_type}]
response = self.rpc_request("sendChatMessage", params)
return response.json()

def set_light_client(self, enabled=True):
params = [{"enabled": enabled}]
response = self.rpc_request("setLightClient", params)
return response.json()
5 changes: 5 additions & 0 deletions tests-functional/clients/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SignalType(Enum):
NODE_READY = "node.ready"
NODE_STARTED = "node.started"
NODE_LOGIN = "node.login"
NODE_LOGOUT = "node.stopped"
MEDIASERVER_STARTED = "mediaserver.started"
WALLET_SUGGESTED_ROUTES = "wallet.suggested.routes"
WALLET_ROUTER_SIGN_TRANSACTIONS = "wallet.router.sign-transactions"
Expand Down Expand Up @@ -98,6 +99,10 @@ def wait_for_login(self):
assert not signal["event"]["error"]
return signal

def wait_for_logout(self):
signal = self.wait_for_signal(SignalType.NODE_LOGOUT.value)
return signal

def find_signal_containing_pattern(self, signal_type, event_pattern, timeout=20):
start_time = time.time()
while True:
Expand Down
63 changes: 63 additions & 0 deletions tests-functional/schemas/wakuext_getSavedAddresses
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"$schema": "http://json-schema.org/schema#",
"properties": {
"id": {
"type": "integer"
},
"jsonrpc": {
"type": "string"
},
"result": {
"items": {
"properties": {
"address": {
"type": "string"
},
"chainShortNames": {
"type": "string"
},
"colorId": {
"type": "string"
},
"createdAt": {
"type": "integer"
},
"ens": {
"type": "string"
},
"isTest": {
"type": "boolean"
},
"mixedcaseAddress": {
"type": "string"
},
"name": {
"type": "string"
},
"removed": {
"type": "boolean"
}
},
"required": [
"address",
"chainShortNames",
"colorId",
"createdAt",
"ens",
"isTest",
"mixedcaseAddress",
"name",
"removed"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"id",
"jsonrpc",
"result"
],
"type": "object"
}
63 changes: 63 additions & 0 deletions tests-functional/schemas/wakuext_getSavedAddressesPerMode
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"$schema": "http://json-schema.org/schema#",
"properties": {
"id": {
"type": "integer"
},
"jsonrpc": {
"type": "string"
},
"result": {
"items": {
"properties": {
"address": {
"type": "string"
},
"chainShortNames": {
"type": "string"
},
"colorId": {
"type": "string"
},
"createdAt": {
"type": "integer"
},
"ens": {
"type": "string"
},
"isTest": {
"type": "boolean"
},
"mixedcaseAddress": {
"type": "string"
},
"name": {
"type": "string"
},
"removed": {
"type": "boolean"
}
},
"required": [
"address",
"chainShortNames",
"colorId",
"createdAt",
"ens",
"isTest",
"mixedcaseAddress",
"name",
"removed"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"id",
"jsonrpc",
"result"
],
"type": "object"
}
35 changes: 1 addition & 34 deletions tests-functional/tests/reliability/test_contact_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,7 @@
class TestContactRequests(MessengerTestCase):

def test_contact_request_baseline(self, execution_number=1, network_condition=None):
message_text = f"test_contact_request_{execution_number}_{uuid4()}"
sender = self.initialize_backend(await_signals=self.await_signals)
receiver = self.initialize_backend(await_signals=self.await_signals)

existing_contacts = receiver.wakuext_service.get_contacts()

if sender.public_key in str(existing_contacts):
pytest.skip("Contact request was already sent for this sender<->receiver. Skipping test!!")

if network_condition:
network_condition(receiver)

response = sender.wakuext_service.send_contact_request(receiver.public_key, message_text)
expected_message = self.get_message_by_content_type(response, content_type=MessageContentType.CONTACT_REQUEST.value)[0]

messages_new_event = receiver.find_signal_containing_pattern(
SignalType.MESSAGES_NEW.value,
event_pattern=expected_message.get("id"),
timeout=60,
)

signal_messages_texts = []
if "messages" in messages_new_event.get("event", {}):
signal_messages_texts.extend(message["text"] for message in messages_new_event["event"]["messages"] if "text" in message)

assert (
f"@{sender.public_key} sent you a contact request" in signal_messages_texts
), "Couldn't find the signal corresponding to the contact request"

self.validate_signal_event_against_response(
signal_event=messages_new_event,
fields_to_validate={"text": "text"},
expected_message=expected_message,
)
self.add_contact(execution_number, network_condition)

@pytest.mark.parametrize("execution_number", range(10))
def test_multiple_contact_requests(self, execution_number):
Expand Down
25 changes: 1 addition & 24 deletions tests-functional/tests/reliability/test_create_private_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest
from tests.test_cases import MessengerTestCase
from clients.signals import SignalType
from resources.enums import MessageContentType


@pytest.mark.usefixtures("setup_two_nodes")
Expand All @@ -12,29 +11,7 @@ class TestCreatePrivateGroups(MessengerTestCase):

def test_create_private_group_baseline(self, private_groups_count=1):
self.make_contacts()

private_groups = []
for i in range(private_groups_count):
private_group_name = f"private_group_{i+1}_{uuid4()}"
response = self.sender.wakuext_service.create_group_chat_with_members([self.receiver.public_key], private_group_name)

expected_group_creation_msg = f"@{self.sender.public_key} created the group {private_group_name}"
expected_message = self.get_message_by_content_type(
response, content_type=MessageContentType.SYSTEM_MESSAGE_CONTENT_PRIVATE_GROUP.value, message_pattern=expected_group_creation_msg
)[0]

private_groups.append(expected_message)
sleep(0.01)

for i, expected_message in enumerate(private_groups):
messages_new_event = self.receiver.find_signal_containing_pattern(
SignalType.MESSAGES_NEW.value, event_pattern=expected_message.get("id"), timeout=60
)
self.validate_signal_event_against_response(
signal_event=messages_new_event,
expected_message=expected_message,
fields_to_validate={"text": "text"},
)
self.create_private_group(private_groups_count)

def test_multiple_one_create_private_groups(self):
self.test_create_private_group_baseline(private_groups_count=50)
Expand Down
21 changes: 1 addition & 20 deletions tests-functional/tests/reliability/test_one_to_one_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,14 @@
import pytest
from tests.test_cases import MessengerTestCase
from clients.signals import SignalType
from resources.enums import MessageContentType


@pytest.mark.usefixtures("setup_two_nodes")
@pytest.mark.reliability
class TestOneToOneMessages(MessengerTestCase):

def test_one_to_one_message_baseline(self, message_count=1):
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)
expected_message = self.get_message_by_content_type(response, content_type=MessageContentType.TEXT_PLAIN.value)[0]
sent_messages.append(expected_message)
sleep(0.01)

for i, expected_message in enumerate(sent_messages):
messages_new_event = self.receiver.find_signal_containing_pattern(
SignalType.MESSAGES_NEW.value,
event_pattern=expected_message.get("id"),
timeout=60,
)
self.validate_signal_event_against_response(
signal_event=messages_new_event,
fields_to_validate={"text": "text"},
expected_message=expected_message,
)
self.one_to_one_message(message_count)

def test_multiple_one_to_one_messages(self):
self.test_one_to_one_message_baseline(message_count=50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest
from tests.test_cases import MessengerTestCase
from clients.signals import SignalType
from resources.enums import MessageContentType


@pytest.mark.usefixtures("setup_two_nodes")
Expand All @@ -13,26 +12,7 @@ class TestPrivateGroupMessages(MessengerTestCase):
def test_private_group_messages_baseline(self, message_count=1):
self.make_contacts()
self.private_group_id = self.join_private_group()

sent_messages = []
for i in range(message_count):
message_text = f"test_message_{i+1}_{uuid4()}"
response = self.sender.wakuext_service.send_group_chat_message(self.private_group_id, message_text)
expected_message = self.get_message_by_content_type(response, content_type=MessageContentType.TEXT_PLAIN.value)[0]
sent_messages.append(expected_message)
sleep(0.01)

for _, expected_message in enumerate(sent_messages):
messages_new_event = self.receiver.find_signal_containing_pattern(
SignalType.MESSAGES_NEW.value,
event_pattern=expected_message.get("id"),
timeout=60,
)
self.validate_signal_event_against_response(
signal_event=messages_new_event,
fields_to_validate={"text": "text"},
expected_message=expected_message,
)
self.private_group_message(message_count, self.private_group_id)

def test_multiple_group_chat_messages(self):
self.test_private_group_messages_baseline(message_count=50)
Expand Down
Loading

0 comments on commit 0f6bc65

Please sign in to comment.