Skip to content

Commit 837ffe9

Browse files
committed
chore: address PR feedback
Signed-off-by: dosi <dosi.kolev@limechain.tech>
1 parent 9a4bc49 commit 837ffe9

File tree

2 files changed

+56
-37
lines changed

2 files changed

+56
-37
lines changed

tests/unit/test_contract_create_transaction.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Unit tests for the ContractCreateTransaction class.
3+
"""
4+
15
import pytest
26

37
from hiero_sdk_python.account.account_id import AccountId
@@ -33,6 +37,7 @@
3337

3438
@pytest.fixture
3539
def contract_params():
40+
"""Fixture for contract parameters."""
3641
return {
3742
"bytecode_file_id": FileId(0, 0, 123),
3843
"proxy_account_id": AccountId(0, 0, 456),

tests/unit/test_contract_id.py

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,181 @@
1+
"""
2+
Unit tests for the ContractId class.
3+
"""
4+
15
import pytest
6+
27
from hiero_sdk_python.contract.contract_id import ContractId
38
from hiero_sdk_python.hapi.services import basic_types_pb2
49

510
pytestmark = pytest.mark.unit
611

12+
713
def test_default_initialization():
814
"""Test ContractId initialization with default values."""
915
contract_id = ContractId()
10-
16+
1117
assert contract_id.shard == 0
1218
assert contract_id.realm == 0
1319
assert contract_id.contract == 0
1420

21+
1522
def test_custom_initialization():
1623
"""Test ContractId initialization with custom values."""
1724
contract_id = ContractId(shard=1, realm=2, contract=3)
18-
25+
1926
assert contract_id.shard == 1
2027
assert contract_id.realm == 2
2128
assert contract_id.contract == 3
2229

30+
2331
def test_str_representation():
2432
"""Test string representation of ContractId."""
2533
contract_id = ContractId(shard=1, realm=2, contract=3)
26-
34+
2735
assert str(contract_id) == "1.2.3"
2836

37+
2938
def test_str_representation_default():
3039
"""Test string representation of ContractId with default values."""
3140
contract_id = ContractId()
32-
41+
3342
assert str(contract_id) == "0.0.0"
3443

44+
3545
def test_from_string_valid():
3646
"""Test creating ContractId from valid string format."""
3747
contract_id = ContractId.from_string("1.2.3")
38-
48+
3949
assert contract_id.shard == 1
4050
assert contract_id.realm == 2
4151
assert contract_id.contract == 3
4252

53+
4354
def test_from_string_with_spaces():
4455
"""Test creating ContractId from string with leading/trailing spaces."""
4556
contract_id = ContractId.from_string(" 1.2.3 ")
46-
57+
4758
assert contract_id.shard == 1
4859
assert contract_id.realm == 2
4960
assert contract_id.contract == 3
5061

62+
5163
def test_from_string_zeros():
5264
"""Test creating ContractId from string with zero values."""
5365
contract_id = ContractId.from_string("0.0.0")
54-
66+
5567
assert contract_id.shard == 0
5668
assert contract_id.realm == 0
5769
assert contract_id.contract == 0
5870

59-
def test_from_string_large_numbers():
60-
"""Test creating ContractId from string with large numbers."""
61-
contract_id = ContractId.from_string("999.888.777")
62-
63-
assert contract_id.shard == 999
64-
assert contract_id.realm == 888
65-
assert contract_id.contract == 777
6671

6772
def test_from_string_invalid_format_too_few_parts():
6873
"""Test creating ContractId from invalid string format with too few parts."""
69-
with pytest.raises(ValueError, match="Invalid ContractId format. Expected 'shard.realm.contract'"):
74+
with pytest.raises(
75+
ValueError, match="Invalid ContractId format. Expected 'shard.realm.contract'"
76+
):
7077
ContractId.from_string("1.2")
7178

79+
7280
def test_from_string_invalid_format_too_many_parts():
7381
"""Test creating ContractId from invalid string format with too many parts."""
74-
with pytest.raises(ValueError, match="Invalid ContractId format. Expected 'shard.realm.contract'"):
82+
with pytest.raises(
83+
ValueError, match="Invalid ContractId format. Expected 'shard.realm.contract'"
84+
):
7585
ContractId.from_string("1.2.3.4")
7686

87+
7788
def test_from_string_invalid_format_non_numeric():
7889
"""Test creating ContractId from invalid string format with non-numeric parts."""
7990
with pytest.raises(ValueError):
8091
ContractId.from_string("a.b.c")
8192

93+
8294
def test_from_string_invalid_format_empty():
8395
"""Test creating ContractId from empty string."""
84-
with pytest.raises(ValueError, match="Invalid ContractId format. Expected 'shard.realm.contract'"):
96+
with pytest.raises(
97+
ValueError, match="Invalid ContractId format. Expected 'shard.realm.contract'"
98+
):
8599
ContractId.from_string("")
86100

101+
87102
def test_from_string_invalid_format_partial_numeric():
88103
"""Test creating ContractId from string with some non-numeric parts."""
89104
with pytest.raises(ValueError):
90105
ContractId.from_string("1.a.3")
91106

107+
92108
def test_to_proto():
93109
"""Test converting ContractId to protobuf format."""
94110
contract_id = ContractId(shard=1, realm=2, contract=3)
95111
proto = contract_id._to_proto()
96-
112+
97113
assert isinstance(proto, basic_types_pb2.ContractID)
98114
assert proto.shardNum == 1
99115
assert proto.realmNum == 2
100116
assert proto.contractNum == 3
101117

118+
102119
def test_to_proto_default_values():
103120
"""Test converting ContractId with default values to protobuf format."""
104121
contract_id = ContractId()
105122
proto = contract_id._to_proto()
106-
123+
107124
assert isinstance(proto, basic_types_pb2.ContractID)
108125
assert proto.shardNum == 0
109126
assert proto.realmNum == 0
110127
assert proto.contractNum == 0
111128

129+
112130
def test_from_proto():
113131
"""Test creating ContractId from protobuf format."""
114-
proto = basic_types_pb2.ContractID(
115-
shardNum=1,
116-
realmNum=2,
117-
contractNum=3
118-
)
119-
132+
proto = basic_types_pb2.ContractID(shardNum=1, realmNum=2, contractNum=3)
133+
120134
contract_id = ContractId._from_proto(proto)
121-
135+
122136
assert contract_id.shard == 1
123137
assert contract_id.realm == 2
124138
assert contract_id.contract == 3
125139

140+
126141
def test_from_proto_zero_values():
127142
"""Test creating ContractId from protobuf format with zero values."""
128-
proto = basic_types_pb2.ContractID(
129-
shardNum=0,
130-
realmNum=0,
131-
contractNum=0
132-
)
133-
143+
proto = basic_types_pb2.ContractID(shardNum=0, realmNum=0, contractNum=0)
144+
134145
contract_id = ContractId._from_proto(proto)
135-
146+
136147
assert contract_id.shard == 0
137148
assert contract_id.realm == 0
138149
assert contract_id.contract == 0
139150

151+
140152
def test_roundtrip_proto_conversion():
141153
"""Test that converting to proto and back preserves values."""
142154
original = ContractId(shard=5, realm=10, contract=15)
143155
proto = original._to_proto()
144156
reconstructed = ContractId._from_proto(proto)
145-
157+
146158
assert original.shard == reconstructed.shard
147159
assert original.realm == reconstructed.realm
148160
assert original.contract == reconstructed.contract
149161

162+
150163
def test_roundtrip_string_conversion():
151164
"""Test that converting to string and back preserves values."""
152165
original = ContractId(shard=7, realm=14, contract=21)
153166
string_repr = str(original)
154167
reconstructed = ContractId.from_string(string_repr)
155-
168+
156169
assert original.shard == reconstructed.shard
157170
assert original.realm == reconstructed.realm
158171
assert original.contract == reconstructed.contract
159172

173+
160174
def test_equality():
161175
"""Test ContractId equality comparison."""
162176
contract_id1 = ContractId(shard=1, realm=2, contract=3)
163177
contract_id2 = ContractId(shard=1, realm=2, contract=3)
164178
contract_id3 = ContractId(shard=1, realm=2, contract=4)
165-
179+
166180
assert contract_id1 == contract_id2
167-
assert contract_id1 != contract_id3
181+
assert contract_id1 != contract_id3

0 commit comments

Comments
 (0)