132 lines
5.7 KiB
Python
Raw Normal View History

from src.libs.custom_logger import get_custom_logger
2023-11-03 17:01:00 +02:00
import json
from urllib.parse import quote
from src.node.api_clients.base_client import BaseClient
logger = get_custom_logger(__name__)
2023-11-03 17:01:00 +02:00
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)
chore: RLN relay tests (#30) * fix: add get_multiaddr_with_id step - temporarily use local docker images * fix: discard containers used for RLN registration * fix: switch to use cluster ID 1 for RLN * test: publish at slow and spam rate * fix: shorten test data set * fix: move RLN related code into separate class * fix: use send only publish function - add spam and alternate rate tests * fix: use math.trunc instead of rounding * fix: first message without delay * fix: add one more second to messages with delay * fix: add methods to setup non default RLN nodes * fix: rewrite tests using steps rather than fixtures - prepare for non default settings for RLN * test: random epoch with valid_payloads_at_slow_rate * test: random user message limit with valid payloads * fix: skip test "random user message limit with valid payloads" * fix: mark flaky "at variable_rate with valid payloads" * fix: rename tests for easier debugging * fix: mark valid_payloads_dynamic_at_slow_rate to skip * fix: forgot to add actual file * test: valid payloads dynamic(on chain) at spam rate - extend timeout for ensure_ready() to 600s - add ensure_healthy() for future use - add text content based rest call - remove NODE1, NODE2 imports * fix: revert env_vars to source images from Harbor * fix: reuse setup first and second rln relay node for setup_main_rln_relay_nodes * fix: reuse register_rln_single_node for register_main_rln_relay_nodes * fix: start using src.steps.common - removed RLN test class inheritance from StepsRelay * fix: test using whole data set at test payloads_at_slow_rate * fix: switch to send msg and check for slow rate tests * fix: add comment for skip check at first message * fix: refactor payloads_at_variable_rate to use only one payload pattern * fix: remove the plural from payloads_at_variable_rate * fix: multiple class inheritance for TestRelayRLN * test: node1 with rln node2 without rln at spam rate * test: mixed epoch at slow rate * test: add lightpush methods * test: send valid payloads lightpush at spam rate * fix: node1 to act as light push receiving node - add setup lightpush node to spin off node2 with lightpush support * fix: use NODE1 NODE2 instead of DEFAULT_NWAKU * fix: no lightpush param required for plain RLN relay * fix: comment for lightpush * fix: comment for lightpush - wait for implementation * fix: comment on chain tests * fix: add lightpush case to publish_message * fix: remove check_light_pushed_message_reaches_receiving_peer from StepsRLN * fix: change comment for mixed_epoch_at_slow_rate * test: happy and common case with 5 nodes * fix: add all required fixtures explicitly * fix: add timeout param to ensure_ready * fix: skip RLN tests for go-waku * fix: reformated with pre-commit * fix: uncomment skip for debugging * fix: put the skip back * fix: change comment for on chain tests * fix: run RLN tests in serial - add grouping of tests to runner - use smaller dataset for spam rate tests * test: Nim to Nim workflow * test: check also additional nodes for go-waku * test: all nodes are nwaku * fix: string quotes * fix: remove additional nodes * fix: re-arrange skip conditions * test: RLN only * fix: change default additional nodes to nwaku only * fix: change additional nodes rather at top level workflow * fix: enable all tests * test: problems with current workdir * test: rln only * test: correct typo * test: re-enable all tests - remove current dir debug * fix: nwaku additional nodes for nim to nim worklfow * fix: re-able discord notification - delete test workflow * fix: add get_multiaddr_with_id step - temporarily use local docker images * fix: discard containers used for RLN registration * fix: switch to use cluster ID 1 for RLN * test: publish at slow and spam rate * fix: shorten test data set * fix: rebase onto master * fix: use send only publish function - add spam and alternate rate tests * fix: use math.trunc instead of rounding * fix: first message without delay * fix: add one more second to messages with delay * fix: add methods to setup non default RLN nodes * fix: rewrite tests using steps rather than fixtures - prepare for non default settings for RLN * test: random epoch with valid_payloads_at_slow_rate * test: random user message limit with valid payloads * fix: skip test "random user message limit with valid payloads" * fix: mark flaky "at variable_rate with valid payloads" * fix: rename tests for easier debugging * fix: mark valid_payloads_dynamic_at_slow_rate to skip * fix: forgot to add actual file * test: valid payloads dynamic(on chain) at spam rate - extend timeout for ensure_ready() to 600s - add ensure_healthy() for future use - add text content based rest call - remove NODE1, NODE2 imports * fix: revert env_vars to source images from Harbor * fix: reuse setup first and second rln relay node for setup_main_rln_relay_nodes * fix: reuse register_rln_single_node for register_main_rln_relay_nodes * fix: start using src.steps.common - removed RLN test class inheritance from StepsRelay * fix: test using whole data set at test payloads_at_slow_rate * fix: switch to send msg and check for slow rate tests * fix: add comment for skip check at first message * fix: refactor payloads_at_variable_rate to use only one payload pattern * fix: remove the plural from payloads_at_variable_rate * fix: multiple class inheritance for TestRelayRLN * test: node1 with rln node2 without rln at spam rate * test: mixed epoch at slow rate * test: add lightpush methods * test: send valid payloads lightpush at spam rate * fix: node1 to act as light push receiving node - add setup lightpush node to spin off node2 with lightpush support * fix: use NODE1 NODE2 instead of DEFAULT_NWAKU * fix: no lightpush param required for plain RLN relay * fix: comment for lightpush * fix: comment for lightpush - wait for implementation * fix: comment on chain tests * fix: add lightpush case to publish_message * fix: remove check_light_pushed_message_reaches_receiving_peer from StepsRLN * fix: change comment for mixed_epoch_at_slow_rate * test: happy and common case with 5 nodes * fix: add all required fixtures explicitly * fix: add timeout param to ensure_ready * fix: skip RLN tests for go-waku * fix: uncomment skip for debugging * fix: put the skip back * fix: change comment for on chain tests * fix: run RLN tests in serial - add grouping of tests to runner - use smaller dataset for spam rate tests * test: Nim to Nim workflow * test: check also additional nodes for go-waku * test: all nodes are nwaku * fix: string quotes * fix: remove additional nodes * fix: re-arrange skip conditions * test: RLN only * fix: change default additional nodes to nwaku only * fix: change additional nodes rather at top level workflow * fix: enable all tests * test: problems with current workdir * test: rln only * test: correct typo * test: re-enable all tests - remove current dir debug * fix: nwaku additional nodes for nim to nim worklfow * fix: re-able discord notification - delete test workflow * test: re-test again after rebase * fix: wait longer for credential store * test: try again with Discord report off * fix: enable Discord - delete test workflow
2024-05-07 08:31:12 +08:00
def rest_call_text(self, method, endpoint, payload=None):
url = f"http://127.0.0.1:{self._rest_port}/{endpoint}"
headers = {"accept": "text/plain"}
return self.make_request(method, url, headers=headers, data=payload)
2023-11-03 17:01:00 +02:00
def info(self):
info_response = self.rest_call("get", "debug/v1/info")
return info_response.json()
chore: RLN relay tests (#30) * fix: add get_multiaddr_with_id step - temporarily use local docker images * fix: discard containers used for RLN registration * fix: switch to use cluster ID 1 for RLN * test: publish at slow and spam rate * fix: shorten test data set * fix: move RLN related code into separate class * fix: use send only publish function - add spam and alternate rate tests * fix: use math.trunc instead of rounding * fix: first message without delay * fix: add one more second to messages with delay * fix: add methods to setup non default RLN nodes * fix: rewrite tests using steps rather than fixtures - prepare for non default settings for RLN * test: random epoch with valid_payloads_at_slow_rate * test: random user message limit with valid payloads * fix: skip test "random user message limit with valid payloads" * fix: mark flaky "at variable_rate with valid payloads" * fix: rename tests for easier debugging * fix: mark valid_payloads_dynamic_at_slow_rate to skip * fix: forgot to add actual file * test: valid payloads dynamic(on chain) at spam rate - extend timeout for ensure_ready() to 600s - add ensure_healthy() for future use - add text content based rest call - remove NODE1, NODE2 imports * fix: revert env_vars to source images from Harbor * fix: reuse setup first and second rln relay node for setup_main_rln_relay_nodes * fix: reuse register_rln_single_node for register_main_rln_relay_nodes * fix: start using src.steps.common - removed RLN test class inheritance from StepsRelay * fix: test using whole data set at test payloads_at_slow_rate * fix: switch to send msg and check for slow rate tests * fix: add comment for skip check at first message * fix: refactor payloads_at_variable_rate to use only one payload pattern * fix: remove the plural from payloads_at_variable_rate * fix: multiple class inheritance for TestRelayRLN * test: node1 with rln node2 without rln at spam rate * test: mixed epoch at slow rate * test: add lightpush methods * test: send valid payloads lightpush at spam rate * fix: node1 to act as light push receiving node - add setup lightpush node to spin off node2 with lightpush support * fix: use NODE1 NODE2 instead of DEFAULT_NWAKU * fix: no lightpush param required for plain RLN relay * fix: comment for lightpush * fix: comment for lightpush - wait for implementation * fix: comment on chain tests * fix: add lightpush case to publish_message * fix: remove check_light_pushed_message_reaches_receiving_peer from StepsRLN * fix: change comment for mixed_epoch_at_slow_rate * test: happy and common case with 5 nodes * fix: add all required fixtures explicitly * fix: add timeout param to ensure_ready * fix: skip RLN tests for go-waku * fix: reformated with pre-commit * fix: uncomment skip for debugging * fix: put the skip back * fix: change comment for on chain tests * fix: run RLN tests in serial - add grouping of tests to runner - use smaller dataset for spam rate tests * test: Nim to Nim workflow * test: check also additional nodes for go-waku * test: all nodes are nwaku * fix: string quotes * fix: remove additional nodes * fix: re-arrange skip conditions * test: RLN only * fix: change default additional nodes to nwaku only * fix: change additional nodes rather at top level workflow * fix: enable all tests * test: problems with current workdir * test: rln only * test: correct typo * test: re-enable all tests - remove current dir debug * fix: nwaku additional nodes for nim to nim worklfow * fix: re-able discord notification - delete test workflow * fix: add get_multiaddr_with_id step - temporarily use local docker images * fix: discard containers used for RLN registration * fix: switch to use cluster ID 1 for RLN * test: publish at slow and spam rate * fix: shorten test data set * fix: rebase onto master * fix: use send only publish function - add spam and alternate rate tests * fix: use math.trunc instead of rounding * fix: first message without delay * fix: add one more second to messages with delay * fix: add methods to setup non default RLN nodes * fix: rewrite tests using steps rather than fixtures - prepare for non default settings for RLN * test: random epoch with valid_payloads_at_slow_rate * test: random user message limit with valid payloads * fix: skip test "random user message limit with valid payloads" * fix: mark flaky "at variable_rate with valid payloads" * fix: rename tests for easier debugging * fix: mark valid_payloads_dynamic_at_slow_rate to skip * fix: forgot to add actual file * test: valid payloads dynamic(on chain) at spam rate - extend timeout for ensure_ready() to 600s - add ensure_healthy() for future use - add text content based rest call - remove NODE1, NODE2 imports * fix: revert env_vars to source images from Harbor * fix: reuse setup first and second rln relay node for setup_main_rln_relay_nodes * fix: reuse register_rln_single_node for register_main_rln_relay_nodes * fix: start using src.steps.common - removed RLN test class inheritance from StepsRelay * fix: test using whole data set at test payloads_at_slow_rate * fix: switch to send msg and check for slow rate tests * fix: add comment for skip check at first message * fix: refactor payloads_at_variable_rate to use only one payload pattern * fix: remove the plural from payloads_at_variable_rate * fix: multiple class inheritance for TestRelayRLN * test: node1 with rln node2 without rln at spam rate * test: mixed epoch at slow rate * test: add lightpush methods * test: send valid payloads lightpush at spam rate * fix: node1 to act as light push receiving node - add setup lightpush node to spin off node2 with lightpush support * fix: use NODE1 NODE2 instead of DEFAULT_NWAKU * fix: no lightpush param required for plain RLN relay * fix: comment for lightpush * fix: comment for lightpush - wait for implementation * fix: comment on chain tests * fix: add lightpush case to publish_message * fix: remove check_light_pushed_message_reaches_receiving_peer from StepsRLN * fix: change comment for mixed_epoch_at_slow_rate * test: happy and common case with 5 nodes * fix: add all required fixtures explicitly * fix: add timeout param to ensure_ready * fix: skip RLN tests for go-waku * fix: uncomment skip for debugging * fix: put the skip back * fix: change comment for on chain tests * fix: run RLN tests in serial - add grouping of tests to runner - use smaller dataset for spam rate tests * test: Nim to Nim workflow * test: check also additional nodes for go-waku * test: all nodes are nwaku * fix: string quotes * fix: remove additional nodes * fix: re-arrange skip conditions * test: RLN only * fix: change default additional nodes to nwaku only * fix: change additional nodes rather at top level workflow * fix: enable all tests * test: problems with current workdir * test: rln only * test: correct typo * test: re-enable all tests - remove current dir debug * fix: nwaku additional nodes for nim to nim worklfow * fix: re-able discord notification - delete test workflow * test: re-test again after rebase * fix: wait longer for credential store * test: try again with Discord report off * fix: enable Discord - delete test workflow
2024-05-07 08:31:12 +08:00
def health(self):
health_response = self.rest_call_text("get", "health")
return health_response.text()
def get_peers(self):
get_peers_response = self.rest_call("get", "admin/v1/peers")
return get_peers_response.json()
def add_peers(self, peers):
return self.rest_call("post", "admin/v1/peers", json.dumps(peers))
def set_relay_subscriptions(self, pubsub_topics):
2023-11-03 17:01:00 +02:00
return self.rest_call("post", "relay/v1/subscriptions", json.dumps(pubsub_topics))
def set_relay_auto_subscriptions(self, content_topics):
return self.rest_call("post", "relay/v1/auto/subscriptions", json.dumps(content_topics))
def delete_relay_subscriptions(self, pubsub_topics):
return self.rest_call("delete", "relay/v1/subscriptions", json.dumps(pubsub_topics))
def delete_relay_auto_subscriptions(self, content_topics):
return self.rest_call("delete", "relay/v1/auto/subscriptions", json.dumps(content_topics))
def send_relay_message(self, message, pubsub_topic):
return self.rest_call("post", f"relay/v1/messages/{quote(pubsub_topic, safe='')}", json.dumps(message))
2023-11-03 17:01:00 +02:00
def send_relay_auto_message(self, message):
return self.rest_call("post", "relay/v1/auto/messages", json.dumps(message))
def send_light_push_message(self, payload):
return self.rest_call("post", "lightpush/v1/message", json.dumps(payload))
def get_relay_messages(self, pubsub_topic):
2023-11-03 17:01:00 +02:00
get_messages_response = self.rest_call("get", f"relay/v1/messages/{quote(pubsub_topic, safe='')}")
return get_messages_response.json()
def get_relay_auto_messages(self, content_topic):
get_messages_response = self.rest_call("get", f"relay/v1/auto/messages/{quote(content_topic, safe='')}")
return get_messages_response.json()
def set_filter_subscriptions(self, subscription):
set_subscriptions_response = self.rest_call("post", "filter/v2/subscriptions", json.dumps(subscription))
return set_subscriptions_response.json()
def update_filter_subscriptions(self, subscription):
update_subscriptions_response = self.rest_call("put", "filter/v2/subscriptions", json.dumps(subscription))
return update_subscriptions_response.json()
def delete_filter_subscriptions(self, subscription):
delete_subscriptions_response = self.rest_call("delete", "filter/v2/subscriptions", json.dumps(subscription))
return delete_subscriptions_response.json()
def delete_all_filter_subscriptions(self, request_id):
delete_all_subscriptions_response = self.rest_call("delete", "filter/v2/subscriptions/all", json.dumps(request_id))
return delete_all_subscriptions_response.json()
def ping_filter_subscriptions(self, request_id):
ping_subscriptions_response = self.rest_call("get", f"filter/v2/subscriptions/{quote(request_id, safe='')}")
return ping_subscriptions_response.json()
def get_filter_messages(self, content_topic, pubsub_topic=None):
if pubsub_topic is not None:
endpoint = f"filter/v2/messages/{quote(pubsub_topic, safe='')}/{quote(content_topic, safe='')}"
else:
endpoint = f"filter/v2/messages/{quote(content_topic, safe='')}"
get_messages_response = self.rest_call("get", endpoint)
return get_messages_response.json()
def get_store_messages(
self, peerAddr, includeData, pubsubTopic, contentTopics, startTime, endTime, hashes, cursor, pageSize, ascending, store_v, **kwargs
):
base_url = f"store/{store_v}/messages"
params = []
if peerAddr is not None:
params.append(f"peerAddr={quote(peerAddr, safe='')}")
if includeData is not None:
params.append(f"includeData={includeData}")
if pubsubTopic is not None:
params.append(f"pubsubTopic={quote(pubsubTopic, safe='')}")
if contentTopics is not None:
params.append(f"contentTopics={quote(contentTopics, safe='')}")
if startTime is not None:
params.append(f"startTime={startTime}")
if endTime is not None:
params.append(f"endTime={endTime}")
if hashes is not None:
params.append(f"hashes={quote(hashes, safe='')}")
if cursor is not None:
params.append(f"cursor={quote(cursor, safe='')}")
if pageSize is not None:
params.append(f"pageSize={pageSize}")
if ascending is not None:
params.append(f"ascending={ascending}")
# Append any additional keyword arguments to the parameters list
for key, value in kwargs.items():
if value is not None:
params.append(f"{key}={quote(str(value), safe='')}")
if params:
base_url += "?" + "&".join(params)
get_messages_response = self.rest_call("get", base_url)
return get_messages_response.json()