-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
226 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
allure-pytest | ||
black | ||
docker | ||
marshmallow-dataclass | ||
pre-commit | ||
pyright | ||
pytest | ||
pytest-instafail | ||
pytest-xdist | ||
pytest-rerunfailures | ||
python-dotenv | ||
requests | ||
tenacity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
from dataclasses import dataclass | ||
from dataclasses import dataclass, field | ||
from marshmallow_dataclass import class_schema | ||
from typing import Optional | ||
|
||
|
||
@dataclass | ||
class KeyPair: | ||
privateKey: str | ||
publicKey: str | ||
|
||
|
||
@dataclass | ||
class MessageRpcQuery: | ||
payload: str # Hex encoded data string without `0x` prefix. | ||
contentTopic: Optional[str] = None | ||
timestamp: Optional[int] = None # Unix epoch time in nanoseconds as a 64-bit integer value. | ||
payload: str | ||
contentTopic: str | ||
timestamp: Optional[int] = None | ||
|
||
|
||
@dataclass | ||
class MessageRpcResponse: | ||
payload: str | ||
contentTopic: Optional[str] = None | ||
version: Optional[int] = None | ||
timestamp: Optional[int] = None # Unix epoch time in nanoseconds as a 64-bit integer value. | ||
ephemeral: Optional[bool] = None | ||
contentTopic: str | ||
version: Optional[int] | ||
timestamp: int | ||
ephemeral: Optional[bool] | ||
rateLimitProof: Optional[dict] = field(default_factory=dict) | ||
rate_limit_proof: Optional[dict] = field(default_factory=dict) | ||
|
||
|
||
message_rpc_response_schema = class_schema(MessageRpcResponse)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import os | ||
import logging | ||
from dotenv import load_dotenv | ||
|
||
logger = logging.getLogger(__name__) | ||
load_dotenv() # This will load environment variables from a .env file if it exists | ||
|
||
|
||
def get_env_var(var_name, default): | ||
def get_env_var(var_name, default=None): | ||
env_var = os.getenv(var_name, default) | ||
logger.debug(f"{var_name}: {env_var}") | ||
if env_var is not None: | ||
print(f"{var_name}: {env_var}") | ||
else: | ||
print(f"{var_name} is not set; using default value: {default}") | ||
return env_var | ||
|
||
|
||
# Configuration constants. Need to be upercase to appear in reports | ||
NODE_1 = get_env_var("NODE_1", "wakuorg/nwaku:deploy-wakuv2-test") | ||
NODE_1 = get_env_var("NODE_1", "wakuorg/nwaku:latest") | ||
NODE_2 = get_env_var("NODE_2", "wakuorg/go-waku:latest") | ||
LOG_DIR = get_env_var("LOG_DIR", "./log") | ||
NETWORK_NAME = get_env_var("NETWORK_NAME", "waku") | ||
SUBNET = get_env_var("SUBNET", "172.18.0.0/16") | ||
IP_RANGE = get_env_var("IP_RANGE", "172.18.0.0/24") | ||
GATEWAY = get_env_var("GATEWAY", "172.18.0.1") | ||
DEFAULT_PUBSUBTOPIC = get_env_var("DEFAULT_PUBSUBTOPIC", "/waku/2/default-waku/proto") | ||
PROTOCOL = get_env_var("PROTOCOL", "REST") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import logging | ||
import requests | ||
from tenacity import retry, stop_after_delay, wait_fixed | ||
from abc import ABC, abstractmethod | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class BaseClient(ABC): | ||
# The retry decorator is applied to handle transient errors gracefully. This is particularly | ||
# useful when running tests in parallel, where occasional network-related errors such as | ||
# connection drops, timeouts, or temporary unavailability of a service can occur. Retrying | ||
# ensures that such intermittent issues don't cause the tests to fail outright. | ||
@retry(stop=stop_after_delay(2), wait=wait_fixed(0.1), reraise=True) | ||
def make_request(self, method, url, headers=None, data=None): | ||
logger.debug("%s call: %s with payload: %s", method.upper(), url, data) | ||
response = requests.request(method.upper(), url, headers=headers, data=data) | ||
try: | ||
response.raise_for_status() | ||
except requests.HTTPError as http_err: | ||
logger.error("HTTP error occurred: %s", http_err) | ||
raise | ||
except Exception as err: | ||
logger.error("An error occurred: %s", err) | ||
raise | ||
else: | ||
logger.info("Response status code: %s", response.status_code) | ||
return response | ||
|
||
@abstractmethod | ||
def info(self): | ||
pass | ||
|
||
@abstractmethod | ||
def set_subscriptions(self, pubsub_topics): | ||
pass | ||
|
||
@abstractmethod | ||
def send_message(self, message, pubsub_topic): | ||
pass | ||
|
||
@abstractmethod | ||
def get_messages(self, pubsub_topic): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import logging | ||
import json | ||
from dataclasses import asdict | ||
from urllib.parse import quote | ||
from src.node.api_clients.base_client import BaseClient | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class REST(BaseClient): | ||
def __init__(self, rest_port): | ||
self._rest_port = rest_port | ||
|
||
def rest_call(self, method, endpoint, payload=None): | ||
url = f"http://127.0.0.1:{self._rest_port}/{endpoint}" | ||
headers = {"Content-Type": "application/json"} | ||
return self.make_request(method, url, headers=headers, data=payload) | ||
|
||
def info(self): | ||
info_response = self.rest_call("get", "debug/v1/info") | ||
return info_response.json() | ||
|
||
def set_subscriptions(self, pubsub_topics): | ||
return self.rest_call("post", "relay/v1/subscriptions", json.dumps(pubsub_topics)) | ||
|
||
def send_message(self, message, pubsub_topic): | ||
return self.rest_call("post", f"relay/v1/messages/{quote(pubsub_topic, safe='')}", json.dumps(asdict(message))) | ||
|
||
def get_messages(self, pubsub_topic): | ||
get_messages_response = self.rest_call("get", f"relay/v1/messages/{quote(pubsub_topic, safe='')}") | ||
return get_messages_response.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import logging | ||
import json | ||
from dataclasses import asdict | ||
from src.node.api_clients.base_client import BaseClient | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RPC(BaseClient): | ||
def __init__(self, rpc_port, image_name): | ||
self._image_name = image_name | ||
self._rpc_port = rpc_port | ||
|
||
def rpc_call(self, endpoint, params=[]): | ||
url = f"http://127.0.0.1:{self._rpc_port}" | ||
headers = {"Content-Type": "application/json"} | ||
payload = {"jsonrpc": "2.0", "method": endpoint, "params": params, "id": 1} | ||
return self.make_request("post", url, headers=headers, data=json.dumps(payload)) | ||
|
||
def info(self): | ||
info_response = self.rpc_call("get_waku_v2_debug_v1_info", []) | ||
return info_response.json()["result"] | ||
|
||
def set_subscriptions(self, pubsub_topics): | ||
if "nwaku" in self._image_name: | ||
return self.rpc_call("post_waku_v2_relay_v1_subscriptions", [pubsub_topics]) | ||
else: | ||
return self.rpc_call("post_waku_v2_relay_v1_subscription", [pubsub_topics]) | ||
|
||
def send_message(self, message, pubsub_topic): | ||
return self.rpc_call("post_waku_v2_relay_v1_message", [pubsub_topic, asdict(message)]) | ||
|
||
def get_messages(self, pubsub_topic): | ||
get_messages_response = self.rpc_call("get_waku_v2_relay_v1_messages", [pubsub_topic]) | ||
return get_messages_response.json()["result"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.