-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a74d8d
commit 0826c12
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import "forge-std/Test.sol"; | ||
|
||
import {EIP712} from "../src/base/EIP712.sol"; | ||
|
||
contract EIP712Test is EIP712, Test { | ||
constructor() EIP712("EIP712Test") {} | ||
|
||
function setUp() public {} | ||
|
||
function test_domainSeparator() public view { | ||
assertEq( | ||
DOMAIN_SEPARATOR(), | ||
keccak256( | ||
abi.encode( | ||
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"), | ||
keccak256(bytes("EIP712Test")), | ||
block.chainid, | ||
address(this) | ||
) | ||
) | ||
); | ||
} | ||
|
||
function test_hashTypedData() public view { | ||
bytes32 dataHash = keccak256(abi.encodePacked("data")); | ||
assertEq(_hashTypedData(dataHash), keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), dataHash))); | ||
} | ||
|
||
function test_rebuildDomainSeparator() public { | ||
uint256 chainId = 4444; | ||
vm.chainId(chainId); | ||
assertEq( | ||
DOMAIN_SEPARATOR(), | ||
keccak256( | ||
abi.encode( | ||
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"), | ||
keccak256(bytes("EIP712Test")), | ||
chainId, | ||
address(this) | ||
) | ||
) | ||
); | ||
} | ||
} |