Skip to content

Commit 4502424

Browse files
committed
feat(schedule): allow omission of schedule ID in ScheduleSignTransaction body
Signed-off-by: Ntege Daniel <danientege785@gmail.com>
1 parent 18f329f commit 4502424

4 files changed

Lines changed: 27 additions & 15 deletions

File tree

src/hiero_sdk_python/schedule/schedule_sign_transaction.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,14 @@ def _build_proto_body(self):
6161
"""
6262
Returns the protobuf body for the schedule sign transaction.
6363
64+
An unset schedule ID is omitted from the body rather than rejected locally, so the
65+
network answers with INVALID_SCHEDULE_ID as it does for the other SDKs.
66+
6467
Returns:
6568
ScheduleSignTransactionBody: The protobuf body for this transaction.
66-
67-
Raises:
68-
ValueError: If schedule_id is not set.
6969
"""
70-
if self.schedule_id is None:
71-
raise ValueError("Missing required ScheduleID")
72-
7370
return ScheduleSignTransactionBody(
74-
scheduleID=self.schedule_id._to_proto(),
71+
scheduleID=self.schedule_id._to_proto() if self.schedule_id is not None else None,
7572
)
7673

7774
def build_transaction_body(self):

tck/handlers/schedule.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,8 @@ def _build_sign_schedule_transaction(params: SignScheduleParams) -> ScheduleSign
146146
"""Build a ScheduleSignTransaction from TCK params."""
147147
transaction = ScheduleSignTransaction().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT)
148148

149-
# The SDK requires an ID to serialize the transaction, while the TCK expects an
150-
# omitted ID to reach the network and return INVALID_SCHEDULE_ID.
151-
schedule_id = ScheduleId.from_string(params.scheduleId) if params.scheduleId is not None else ScheduleId()
152-
transaction.set_schedule_id(schedule_id)
149+
if params.scheduleId is not None:
150+
transaction.set_schedule_id(ScheduleId.from_string(params.scheduleId))
153151

154152
return transaction
155153

tests/integration/schedule_sign_transaction_e2e_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import pytest
88

9+
from hiero_sdk_python.exceptions import PrecheckError
910
from hiero_sdk_python.response_code import ResponseCode
1011
from hiero_sdk_python.schedule.schedule_id import ScheduleId
1112
from hiero_sdk_python.schedule.schedule_info_query import ScheduleInfoQuery
@@ -187,6 +188,17 @@ def test_integration_schedule_sign_transaction_fails_invalid_schedule_id(env):
187188
)
188189

189190

191+
@pytest.mark.integration
192+
def test_integration_schedule_sign_transaction_fails_without_schedule_id(env):
193+
"""Test that ScheduleSignTransaction fails precheck when no schedule ID is set.
194+
195+
The body omits scheduleID entirely, which the network rejects in pureChecks, so the
196+
failure arrives as a precheck error rather than a receipt status.
197+
"""
198+
with pytest.raises(PrecheckError, match="failed precheck with status: INVALID_SCHEDULE_ID"):
199+
ScheduleSignTransaction().freeze_with(env.client).sign(env.operator_key).execute(env.client)
200+
201+
190202
def test_integration_schedule_sign_transaction_fails_with_already_executed(env):
191203
"""Test that ScheduleSignTransaction fails when the schedule has already been executed."""
192204
account = env.create_account()

tests/unit/schedule_sign_transaction_test.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,17 @@ def test_build_proto_body_with_schedule_id(schedule_id):
7676
assert proto_body.scheduleID == schedule_id._to_proto()
7777

7878

79-
def test_build_proto_body_without_schedule_id_raises_error():
80-
"""Test building protobuf body without a schedule ID."""
79+
def test_build_proto_body_without_schedule_id_omits_field():
80+
"""Test that building a protobuf body without a schedule ID leaves the field unset.
81+
82+
The network rejects a body with no scheduleID with INVALID_SCHEDULE_ID, so the
83+
omission is left for it to answer instead of failing locally.
84+
"""
8185
schedule_sign_tx = ScheduleSignTransaction()
8286

83-
with pytest.raises(ValueError, match="Missing required ScheduleID"):
84-
schedule_sign_tx._build_proto_body()
87+
proto_body = schedule_sign_tx._build_proto_body()
88+
89+
assert not proto_body.HasField("scheduleID")
8590

8691

8792
def test_build_transaction_body_with_valid_schedule_id(mock_account_ids, schedule_id):

0 commit comments

Comments
 (0)