-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathIdGatewayTestSuite.sol
More file actions
68 lines (53 loc) · 2.33 KB
/
Copy pathIdGatewayTestSuite.sol
File metadata and controls
68 lines (53 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;
import {TestSuiteSetup} from "../TestSuiteSetup.sol";
import {StorageRegistryTestSuite} from "../StorageRegistry/StorageRegistryTestSuite.sol";
import {IdRegistryTestSuite} from "../IdRegistry/IdRegistryTestSuite.sol";
import {KeyRegistryTestSuite} from "../KeyRegistry/KeyRegistryTestSuite.sol";
import {IdGateway} from "../../src/IdGateway.sol";
/* solhint-disable state-visibility */
abstract contract IdGatewayTestSuite is StorageRegistryTestSuite, KeyRegistryTestSuite {
IdGateway idGateway;
function setUp() public virtual override(StorageRegistryTestSuite, KeyRegistryTestSuite) {
super.setUp();
idGateway = new IdGateway(address(idRegistry), address(storageRegistry), owner);
vm.startPrank(owner);
idRegistry.setIdGateway(address(idGateway));
vm.stopPrank();
addKnownContract(address(idGateway));
}
function _registerTo(
address caller
) internal returns (uint256 fid) {
fid = _registerWithRecovery(caller, address(0));
}
function _registerToWithRecovery(address caller, address recovery) internal returns (uint256 fid) {
vm.prank(caller);
(fid,) = idGateway.register(recovery);
}
function _registerFor(uint256 callerPk, uint40 _deadline) internal {
_registerForWithRecovery(callerPk, address(0), _deadline);
}
function _registerForWithRecovery(uint256 callerPk, address recovery, uint40 _deadline) internal {
uint256 deadline = _boundDeadline(_deadline);
callerPk = _boundPk(callerPk);
address caller = vm.addr(callerPk);
bytes memory sig = _signRegister(callerPk, caller, recovery, deadline);
vm.prank(caller);
idGateway.registerFor(caller, recovery, deadline, sig);
}
function _signRegister(
uint256 pk,
address to,
address recovery,
uint256 deadline
) internal view returns (bytes memory signature) {
address signer = vm.addr(pk);
bytes32 digest = idGateway.hashTypedDataV4(
keccak256(abi.encode(idGateway.REGISTER_TYPEHASH(), to, recovery, idGateway.nonces(signer), deadline))
);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk, digest);
signature = abi.encodePacked(r, s, v);
assertEq(signature.length, 65);
}
}