remove deprecated RPC client/protocol (#11)

* remove deprecated RPC client/protocol

* small fixes

* revert base client
This commit is contained in:
Florin Barbu 2024-01-08 10:32:56 +02:00 committed by GitHub
parent d1e624e2e0
commit 5b7045ace8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 115 deletions

View File

@ -27,21 +27,12 @@ on:
description: "Additional optional nodes used in e2e tests, separated by ,"
type: string
default: "harbor.status.im/wakuorg/nwaku:latest,harbor.status.im/wakuorg/go-waku:latest,harbor.status.im/wakuorg/nwaku:latest"
protocol:
description: "Protocol used to comunicate inside the network"
required: true
type: choice
default: "REST"
options:
- "REST"
- "RPC"
env:
FORCE_COLOR: "1"
NODE_1: ${{ inputs.node1 }}
NODE_2: ${{ inputs.node2 }}
ADDITIONAL_NODES: ${{ inputs.additional_nodes }}
PROTOCOL: ${{ inputs.protocol || 'REST' }}
jobs:
@ -95,6 +86,5 @@ jobs:
echo "- **Node1**: ${{ env.NODE_1 }}" >> $GITHUB_STEP_SUMMARY
echo "- **Node2**: ${{ env.NODE_2}}" >> $GITHUB_STEP_SUMMARY
echo "- **Additonal Nodes**: ${{ env.ADDITIONAL_NODES}}" >> $GITHUB_STEP_SUMMARY
echo "- **Protocol**: ${{ env.PROTOCOL }}" >> $GITHUB_STEP_SUMMARY
echo "## Test Results" >> $GITHUB_STEP_SUMMARY
echo "Allure report will be available at: https://waku-org.github.io/waku-interop-tests/${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY

View File

@ -26,7 +26,6 @@ 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_PUBSUB_TOPIC = get_env_var("DEFAULT_PUBSUB_TOPIC", "/waku/2/default-waku/proto")
PROTOCOL = get_env_var("PROTOCOL", "REST")
RUNNING_IN_CI = get_env_var("CI")
NODEKEY = get_env_var("NODEKEY", "30348dd51465150e04a5d9d932c72864c8967f806cce60b5d26afeca1e77eb68")
API_REQUEST_TIMEOUT = get_env_var("API_REQUEST_TIMEOUT", 10)

View File

@ -1,65 +0,0 @@
from src.libs.custom_logger import get_custom_logger
import json
from dataclasses import asdict
from src.node.api_clients.base_client import BaseClient
logger = get_custom_logger(__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_relay_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 delete_relay_subscriptions(self, pubsub_topics):
if "nwaku" in self._image_name:
return self.rpc_call("delete_waku_v2_relay_v1_subscriptions", [pubsub_topics])
else:
return self.rpc_call("delete_waku_v2_relay_v1_subscription", [pubsub_topics])
def send_relay_message(self, message, pubsub_topic):
return self.rpc_call("post_waku_v2_relay_v1_message", [pubsub_topic, message])
def get_relay_messages(self, pubsub_topic):
get_messages_response = self.rpc_call("get_waku_v2_relay_v1_messages", [pubsub_topic])
return get_messages_response.json()["result"]
def set_filter_subscriptions(self, subscription):
set_subscriptions_response = self.rpc_call(
"post_waku_v2_filter_v1_subscription",
[
subscription.get("contentFilters", []),
subscription.get("pubsubTopic", None),
],
)
return set_subscriptions_response.json()["result"]
def delete_filter_subscriptions(self, subscription):
delete_subscriptions_response = self.rpc_call(
"delete_waku_v2_filter_v1_subscription",
[
subscription.get("contentFilters", []),
subscription.get("pubsubTopic", None),
],
)
return delete_subscriptions_response.json()["result"]
def get_filter_messages(self, content_topic):
get_messages_response = self.rpc_call("get_waku_v2_filter_v1_messages", [content_topic])
return get_messages_response.json()["result"]

View File

@ -59,10 +59,10 @@ class DockerManager:
for chunk in container.logs(stream=True):
log_file.write(chunk)
def generate_ports(self, base_port=None, count=6):
def generate_ports(self, base_port=None, count=5):
if base_port is None:
base_port = random.randint(1024, 65535 - count)
ports = [base_port + i for i in range(count)]
ports = [str(base_port + i) for i in range(count)]
logger.debug(f"Generated ports {ports}")
return ports

View File

@ -4,10 +4,9 @@ import requests
from src.libs.common import delay
from src.libs.custom_logger import get_custom_logger
from tenacity import retry, stop_after_delay, wait_fixed
from src.node.api_clients.rpc import RPC
from src.node.api_clients.rest import REST
from src.node.docker_mananger import DockerManager
from src.env_vars import DOCKER_LOG_DIR, PROTOCOL
from src.env_vars import DOCKER_LOG_DIR
from src.data_storage import DS
logger = get_custom_logger(__name__)
@ -28,33 +27,23 @@ class WakuNode:
self._ext_ip = self._docker_manager.generate_random_ext_ip()
self._ports = self._docker_manager.generate_ports()
self._rest_port = self._ports[0]
self._rpc_port = self._ports[1]
self._tcp_port = self._ports[2]
self._websocket_port = self._ports[3]
self._metrics_port = self._ports[5]
if PROTOCOL == "RPC":
self._api = RPC(self._rpc_port, self._image_name)
elif PROTOCOL == "REST":
self._api = REST(self._rest_port)
else:
raise ValueError(f"Unknown protocol: {PROTOCOL}")
self._tcp_port = self._ports[1]
self._websocket_port = self._ports[2]
self._discv5_port = self._ports[3]
self._metrics_port = self._ports[4]
self._api = REST(self._rest_port)
default_args = {
"listen-address": "0.0.0.0",
"rpc": "true",
"rpc-admin": "true",
"rest": "true",
"rest-admin": "true",
"websocket-support": "true",
"log-level": "TRACE",
"rest-relay-cache-capacity": "100",
"websocket-port": str(self._ports[3]),
"rpc-port": self._rpc_port,
"websocket-port": self._websocket_port,
"rest-port": self._rest_port,
"tcp-port": str(self._ports[2]),
"discv5-udp-port": str(self._ports[4]),
"rpc-address": "0.0.0.0",
"tcp-port": self._tcp_port,
"discv5-udp-port": self._discv5_port,
"rest-address": "0.0.0.0",
"nat": f"extip:{self._ext_ip}",
"peer-exchange": "true",
@ -86,15 +75,13 @@ class WakuNode:
default_args[key] = value
self._container = self._docker_manager.start_container(self._docker_manager.image, self._ports, default_args, self._log_path, self._ext_ip)
logger.debug(
f"Started container from image {self._image_name}. RPC: {self._rpc_port} REST: {self._rest_port} WebSocket: {self._websocket_port} TCP: {self._tcp_port}"
)
logger.debug(f"Started container from image {self._image_name}. REST: {self._rest_port}")
DS.waku_nodes.append(self)
delay(1) # if we fire requests to soon after starting the node will sometimes fail to start correctly
try:
self.ensure_ready()
except Exception as ex:
logger.error(f"{PROTOCOL} service did not become ready in time: {ex}")
logger.error(f"REST service did not become ready in time: {ex}")
raise
@retry(stop=stop_after_delay(5), wait=wait_fixed(0.1), reraise=True)
@ -123,7 +110,7 @@ class WakuNode:
@retry(stop=stop_after_delay(10), wait=wait_fixed(0.1), reraise=True)
def ensure_ready(self):
self.info_response = self.info()
logger.info(f"{PROTOCOL} service is ready !!")
logger.info("REST service is ready !!")
def get_enr_uri(self):
try:
@ -160,25 +147,16 @@ class WakuNode:
return self._api.set_filter_subscriptions(subscription)
def update_filter_subscriptions(self, subscription):
if PROTOCOL == "RPC":
pytest.skip("This method doesn't exist for RPC protocol")
else:
return self._api.update_filter_subscriptions(subscription)
return self._api.update_filter_subscriptions(subscription)
def delete_filter_subscriptions(self, subscription):
return self._api.delete_filter_subscriptions(subscription)
def delete_all_filter_subscriptions(self, request_id):
if PROTOCOL == "RPC":
pytest.skip("This method doesn't exist for RPC protocol")
else:
return self._api.delete_all_filter_subscriptions(request_id)
return self._api.delete_all_filter_subscriptions(request_id)
def ping_filter_subscriptions(self, request_id):
if PROTOCOL == "RPC":
pytest.skip("This method doesn't exist for RPC protocol")
else:
return self._api.ping_filter_subscriptions(request_id)
return self._api.ping_filter_subscriptions(request_id)
def get_filter_messages(self, content_topic, pubsub_topic=None):
return self._api.get_filter_messages(content_topic, pubsub_topic)