test_: added test case for Signals via ws endpoint

This commit is contained in:
Anton 2024-09-16 10:23:57 +02:00 committed by Anton Danchenko
parent f859b58c38
commit f51d4654f6
5 changed files with 63 additions and 12 deletions

View File

@ -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",

View File

@ -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:

View File

@ -1,6 +1,9 @@
[pytest]
addopts = -s -v --tb=short --junitxml=results.xml
log_cli=true
log_level=INFO
markers =
rpc
wallet

View File

@ -2,4 +2,5 @@ deepdiff==5.5.0
jsonschema~=3.2.0
pytest==6.2.4
requests==2.31.0
genson~=1.2.2
genson~=1.2.2
websocket-client~=1.4.2

View File

@ -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()