-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2a76ce
commit a686655
Showing
15 changed files
with
387 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,6 @@ src/hedera_sdk_python/hapi | |
.idea | ||
|
||
# Pytest | ||
.pytest_cache | ||
.pytest_cache | ||
|
||
uv.lock |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import pytest | ||
from unittest.mock import MagicMock | ||
from hedera_sdk_python.consensus.topic_create_transaction import TopicCreateTransaction | ||
from hedera_sdk_python.account.account_id import AccountId | ||
from hedera_sdk_python.crypto.private_key import PrivateKey | ||
from hedera_sdk_python.client.client import Client | ||
from hedera_sdk_python.response_code import ResponseCode | ||
from hedera_sdk_python.hapi import ( | ||
transaction_receipt_pb2 | ||
) | ||
from hedera_sdk_python.transaction.transaction_receipt import TransactionReceipt | ||
from hedera_sdk_python.transaction.transaction_id import TransactionId | ||
from hedera_sdk_python.hapi import timestamp_pb2 as hapi_timestamp_pb2 | ||
|
||
@pytest.mark.usefixtures("mock_account_ids") | ||
def test_build_topic_create_transaction_body(mock_account_ids): | ||
""" | ||
Test building a TopicCreateTransaction body with valid memo, admin key. | ||
""" | ||
_, _, node_account_id, _, _ = mock_account_ids | ||
|
||
tx = TopicCreateTransaction(memo="Hello Topic", admin_key=PrivateKey.generate().public_key()) | ||
|
||
tx.operator_account_id = AccountId(0, 0, 2) | ||
tx.node_account_id = node_account_id | ||
|
||
transaction_body = tx.build_transaction_body() | ||
|
||
assert transaction_body.consensusCreateTopic.memo == "Hello Topic" | ||
assert transaction_body.consensusCreateTopic.adminKey.ed25519 | ||
|
||
def test_missing_operator_in_topic_create(mock_account_ids): | ||
""" | ||
Test that building the body fails if no operator ID is set. | ||
""" | ||
_, _, node_account_id, _, _ = mock_account_ids | ||
|
||
tx = TopicCreateTransaction(memo="No Operator") | ||
tx.node_account_id = node_account_id | ||
|
||
with pytest.raises(ValueError, match="Operator account ID is not set."): | ||
tx.build_transaction_body() | ||
|
||
def test_missing_node_in_topic_create(mock_account_ids): | ||
""" | ||
Test that building the body fails if no node account ID is set. | ||
""" | ||
tx = TopicCreateTransaction(memo="No Node") | ||
tx.operator_account_id = AccountId(0, 0, 2) | ||
|
||
with pytest.raises(ValueError, match="Node account ID is not set."): | ||
tx.build_transaction_body() | ||
|
||
def test_sign_topic_create_transaction(mock_account_ids): | ||
""" | ||
Test signing the TopicCreateTransaction with a private key. | ||
""" | ||
_, _, node_account_id, _, _ = mock_account_ids | ||
tx = TopicCreateTransaction(memo="Signing test") | ||
tx.operator_account_id = AccountId(0, 0, 2) | ||
tx.node_account_id = node_account_id | ||
|
||
private_key = PrivateKey.generate() | ||
|
||
body_bytes = tx.build_transaction_body().SerializeToString() | ||
tx.transaction_body_bytes = body_bytes | ||
|
||
tx.sign(private_key) | ||
assert len(tx.signature_map.sigPair) == 1 | ||
|
||
def test_execute_topic_create_transaction(mock_account_ids): | ||
""" | ||
Test executing the TopicCreateTransaction with a mock Client. | ||
""" | ||
_, _, node_account_id, _, _ = mock_account_ids | ||
|
||
tx = TopicCreateTransaction(memo="Execute test") | ||
tx.operator_account_id = AccountId(0, 0, 2) | ||
|
||
client = MagicMock(spec=Client) | ||
client.operator_private_key = PrivateKey.generate() | ||
client.operator_account_id = AccountId(0, 0, 2) | ||
client.node_account_id = node_account_id | ||
|
||
real_tx_id = TransactionId( | ||
account_id=AccountId(0, 0, 2), | ||
valid_start=hapi_timestamp_pb2.Timestamp(seconds=11111, nanos=222) | ||
) | ||
client.generate_transaction_id.return_value = real_tx_id | ||
|
||
client.topic_stub = MagicMock() | ||
|
||
mock_response = MagicMock() | ||
mock_response.nodeTransactionPrecheckCode = ResponseCode.OK | ||
client.topic_stub.createTopic.return_value = mock_response | ||
|
||
proto_receipt = transaction_receipt_pb2.TransactionReceipt(status=ResponseCode.OK) | ||
real_receipt = TransactionReceipt.from_proto(proto_receipt) | ||
client.get_transaction_receipt.return_value = real_receipt | ||
|
||
receipt = tx.execute(client) | ||
|
||
client.topic_stub.createTopic.assert_called_once() | ||
assert receipt is not None | ||
assert receipt.status == ResponseCode.OK | ||
print("Test passed: TopicCreateTransaction executed successfully.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import pytest | ||
from unittest.mock import MagicMock | ||
from hedera_sdk_python.consensus.topic_delete_transaction import TopicDeleteTransaction | ||
from hedera_sdk_python.consensus.topic_id import TopicId | ||
from hedera_sdk_python.account.account_id import AccountId | ||
from hedera_sdk_python.crypto.private_key import PrivateKey | ||
from hedera_sdk_python.client.client import Client | ||
from hedera_sdk_python.response_code import ResponseCode | ||
from hedera_sdk_python.hapi import transaction_receipt_pb2 | ||
from hedera_sdk_python.transaction.transaction_receipt import TransactionReceipt | ||
from hedera_sdk_python.transaction.transaction_id import TransactionId | ||
from hedera_sdk_python.hapi import timestamp_pb2 as hapi_timestamp_pb2 | ||
|
||
@pytest.mark.usefixtures("mock_account_ids") | ||
def test_build_topic_delete_transaction_body(mock_account_ids): | ||
""" | ||
Test building a TopicDeleteTransaction body with a valid topic ID. | ||
""" | ||
_, _, node_account_id, _, _ = mock_account_ids | ||
topic_id = TopicId(0,0,1234) | ||
tx = TopicDeleteTransaction(topic_id=topic_id) | ||
|
||
tx.operator_account_id = AccountId(0, 0, 2) | ||
tx.node_account_id = node_account_id | ||
|
||
transaction_body = tx.build_transaction_body() | ||
assert transaction_body.consensusDeleteTopic.topicID.topicNum == 1234 | ||
|
||
def test_missing_topic_id_in_delete(mock_account_ids): | ||
""" | ||
Test that building fails if no topic ID is provided. | ||
""" | ||
_, _, node_account_id, _, _ = mock_account_ids | ||
tx = TopicDeleteTransaction(topic_id=None) | ||
tx.operator_account_id = AccountId(0, 0, 2) | ||
tx.node_account_id = node_account_id | ||
|
||
with pytest.raises(ValueError, match="Missing required fields"): | ||
tx.build_transaction_body() | ||
|
||
def test_sign_topic_delete_transaction(mock_account_ids): | ||
""" | ||
Test signing the TopicDeleteTransaction with a private key. | ||
""" | ||
_, _, node_account_id, _, _ = mock_account_ids | ||
tx = TopicDeleteTransaction(topic_id=TopicId(0,0,9876)) | ||
tx.operator_account_id = AccountId(0, 0, 2) | ||
tx.node_account_id = node_account_id | ||
|
||
private_key = PrivateKey.generate() | ||
|
||
body_bytes = tx.build_transaction_body().SerializeToString() | ||
tx.transaction_body_bytes = body_bytes | ||
|
||
tx.sign(private_key) | ||
assert len(tx.signature_map.sigPair) == 1 | ||
|
||
def test_execute_topic_delete_transaction(mock_account_ids): | ||
""" | ||
Test executing the TopicDeleteTransaction with a mock Client. | ||
""" | ||
_, _, node_account_id, _, _ = mock_account_ids | ||
topic_id = TopicId(0,0,9876) | ||
tx = TopicDeleteTransaction(topic_id=topic_id) | ||
tx.operator_account_id = AccountId(0, 0, 2) | ||
|
||
client = MagicMock(spec=Client) | ||
client.operator_private_key = PrivateKey.generate() | ||
client.operator_account_id = AccountId(0, 0, 2) | ||
client.node_account_id = node_account_id | ||
|
||
real_tx_id = TransactionId( | ||
account_id=AccountId(0, 0, 2), | ||
valid_start=hapi_timestamp_pb2.Timestamp(seconds=20000, nanos=3333) | ||
) | ||
client.generate_transaction_id.return_value = real_tx_id | ||
|
||
client.topic_stub = MagicMock() | ||
mock_response = MagicMock() | ||
mock_response.nodeTransactionPrecheckCode = ResponseCode.OK | ||
client.topic_stub.deleteTopic.return_value = mock_response | ||
|
||
proto_receipt = transaction_receipt_pb2.TransactionReceipt(status=ResponseCode.OK) | ||
real_receipt = TransactionReceipt.from_proto(proto_receipt) | ||
client.get_transaction_receipt.return_value = real_receipt | ||
|
||
# Act | ||
receipt = tx.execute(client) | ||
|
||
# Assert | ||
client.topic_stub.deleteTopic.assert_called_once() | ||
assert receipt is not None | ||
assert receipt.status == ResponseCode.OK | ||
print("Test passed: TopicDeleteTransaction executed successfully.") |
Oops, something went wrong.