-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEquityToken.System.t.sol
More file actions
199 lines (136 loc) · 5.43 KB
/
EquityToken.System.t.sol
File metadata and controls
199 lines (136 loc) · 5.43 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
/*
SYSTEM INTEGRATION TEST (NO MOCKS)
Purpose:
- Verify equityToken enforces compliance rules
using REAL production contracts:
- ComplianceRegistry
- ComplianceModule
- equityToken
- Verify proxy + initializer wiring
- Verify pause, blacklist, lockup, forced transfer end-to-end
This answers:
"Does the system work exactly as deployed?"
*/
import "forge-std/Test.sol";
import "../src/equityToken.sol";
import "../src/ComplianceModule.sol";
import "../src/complianceRegistry.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
contract EquityTokenSystemTest is Test {
//====================== ACTORS=====================================
address admin = address(0xA11CE);
address alice = address(0xBEEF);
address bob = address(0xCAFE);
address attacker = address(0xBAD);
//==================CONTRACTS============================================
equityToken token;
ComplianceModule compliance;
ComplianceRegistry registry;
//=========================SETUP==============================================
function setUp() public {
/* ---------------- ComplianceRegistry ---------------- */
ComplianceRegistry registryImpl = new ComplianceRegistry();
bytes memory registryInit =
abi.encodeWithSelector(
ComplianceRegistry.initialize.selector,
admin
);
registry = ComplianceRegistry(
address(new ERC1967Proxy(address(registryImpl), registryInit))
);
/* ---------------- ComplianceModule ---------------- */
ComplianceModule complianceImpl = new ComplianceModule();
bytes memory complianceInit =
abi.encodeWithSelector(
ComplianceModule.initialize.selector,
admin,
address(registry)
);
compliance = ComplianceModule(
address(new ERC1967Proxy(address(complianceImpl), complianceInit))
);
/* ---------------- equityToken ---------------- */
equityToken tokenImpl = new equityToken();
bytes memory tokenInit =
abi.encodeWithSelector(
equityToken.initialize.selector,
address(compliance),
admin
);
token = equityToken(
address(new ERC1967Proxy(address(tokenImpl), tokenInit))
);
/* ---------------- Baseline Compliance ---------------- */
vm.startPrank(admin);
registry.approve(admin);
registry.approve(alice);
registry.approve(bob);
registry.removeFromBlackList(admin);
registry.removeFromBlackList(alice);
registry.removeFromBlackList(bob);
vm.stopPrank();
/* ---------------- Distribute Shares ---------------- */
vm.prank(admin);
token.transfer(alice, 10);
}
function test_transfer_succeeds_when_compliant() public {
vm.prank(alice);
token.transfer(bob, 1);
assertEq(token.balanceOf(bob), 1);
assertEq(token.balanceOf(alice), 9);
}
//======================Pause================================
function test_transfer_reverts_when_paused() public {
vm.prank(admin);
compliance.pauseTransfers();
vm.expectRevert(" Tranfer Not Compliant");
vm.prank(alice);
token.transfer(bob, 1);
}
//===========================BLACKLIST=================================
function test_transfer_reverts_when_sender_blacklisted() public {
vm.prank(admin);
registry.blackList(alice);
vm.expectRevert(" Tranfer Not Compliant");
vm.prank(alice);
token.transfer(bob, 1);
}
function test_transfer_reverts_when_recipient_blacklisted() public {
vm.prank(admin);
registry.blackList(bob);
vm.expectRevert(" Tranfer Not Compliant");
vm.prank(alice);
token.transfer(bob, 1);
}
//=========================APPROVAL===================================
function test_transfer_reverts_when_recipient_not_approved() public {
vm.prank(admin);
registry.revoke(bob);
vm.expectRevert(" Tranfer Not Compliant");
vm.prank(alice);
token.transfer(bob, 1);
}
//=======================LOCKUP=============================================
function test_transfer_reverts_when_sender_locked() public {
vm.prank(admin);
compliance.setLockUp(alice, uint64(block.timestamp + 1 days));
vm.expectRevert(" Tranfer Not Compliant");
vm.prank(alice);
token.transfer(bob, 1);
}
//=================== FORCED TRANSFER=====================================
function test_admin_can_force_transfer() public {
vm.prank(admin);
token.forcedTransfer(alice, bob, 1);
assertEq(token.balanceOf(bob), 1);
}
function test_forced_transfer_respects_pause() public {
vm.prank(admin);
compliance.pauseTransfers();
vm.expectRevert(" Tranfer Not Compliant");
vm.prank(admin);
token.forcedTransfer(alice, bob, 1);
}
}