Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Prepare Hiero Solo
id: solo
uses: hiero-ledger/hiero-solo-action@b76850c1ac44466900f8e7412b309c3aa0f539c1 # v0.14
with:
installMirrorNode: true

- name: Run tests
run: poetry run pytest tests --cov --cov-config=pyproject.toml --cov-report=xml
env:
OPERATOR_ID: ${{ secrets.OPERATOR_ID }}
OPERATOR_KEY: ${{ secrets.OPERATOR_KEY }}
OPERATOR_ID: ${{ steps.solo.outputs.accountId }}
OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }}
NETWORK: solo

- name: Check typing
run: poetry run pyright
Expand Down
1 change: 1 addition & 0 deletions hiero_did_sdk_python/did/did_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
HEDERA_NETWORK_MAINNET = "mainnet"
HEDERA_NETWORK_TESTNET = "testnet"
HEDERA_NETWORK_PREVIEWNET = "previewnet"
HEDERA_NETWORK_SOLO = "solo"

HEDERA_DID_METHOD = "hedera"

Expand Down
2 changes: 2 additions & 0 deletions hiero_did_sdk_python/did/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
HEDERA_DID_METHOD,
HEDERA_NETWORK_MAINNET,
HEDERA_NETWORK_PREVIEWNET,
HEDERA_NETWORK_SOLO,
HEDERA_NETWORK_TESTNET,
)

Expand Down Expand Up @@ -94,6 +95,7 @@ def parse_identifier(identifier: str) -> ParsedIdentifier:
network_name != HEDERA_NETWORK_MAINNET
and network_name != HEDERA_NETWORK_TESTNET
and network_name != HEDERA_NETWORK_PREVIEWNET
and network_name != HEDERA_NETWORK_SOLO
):
raise DidException("DID string is invalid. Invalid Hedera network.", DidErrorCode.INVALID_NETWORK)

Expand Down
11 changes: 7 additions & 4 deletions hiero_did_sdk_python/hcs/hcs_message_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .hcs_message_envelope import HcsMessageEnvelope
from .hcs_topic_listener import HcsTopicListener

DEFAULT_TIMEOUT_SECONDS = float(5)
DEFAULT_TIMEOUT_SECONDS = float(20)

TOPIC_UNSUBSCRIBED_ERROR = "CANCELLED: unsubscribe"

Expand Down Expand Up @@ -61,13 +61,16 @@ def handle_error(error: Exception):
if self._timestamp_from:
self._topic_listener.set_start_time(self._timestamp_from)

if self._timestamp_to:
self._topic_listener.set_end_time(self._timestamp_to)

if self._limit:
self._topic_listener.set_limit(self._limit)

(
self._topic_listener.set_end_time(self._timestamp_to or Timestamp(seconds=int(time.time()), nanos=0))
.set_completion_handler(handle_completion)
.subscribe(client, self._handle_message, handle_error)
self._topic_listener.set_completion_handler(handle_completion).subscribe(
client, self._handle_message, handle_error
)
)

self._last_message_arrival_time = time.time()
Expand Down
2 changes: 1 addition & 1 deletion hiero_did_sdk_python/hcs/hcs_topic_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(
self._query = (
TopicMessageQuery(topic_id=TopicId.from_string(topic_id), start_time=Timestamp(0, 0).to_date())
.set_max_backoff(2.0)
.set_max_attempts(5)
.set_max_attempts(10)
)

def set_start_time(self, start_time: Timestamp):
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
"You can obtain them by creating developer account on https://portal.hedera.com/"
)

NETWORK: str = os.environ.get("NETWORK") or "testnet"

OPERATOR_KEY = PrivateKey.from_string(OPERATOR_KEY_DER)

OPERATOR_KEY_TYPE = get_key_type(OPERATOR_KEY)


@pytest.fixture(scope="class")
def client():
client = Client(network=Network("testnet"))
client = Client(network=Network(NETWORK))
client.set_operator(AccountId.from_string(OPERATOR_ID), private_key=OPERATOR_KEY)

yield client
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async def test_demo(self, client: Client):
)

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

# Create Hedera DID resolver instance
did_resolver = HederaDidResolver(client)
Expand Down Expand Up @@ -135,7 +135,7 @@ async def test_demo(self, client: Client):
)

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

print("Resolving schema object...")

Expand Down Expand Up @@ -174,7 +174,7 @@ async def test_demo(self, client: Client):
)

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

print("Resolving credential definition object...")

Expand Down Expand Up @@ -224,7 +224,7 @@ async def test_demo(self, client: Client):
)

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

print("Resolving revocation registry definition object...")

Expand Down Expand Up @@ -257,7 +257,7 @@ async def test_demo(self, client: Client):
rev_list_timestamp = int(time.time())

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

