|
| 1 | +from hiero_sdk_python.client.client import Client |
1 | 2 | import pytest |
| 3 | +from unittest import mock |
2 | 4 | from hiero_sdk_python.tokens.custom_fee import CustomFee |
3 | 5 | from hiero_sdk_python.tokens.custom_fixed_fee import CustomFixedFee |
4 | 6 | from hiero_sdk_python.tokens.custom_fractional_fee import CustomFractionalFee |
@@ -200,3 +202,54 @@ def test_custom_royalty_fee_str(custom_royalty_fee: CustomRoyaltyFee, expected_s |
200 | 202 | """Test the string representation of CustomRoyaltyFee.""" |
201 | 203 | fee_str = str(custom_royalty_fee) |
202 | 204 | assert fee_str == expected_str |
| 205 | + |
| 206 | +class DummyCustomFee(CustomFee): |
| 207 | + def _to_proto(self): |
| 208 | + return "dummy-proto" |
| 209 | + |
| 210 | +def test_custom_fee_init_and_setters(): |
| 211 | + fee = DummyCustomFee() |
| 212 | + assert fee.fee_collector_account_id is None |
| 213 | + assert fee.all_collectors_are_exempt is False |
| 214 | + |
| 215 | + mock_account = AccountId(0, 0, 123) |
| 216 | + fee.set_fee_collector_account_id(mock_account) |
| 217 | + assert fee.fee_collector_account_id == mock_account |
| 218 | + |
| 219 | + fee.set_all_collectors_are_exempt(True) |
| 220 | + assert fee.all_collectors_are_exempt is True |
| 221 | + |
| 222 | +def test_custom_fee_equality(): |
| 223 | + fee1 = DummyCustomFee() |
| 224 | + fee2 = DummyCustomFee() |
| 225 | + assert fee1 == fee2 |
| 226 | + |
| 227 | + fee1.set_all_collectors_are_exempt(True) |
| 228 | + assert fee1 != fee2 |
| 229 | + |
| 230 | +def test_custom_fee_get_fee_collector_account_id_protobuf(): |
| 231 | + fee = DummyCustomFee() |
| 232 | + assert fee._get_fee_collector_account_id_protobuf() is None |
| 233 | + |
| 234 | + mock_account = mock.Mock(AccountId) |
| 235 | + mock_account._to_proto.return_value = "proto-account" |
| 236 | + fee.set_fee_collector_account_id(mock_account) |
| 237 | + assert fee._get_fee_collector_account_id_protobuf() == "proto-account" |
| 238 | + |
| 239 | +def test_custom_fee_validate_checksums(): |
| 240 | + fee = DummyCustomFee() |
| 241 | + # No account, should not call validate_checksum |
| 242 | + client = mock.Mock(Client) |
| 243 | + fee._validate_checksums(client) |
| 244 | + |
| 245 | + mock_account = mock.Mock(AccountId) |
| 246 | + fee.set_fee_collector_account_id(mock_account) |
| 247 | + fee._validate_checksums(client) |
| 248 | + mock_account.validate_checksum.assert_called_once_with(client) |
| 249 | + |
| 250 | +def test_custom_fee_from_proto_unrecognized(): |
| 251 | + class FakeProto: |
| 252 | + def WhichOneof(self, name): |
| 253 | + return "unknown_fee" |
| 254 | + with pytest.raises(ValueError): |
| 255 | + CustomFee._from_proto(FakeProto()) |
0 commit comments