Correct Strings.toHexString Usage for Address Variables #387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes incorrect usage of Strings.toHexString for address type variables in the following files:
-MockAllMetadataViewModule.sol
-MockCoreMetadataViewModule.sol
Changes:
1-Converted Strings.toHexString(ipId) to Strings.toHexString(uint160(ipId)) to handle the address type correctly.
2-Updated Strings.toHexString(owner(ipId)) to Strings.toHexString(uint160(owner(ipId))).
3-Minor formatting corrections in the code for better readability.
These fixes ensure proper hexadecimal string conversion and resolve potential compilation issues.
Test Plan
The changes have been validated with test cases to ensure the correctness of the fixes:
1-Created a dedicated test file, TestToHexString.t.sol, to verify:
Incorrect usage: Using Strings.toHexString(ipId) directly with an address type.
Correct usage: Using Strings.toHexString(uint160(ipId)) for proper conversion.
2-Observed the following:
Compilation failed for incorrect usage.
Compilation passed successfully with the fixed code.
Example Test:
address ipId = 0x1234567890123456789012345678901234567890;
string memory result = Strings.toHexString(uint160(ipId));
emit log(result); // Successfully outputs hexadecimal string.
3-Test Results: Below is the screenshot of the successful test result:
Related Issue
Fixes: #386
Notes
Ensure this fix is applied consistently across other files that use Strings.toHexString with address types, if applicable.
The changes are backward compatible and do not affect the functionality beyond fixing the conversion issue.