Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct Strings.toHexString Usage for Address Variables #387

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Himess
Copy link

@Himess Himess commented Jan 23, 2025

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:
image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect Usage of Strings.toHexString Without Proper Address Conversion in Two Files
1 participant