Files
openzeppelin-contracts/test/utils/cryptography/MessageHashUtils.t.sol
Hadrien Croubois 887697148d Release v5.3 cherrypick #2 (#5526)
Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Ernesto García <ernestognw@gmail.com>
Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
Co-authored-by: Voronor <129545215+voronor@users.noreply.github.com>
Co-authored-by: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com>
Co-authored-by: Michalis Kargakis <kargakis@protonmail.com>
2025-03-03 07:51:41 -07:00

34 lines
1.2 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Test} from "forge-std/Test.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
contract MessageHashUtilsTest is Test {
function testToDataWithIntendedValidatorHash(address validator, bytes memory data) external pure {
assertEq(
MessageHashUtils.toDataWithIntendedValidatorHash(validator, data),
MessageHashUtils.toDataWithIntendedValidatorHash(_dirty(validator), data)
);
}
function testToDataWithIntendedValidatorHash(address validator, bytes32 messageHash) external pure {
assertEq(
MessageHashUtils.toDataWithIntendedValidatorHash(validator, messageHash),
MessageHashUtils.toDataWithIntendedValidatorHash(_dirty(validator), messageHash)
);
assertEq(
MessageHashUtils.toDataWithIntendedValidatorHash(validator, messageHash),
MessageHashUtils.toDataWithIntendedValidatorHash(validator, abi.encodePacked(messageHash))
);
}
function _dirty(address input) private pure returns (address output) {
assembly ("memory-safe") {
output := or(input, shl(160, not(0)))
}
}
}