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>
This commit is contained in:
33
test/utils/cryptography/MessageHashUtils.t.sol
Normal file
33
test/utils/cryptography/MessageHashUtils.t.sol
Normal file
@ -0,0 +1,33 @@
|
||||
// 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)))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user