Skip to content

Commit 44e60ed

Browse files
test case
Signed-off-by: mukundkumarjha <mukundiiitg@gmail.com>
1 parent fa034c2 commit 44e60ed

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

src/hiero_sdk_python/account/account_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from hiero_sdk_python.account.account_id import AccountId
1010
from hiero_sdk_python.crypto.public_key import PublicKey
1111
from hiero_sdk_python.Duration import Duration
12-
from hiero_sdk_python.hapi.services.basic_types_pb2 import StakingInfo
12+
from hiero_sdk_python.staking_info import StakingInfo
1313
from hiero_sdk_python.hapi.services.crypto_get_info_pb2 import CryptoGetInfoResponse
1414
from hiero_sdk_python.hbar import Hbar
1515
from hiero_sdk_python.timestamp import Timestamp
@@ -100,7 +100,7 @@ def _from_proto(cls, proto: CryptoGetInfoResponse.AccountInfo) -> "AccountInfo":
100100
owned_nfts=proto.ownedNfts,
101101
max_automatic_token_associations=proto.max_automatic_token_associations,
102102
staking_info=(
103-
StakingInfo.from_proto(proto.staking_info)
103+
StakingInfo._from_proto(proto.staking_info)
104104
if proto.HasField("staking_info")
105105
else None
106106
)

tests/unit/account_info_test.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from hiero_sdk_python.tokens.token_relationship import TokenRelationship
1010
from hiero_sdk_python.tokens.token_id import TokenId
1111
from hiero_sdk_python.hapi.services.crypto_get_info_pb2 import CryptoGetInfoResponse
12+
from hiero_sdk_python.staking_info import StakingInfo
1213

1314
pytestmark = pytest.mark.unit
1415

@@ -72,6 +73,28 @@ def test_account_info_initialization(account_info):
7273
assert account_info.max_automatic_token_associations == 10
7374
assert account_info.staking_info is None
7475

76+
def test_from_proto_with_staking_info():
77+
"""Test the from_proto method of the AccountInfo class with staking info"""
78+
public_key = PrivateKey.generate_ed25519().public_key()
79+
80+
proto = CryptoGetInfoResponse.AccountInfo(
81+
accountID=AccountId(0, 0, 100)._to_proto(),
82+
key=public_key._to_proto(),
83+
balance=5000000,
84+
85+
staking_info={
86+
"decline_reward": True,
87+
"staked_node_id": 3,
88+
"staked_account_id": None
89+
}
90+
)
91+
92+
account_info = AccountInfo._from_proto(proto)
93+
94+
assert account_info.staking_info is not None
95+
assert account_info.staking_info.decline_reward is True
96+
assert account_info.staking_info.staked_node_id == 3
97+
7598

7699
def test_account_info_default_initialization():
77100
"""Test the default initialization of the AccountInfo class"""
@@ -91,6 +114,22 @@ def test_account_info_default_initialization():
91114
assert account_info.max_automatic_token_associations is None
92115
assert account_info.staking_info is None
93116

117+
def test_staking_info_persistence(account_info):
118+
"""Ensure staking info is preserved through proto conversion"""
119+
120+
account_info.staking_info = StakingInfo(
121+
decline_reward=True,
122+
staked_node_id=5,
123+
staked_account_id=None
124+
)
125+
126+
proto = account_info._to_proto()
127+
converted_info = AccountInfo._from_proto(proto)
128+
129+
assert converted_info.staking_info is not None
130+
assert converted_info.staking_info.decline_reward is True
131+
assert converted_info.staking_info.staked_node_id == 5
132+
assert converted_info.staking_info.staked_account_id is None
94133

95134
def test_from_proto(proto_account_info):
96135
"""Test the from_proto method of the AccountInfo class"""
@@ -109,7 +148,7 @@ def test_from_proto(proto_account_info):
109148
assert account_info.account_memo == "Test account memo"
110149
assert account_info.owned_nfts == 5
111150
assert account_info.max_automatic_token_associations == 10
112-
#assert account_info.staking_info == None
151+
assert account_info.staking_info == None
113152

114153

115154
def test_from_proto_with_token_relationships():

0 commit comments

Comments
 (0)