print(
f"Revocation list has been registered, initial revocation entry can be found in HCS topic: https://hashscan.io/testnet/topic/{rev_reg_entries_topic_id}"
Expand All @@ -281,7 +281,7 @@ async def test_demo(self, client: Client):
assert rev_list_update_result.revocation_list_state.state == "finished"

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

print("Resolving revocation list states...")

Expand Down
30 changes: 14 additions & 16 deletions tests/integration/test_hcs_file_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,40 @@
from .conftest import OPERATOR_KEY_DER


@pytest.mark.flaky(retries=3, delay=1)
# @pytest.mark.flaky(retries=3, delay=1)
@pytest.mark.asyncio(loop_scope="session")
class TestHcsFileService:
@pytest.mark.parametrize(
"test_file_path, expected_chunks_count",
[("./tests/test_data/test_file.txt", 1), ("./tests/test_data/test_file_large.txt", 6)],
"test_file_path, expected_chunks_count, expected_hash",
[
("./tests/test_data/test_file.txt", 1, "48457c7f847ac24fc2419106eae4bb62cf90e25cfb4de0e334fb57df4f7aa4c4"),
(
"./tests/test_data/test_file_large.txt",
6,
"96ec5e6330a0850610a81b24b103b1b61ccf38884f5453427229c27e818f42ef",
),
],
)
async def test_submit_file(self, test_file_path: str, expected_chunks_count: int, client: Client):
async def test_submit_and_resolve_file(
self, test_file_path: str, expected_chunks_count: int, expected_hash: str, client: Client
):
service = HcsFileService(client)
file_payload = Path(test_file_path).read_bytes()

topic_id = await service.submit_file(file_payload, OPERATOR_KEY_DER)

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

topic_info = await execute_hcs_query_async(TopicInfoQuery(topic_id=TopicId.from_string(topic_id)), client)
topic_messages = await HcsMessageResolver(topic_id, HcsFileChunkMessage).execute(client)

assert topic_info.memo == f"{sha256(file_payload).hexdigest()}:zstd:base64"
assert len(topic_messages) == expected_chunks_count

@pytest.mark.parametrize(
"topic_id, expected_hash",
[
("0.0.5123926", "ea4d17b8c0cf44c215ade6b4ad36832672ea3188b1dad12b68c2472dfbcdeff1"),
("0.0.5123993", "dce9e97491cb7bbaeb6f1af9c236a62f5b6f3f4c07952b5431daa52ec58fbc0b"),
],
)
async def test_resolve_file(self, topic_id: str, expected_hash: str, client: Client):
service = HcsFileService(client)

resolved_payload = await service.resolve_file(topic_id)
assert resolved_payload

topic_info = await execute_hcs_query_async(TopicInfoQuery(topic_id=TopicId.from_string(topic_id)), client)
topic_file_hash, _, _ = topic_info.memo.split(":")

assert topic_file_hash == sha256(resolved_payload).hexdigest()
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_hcs_topic_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .conftest import OPERATOR_KEY


@pytest.mark.flaky(retries=3, delay=1)
# @pytest.mark.flaky(retries=3, delay=1)
@pytest.mark.asyncio(loop_scope="session")
class TestHcsTopicService:
async def test_creates_and_updates_hcs_topic(self, client: Client):
Expand Down
18 changes: 9 additions & 9 deletions tests/integration/test_hedera_anoncreds_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
from hiero_did_sdk_python.anoncreds.utils import AnonCredsObjectType, parse_anoncreds_identifier
from hiero_did_sdk_python.hcs import HcsMessageResolver

from .conftest import OPERATOR_KEY_DER
from .conftest import NETWORK, OPERATOR_KEY_DER

ISSUER_ID = "did:hedera:testnet:zvAQyPeUecGck2EsxcsihxhAB6jZurFrBbj2gC7CNkS5o_0.0.5063027"
ISSUER_ID = f"did:hedera:{NETWORK}:zvAQyPeUecGck2EsxcsihxhAB6jZurFrBbj2gC7CNkS5o_0.0.5063027"

MOCK_SCHEMA_PARAMS = {
"name": "mock-schema",
Expand Down Expand Up @@ -69,7 +69,7 @@
ACCUM_2 = "mock-accum-2"


@pytest.mark.flaky(retries=3, delay=1)
# @pytest.mark.flaky(retries=3, delay=1)
@pytest.mark.asyncio(loop_scope="session")
class TestHederaAnonCredsRegistry:
async def test_creates_anoncreds_schema(self, client: Client, Something):
Expand All @@ -92,7 +92,7 @@ async def test_creates_anoncreds_schema(self, client: Client, Something):
assert parsed_identifier.object_type == AnonCredsObjectType.SCHEMA

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

resolution_result = await registry.get_schema(schema_id)

Expand Down Expand Up @@ -124,7 +124,7 @@ async def test_creates_anoncreds_cred_def(self, client: Client, Something):
assert parsed_identifier.object_type == AnonCredsObjectType.PUBLIC_CRED_DEF

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

resolution_result = await registry.get_cred_def(cred_def_id)

Expand Down Expand Up @@ -159,7 +159,7 @@ async def test_creates_anoncreds_rev_reg_def(self, client: Client, Something):
assert parsed_identifier.object_type == AnonCredsObjectType.REV_REG

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

resolution_result = await registry.get_rev_reg_def(rev_reg_def_id)

Expand All @@ -182,7 +182,7 @@ async def test_creates_and_updates_rev_list(self, client: Client, Something):
assert rev_reg_def_id

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

rev_list = AnonCredsRevList(
issuer_id=ISSUER_ID,
Expand All @@ -205,7 +205,7 @@ async def test_creates_and_updates_rev_list(self, client: Client, Something):
assert rev_reg_entries_topic_id

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

entries_messages = await HcsMessageResolver(rev_reg_entries_topic_id, HcsRevRegEntryMessage).execute(client)

Expand Down Expand Up @@ -240,7 +240,7 @@ async def test_creates_and_updates_rev_list(self, client: Client, Something):
)

# Wait until changes are propagated to Hedera Mirror node
await asyncio.sleep(5)
await asyncio.sleep(10)

entries_messages = await HcsMessageResolver(rev_reg_entries_topic_id, HcsRevRegEntryMessage).execute(client)

Expand Down
Loading
Loading