Skip to content

Commit bcb2b07

Browse files
committed
chore: adding new to_proto, from_proto and int enum .name
Signed-off-by: exploreriii <[email protected]>
1 parent 9a07eeb commit bcb2b07

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

examples/token_pause.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def assert_success(receipt, action: str):
4444
indicating which action failed and the status name.
4545
"""
4646
if receipt.status != ResponseCode.SUCCESS:
47-
name = ResponseCode.get_name(receipt.status)
47+
name = ResponseCode(receipt.status).name
4848
raise RuntimeError(f"{action!r} failed with status {name}")
4949

5050
def create_token(client, operator_id, admin_key, pause_key):

src/hiero_sdk_python/tokens/token_pause_transaction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def build_transaction_body(self):
5555
raise ValueError("token_id must be set before building the transaction body")
5656

5757
token_pause_body = TokenPauseTransactionBody(
58-
token=self.token_id.to_proto()
58+
token=self.token_id._to_proto()
5959
)
6060
transaction_body = self.build_base_transaction_body()
6161
transaction_body.token_pause.CopyFrom(token_pause_body)
@@ -67,7 +67,7 @@ def _get_method(self, channel: _Channel) -> _Method:
6767
query_func=None
6868
)
6969

70-
def from_proto(self, proto: TokenPauseTransactionBody):
70+
def _from_proto(self, proto: TokenPauseTransactionBody):
7171
"""
7272
Deserializes a TokenPauseTransactionBody from a protobuf object.
7373
@@ -77,5 +77,5 @@ def from_proto(self, proto: TokenPauseTransactionBody):
7777
Returns:
7878
TokenPauseTransaction: Returns self for method chaining.
7979
"""
80-
self.token_id = TokenId.from_proto(proto.token)
80+
self.token_id = TokenId._from_proto(proto.token)
8181
return self

tests/integration/token_pause_transaction_e2e_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_pause_nonexistent_token_id_raises_precheck_error(env):
5757

5858
assert receipt.status == ResponseCode.INVALID_TOKEN_ID, (
5959
f"Expected INVALID_TOKEN_ID but got "
60-
f"{ResponseCode.get_name(receipt.status)}"
60+
f"{ResponseCode(receipt.status).name}"
6161
)
6262

6363
@mark.integration
@@ -72,7 +72,7 @@ def test_pause_fails_for_unpausable_token(env, unpausable_token):
7272

7373
assert receipt.status == ResponseCode.TOKEN_HAS_NO_PAUSE_KEY, (
7474
f"Expected TOKEN_HAS_NO_PAUSE_KEY but got "
75-
f"{ResponseCode.get_name(receipt.status)}"
75+
f"{ResponseCode(receipt.status).name}"
7676
)
7777

7878
@mark.integration
@@ -89,7 +89,7 @@ def test_pause_requires_pause_key_signature(env, pausable_token):
8989

9090
assert receipt.status == ResponseCode.INVALID_SIGNATURE, (
9191
f"Expected INVALID_SIGNATURE but got "
92-
f"{ResponseCode.get_name(receipt.status)}"
92+
f"{ResponseCode(receipt.status).name}"
9393
)
9494

9595
@mark.integration
@@ -106,7 +106,7 @@ def test_pause_with_invalid_key(env, pausable_token):
106106

107107
assert receipt.status == ResponseCode.INVALID_SIGNATURE, (
108108
f"Expected INVALID_SIGNATURE but got "
109-
f"{ResponseCode.get_name(receipt.status)}"
109+
f"{ResponseCode(receipt.status).name}"
110110
)
111111

112112
@mark.integration
@@ -184,5 +184,5 @@ def test_transfers_blocked_when_paused(env, account: Account, pausable_token):
184184
)
185185
assert transfer_receipt.status == ResponseCode.TOKEN_IS_PAUSED, (
186186
f"Expected TOKEN_IS_PAUSED but got "
187-
f"{ResponseCode.get_name(transfer_receipt.status)}"
187+
f"{ResponseCode(transfer_receipt.status).name}"
188188
)

tests/integration/utils_for_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def create_account(self, initial_hbar: float = 1.0) -> Account:
6262
receipt = tx.execute(self.client)
6363
if receipt.status != ResponseCode.SUCCESS:
6464
raise AssertionError(
65-
f"Account creation failed: {ResponseCode.get_name(receipt.status)}"
65+
f"Account creation failed: {ResponseCode(receipt.status).name}"
6666
)
6767
return Account(id=receipt.accountId, key=key)
6868

@@ -81,7 +81,7 @@ def associate_and_transfer(self, receiver: AccountId, receiver_key: PrivateKey,
8181
)
8282
if assoc_receipt.status != ResponseCode.SUCCESS:
8383
raise AssertionError(
84-
f"Association failed: {ResponseCode.get_name(assoc_receipt.status)}"
84+
f"Association failed: {ResponseCode(assoc_receipt.status).name}"
8585
)
8686

8787
transfer_receipt = (
@@ -92,7 +92,7 @@ def associate_and_transfer(self, receiver: AccountId, receiver_key: PrivateKey,
9292
)
9393
if transfer_receipt.status != ResponseCode.SUCCESS:
9494
raise AssertionError(
95-
f"Transfer failed: {ResponseCode.get_name(transfer_receipt.status)}"
95+
f"Transfer failed: {ResponseCode(transfer_receipt.status).name}"
9696
)
9797

9898
def create_fungible_token(env, opts=[]):

tests/unit/test_token_pause_transaction.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def test_build_transaction_body(mock_account_ids, token_id):
3131

3232
transaction_body = pause_tx.build_transaction_body() # Will generate a transaction_id
3333

34-
assert transaction_body.token_pause.token == token_id.to_proto()
35-
assert transaction_body.transactionID == pause_tx.transaction_id.to_proto()
36-
assert transaction_body.nodeAccountID == pause_tx.node_account_id.to_proto()
34+
assert transaction_body.token_pause.token == token_id._to_proto()
35+
assert transaction_body.transactionID == pause_tx.transaction_id._to_proto()
36+
assert transaction_body.nodeAccountID == pause_tx.node_account_id._to_proto()
3737

3838
def test_build_transaction_body_nft(mock_account_ids, nft_id):
3939
"""Test building an NFT‐pause transaction body with valid values."""
@@ -48,12 +48,12 @@ def test_build_transaction_body_nft(mock_account_ids, nft_id):
4848

4949
transaction_body = pause_tx.build_transaction_body()
5050

51-
assert transaction_body.token_pause.token == base_token_id.to_proto()
52-
assert transaction_body.transactionID == pause_tx.transaction_id.to_proto()
53-
assert transaction_body.nodeAccountID == pause_tx.node_account_id.to_proto()
51+
assert transaction_body.token_pause.token == base_token_id._to_proto()
52+
assert transaction_body.transactionID == pause_tx.transaction_id._to_proto()
53+
assert transaction_body.nodeAccountID == pause_tx.node_account_id._to_proto()
5454

5555
# This test uses fixture (token_id, mock_client) as parameter
56-
def test_to_proto(token_id, mock_client):
56+
def test__to_proto(token_id, mock_client):
5757
"""Test converting the token pause transaction to protobuf format after signing."""
5858

5959
# Build the TokenPauseTransaction
@@ -72,20 +72,20 @@ def test_to_proto(token_id, mock_client):
7272
pause_tx.sign(pause_key)
7373

7474
# Convert to proto and verify that signedTransactionBytes is non-empty:
75-
proto = pause_tx.to_proto()
75+
proto = pause_tx._to_proto()
7676

7777
assert proto.signedTransactionBytes
7878
assert len(proto.signedTransactionBytes) > 0
7979

80-
def test_from_proto_restores_token_id():
80+
def test__from_proto_restores_token_id():
8181
"""
82-
from_proto() must deserialize TokenPauseTransactionBody → .token_id correctly.
82+
_from_proto() must deserialize TokenPauseTransactionBody → .token_id correctly.
8383
"""
8484
# Construct a TokenPauseTransactionBody protobuf for an example token id.
85-
proto_body = TokenPauseTransactionBody(token=TokenId(7, 8, 9).to_proto())
85+
proto_body = TokenPauseTransactionBody(token=TokenId(7, 8, 9)._to_proto())
8686

87-
# Use from_proto to build a TokenPauseTransaction whose token_id comes from the protobuf just created.
88-
tx = TokenPauseTransaction().from_proto(proto_body)
87+
# Use _from_proto to build a TokenPauseTransaction whose token_id comes from the protobuf just created.
88+
tx = TokenPauseTransaction()._from_proto(proto_body)
8989

9090
# Verify that tx.token_id matches TokenId(7, 8, 9)
9191
assert tx.token_id == TokenId(7, 8, 9)

0 commit comments

Comments
 (0)