Skip to content

Commit

Permalink
Add tests for 'query slot-number'
Browse files Browse the repository at this point in the history
  • Loading branch information
saratomaz committed Jun 5, 2023
1 parent 3e2d9b7 commit f26bb35
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions cardano_node_tests/tests/test_cli.py
Expand Up @@ -4,6 +4,8 @@
import os
import string
import time
from datetime import datetime
from datetime import timezone
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -1275,3 +1277,78 @@ def test_ping_unix_socket(

last_pong = ping_data["pongs"][-1]
assert last_pong["cookie"] == count - 1, f"Expected cookie {count - 1}, got {last_pong}"


@pytest.mark.smoke
class TestQuerySlotNumber:
"""Tests for `cardano-cli query slot-number`."""

@pytest.fixture(scope="class")
def query_slot_number_available(self) -> None:
if not clusterlib_utils.cli_has("query slot-number"):
pytest.skip("CLI command `query slot-number` is not available")

@allure.link(helpers.get_vcs_link())
def test_slot_number(
self, cluster: clusterlib.ClusterLib, query_slot_number_available: None # noqa: ARG002
):
"""Test `query slot-number`."""
# pylint: disable=unused-argument
common.get_test_id(cluster)

timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")

slot_number = cluster.g_query.get_slot_number(timestamp=timestamp)

# Check that 'slot' returned is never greater than the total number of slots
tip_out = cluster.g_query.get_tip()
assert slot_number <= (tip_out["epoch"] + 1) * cluster.epoch_length - cluster.slots_offset

@allure.link(helpers.get_vcs_link())
def test_slot_number_invalid_format(
self, cluster: clusterlib.ClusterLib, query_slot_number_available: None # noqa: ARG002
):
"""Test `query slot-number` with a timestamp invalid format.
Expect failure.
"""
# pylint: disable=unused-argument
common.get_test_id(cluster)

timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT")

with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_query.get_slot_number(timestamp=timestamp)

err_str = str(excinfo.value)

assert "parseTimeOrError" in err_str, err_str

@allure.link(helpers.get_vcs_link())
@pytest.mark.parametrize("timestamp", ("above", "bellow"))
def test_slot_number_out_of_range(
self,
cluster: clusterlib.ClusterLib,
timestamp: str,
query_slot_number_available: None, # noqa: ARG002
):
"""Test `query slot-number` with a timestamp out of range.
Expect failure.
"""
# pylint: disable=unused-argument
common.get_test_id(cluster)

now = datetime.now(timezone.utc)

if timestamp == "above":
timestamp = now.strftime(f"{now.year*100}-%m-%dT%H:%M:%SZ")
else:
timestamp = now.strftime("1-%m-%dT%H:%M:%SZ")

with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_query.get_slot_number(timestamp=timestamp)

err_str = str(excinfo.value)

assert "PastHorizon" in err_str, err_str

0 comments on commit f26bb35

Please sign in to comment.