Skip to content

Commit 205a8e8

Browse files
committed
fix(tokens): align TokenGrantKyc/RevokeKyc validation with TCK spec
Signed-off-by: iron-prog <dt915725@gmail.com>
1 parent 21bded8 commit 205a8e8

6 files changed

Lines changed: 32 additions & 284 deletions

File tree

src/hiero_sdk_python/tokens/token_grant_kyc_transaction.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,14 @@ def _build_proto_body(self) -> token_grant_kyc_pb2.TokenGrantKycTransactionBody:
7676
7777
Returns:
7878
TokenGrantKycTransactionBody: The protobuf body for this transaction.
79-
80-
Raises:
81-
ValueError: If the token ID or account ID is not set.
8279
"""
83-
if self.token_id is None:
84-
raise ValueError("Missing token ID")
85-
86-
if self.account_id is None:
87-
raise ValueError("Missing account ID")
80+
kwargs = {}
81+
if self.token_id is not None:
82+
kwargs["token"] = self.token_id._to_proto()
83+
if self.account_id is not None:
84+
kwargs["account"] = self.account_id._to_proto()
8885

89-
return TokenGrantKycTransactionBody(token=self.token_id._to_proto(), account=self.account_id._to_proto())
86+
return TokenGrantKycTransactionBody(**kwargs)
9087

9188
def build_transaction_body(self) -> transaction_pb2.TransactionBody:
9289
"""

src/hiero_sdk_python/tokens/token_revoke_kyc_transaction.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,14 @@ def _build_proto_body(self) -> token_revoke_kyc_pb2.TokenRevokeKycTransactionBod
7777
7878
Returns:
7979
TokenRevokeKycTransactionBody: The protobuf body for this transaction.
80-
81-
Raises:
82-
ValueError: If the token ID or account ID is not set.
8380
"""
84-
if self.token_id is None:
85-
raise ValueError("Missing token ID")
86-
87-
if self.account_id is None:
88-
raise ValueError("Missing account ID")
81+
kwargs = {}
82+
if self.token_id is not None:
83+
kwargs["token"] = self.token_id._to_proto()
84+
if self.account_id is not None:
85+
kwargs["account"] = self.account_id._to_proto()
8986

90-
return TokenRevokeKycTransactionBody(token=self.token_id._to_proto(), account=self.account_id._to_proto())
87+
return TokenRevokeKycTransactionBody(**kwargs)
9188

9289
def build_transaction_body(self) -> transaction_pb2.AtomicBatchTransactionBody:
9390
"""

tck/handlers/token.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,11 @@ def _build_delete_token_transaction(params: DeleteTokenParams) -> TokenDeleteTra
302302
def _build_freeze_token_transaction(params: FreezeTokenParams) -> TokenFreezeTransaction:
303303
"""Build a TokenFreezeTransaction from TCK params."""
304304
transaction = TokenFreezeTransaction().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT)
305-
306305
if params.tokenId is not None:
307306
transaction.set_token_id(TokenId.from_string(params.tokenId))
308307

309308
if params.accountId is not None:
310309
transaction.set_account_id(AccountId.from_string(params.accountId))
311-
312310
return transaction
313311

314312

@@ -325,26 +323,22 @@ def _build_pause_token_transaction(params: PauseTokenParams) -> TokenPauseTransa
325323
def _build_grant_token_kyc_transaction(params: GrantTokenKycParams) -> TokenGrantKycTransaction:
326324
"""Build a TokenGrantKycTransaction from TCK params."""
327325
transaction = TokenGrantKycTransaction().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT)
328-
329326
if params.tokenId is not None:
330327
transaction.set_token_id(TokenId.from_string(params.tokenId))
331328

332329
if params.accountId is not None:
333330
transaction.set_account_id(AccountId.from_string(params.accountId))
334-
335331
return transaction
336332

337333

338334
def _build_revoke_token_kyc_transaction(params: RevokeTokenKycParams) -> TokenRevokeKycTransaction:
339335
"""Build a TokenRevokeKycTransaction from TCK params."""
340336
transaction = TokenRevokeKycTransaction().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT)
341-
342337
if params.tokenId is not None:
343338
transaction.set_token_id(TokenId.from_string(params.tokenId))
344339

345340
if params.accountId is not None:
346341
transaction.set_account_id(AccountId.from_string(params.accountId))
347-
348342
return transaction
349343

350344

tests/tck/token_kyc_handlers_test.py

Lines changed: 0 additions & 240 deletions
This file was deleted.

tests/unit/token_grant_kyc_transaction_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ def test_build_transaction_body(mock_account_ids):
3535
assert transaction_body.tokenGrantKyc.account == account_id._to_proto()
3636

3737

38-
def test_build_transaction_body_validation(mock_account_ids):
39-
"""Test validation when building transaction body."""
38+
def test_build_transaction_body_allows_missing_ids(mock_account_ids):
39+
"""Do not reject missing IDs locally; defer validation to the network per TCK."""
4040
account_id, _, _, token_id, _ = mock_account_ids
4141

42-
# Test missing token ID
42+
# Missing token ID: build must succeed, with the token field left unset.
4343
grant_kyc_tx = TokenGrantKycTransaction(account_id=account_id)
44+
body = grant_kyc_tx._build_proto_body()
45+
assert not body.HasField("token")
46+
assert body.account == account_id._to_proto()
4447

45-
with pytest.raises(ValueError, match="Missing token ID"):
46-
grant_kyc_tx.build_transaction_body()
47-
48-
# Test missing account ID
48+
# Missing account ID: build must succeed, with the account field left unset.
4949
grant_kyc_tx = TokenGrantKycTransaction(token_id=token_id)
50-
51-
with pytest.raises(ValueError, match="Missing account ID"):
52-
grant_kyc_tx.build_transaction_body()
50+
body = grant_kyc_tx._build_proto_body()
51+
assert body.token == token_id._to_proto()
52+
assert not body.HasField("account")
5353

5454

5555
def test_constructor_with_parameters(mock_account_ids):

tests/unit/token_revoke_kyc_transaction_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ def test_build_transaction_body(mock_account_ids):
3535
assert transaction_body.tokenRevokeKyc.account == account_id._to_proto()
3636

3737

38-
def test_build_transaction_body_validation(mock_account_ids):
39-
"""Test validation when building transaction body."""
38+
def test_build_transaction_body_allows_missing_ids(mock_account_ids):
39+
"""Allow missing IDs so validation is performed by the network, per the TCK spec."""
4040
account_id, _, _, token_id, _ = mock_account_ids
4141

42-
# Test missing token ID
42+
# Missing token ID: build must succeed, with the token field left unset.
4343
revoke_kyc_tx = TokenRevokeKycTransaction(account_id=account_id)
44+
body = revoke_kyc_tx._build_proto_body()
45+
assert not body.HasField("token")
46+
assert body.account == account_id._to_proto()
4447

45-
with pytest.raises(ValueError, match="Missing token ID"):
46-
revoke_kyc_tx.build_transaction_body()
47-
48-
# Test missing account ID
48+
# Missing account ID: build must succeed, with the account field left unset.
4949
revoke_kyc_tx = TokenRevokeKycTransaction(token_id=token_id)
50-
51-
with pytest.raises(ValueError, match="Missing account ID"):
52-
revoke_kyc_tx.build_transaction_body()
50+
body = revoke_kyc_tx._build_proto_body()
51+
assert body.token == token_id._to_proto()
52+
assert not body.HasField("account")
5353

5454

5555
def test_constructor_with_parameters(mock_account_ids):

0 commit comments

Comments
 (0)