From 2c894246219fed939a2658909438b873d5990fe6 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Thu, 2 Jan 2025 16:40:52 +0100 Subject: [PATCH] topic info query test in --- tests/test_topic_info_query.py | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/test_topic_info_query.py diff --git a/tests/test_topic_info_query.py b/tests/test_topic_info_query.py new file mode 100644 index 0000000..d2672bc --- /dev/null +++ b/tests/test_topic_info_query.py @@ -0,0 +1,47 @@ +import pytest +from unittest.mock import MagicMock +from hedera_sdk_python.query.topic_info_query import TopicInfoQuery +from hedera_sdk_python.client.client import Client +from hedera_sdk_python.consensus.topic_id import TopicId +from hedera_sdk_python.hapi.services import basic_types_pb2, consensus_get_topic_info_pb2 +from hedera_sdk_python.hapi.services.consensus_topic_info_pb2 import ConsensusTopicInfo +from hedera_sdk_python.hapi.services.response_header_pb2 import ResponseHeader + + +@pytest.fixture +def mock_topic_info_response(): + """Fixture to provide a mock response for the topic info query.""" + topic_info = ConsensusTopicInfo( + memo="Test topic", + runningHash=b"\x00" * 48, + sequenceNumber=10 + ) + response = consensus_get_topic_info_pb2.ConsensusGetTopicInfoResponse( + header=ResponseHeader(nodeTransactionPrecheckCode=0), + topicInfo=topic_info + ) + return response + + +def test_topic_info_query(mock_topic_info_response): + """ + Test the TopicInfoQuery with a mocked response. + """ + topic_id = TopicId(0, 0, 1234) + + query = TopicInfoQuery().set_topic_id(topic_id) + + query.node_account_ids = [MagicMock()] + query._make_request = MagicMock(return_value="mock_request") + query._get_status_from_response = MagicMock(return_value=0) + query._map_response = MagicMock(return_value=mock_topic_info_response.topicInfo) + + mock_client = MagicMock(spec=Client) + mock_client.send_query = MagicMock(return_value=mock_topic_info_response) + + topic_info = query.execute(mock_client) + + assert topic_info.memo == "Test topic" + assert topic_info.runningHash == b"\x00" * 48 + assert topic_info.sequenceNumber == 10 + print("Test passed: TopicInfoQuery works as expected.")