diff --git a/src/test_data.py b/src/test_data.py index d89e52db9..2c1c6946b 100644 --- a/src/test_data.py +++ b/src/test_data.py @@ -1,3 +1,4 @@ +import os from time import time from datetime import datetime, timedelta @@ -150,50 +151,36 @@ PUBSUB_TOPICS_WRONG_FORMAT = [ {"description": "A bool", "value": True}, ] -SAMPLE_TIMESTAMPS = [ - {"description": "Now", "value": int(time() * 1e9), "valid_for": ["nwaku"]}, - { - "description": "Far future", - "value": int((NOW + timedelta(days=365 * 10)).timestamp() * 1e9), - "valid_for": ["nwaku"], - }, # 10 years from now - {"description": "Recent past", "value": int((NOW - timedelta(hours=1)).timestamp() * 1e9), "valid_for": ["nwaku"]}, # 1 hour ago - {"description": "Near future", "value": int((NOW + timedelta(hours=1)).timestamp() * 1e9), "valid_for": ["nwaku"]}, # 1 hour ahead - {"description": "Positive number", "value": 1, "valid_for": ["nwaku"]}, - {"description": "Negative number", "value": -1, "valid_for": ["nwaku"]}, - {"description": "DST change", "value": int(datetime(2020, 3, 8, 2, 0, 0).timestamp() * 1e9), "valid_for": ["nwaku"]}, # DST starts - {"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": []}, - {"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": []}, - {"description": "Missing", "value": None, "valid_for": []}, -] - def get_sample_timestamps(): """Return timestamp test-cases with values evaluated fresh at call time. This factory function MUST be called from inside each test (never at module - import time) so that the "Now" value maps to the active RLN epoch when the - message is actually published. + import time) so that the "Now" value reflects the actual time when the + message is published. Valid_for semantics: - ``["nwaku"]`` – accepted by nwaku in both standalone and fleet (RLN) mode. - ``[]`` – rejected by nwaku in fleet (RLN) mode; kept for completeness - and for use by the companion invalid-timestamp tests. + ``["nwaku"]`` – accepted by nwaku in the current run mode. + ``[]`` – rejected by nwaku in the current run mode (either + structurally invalid type, or out-of-epoch in fleet/RLN + mode). """ now_ns = int(time() * 1e9) now_dt = datetime.now() + fleet_mode = os.getenv("FLEET_BOOTSTRAP", "false").lower() == "true" + standalone_valid = [] if fleet_mode else ["nwaku"] return [ {"description": "Now", "value": now_ns, "valid_for": ["nwaku"]}, - {"description": "Far future", "value": int((now_dt + timedelta(days=365 * 10)).timestamp() * 1e9), "valid_for": []}, - {"description": "Recent past", "value": int((now_dt - timedelta(hours=1)).timestamp() * 1e9), "valid_for": []}, - {"description": "Near future", "value": int((now_dt + timedelta(hours=1)).timestamp() * 1e9), "valid_for": []}, - {"description": "Positive number", "value": 1, "valid_for": []}, - {"description": "Negative number", "value": -1, "valid_for": []}, - {"description": "DST change", "value": int(datetime(2020, 3, 8, 2, 0, 0).timestamp() * 1e9), "valid_for": []}, + # 10 years from now + {"description": "Far future", "value": int((now_dt + timedelta(days=365 * 10)).timestamp() * 1e9), "valid_for": standalone_valid}, + # 1 hour ago + {"description": "Recent past", "value": int((now_dt - timedelta(hours=1)).timestamp() * 1e9), "valid_for": standalone_valid}, + # 1 hour ahead + {"description": "Near future", "value": int((now_dt + timedelta(hours=1)).timestamp() * 1e9), "valid_for": standalone_valid}, + {"description": "Positive number", "value": 1, "valid_for": standalone_valid}, + {"description": "Negative number", "value": -1, "valid_for": standalone_valid}, + # DST starts + {"description": "DST change", "value": int(datetime(2020, 3, 8, 2, 0, 0).timestamp() * 1e9), "valid_for": standalone_valid}, {"description": "Timestamp as string number", "value": str(now_ns), "valid_for": []}, {"description": "Invalid large number", "value": 2**63, "valid_for": []}, {"description": "Float number", "value": float(now_ns), "valid_for": []}, diff --git a/tests/conftest.py b/tests/conftest.py index e3f233ca7..28f87dd73 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -116,6 +116,8 @@ def configure_fleet_bootstrap(request, fleet_rln_state): yield return + os.environ["FLEET_BOOTSTRAP"] = "true" + from src.node.fleet_waku_node import FleetBootstrapConfig from src.node.waku_node import WakuNode diff --git a/tests/filter/test_get_messages.py b/tests/filter/test_get_messages.py index 00e348ff1..89df2ff7e 100644 --- a/tests/filter/test_get_messages.py +++ b/tests/filter/test_get_messages.py @@ -2,7 +2,7 @@ import pytest from src.env_vars import NODE_1, NODE_2 from src.libs.common import delay, to_base64 from src.libs.custom_logger import get_custom_logger -from src.test_data import SAMPLE_INPUTS, SAMPLE_TIMESTAMPS, get_sample_timestamps +from src.test_data import SAMPLE_INPUTS, get_sample_timestamps from src.steps.filter import StepsFilter logger = get_custom_logger(__name__) diff --git a/tests/light_push/test_publish.py b/tests/light_push/test_publish.py index fb404e7d0..5e90b4edc 100644 --- a/tests/light_push/test_publish.py +++ b/tests/light_push/test_publish.py @@ -9,7 +9,6 @@ from src.test_data import ( INVALID_PAYLOADS, PUBSUB_TOPICS_WRONG_FORMAT, SAMPLE_INPUTS, - SAMPLE_TIMESTAMPS, VALID_PUBSUB_TOPICS, get_sample_timestamps, ) @@ -177,7 +176,7 @@ class TestLightPushPublish(StepsLightPush): def test_light_push_with_invalid_timestamps(self): success_timestamps = [] - for timestamp in SAMPLE_TIMESTAMPS: + for timestamp in get_sample_timestamps(): if self.light_push_node1.type() not in timestamp["valid_for"]: logger.debug(f'Running test with timestamp {timestamp["description"]}') message = self.create_message(timestamp=timestamp["value"]) diff --git a/tests/relay/test_publish.py b/tests/relay/test_publish.py index f1f432117..d61ea1dbd 100644 --- a/tests/relay/test_publish.py +++ b/tests/relay/test_publish.py @@ -4,7 +4,7 @@ from src.libs.custom_logger import get_custom_logger from time import time from src.libs.common import delay, to_base64 from src.steps.relay import StepsRelay -from src.test_data import INVALID_CONTENT_TOPICS, INVALID_PAYLOADS, SAMPLE_INPUTS, SAMPLE_TIMESTAMPS, VALID_PUBSUB_TOPICS, get_sample_timestamps +from src.test_data import INVALID_CONTENT_TOPICS, INVALID_PAYLOADS, SAMPLE_INPUTS, VALID_PUBSUB_TOPICS, get_sample_timestamps from src.node.waku_message import WakuMessage logger = get_custom_logger(__name__) @@ -138,7 +138,7 @@ class TestRelayPublish(StepsRelay): def test_publish_with_invalid_timestamps(self): success_timestamps = [] - for timestamp in SAMPLE_TIMESTAMPS: + for timestamp in get_sample_timestamps(): if self.node1.type() not in timestamp["valid_for"]: logger.debug(f'Running test with timestamp {timestamp["description"]}') message = self.create_message(timestamp=timestamp["value"])