Skip to content

Commit ec31a1d

Browse files
committed
refactor: update entity ID fuzz target and improve exception handling in fuzzers
Signed-off-by: Ntege Daniel <danientege785@gmail.com>
1 parent a884693 commit ec31a1d

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

.clusterfuzzlite/entity_id_fuzzer.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Atheris fuzz target: entity ID string parsing (AccountId, TokenId, ContractId)."""
1+
"""Atheris fuzz target: entity ID string parsing."""
22

33
from __future__ import annotations
44

@@ -8,10 +8,16 @@
88

99

1010
with atheris.instrument_imports():
11-
from hiero_sdk_python import AccountId, TokenId
12-
from hiero_sdk_python.contract.contract_id import ContractId
11+
from hiero_sdk_python import AccountId, ContractId, FileId, TokenId, TopicId
1312

14-
_CLASSES = (AccountId, TokenId, ContractId)
13+
_CLASSES = (AccountId, TokenId, ContractId, FileId, TopicId)
14+
15+
16+
def _try_parse_entity_id(entity_id_class, text: str) -> None:
17+
try:
18+
entity_id_class.from_string(text)
19+
except (TypeError, ValueError):
20+
pass
1521

1622

1723
def TestOneInput(data: bytes) -> None:
@@ -20,10 +26,7 @@ def TestOneInput(data: bytes) -> None:
2026
text = fdp.ConsumeUnicodeNoSurrogates(256)
2127

2228
for cls in _CLASSES:
23-
try:
24-
cls.from_string(text)
25-
except Exception: # noqa: PERF203
26-
pass
29+
_try_parse_entity_id(cls, text)
2730

2831

2932
atheris.Setup(sys.argv, TestOneInput)

.clusterfuzzlite/keys_fuzzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def TestOneInput(data: bytes) -> None:
3737
else:
3838
raw = fdp.ConsumeBytes(128)
3939
_quiet(PublicKey.from_bytes, raw)
40-
except Exception:
40+
except ValueError:
4141
pass
4242

4343

.clusterfuzzlite/transaction_from_bytes_fuzzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def TestOneInput(data: bytes) -> None:
1616
try:
1717
tx = Transaction.from_bytes(data)
1818
tx.to_bytes()
19-
except Exception:
19+
except ValueError:
2020
# All parsing / validation failures are expected; only unhandled
2121
# exceptions that escape this function are reported as fuzzer crashes.
2222
pass

src/hiero_sdk_python/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from .contract.contract_execute_transaction import ContractExecuteTransaction
3232
from .contract.contract_function_parameters import ContractFunctionParameters
3333
from .contract.contract_function_result import ContractFunctionResult
34+
from .contract.contract_id import ContractId
3435
from .contract.contract_info import ContractInfo
3536
from .contract.contract_info_query import ContractInfoQuery
3637
from .contract.contract_update_transaction import ContractUpdateTransaction
@@ -52,6 +53,7 @@
5253
from .file.file_contents_query import FileContentsQuery
5354
from .file.file_create_transaction import FileCreateTransaction
5455
from .file.file_delete_transaction import FileDeleteTransaction
56+
from .file.file_id import FileId
5557
from .file.file_info import FileInfo
5658
from .file.file_info_query import FileInfoQuery
5759
from .file.file_update_transaction import FileUpdateTransaction
@@ -249,6 +251,7 @@
249251
# File
250252
"FileCreateTransaction",
251253
"FileAppendTransaction",
254+
"FileId",
252255
"FileInfoQuery",
253256
"FileInfo",
254257
"FileContentsQuery",
@@ -257,6 +260,7 @@
257260
# Contract
258261
"ContractCreateTransaction",
259262
"ContractCallQuery",
263+
"ContractId",
260264
"ContractInfoQuery",
261265
"ContractBytecodeQuery",
262266
"ContractExecuteTransaction",

0 commit comments

Comments
 (0)