1
- import { SignerWithAddress } from ' @nomiclabs/hardhat-ethers/dist/src/signer-with-address' ;
1
+ import { SignerWithAddress } from " @nomiclabs/hardhat-ethers/dist/src/signer-with-address" ;
2
2
3
- import { id } from ' ../src/index' ;
3
+ import { id } from " ../src/index" ;
4
4
5
- import RestrictedERC20MockArtifact from ' ../artifacts/contracts/mocks/RestrictedERC20Mock.sol/RestrictedERC20Mock.json' ;
6
- import EmergencyBrakeArtifact from ' ../artifacts/contracts/utils/EmergencyBrake.sol/EmergencyBrake.json' ;
7
- import { RestrictedERC20Mock as ERC20 } from ' ../typechain/RestrictedERC20Mock' ;
8
- import { EmergencyBrake } from ' ../typechain/EmergencyBrake' ;
5
+ import RestrictedERC20MockArtifact from " ../artifacts/contracts/mocks/RestrictedERC20Mock.sol/RestrictedERC20Mock.json" ;
6
+ import EmergencyBrakeArtifact from " ../artifacts/contracts/utils/EmergencyBrake.sol/EmergencyBrake.json" ;
7
+ import { RestrictedERC20Mock as ERC20 } from " ../typechain/RestrictedERC20Mock" ;
8
+ import { EmergencyBrake } from " ../typechain/EmergencyBrake" ;
9
9
10
- import { BigNumber } from ' ethers' ;
10
+ import { BigNumber } from " ethers" ;
11
11
12
- import { ethers , waffle } from ' hardhat' ;
13
- import { expect } from ' chai' ;
12
+ import { ethers , waffle } from " hardhat" ;
13
+ import { expect } from " chai" ;
14
14
const { deployContract, loadFixture } = waffle ;
15
15
16
- describe ( ' EmergencyBrake' , async function ( ) {
16
+ describe ( " EmergencyBrake" , async function ( ) {
17
17
this . timeout ( 0 ) ;
18
18
19
19
let plannerAcc : SignerWithAddress ;
@@ -34,14 +34,14 @@ describe('EmergencyBrake', async function () {
34
34
TERMINATED : 3 ,
35
35
} ;
36
36
37
- const MINT = id ( ' mint(address,uint256)' )
38
- const BURN = id ( ' burn(address,uint256)' )
39
- const APPROVE = id ( ' approve(address,uint256)' )
40
- const TRANSFER = id ( ' transfer(address,uint256)' )
41
- const ROOT = ' 0x00000000'
42
-
43
- let contacts : string [ ]
44
- let signatures : string [ ] [ ]
37
+ const MINT = id ( " mint(address,uint256)" ) ;
38
+ const BURN = id ( " burn(address,uint256)" ) ;
39
+ const APPROVE = id ( " approve(address,uint256)" ) ;
40
+ const TRANSFER = id ( " transfer(address,uint256)" ) ;
41
+ const ROOT = " 0x00000000" ;
42
+
43
+ let contacts : string [ ] ;
44
+ let signatures : string [ ] [ ] ;
45
45
46
46
beforeEach ( async ( ) => {
47
47
const signers = await ethers . getSigners ( ) ;
@@ -53,186 +53,202 @@ describe('EmergencyBrake', async function () {
53
53
target = targetAcc . address ;
54
54
55
55
contact1 = ( await deployContract ( plannerAcc , RestrictedERC20MockArtifact , [
56
- ' Contact1' ,
57
- ' CT1' ,
56
+ " Contact1" ,
57
+ " CT1" ,
58
58
] ) ) as ERC20 ;
59
59
contact2 = ( await deployContract ( plannerAcc , RestrictedERC20MockArtifact , [
60
- ' Contact2' ,
61
- ' CT2' ,
60
+ " Contact2" ,
61
+ " CT2" ,
62
62
] ) ) as ERC20 ;
63
63
brake = ( await deployContract ( plannerAcc , EmergencyBrakeArtifact , [
64
64
planner ,
65
65
executor ,
66
66
] ) ) as EmergencyBrake ;
67
67
68
- await contact1 . grantRoles ( [ MINT , BURN ] , target )
69
- await contact2 . grantRoles ( [ TRANSFER , APPROVE ] , target )
68
+ await contact1 . grantRoles ( [ MINT , BURN ] , target ) ;
69
+ await contact2 . grantRoles ( [ TRANSFER , APPROVE ] , target ) ;
70
70
71
- await contact1 . grantRole ( ROOT , brake . address )
72
- await contact2 . grantRole ( ROOT , brake . address )
71
+ await contact1 . grantRole ( ROOT , brake . address ) ;
72
+ await contact2 . grantRole ( ROOT , brake . address ) ;
73
73
74
74
contacts = [ contact1 . address , contact2 . address ] ;
75
- signatures = [ [ MINT , BURN ] , [ TRANSFER , APPROVE ] ] ;
75
+ signatures = [
76
+ [ MINT , BURN ] ,
77
+ [ TRANSFER , APPROVE ] ,
78
+ ] ;
76
79
} ) ;
77
80
78
- it ( ' doesn\ 't allow mismatched inputs' , async ( ) => {
81
+ it ( " doesn't allow mismatched inputs" , async ( ) => {
79
82
const mismatch = [ [ MINT , BURN ] ] ;
80
83
81
84
await expect (
82
85
brake . connect ( plannerAcc ) . plan ( target , contacts , mismatch )
83
- ) . to . be . revertedWith ( ' Mismatched inputs' ) ;
86
+ ) . to . be . revertedWith ( " Mismatched inputs" ) ;
84
87
await expect (
85
88
brake . connect ( plannerAcc ) . cancel ( target , contacts , mismatch )
86
- ) . to . be . revertedWith ( ' Mismatched inputs' ) ;
89
+ ) . to . be . revertedWith ( " Mismatched inputs" ) ;
87
90
await expect (
88
91
brake . connect ( executorAcc ) . execute ( target , contacts , mismatch )
89
- ) . to . be . revertedWith ( ' Mismatched inputs' ) ;
92
+ ) . to . be . revertedWith ( " Mismatched inputs" ) ;
90
93
await expect (
91
94
brake . connect ( plannerAcc ) . restore ( target , contacts , mismatch )
92
- ) . to . be . revertedWith ( ' Mismatched inputs' ) ;
95
+ ) . to . be . revertedWith ( " Mismatched inputs" ) ;
93
96
await expect (
94
97
brake . connect ( plannerAcc ) . terminate ( target , contacts , mismatch )
95
- ) . to . be . revertedWith ( ' Mismatched inputs' ) ;
98
+ ) . to . be . revertedWith ( " Mismatched inputs" ) ;
96
99
} ) ;
97
100
98
- it ( ' doesn\ 't allow to cancel, execute, restore or terminate an unknown plan' , async ( ) => {
101
+ it ( " doesn't allow to cancel, execute, restore or terminate an unknown plan" , async ( ) => {
99
102
await expect (
100
103
brake . connect ( plannerAcc ) . cancel ( target , contacts , signatures )
101
- ) . to . be . revertedWith ( ' Emergency not planned for.' ) ;
104
+ ) . to . be . revertedWith ( " Emergency not planned for." ) ;
102
105
await expect (
103
106
brake . connect ( executorAcc ) . execute ( target , contacts , signatures )
104
- ) . to . be . revertedWith ( ' Emergency not planned for.' ) ;
107
+ ) . to . be . revertedWith ( " Emergency not planned for." ) ;
105
108
await expect (
106
109
brake . connect ( plannerAcc ) . restore ( target , contacts , signatures )
107
- ) . to . be . revertedWith ( ' Emergency plan not executed.' ) ;
110
+ ) . to . be . revertedWith ( " Emergency plan not executed." ) ;
108
111
await expect (
109
112
brake . connect ( plannerAcc ) . terminate ( target , contacts , signatures )
110
- ) . to . be . revertedWith ( ' Emergency plan not executed.' ) ;
113
+ ) . to . be . revertedWith ( " Emergency plan not executed." ) ;
111
114
} ) ;
112
115
113
- it ( ' only the planner can plan' , async ( ) => {
116
+ it ( " only the planner can plan" , async ( ) => {
114
117
await expect (
115
118
brake . connect ( executorAcc ) . plan ( target , contacts , signatures )
116
- ) . to . be . revertedWith ( ' Access denied' ) ;
119
+ ) . to . be . revertedWith ( " Access denied" ) ;
117
120
} ) ;
118
121
119
- it ( ' ROOT is out of bounds' , async ( ) => {
122
+ it ( " ROOT is out of bounds" , async ( ) => {
120
123
const tryRoot = [ [ ROOT ] , [ TRANSFER , APPROVE ] ] ;
121
124
await expect (
122
125
brake . connect ( plannerAcc ) . plan ( target , contacts , tryRoot )
123
- ) . to . be . revertedWith ( ' Can\ 't remove ROOT' ) ;
126
+ ) . to . be . revertedWith ( " Can't remove ROOT" ) ;
124
127
} ) ;
125
128
126
- it ( 'emergencies can be planned' , async ( ) => {
127
- const txHash = await brake . connect ( plannerAcc ) . callStatic . plan ( target , contacts , signatures ) ;
129
+ it ( "emergencies can be planned" , async ( ) => {
130
+ const txHash = await brake
131
+ . connect ( plannerAcc )
132
+ . callStatic . plan ( target , contacts , signatures ) ;
128
133
129
- expect ( await brake . connect ( plannerAcc ) . plan ( target , contacts , signatures ) )
130
- . to . emit ( brake , 'Planned' ) ;
134
+ expect (
135
+ await brake . connect ( plannerAcc ) . plan ( target , contacts , signatures )
136
+ ) . to . emit ( brake , "Planned" ) ;
131
137
132
- expect ( await brake . plans ( txHash ) ) . to . equal ( state . PLANNED )
138
+ expect ( await brake . plans ( txHash ) ) . to . equal ( state . PLANNED ) ;
133
139
} ) ;
134
140
135
- describe ( ' with a planned emergency' , async ( ) => {
141
+ describe ( " with a planned emergency" , async ( ) => {
136
142
let txHash : string ;
137
143
138
144
beforeEach ( async ( ) => {
139
- txHash = await brake . connect ( plannerAcc ) . callStatic . plan ( target , contacts , signatures ) ;
140
-
141
- await brake . connect ( plannerAcc ) . plan ( target , contacts , signatures )
145
+ txHash = await brake
146
+ . connect ( plannerAcc )
147
+ . callStatic . plan ( target , contacts , signatures ) ;
148
+
149
+ await brake . connect ( plannerAcc ) . plan ( target , contacts , signatures ) ;
142
150
} ) ;
143
151
144
- it ( ' the same emergency plan cant\ 't registered twice' , async ( ) => {
152
+ it ( " the same emergency plan cant't registered twice" , async ( ) => {
145
153
await expect (
146
154
brake . connect ( plannerAcc ) . plan ( target , contacts , signatures )
147
- ) . to . be . revertedWith ( ' Emergency already planned for.' ) ;
155
+ ) . to . be . revertedWith ( " Emergency already planned for." ) ;
148
156
} ) ;
149
157
150
- it ( ' only the planner can cancel' , async ( ) => {
158
+ it ( " only the planner can cancel" , async ( ) => {
151
159
await expect (
152
160
brake . connect ( executorAcc ) . cancel ( target , contacts , signatures )
153
- ) . to . be . revertedWith ( ' Access denied' ) ;
161
+ ) . to . be . revertedWith ( " Access denied" ) ;
154
162
} ) ;
155
163
156
- it ( ' cancels a plan' , async ( ) => {
164
+ it ( " cancels a plan" , async ( ) => {
157
165
await expect (
158
166
await brake . connect ( plannerAcc ) . cancel ( target , contacts , signatures )
159
- ) . to . emit ( brake , ' Cancelled' ) ;
167
+ ) . to . emit ( brake , " Cancelled" ) ;
160
168
// .withArgs(txHash, target, contacts, signatures)
161
169
expect ( await brake . plans ( txHash ) ) . to . equal ( state . UNKNOWN ) ;
162
170
} ) ;
163
171
164
- it ( ' cant\ 't restore or terminate a plan that hasn\ 't been executed' , async ( ) => {
172
+ it ( " cant't restore or terminate a plan that hasn't been executed" , async ( ) => {
165
173
await expect (
166
174
brake . connect ( plannerAcc ) . restore ( target , contacts , signatures )
167
- ) . to . be . revertedWith ( ' Emergency plan not executed.' ) ;
175
+ ) . to . be . revertedWith ( " Emergency plan not executed." ) ;
168
176
await expect (
169
177
brake . connect ( plannerAcc ) . terminate ( target , contacts , signatures )
170
- ) . to . be . revertedWith ( ' Emergency plan not executed.' ) ;
178
+ ) . to . be . revertedWith ( " Emergency plan not executed." ) ;
171
179
} ) ;
172
-
173
- it ( ' only the executor can execute' , async ( ) => {
180
+
181
+ it ( " only the executor can execute" , async ( ) => {
174
182
await expect (
175
183
brake . connect ( plannerAcc ) . execute ( target , contacts , signatures )
176
- ) . to . be . revertedWith ( ' Access denied' ) ;
184
+ ) . to . be . revertedWith ( " Access denied" ) ;
177
185
} ) ;
178
186
179
- it ( 'can\'t revoke non-existing permissions' , async ( ) => {
180
- const nonExisting = [ [ MINT , BURN ] , [ MINT , BURN ] ] ;
181
- await brake . connect ( plannerAcc ) . plan ( target , contacts , nonExisting ) // It can be planned, because permissions could be different at execution time
187
+ it ( "can't revoke non-existing permissions" , async ( ) => {
188
+ const nonExisting = [
189
+ [ MINT , BURN ] ,
190
+ [ MINT , BURN ] ,
191
+ ] ;
192
+ await brake . connect ( plannerAcc ) . plan ( target , contacts , nonExisting ) ; // It can be planned, because permissions could be different at execution time
182
193
await expect (
183
194
brake . connect ( executorAcc ) . execute ( target , contacts , nonExisting )
184
- ) . to . be . revertedWith ( ' Permission not found' ) ;
195
+ ) . to . be . revertedWith ( " Permission not found" ) ;
185
196
} ) ;
186
197
187
- it ( 'plans can be executed' , async ( ) => {
188
- expect ( await brake . connect ( executorAcc ) . execute ( target , contacts , signatures ) )
189
- . to . emit ( brake , 'Executed' ) ;
198
+ it ( "plans can be executed" , async ( ) => {
199
+ expect (
200
+ await brake . connect ( executorAcc ) . execute ( target , contacts , signatures )
201
+ ) . to . emit ( brake , "Executed" ) ;
190
202
191
- expect ( await contact1 . hasRole ( MINT , target ) ) . to . be . false
192
- expect ( await contact1 . hasRole ( BURN , target ) ) . to . be . false
193
- expect ( await contact2 . hasRole ( APPROVE , target ) ) . to . be . false
194
- expect ( await contact2 . hasRole ( TRANSFER , target ) ) . to . be . false
203
+ expect ( await contact1 . hasRole ( MINT , target ) ) . to . be . false ;
204
+ expect ( await contact1 . hasRole ( BURN , target ) ) . to . be . false ;
205
+ expect ( await contact2 . hasRole ( APPROVE , target ) ) . to . be . false ;
206
+ expect ( await contact2 . hasRole ( TRANSFER , target ) ) . to . be . false ;
195
207
196
- expect ( await brake . plans ( txHash ) ) . to . equal ( state . EXECUTED )
208
+ expect ( await brake . plans ( txHash ) ) . to . equal ( state . EXECUTED ) ;
197
209
} ) ;
198
210
199
- describe ( ' with an executed emergency plan' , async ( ) => {
211
+ describe ( " with an executed emergency plan" , async ( ) => {
200
212
beforeEach ( async ( ) => {
201
213
await brake . connect ( executorAcc ) . execute ( target , contacts , signatures ) ;
202
214
} ) ;
203
215
204
- it ( ' the same emergency plan cant\ 't executed twice' , async ( ) => {
216
+ it ( " the same emergency plan cant't executed twice" , async ( ) => {
205
217
await expect (
206
218
brake . connect ( executorAcc ) . execute ( target , contacts , signatures )
207
- ) . to . be . revertedWith ( ' Emergency not planned for.' ) ;
219
+ ) . to . be . revertedWith ( " Emergency not planned for." ) ;
208
220
} ) ;
209
-
210
- it ( ' only the planner can restore or terminate' , async ( ) => {
221
+
222
+ it ( " only the planner can restore or terminate" , async ( ) => {
211
223
await expect (
212
224
brake . connect ( executorAcc ) . restore ( target , contacts , signatures )
213
- ) . to . be . revertedWith ( ' Access denied' ) ;
225
+ ) . to . be . revertedWith ( " Access denied" ) ;
214
226
await expect (
215
227
brake . connect ( executorAcc ) . terminate ( target , contacts , signatures )
216
- ) . to . be . revertedWith ( ' Access denied' ) ;
228
+ ) . to . be . revertedWith ( " Access denied" ) ;
217
229
} ) ;
218
230
219
- it ( 'state can be restored' , async ( ) => {
220
- expect ( await brake . connect ( plannerAcc ) . restore ( target , contacts , signatures ) )
221
- . to . emit ( brake , 'Restored' ) ;
231
+ it ( "state can be restored" , async ( ) => {
232
+ expect (
233
+ await brake . connect ( plannerAcc ) . restore ( target , contacts , signatures )
234
+ ) . to . emit ( brake , "Restored" ) ;
222
235
223
- expect ( await contact1 . hasRole ( MINT , target ) ) . to . be . true
224
- expect ( await contact1 . hasRole ( BURN , target ) ) . to . be . true
225
- expect ( await contact2 . hasRole ( APPROVE , target ) ) . to . be . true
226
- expect ( await contact2 . hasRole ( TRANSFER , target ) ) . to . be . true
236
+ expect ( await contact1 . hasRole ( MINT , target ) ) . to . be . true ;
237
+ expect ( await contact1 . hasRole ( BURN , target ) ) . to . be . true ;
238
+ expect ( await contact2 . hasRole ( APPROVE , target ) ) . to . be . true ;
239
+ expect ( await contact2 . hasRole ( TRANSFER , target ) ) . to . be . true ;
227
240
228
- expect ( await brake . plans ( txHash ) ) . to . equal ( state . PLANNED )
241
+ expect ( await brake . plans ( txHash ) ) . to . equal ( state . PLANNED ) ;
229
242
} ) ;
230
243
231
- it ( 'target can be terminated' , async ( ) => {
232
- expect ( await brake . connect ( plannerAcc ) . terminate ( target , contacts , signatures ) )
233
- . to . emit ( brake , 'Terminated' ) ;
244
+ it ( "target can be terminated" , async ( ) => {
245
+ expect (
246
+ await brake
247
+ . connect ( plannerAcc )
248
+ . terminate ( target , contacts , signatures )
249
+ ) . to . emit ( brake , "Terminated" ) ;
234
250
235
- expect ( await brake . plans ( txHash ) ) . to . equal ( state . TERMINATED )
251
+ expect ( await brake . plans ( txHash ) ) . to . equal ( state . TERMINATED ) ;
236
252
} ) ;
237
253
} ) ;
238
254
} ) ;
0 commit comments