new tests

This commit is contained in:
fbarbu15 2023-11-13 19:09:48 +02:00
parent aab1a6b63f
commit aee2128b7e
No known key found for this signature in database
GPG Key ID: D75221C8DEA22501
4 changed files with 34 additions and 24 deletions

View File

@ -89,7 +89,7 @@ class WakuNode:
@retry(stop=stop_after_delay(10), wait=wait_fixed(0.1), reraise=True)
def ensure_ready(self):
self.info()
logger.debug("RPC service is ready.")
logger.info("%s service is ready !!", PROTOCOL)
def info(self):
return self._api.info()

View File

@ -33,6 +33,7 @@ class StepsRelay:
message = {"payload": to_base64(self.test_payload), "contentTopic": self.test_content_topic, "timestamp": int(time() * 1e9)}
try:
self.check_published_message_reaches_peer(message)
logger.info("WARM UP successful !!")
except Exception as ex:
raise Exception(f"WARM UP FAILED WITH: {ex}")
@ -51,7 +52,7 @@ class StepsRelay:
def assert_received_message(self, sent_message, received_message):
def assert_fail_message(field_name):
return f"Incorrect {field_name}. Published {sent_message[field_name]} Received {getattr(received_message, field_name)}"
return f"Incorrect field: {field_name}. Published: {sent_message[field_name]} Received: {getattr(received_message, field_name)}"
assert (
received_message.payload == sent_message["payload"]
@ -68,3 +69,7 @@ class StepsRelay:
assert str(received_message.version) == str(sent_message["version"]), assert_fail_message("version")
if "meta" in sent_message and sent_message["meta"]:
assert str(received_message.meta) == str(sent_message["meta"]), assert_fail_message("meta")
if "ephemeral" in sent_message and sent_message["ephemeral"]:
assert str(received_message.ephemeral) == str(sent_message["ephemeral"]), assert_fail_message("ephemeral")
if "rateLimitProof" in sent_message and sent_message["rateLimitProof"]:
assert str(received_message.rateLimitProof) == str(sent_message["rateLimitProof"]), assert_fail_message("rateLimitProof")

View File

@ -76,9 +76,9 @@ SAMPLE_TIMESTAMPS = [
{"description": "Positive number", "value": 1, "valid_for": ["nwaku", "gowaku"]},
{"description": "Negative number", "value": -1, "valid_for": ["nwaku", "gowaku"]},
{"description": "DST change", "value": int(datetime(2020, 3, 8, 2, 0, 0).timestamp() * 1e9), "valid_for": ["nwaku", "gowaku"]}, # DST starts
{"description": "Timestamp as string number", "value": str(int(time() * 1e9)), "valid_for": ["gowaku"]},
{"description": "Timestamp as string number", "value": str(int(time() * 1e9)), "valid_for": []},
{"description": "Invalid large number", "value": 2**63, "valid_for": []},
{"description": "Float number", "value": float(time() * 1e9), "valid_for": ["gowaku"]},
{"description": "Float number", "value": float(time() * 1e9), "valid_for": []},
{"description": "Array instead of timestamp", "value": [int(time() * 1e9)], "valid_for": []},
{"description": "Object instead of timestamp", "value": {"time": int(time() * 1e9)}, "valid_for": []},
{"description": "ISO 8601 timestamp", "value": "2023-12-26T10:58:51", "valid_for": []},

View File

@ -29,7 +29,7 @@ class TestRelayPublish(StepsRelay):
self.node1.send_message(message, self.test_pubsub_topic)
success_payloads.append(payload)
except Exception as ex:
assert "Bad Request" in str(ex)
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)
assert not success_payloads, f"Invalid Payloads that didn't failed: {success_payloads}"
def test_publish_with_missing_payload(self):
@ -38,12 +38,7 @@ class TestRelayPublish(StepsRelay):
self.node1.send_message(message, self.test_pubsub_topic)
raise AssertionError("Publish with missing payload worked!!!")
except Exception as ex:
if self.node1.is_nwaku():
assert "Bad Request" in str(ex)
elif self.node1.is_gowaku():
assert "Internal Server Error" in str(ex)
else:
raise Exception("Not implemented")
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)
def test_publish_with_payload_less_than_one_mb(self):
payload_length = 1024 * 1023
@ -83,7 +78,7 @@ class TestRelayPublish(StepsRelay):
self.node1.send_message(message, self.test_pubsub_topic)
success_content_topics.append(content_topic)
except Exception as ex:
assert "Bad Request" in str(ex)
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)
assert not success_content_topics, f"Invalid Content topics that didn't failed: {success_content_topics}"
def test_publish_with_missing_content_topic(self):
@ -92,24 +87,14 @@ class TestRelayPublish(StepsRelay):
self.node1.send_message(message, self.test_pubsub_topic)
raise AssertionError("Publish with missing content_topic worked!!!")
except Exception as ex:
if self.node1.is_nwaku():
assert "Bad Request" in str(ex)
elif self.node1.is_gowaku():
assert "Internal Server Error" in str(ex)
else:
raise Exception("Not implemented")
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)
def test_publish_on_unsubscribed_pubsub_topic(self):
try:
self.check_published_message_reaches_peer(self.test_message, pubsub_topic="/waku/2/rs/19/1")
raise AssertionError("Publish on unsubscribed pubsub_topic worked!!!")
except Exception as ex:
if self.node1.is_nwaku():
assert "Bad Request" in str(ex)
elif self.node1.is_gowaku():
assert "Internal Server Error" in str(ex)
else:
raise Exception("Not implemented")
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)
def test_publish_with_valid_timestamps(self):
failed_timestamps = []
@ -165,6 +150,26 @@ class TestRelayPublish(StepsRelay):
except Exception as ex:
assert "Bad Request" in str(ex)
def test_publish_with_rate_limit_proof(self):
self.test_message["rateLimitProof"] = {
"proof": to_base64("proofData"),
"epoch": to_base64("epochData"),
"nullifier": to_base64("nullifierData"),
}
self.check_published_message_reaches_peer(self.test_message)
def test_publish_with_ephemeral(self):
failed_ephemeral = []
for ephemeral in [True, False]:
logger.debug("Running test with Ephemeral %s", ephemeral)
self.test_message["ephemeral"] = ephemeral
try:
self.check_published_message_reaches_peer(self.test_message)
except Exception as e:
logger.error("Massage with Ephemeral %s failed: %s", ephemeral, str(e))
failed_ephemeral.append(ephemeral)
assert not failed_ephemeral, f"Ephemeral that failed: {failed_ephemeral}"
def test_publish_and_retrieve_duplicate_message(self):
self.check_published_message_reaches_peer(self.test_message)
try: