1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^ 0.8.22 ;
3
+
4
+ import "forge-std/Test.sol " ;
5
+ import "../src/shutter-service/ShutterRegistry.sol " ;
6
+
7
+ contract ShutterRegistryTest is Test {
8
+ ShutterRegistry public shutterRegistry;
9
+
10
+ function setUp () public {
11
+ shutterRegistry = new ShutterRegistry ();
12
+ }
13
+
14
+ function testIdentityRegistration () public {
15
+ uint64 eon = 5 ;
16
+ bytes32 identityPrefix = hex "001122 " ;
17
+ uint64 timestamp = uint64 (block .timestamp ) + 100 ;
18
+ address sender = makeAddr ("sender " );
19
+
20
+ vm.expectEmit (address (shutterRegistry));
21
+ emit ShutterRegistry.IdentityRegistered (
22
+ eon,
23
+ identityPrefix,
24
+ sender,
25
+ timestamp
26
+ );
27
+
28
+ hoax (sender);
29
+ shutterRegistry.register (
30
+ eon,
31
+ identityPrefix,
32
+ timestamp
33
+ );
34
+
35
+ bytes32 identity = keccak256 (
36
+ abi.encodePacked (identityPrefix, sender)
37
+ );
38
+ (uint64 registeredEon , uint64 registeredTimestamp ) = shutterRegistry.registrations (identity);
39
+
40
+ //verifying registered timestamp
41
+ assertEqUint (registeredEon, eon);
42
+ assertEqUint (registeredTimestamp, timestamp);
43
+ }
44
+
45
+ function testDuplicateRegistration () public {
46
+ uint64 eon = 5 ;
47
+ bytes32 identityPrefix = hex "001122 " ;
48
+ uint64 timestamp = uint64 (block .timestamp ) + 100 ;
49
+ address sender = makeAddr ("sender " );
50
+
51
+ vm.expectEmit (address (shutterRegistry));
52
+ emit ShutterRegistry.IdentityRegistered (
53
+ eon,
54
+ identityPrefix,
55
+ sender,
56
+ timestamp
57
+ );
58
+
59
+ hoax (sender);
60
+ shutterRegistry.register (
61
+ eon,
62
+ identityPrefix,
63
+ timestamp
64
+ );
65
+
66
+ uint64 newTimestamp = uint64 (block .timestamp ) + 200 ;
67
+ vm.expectRevert (ShutterRegistry.AlreadyRegistered.selector );
68
+ hoax (sender);
69
+ shutterRegistry.register (
70
+ eon,
71
+ identityPrefix,
72
+ newTimestamp
73
+ );
74
+
75
+ //verifying registered timestamp
76
+ bytes32 identity = keccak256 (
77
+ abi.encodePacked (identityPrefix, sender)
78
+ );
79
+ (, uint64 registeredTimestamp ) = shutterRegistry.registrations (identity);
80
+ assertEqUint (registeredTimestamp, timestamp);
81
+ }
82
+
83
+ function testInvalidTimestamp () public {
84
+ uint64 eon = 5 ;
85
+ bytes32 identityPrefix = hex "001122 " ;
86
+ uint64 timestamp = uint64 (block .timestamp ) - 1 ;
87
+ address sender = makeAddr ("sender " );
88
+
89
+ vm.expectRevert (ShutterRegistry.TimestampInThePast.selector );
90
+ hoax (sender);
91
+ shutterRegistry.register (
92
+ eon,
93
+ identityPrefix,
94
+ timestamp
95
+ );
96
+ }
97
+
98
+ function testMissingIdentity () public {
99
+ uint64 eon = 5 ;
100
+ // zero bytes for identity prefix should fail
101
+ bytes32 identityPrefix = hex "00 " ;
102
+ uint64 timestamp = uint64 (block .timestamp ) + 100 ;
103
+ address sender = makeAddr ("sender " );
104
+
105
+ vm.expectRevert (ShutterRegistry.InvalidIdentityPrefix.selector );
106
+ hoax (sender);
107
+ shutterRegistry.register (
108
+ eon,
109
+ identityPrefix,
110
+ timestamp
111
+ );
112
+ }
113
+ }
0 commit comments