From f51d4654f637bed3d8e09cb61c72ff2e52038656 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 16 Sep 2024 10:23:57 +0200 Subject: [PATCH] test_: added test case for Signals via ws endpoint --- integration-tests/conftest.py | 7 ++- .../docker-compose.test.status-go.yml | 15 +++--- integration-tests/pytest.ini | 3 ++ integration-tests/requirements.txt | 3 +- integration-tests/tests/test_cases.py | 47 +++++++++++++++++-- 5 files changed, 63 insertions(+), 12 deletions(-) diff --git a/integration-tests/conftest.py b/integration-tests/conftest.py index d22eb4f8e..ec58edf3d 100644 --- a/integration-tests/conftest.py +++ b/integration-tests/conftest.py @@ -15,7 +15,12 @@ def pytest_addoption(parser): help="", default="http://0.0.0.0:3334", ) - + parser.addoption( + "--ws_url", + action="store", + help="", + default="ws://0.0.0.0:8354", + ) parser.addoption( "--password", action="store", diff --git a/integration-tests/docker-compose.test.status-go.yml b/integration-tests/docker-compose.test.status-go.yml index 680b0b05c..8ec96b268 100644 --- a/integration-tests/docker-compose.test.status-go.yml +++ b/integration-tests/docker-compose.test.status-go.yml @@ -7,9 +7,10 @@ services: build_tags: gowaku_no_rln build_target: statusd build_flags: -ldflags="-X github.com/status-im/status-go/params.Version= -X github.com/status-im/status-go/params.GitCommit=11f83780d -X github.com/status-im/status-go/params.IpfsGatewayURL=https://ipfs.status.im/ -X github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/metrics.EnabledStr=true" - entrypoint: ["statusd", "-c", "/static/configs/config.json", "--seed-phrase=test test test test test test test test test test test junk", "--password=Strong12345"] - ports: - - 3333:3333 + entrypoint: ["statusd", "-c", "/static/configs/config.json", "--server=0.0.0.0:8354", "--seed-phrase=test test test test test test test test test test test junk", "--password=Strong12345"] + # ports: + # - 3333:3333 + # - 8354:8354 # use for local debbuging only healthcheck: test: ["CMD-SHELL", "curl -X POST --data '{\"jsonrpc\":\"2.0\",\"method\":\"net_version\",\"params\":[],\"id\":1}' -H 'Content-Type: application/json' http://0.0.0.0:3333 || exit 1"] interval: 5s @@ -25,8 +26,8 @@ services: build_target: statusd build_flags: -ldflags="-X github.com/status-im/status-go/params.Version= -X github.com/status-im/status-go/params.GitCommit=11f83780d -X github.com/status-im/status-go/params.IpfsGatewayURL=https://ipfs.status.im/ -X github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/metrics.EnabledStr=true" entrypoint: ["statusd", "-c", "/static/configs/config.json", "--seed-phrase=test test test test test test test test test test test takoe", "--password=Strong12345"] - ports: - - 3334:3333 + # ports: + # - 3334:3333 # use for local debbuging only healthcheck: test: ["CMD-SHELL", "curl -X POST --data '{\"jsonrpc\":\"2.0\",\"method\":\"net_version\",\"params\":[],\"id\":1}' -H 'Content-Type: application/json' http://0.0.0.0:3333 || exit 1"] interval: 5s @@ -38,8 +39,8 @@ services: depends_on: status-go: condition: service_healthy - # status-go-no-funds: - # condition: service_healthy + status-go-no-funds: + condition: service_healthy deploy-communities-contracts: condition: service_completed_successfully build: diff --git a/integration-tests/pytest.ini b/integration-tests/pytest.ini index 68bb664ee..198647e22 100644 --- a/integration-tests/pytest.ini +++ b/integration-tests/pytest.ini @@ -1,6 +1,9 @@ [pytest] addopts = -s -v --tb=short --junitxml=results.xml +log_cli=true +log_level=INFO + markers = rpc wallet diff --git a/integration-tests/requirements.txt b/integration-tests/requirements.txt index db02b5920..6d778112d 100644 --- a/integration-tests/requirements.txt +++ b/integration-tests/requirements.txt @@ -2,4 +2,5 @@ deepdiff==5.5.0 jsonschema~=3.2.0 pytest==6.2.4 requests==2.31.0 -genson~=1.2.2 \ No newline at end of file +genson~=1.2.2 +websocket-client~=1.4.2 diff --git a/integration-tests/tests/test_cases.py b/integration-tests/tests/test_cases.py index 729b0ab37..222a2c06d 100644 --- a/integration-tests/tests/test_cases.py +++ b/integration-tests/tests/test_cases.py @@ -1,4 +1,7 @@ import json +import websocket +import threading +import logging import jsonschema import requests from conftest import option, user_1, user_2 @@ -44,7 +47,9 @@ class RpcTestCase: def verify_json_schema(self, response, method): with open(f"{option.base_dir}/schemas/{method}", "r") as schema: - jsonschema.validate(instance=response.json(), schema=json.load(schema)) + jsonschema.validate(instance=response.json(), + schema=json.load(schema)) + class TransactionTestCase(RpcTestCase): @@ -86,10 +91,46 @@ class TransactionTestCase(RpcTestCase): def setup_method(self): super().setup_method() - + response = self.wallet_create_multi_transaction() try: - self.tx_hash = response.json()["result"]["hashes"][str(self.network_id)][0] + self.tx_hash = response.json( + )["result"]["hashes"][str(self.network_id)][0] except (KeyError, json.JSONDecodeError): raise Exception(response.content) + +class SignalTestCase(RpcTestCase): + + received_signals = [] + + def _on_message(self, ws, signal): + self.received_signals.append(signal) + + def _on_error(self, ws, error): + logging.info(f"Error: {error}") + + def _on_close(self, ws, close_status_code, close_msg): + logging.info(f"Connection closed: {close_status_code}, {close_msg}") + + def _on_open(self, ws): + logging.info("Connection opened") + + def _connect(self): + self.url = f"{option.ws_url}/signals" + + ws = websocket.WebSocketApp(self.url, + on_message=self._on_message, + on_error=self._on_error, + on_close=self._on_close) + + ws.on_open = self._on_open + + ws.run_forever() + + def setup_method(self): + super().setup_method() + + websocket_thread = threading.Thread(target=self._connect) + websocket_thread.daemon = True + websocket_thread.start()