@@ -81,23 +81,25 @@ describe("Draw Benchmark", async () => {
81
81
} ) ;
82
82
rng = ( await ethers . getContract ( "IncrementalNG" ) ) as IncrementalNG ;
83
83
84
- await sortitionModule . changeRandomNumberGenerator ( rng . target , 20 ) ;
84
+ await sortitionModule . changeRandomNumberGenerator ( rng . target , 20 ) . then ( ( tx ) => tx . wait ( ) ) ;
85
85
86
86
// CourtId 2 = CHILD_COURT
87
87
const minStake = 3n * 10n ** 20n ; // 300 PNK
88
88
const alpha = 10000n ;
89
89
const feeForJuror = ONE_TENTH_ETH ;
90
- await core . createCourt (
91
- 1 ,
92
- false ,
93
- minStake ,
94
- alpha ,
95
- feeForJuror ,
96
- 256 ,
97
- [ 0 , 0 , 0 , 10 ] , // evidencePeriod, commitPeriod, votePeriod, appealPeriod
98
- ethers . toBeHex ( 5 ) , // Extra data for sortition module will return the default value of K)
99
- [ 1 ]
100
- ) ;
90
+ await core
91
+ . createCourt (
92
+ 1 ,
93
+ false ,
94
+ minStake ,
95
+ alpha ,
96
+ feeForJuror ,
97
+ 256 ,
98
+ [ 0 , 0 , 0 , 10 ] , // evidencePeriod, commitPeriod, votePeriod, appealPeriod
99
+ ethers . toBeHex ( 5 ) , // Extra data for sortition module will return the default value of K)
100
+ [ 1 ]
101
+ )
102
+ . then ( ( tx ) => tx . wait ( ) ) ;
101
103
} ) ;
102
104
103
105
type CountedDraws = { [ address : string ] : number } ;
@@ -119,16 +121,21 @@ describe("Draw Benchmark", async () => {
119
121
const wallet = ethers . Wallet . createRandom ( ) . connect ( ethers . provider ) ;
120
122
wallets . push ( wallet ) ;
121
123
122
- await bridger . sendTransaction ( {
123
- to : wallet . address ,
124
- value : ethers . parseEther ( "10" ) ,
125
- } ) ;
124
+ await bridger
125
+ . sendTransaction ( {
126
+ to : wallet . address ,
127
+ value : ethers . parseEther ( "10" ) ,
128
+ } )
129
+ . then ( ( tx ) => tx . wait ( ) ) ;
126
130
expect ( await ethers . provider . getBalance ( wallet ) ) . to . equal ( ethers . parseEther ( "10" ) ) ;
127
131
128
- await pnk . transfer ( wallet . address , ONE_THOUSAND_PNK * 10n ) ;
132
+ await pnk . transfer ( wallet . address , ONE_THOUSAND_PNK * 10n ) . then ( ( tx ) => tx . wait ( ) ) ;
129
133
expect ( await pnk . balanceOf ( wallet . address ) ) . to . equal ( ONE_THOUSAND_PNK * 10n ) ;
130
134
131
- await pnk . connect ( wallet ) . approve ( core . target , ONE_THOUSAND_PNK * 10n , { gasLimit : 300000 } ) ;
135
+ await pnk
136
+ . connect ( wallet )
137
+ . approve ( core . target , ONE_THOUSAND_PNK * 10n , { gasLimit : 300000 } )
138
+ . then ( ( tx ) => tx . wait ( ) ) ;
132
139
133
140
await stake ( wallet ) ;
134
141
}
@@ -159,22 +166,23 @@ describe("Draw Benchmark", async () => {
159
166
extraData : `0x000000000000000000000000000000000000000000000000000000000000000${ createDisputeCourtId } 0000000000000000000000000000000000000000000000000000000000000003` ,
160
167
} ,
161
168
{ value : arbitrationCost }
162
- ) ;
169
+ )
170
+ . then ( ( tx ) => tx . wait ( ) ) ;
163
171
164
172
await network . provider . send ( "evm_increaseTime" , [ 2000 ] ) ; // Wait for minStakingTime
165
173
await network . provider . send ( "evm_mine" ) ;
166
- await sortitionModule . passPhase ( ) ; // Staking -> Generating
174
+ await sortitionModule . passPhase ( ) . then ( ( tx ) => tx . wait ( ) ) ; // Staking -> Generating
167
175
168
176
const lookahead = await sortitionModule . rngLookahead ( ) ;
169
177
for ( let index = 0 ; index < lookahead ; index ++ ) {
170
178
await network . provider . send ( "evm_mine" ) ;
171
179
}
172
180
173
- await sortitionModule . passPhase ( ) ; // Generating -> Drawing
181
+ await sortitionModule . passPhase ( ) . then ( ( tx ) => tx . wait ( ) ) ; // Generating -> Drawing
174
182
await expectFromDraw ( core . draw ( 0 , 20 , { gasLimit : 1000000 } ) ) ;
175
183
176
184
await network . provider . send ( "evm_increaseTime" , [ 2000 ] ) ; // Wait for maxDrawingTime
177
- await sortitionModule . passPhase ( ) ; // Drawing -> Staking
185
+ await sortitionModule . passPhase ( ) . then ( ( tx ) => tx . wait ( ) ) ; // Drawing -> Staking
178
186
expect ( await sortitionModule . phase ( ) ) . to . equal ( Phase . staking ) ;
179
187
180
188
// Unstake jurors
@@ -194,7 +202,10 @@ describe("Draw Benchmark", async () => {
194
202
195
203
it ( "Stakes in parent court and should draw jurors in parent court" , async ( ) => {
196
204
const stake = async ( wallet : HDNodeWallet ) => {
197
- await core . connect ( wallet ) . setStake ( PARENT_COURT , ONE_THOUSAND_PNK * 5n , { gasLimit : 5000000 } ) ;
205
+ await core
206
+ . connect ( wallet )
207
+ . setStake ( PARENT_COURT , ONE_THOUSAND_PNK * 5n , { gasLimit : 5000000 } )
208
+ . then ( ( tx ) => tx . wait ( ) ) ;
198
209
199
210
expect ( await sortitionModule . getJurorBalance ( wallet . address , 1 ) ) . to . deep . equal ( [
200
211
ONE_THOUSAND_PNK * 5n , // totalStaked
@@ -205,9 +216,6 @@ describe("Draw Benchmark", async () => {
205
216
} ;
206
217
let countedDraws : CountedDraws ;
207
218
const expectFromDraw = async ( drawTx : Promise < ContractTransactionResponse > ) => {
208
- console . log ( ( await core . getRoundInfo ( 0 , 0 ) ) . drawIterations ) ;
209
- expect ( await core . getRoundInfo ( 0 , 0 ) . then ( ( round ) => round . drawIterations ) ) . to . equal ( 3 ) ;
210
-
211
219
const tx = await ( await drawTx ) . wait ( ) ;
212
220
if ( ! tx ) throw new Error ( "Failed to get transaction receipt" ) ;
213
221
expect ( tx )
@@ -233,10 +241,14 @@ describe("Draw Benchmark", async () => {
233
241
1 , // nbOfCourts
234
242
] ) ;
235
243
}
244
+ expect ( await core . getRoundInfo ( 0 , 0 ) . then ( ( round ) => round . drawIterations ) ) . to . equal ( 3 ) ;
236
245
} ;
237
246
238
247
const unstake = async ( wallet : HDNodeWallet ) => {
239
- await core . connect ( wallet ) . setStake ( PARENT_COURT , 0 , { gasLimit : 5000000 } ) ;
248
+ await core
249
+ . connect ( wallet )
250
+ . setStake ( PARENT_COURT , 0 , { gasLimit : 5000000 } )
251
+ . then ( ( tx ) => tx . wait ( ) ) ;
240
252
const locked = parentCourtMinStake * toBigInt ( countedDraws [ wallet . address ] ?? 0 ) ;
241
253
expect (
242
254
await sortitionModule . getJurorBalance ( wallet . address , PARENT_COURT ) ,
@@ -261,20 +273,24 @@ describe("Draw Benchmark", async () => {
261
273
await draw ( stake , PARENT_COURT , expectFromDraw , unstake ) ;
262
274
} ) ;
263
275
264
- // Warning: we are skipping this during `hardhat coverage` because it fails, although it passes with `hardhat test`
265
276
it ( "Stakes in parent court and should draw nobody in subcourt [ @skip-on-coverage ]" , async ( ) => {
266
277
const stake = async ( wallet : HDNodeWallet ) => {
267
- await core . connect ( wallet ) . setStake ( PARENT_COURT , ONE_THOUSAND_PNK * 5n , { gasLimit : 5000000 } ) ;
278
+ await core
279
+ . connect ( wallet )
280
+ . setStake ( PARENT_COURT , ONE_THOUSAND_PNK * 5n , { gasLimit : 5000000 } )
281
+ . then ( ( tx ) => tx . wait ( ) ) ;
268
282
} ;
269
283
270
284
const expectFromDraw = async ( drawTx : Promise < ContractTransactionResponse > ) => {
271
- console . log ( ( await core . getRoundInfo ( 0 , 0 ) ) . drawIterations ) ;
272
- expect ( await core . getRoundInfo ( 0 , 0 ) . then ( ( round ) => round . drawIterations ) ) . to . equal ( 20 ) ;
273
285
expect ( await drawTx ) . to . not . emit ( core , "Draw" ) ;
286
+ expect ( await core . getRoundInfo ( 0 , 0 ) . then ( ( round ) => round . drawIterations ) ) . to . equal ( 20 ) ;
274
287
} ;
275
288
276
289
const unstake = async ( wallet : HDNodeWallet ) => {
277
- await core . connect ( wallet ) . setStake ( PARENT_COURT , 0 , { gasLimit : 5000000 } ) ;
290
+ await core
291
+ . connect ( wallet )
292
+ . setStake ( PARENT_COURT , 0 , { gasLimit : 5000000 } )
293
+ . then ( ( tx ) => tx . wait ( ) ) ;
278
294
expect (
279
295
await sortitionModule . getJurorBalance ( wallet . address , PARENT_COURT ) ,
280
296
"No locked stake in the parent court"
@@ -300,13 +316,13 @@ describe("Draw Benchmark", async () => {
300
316
301
317
it ( "Stakes in subcourt and should draw jurors in parent court" , async ( ) => {
302
318
const stake = async ( wallet : HDNodeWallet ) => {
303
- await core . connect ( wallet ) . setStake ( CHILD_COURT , ONE_THOUSAND_PNK * 5n , { gasLimit : 5000000 } ) ;
319
+ await core
320
+ . connect ( wallet )
321
+ . setStake ( CHILD_COURT , ONE_THOUSAND_PNK * 5n , { gasLimit : 5000000 } )
322
+ . then ( ( tx ) => tx . wait ( ) ) ;
304
323
} ;
305
324
let countedDraws : CountedDraws ;
306
325
const expectFromDraw = async ( drawTx : Promise < ContractTransactionResponse > ) => {
307
- console . log ( ( await core . getRoundInfo ( 0 , 0 ) ) . drawIterations ) ;
308
- expect ( await core . getRoundInfo ( 0 , 0 ) . then ( ( round ) => round . drawIterations ) ) . to . equal ( 3 ) ;
309
-
310
326
const tx = await ( await drawTx ) . wait ( ) ;
311
327
if ( ! tx ) throw new Error ( "Failed to get transaction receipt" ) ;
312
328
expect ( tx )
@@ -332,10 +348,14 @@ describe("Draw Benchmark", async () => {
332
348
1 , // nbOfCourts
333
349
] ) ;
334
350
}
351
+ expect ( await core . getRoundInfo ( 0 , 0 ) . then ( ( round ) => round . drawIterations ) ) . to . equal ( 3 ) ;
335
352
} ;
336
353
337
354
const unstake = async ( wallet : HDNodeWallet ) => {
338
- await core . connect ( wallet ) . setStake ( CHILD_COURT , 0 , { gasLimit : 5000000 } ) ;
355
+ await core
356
+ . connect ( wallet )
357
+ . setStake ( CHILD_COURT , 0 , { gasLimit : 5000000 } )
358
+ . then ( ( tx ) => tx . wait ( ) ) ;
339
359
const locked = parentCourtMinStake * toBigInt ( countedDraws [ wallet . address ] ?? 0 ) ;
340
360
expect (
341
361
await sortitionModule . getJurorBalance ( wallet . address , PARENT_COURT ) ,
@@ -362,13 +382,13 @@ describe("Draw Benchmark", async () => {
362
382
363
383
it ( "Stakes in subcourt and should draw jurors in subcourt" , async ( ) => {
364
384
const stake = async ( wallet : HDNodeWallet ) => {
365
- await core . connect ( wallet ) . setStake ( CHILD_COURT , ONE_THOUSAND_PNK * 5n , { gasLimit : 5000000 } ) ;
385
+ await core
386
+ . connect ( wallet )
387
+ . setStake ( CHILD_COURT , ONE_THOUSAND_PNK * 5n , { gasLimit : 5000000 } )
388
+ . then ( ( tx ) => tx . wait ( ) ) ;
366
389
} ;
367
390
let countedDraws : CountedDraws ;
368
391
const expectFromDraw = async ( drawTx : Promise < ContractTransactionResponse > ) => {
369
- console . log ( ( await core . getRoundInfo ( 0 , 0 ) ) . drawIterations ) ;
370
- expect ( await core . getRoundInfo ( 0 , 0 ) . then ( ( round ) => round . drawIterations ) ) . to . equal ( 3 ) ;
371
-
372
392
const tx = await ( await drawTx ) . wait ( ) ;
373
393
if ( ! tx ) throw new Error ( "Failed to get transaction receipt" ) ;
374
394
expect ( tx )
@@ -394,10 +414,14 @@ describe("Draw Benchmark", async () => {
394
414
1 , // nbOfCourts
395
415
] ) ;
396
416
}
417
+ expect ( await core . getRoundInfo ( 0 , 0 ) . then ( ( round ) => round . drawIterations ) ) . to . equal ( 3 ) ;
397
418
} ;
398
419
399
420
const unstake = async ( wallet : HDNodeWallet ) => {
400
- await core . connect ( wallet ) . setStake ( CHILD_COURT , 0 , { gasLimit : 5000000 } ) ;
421
+ await core
422
+ . connect ( wallet )
423
+ . setStake ( CHILD_COURT , 0 , { gasLimit : 5000000 } )
424
+ . then ( ( tx ) => tx . wait ( ) ) ;
401
425
const locked = childCourtMinStake * toBigInt ( countedDraws [ wallet . address ] ?? 0 ) ;
402
426
expect (
403
427
await sortitionModule . getJurorBalance ( wallet . address , PARENT_COURT ) ,
0 commit comments