Skip to content

Commit 11f22f5

Browse files
test: add tests for the custom fee class (#991) (#1011)
Signed-off-by: HusseinYasser <husseinyasser388@gmail.com>
1 parent c3462f6 commit 11f22f5

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
2929

3030
- Allow `PublicKey` for `TokenUpdateKeys` in `TokenUpdateTransaction`, enabling non-custodial workflows where operators can build transactions using only public keys (#934).
3131
- Bump protobuf toml to protobuf==6.33.2
32+
- Added more tests to the CustomFee class for different functionalities (#991)
3233

3334
### Fixed
3435

tests/unit/test_custom_fee.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
from hiero_sdk_python.client.client import Client
12
import pytest
3+
from unittest import mock
24
from hiero_sdk_python.tokens.custom_fee import CustomFee
35
from hiero_sdk_python.tokens.custom_fixed_fee import CustomFixedFee
46
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
200202
"""Test the string representation of CustomRoyaltyFee."""
201203
fee_str = str(custom_royalty_fee)
202204
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

Comments
 (0)