1
1
import { ethers , getNamedAccounts , network , deployments } from "hardhat" ;
2
2
const { anyValue } = require ( "@nomicfoundation/hardhat-chai-matchers/withArgs" ) ;
3
- import { BigNumber } from "ethers" ;
3
+ import { toBigInt , BytesLike } from "ethers" ;
4
4
import { PNK , KlerosCore , SortitionModule , RandomizerRNG , RandomizerMock } from "../../typechain-types" ;
5
5
import { expect } from "chai" ;
6
6
7
7
/* eslint-disable no-unused-vars */
8
8
/* eslint-disable no-unused-expressions */
9
9
10
10
describe ( "Staking" , async ( ) => {
11
- const ETH = ( amount : number ) => ethers . utils . parseUnits ( amount . toString ( ) ) ;
11
+ const ETH = ( amount : number ) => ethers . parseUnits ( amount . toString ( ) ) ;
12
12
const PNK = ETH ;
13
13
14
14
// 2nd court, 3 jurors, 1 dispute kit
15
15
const extraData =
16
16
"0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001" ;
17
17
18
18
let deployer ;
19
- let pnk ;
20
- let core ;
21
- let sortition ;
22
- let rng ;
23
- let randomizer ;
19
+ let pnk : PNK ;
20
+ let core : KlerosCore ;
21
+ let sortition : SortitionModule ;
22
+ let rng : RandomizerRNG ;
23
+ let randomizer : RandomizerMock ;
24
24
25
25
const deploy = async ( ) => {
26
26
( { deployer } = await getNamedAccounts ( ) ) ;
@@ -40,17 +40,16 @@ describe("Staking", async () => {
40
40
41
41
const reachDrawingPhase = async ( ) => {
42
42
expect ( await sortition . phase ( ) ) . to . be . equal ( 0 ) ; // Staking
43
- const arbitrationCost = ETH ( 0.1 ) . mul ( 3 ) ;
43
+ const arbitrationCost = ETH ( 0.1 ) * toBigInt ( 3 ) ;
44
+ await core . createCourt ( 1 , false , PNK ( 1000 ) , 1000 , ETH ( 0.1 ) , 3 , [ 0 , 0 , 0 , 0 ] , ethers . toBeHex ( 3 ) , [ 1 ] ) ; // Parent - general court, Classic dispute kit
44
45
45
- await core . createCourt ( 1 , false , PNK ( 1000 ) , 1000 , ETH ( 0.1 ) , 3 , [ 0 , 0 , 0 , 0 ] , 3 , [ 1 ] ) ; // Parent - general court, Classic dispute kit
46
-
47
- await pnk . approve ( core . address , PNK ( 4000 ) ) ;
46
+ await pnk . approve ( core . target , PNK ( 4000 ) ) ;
48
47
await core . setStake ( 1 , PNK ( 2000 ) ) ;
49
48
await core . setStake ( 2 , PNK ( 2000 ) ) ;
50
49
51
- expect ( await sortition . getJurorCourtIDs ( deployer ) ) . to . be . deep . equal ( [ BigNumber . from ( "1" ) , BigNumber . from ( "2" ) ] ) ;
50
+ expect ( await sortition . getJurorCourtIDs ( deployer ) ) . to . be . deep . equal ( [ toBigInt ( "1" ) , toBigInt ( "2" ) ] ) ;
52
51
53
- await core . functions [ "createDispute(uint256,bytes)" ] ( 2 , extraData , { value : arbitrationCost } ) ;
52
+ await core [ "createDispute(uint256,bytes)" ] ( 2 , extraData , { value : arbitrationCost } ) ;
54
53
55
54
await network . provider . send ( "evm_increaseTime" , [ 2000 ] ) ; // Wait for minStakingTime
56
55
await network . provider . send ( "evm_mine" ) ;
@@ -65,7 +64,7 @@ describe("Staking", async () => {
65
64
} ;
66
65
67
66
const reachStakingPhaseAfterDrawing = async ( ) => {
68
- await randomizer . relay ( rng . address , 0 , ethers . utils . randomBytes ( 32 ) ) ;
67
+ await randomizer . relay ( rng . target , 0 , ethers . randomBytes ( 32 ) ) ;
69
68
await sortition . passPhase ( ) ; // Generating -> Drawing
70
69
await core . draw ( 0 , 5000 ) ;
71
70
await sortition . passPhase ( ) ; // Drawing -> Staking
@@ -86,7 +85,7 @@ describe("Staking", async () => {
86
85
it ( "Should transfer PNK but delay the stake increase" , async ( ) => {
87
86
expect ( await sortition . delayedStakeWriteIndex ( ) ) . to . be . equal ( 0 ) ;
88
87
expect ( await sortition . delayedStakeReadIndex ( ) ) . to . be . equal ( 1 ) ;
89
- await pnk . approve ( core . address , PNK ( 1000 ) ) ;
88
+ await pnk . approve ( core . target , PNK ( 1000 ) ) ;
90
89
expect ( await sortition . latestDelayedStakeIndex ( deployer , 2 ) ) . to . be . equal ( 0 ) ;
91
90
await expect ( core . setStake ( 2 , PNK ( 3000 ) ) )
92
91
. to . emit ( sortition , "StakeDelayedAlreadyTransferred" )
@@ -95,7 +94,7 @@ describe("Staking", async () => {
95
94
} ) ;
96
95
97
96
it ( "Should transfer some PNK out of the juror's account" , async ( ) => {
98
- expect ( await pnk . balanceOf ( deployer ) ) . to . be . equal ( balanceBefore . sub ( PNK ( 1000 ) ) ) ; // PNK is transferred out of the juror's account
97
+ expect ( await pnk . balanceOf ( deployer ) ) . to . be . equal ( balanceBefore - toBigInt ( PNK ( 1000 ) ) ) ; // PNK is transferred out of the juror's account
99
98
} ) ;
100
99
101
100
it ( "Should store the delayed stake for later" , async ( ) => {
@@ -127,8 +126,8 @@ describe("Staking", async () => {
127
126
] ) ; // stake unchanged, delayed
128
127
expect ( await sortition . delayedStakeWriteIndex ( ) ) . to . be . equal ( 1 ) ;
129
128
expect ( await sortition . delayedStakeReadIndex ( ) ) . to . be . equal ( 2 ) ;
130
- expect ( await sortition . delayedStakes ( 1 ) ) . to . be . deep . equal ( [ ethers . constants . AddressZero , 0 , 0 , false ] ) ; // the 1st delayed stake got deleted
131
- expect ( await sortition . delayedStakes ( 2 ) ) . to . be . deep . equal ( [ ethers . constants . AddressZero , 0 , 0 , false ] ) ; // the 2nd delayed stake got deleted
129
+ expect ( await sortition . delayedStakes ( 1 ) ) . to . be . deep . equal ( [ ethers . ZeroAddress , 0 , 0 , false ] ) ; // the 1st delayed stake got deleted
130
+ expect ( await sortition . delayedStakes ( 2 ) ) . to . be . deep . equal ( [ ethers . ZeroAddress , 0 , 0 , false ] ) ; // the 2nd delayed stake got deleted
132
131
expect ( await sortition . latestDelayedStakeIndex ( deployer , 1 ) ) . to . be . equal ( 0 ) ; // no delayed stakes left
133
132
} ) ;
134
133
@@ -190,13 +189,13 @@ describe("Staking", async () => {
190
189
] ) ; // stake unchanged, delayed
191
190
expect ( await sortition . delayedStakeWriteIndex ( ) ) . to . be . equal ( 1 ) ;
192
191
expect ( await sortition . delayedStakeReadIndex ( ) ) . to . be . equal ( 2 ) ;
193
- expect ( await sortition . delayedStakes ( 1 ) ) . to . be . deep . equal ( [ ethers . constants . AddressZero , 0 , 0 , false ] ) ; // the 1st delayed stake got deleted
194
- expect ( await sortition . delayedStakes ( 2 ) ) . to . be . deep . equal ( [ ethers . constants . AddressZero , 0 , 0 , false ] ) ; // the 2nd delayed stake got deleted
192
+ expect ( await sortition . delayedStakes ( 1 ) ) . to . be . deep . equal ( [ ethers . ZeroAddress , 0 , 0 , false ] ) ; // the 1st delayed stake got deleted
193
+ expect ( await sortition . delayedStakes ( 2 ) ) . to . be . deep . equal ( [ ethers . ZeroAddress , 0 , 0 , false ] ) ; // the 2nd delayed stake got deleted
195
194
expect ( await sortition . latestDelayedStakeIndex ( deployer , 1 ) ) . to . be . equal ( 0 ) ; // no delayed stakes left
196
195
} ) ;
197
196
198
197
it ( "Should withdraw some PNK" , async ( ) => {
199
- expect ( await pnk . balanceOf ( deployer ) ) . to . be . equal ( balanceBefore . add ( PNK ( 1000 ) ) ) ; // No PNK transfer yet
198
+ expect ( await pnk . balanceOf ( deployer ) ) . to . be . equal ( balanceBefore + toBigInt ( PNK ( 1000 ) ) ) ; // No PNK transfer yet
200
199
} ) ;
201
200
} ) ;
202
201
} ) ;
@@ -254,7 +253,7 @@ describe("Staking", async () => {
254
253
expect ( await sortition . latestDelayedStakeIndex ( deployer , 2 ) ) . to . be . equal ( 2 ) ;
255
254
expect ( await sortition . delayedStakeWriteIndex ( ) ) . to . be . equal ( 2 ) ;
256
255
expect ( await sortition . delayedStakeReadIndex ( ) ) . to . be . equal ( 1 ) ;
257
- expect ( await sortition . delayedStakes ( 1 ) ) . to . be . deep . equal ( [ ethers . constants . AddressZero , 0 , 0 , false ] ) ; // the 1st delayed stake got deleted
256
+ expect ( await sortition . delayedStakes ( 1 ) ) . to . be . deep . equal ( [ ethers . ZeroAddress , 0 , 0 , false ] ) ; // the 1st delayed stake got deleted
258
257
expect ( await sortition . delayedStakes ( 2 ) ) . to . be . deep . equal ( [ deployer , 2 , PNK ( 2000 ) , false ] ) ;
259
258
} ) ;
260
259
} ) ;
@@ -277,8 +276,8 @@ describe("Staking", async () => {
277
276
] ) ; // stake unchanged, delayed
278
277
expect ( await sortition . delayedStakeWriteIndex ( ) ) . to . be . equal ( 2 ) ;
279
278
expect ( await sortition . delayedStakeReadIndex ( ) ) . to . be . equal ( 3 ) ;
280
- expect ( await sortition . delayedStakes ( 1 ) ) . to . be . deep . equal ( [ ethers . constants . AddressZero , 0 , 0 , false ] ) ; // the 1st delayed stake got deleted
281
- expect ( await sortition . delayedStakes ( 2 ) ) . to . be . deep . equal ( [ ethers . constants . AddressZero , 0 , 0 , false ] ) ; // the 2nd delayed stake got deleted
279
+ expect ( await sortition . delayedStakes ( 1 ) ) . to . be . deep . equal ( [ ethers . ZeroAddress , 0 , 0 , false ] ) ; // the 1st delayed stake got deleted
280
+ expect ( await sortition . delayedStakes ( 2 ) ) . to . be . deep . equal ( [ ethers . ZeroAddress , 0 , 0 , false ] ) ; // the 2nd delayed stake got deleted
282
281
expect ( await sortition . latestDelayedStakeIndex ( deployer , 2 ) ) . to . be . equal ( 0 ) ; // no delayed stakes left
283
282
} ) ;
284
283
@@ -303,7 +302,7 @@ describe("Staking", async () => {
303
302
it ( "Should transfer PNK but delay the stake increase" , async ( ) => {
304
303
expect ( await sortition . delayedStakeWriteIndex ( ) ) . to . be . equal ( 0 ) ;
305
304
expect ( await sortition . delayedStakeReadIndex ( ) ) . to . be . equal ( 1 ) ;
306
- await pnk . approve ( core . address , PNK ( 1000 ) ) ;
305
+ await pnk . approve ( core . target , PNK ( 1000 ) ) ;
307
306
expect ( await sortition . latestDelayedStakeIndex ( deployer , 2 ) ) . to . be . equal ( 0 ) ;
308
307
await expect ( core . setStake ( 2 , PNK ( 3000 ) ) )
309
308
. to . emit ( sortition , "StakeDelayedAlreadyTransferred" )
@@ -312,7 +311,7 @@ describe("Staking", async () => {
312
311
} ) ;
313
312
314
313
it ( "Should transfer some PNK out of the juror's account" , async ( ) => {
315
- expect ( await pnk . balanceOf ( deployer ) ) . to . be . equal ( balanceBefore . sub ( PNK ( 1000 ) ) ) ; // PNK is transferred out of the juror's account
314
+ expect ( await pnk . balanceOf ( deployer ) ) . to . be . equal ( balanceBefore - toBigInt ( PNK ( 1000 ) ) ) ; // PNK is transferred out of the juror's account
316
315
} ) ;
317
316
318
317
it ( "Should store the delayed stake for later" , async ( ) => {
@@ -336,14 +335,14 @@ describe("Staking", async () => {
336
335
} ) ;
337
336
338
337
it ( "Should transfer back some PNK to the juror" , async ( ) => {
339
- expect ( await pnk . balanceOf ( deployer ) ) . to . be . equal ( balanceBefore . add ( PNK ( 1000 ) ) ) ; // PNK is sent back to the juror
338
+ expect ( await pnk . balanceOf ( deployer ) ) . to . be . equal ( balanceBefore + toBigInt ( PNK ( 1000 ) ) ) ; // PNK is sent back to the juror
340
339
} ) ;
341
340
342
341
it ( "Should store the delayed stake for later" , async ( ) => {
343
342
expect ( await sortition . latestDelayedStakeIndex ( deployer , 2 ) ) . to . be . equal ( 2 ) ;
344
343
expect ( await sortition . delayedStakeWriteIndex ( ) ) . to . be . equal ( 2 ) ;
345
344
expect ( await sortition . delayedStakeReadIndex ( ) ) . to . be . equal ( 1 ) ;
346
- expect ( await sortition . delayedStakes ( 1 ) ) . to . be . deep . equal ( [ ethers . constants . AddressZero , 0 , 0 , false ] ) ; // the 1st delayed stake got deleted
345
+ expect ( await sortition . delayedStakes ( 1 ) ) . to . be . deep . equal ( [ ethers . ZeroAddress , 0 , 0 , false ] ) ; // the 1st delayed stake got deleted
347
346
expect ( await sortition . delayedStakes ( 2 ) ) . to . be . deep . equal ( [ deployer , 2 , PNK ( 2000 ) , false ] ) ;
348
347
} ) ;
349
348
} ) ;
@@ -369,8 +368,8 @@ describe("Staking", async () => {
369
368
] ) ; // stake unchanged, delayed
370
369
expect ( await sortition . delayedStakeWriteIndex ( ) ) . to . be . equal ( 2 ) ;
371
370
expect ( await sortition . delayedStakeReadIndex ( ) ) . to . be . equal ( 3 ) ;
372
- expect ( await sortition . delayedStakes ( 1 ) ) . to . be . deep . equal ( [ ethers . constants . AddressZero , 0 , 0 , false ] ) ; // the 1st delayed stake got deleted
373
- expect ( await sortition . delayedStakes ( 2 ) ) . to . be . deep . equal ( [ ethers . constants . AddressZero , 0 , 0 , false ] ) ; // the 2nd delayed stake got deleted
371
+ expect ( await sortition . delayedStakes ( 1 ) ) . to . be . deep . equal ( [ ethers . ZeroAddress , 0 , 0 , false ] ) ; // the 1st delayed stake got deleted
372
+ expect ( await sortition . delayedStakes ( 2 ) ) . to . be . deep . equal ( [ ethers . ZeroAddress , 0 , 0 , false ] ) ; // the 2nd delayed stake got deleted
374
373
expect ( await sortition . latestDelayedStakeIndex ( deployer , 2 ) ) . to . be . equal ( 0 ) ; // no delayed stakes left
375
374
} ) ;
376
375
@@ -387,17 +386,16 @@ describe("Staking", async () => {
387
386
} ) ;
388
387
389
388
it ( "Should unstake from all courts" , async ( ) => {
390
- const arbitrationCost = ETH ( 0.1 ) . mul ( 3 ) ;
391
-
392
- await core . createCourt ( 1 , false , PNK ( 1000 ) , 1000 , ETH ( 0.1 ) , 3 , [ 0 , 0 , 0 , 0 ] , 3 , [ 1 ] ) ; // Parent - general court, Classic dispute kit
389
+ const arbitrationCost = ETH ( 0.1 ) * toBigInt ( 3 ) ;
390
+ await core . createCourt ( 1 , false , PNK ( 1000 ) , 1000 , ETH ( 0.1 ) , 3 , [ 0 , 0 , 0 , 0 ] , ethers . toBeHex ( 3 ) , [ 1 ] ) ; // Parent - general court, Classic dispute kit
393
391
394
- await pnk . approve ( core . address , PNK ( 4000 ) ) ;
392
+ await pnk . approve ( core . target , PNK ( 4000 ) ) ;
395
393
await core . setStake ( 1 , PNK ( 2000 ) ) ;
396
394
await core . setStake ( 2 , PNK ( 2000 ) ) ;
397
395
398
396
expect ( await sortition . getJurorCourtIDs ( deployer ) ) . to . be . deep . equal ( [ 1 , 2 ] ) ;
399
397
400
- await core . functions [ "createDispute(uint256,bytes)" ] ( 2 , extraData , { value : arbitrationCost } ) ;
398
+ await core [ "createDispute(uint256,bytes)" ] ( 2 , extraData , { value : arbitrationCost } ) ;
401
399
402
400
await network . provider . send ( "evm_increaseTime" , [ 2000 ] ) ; // Wait for minStakingTime
403
401
await network . provider . send ( "evm_mine" ) ;
@@ -407,7 +405,7 @@ describe("Staking", async () => {
407
405
for ( let index = 0 ; index < lookahead ; index ++ ) {
408
406
await network . provider . send ( "evm_mine" ) ;
409
407
}
410
- await randomizer . relay ( rng . address , 0 , ethers . utils . randomBytes ( 32 ) ) ;
408
+ await randomizer . relay ( rng . target , 0 , ethers . randomBytes ( 32 ) ) ;
411
409
await sortition . passPhase ( ) ; // Generating -> Drawing
412
410
413
411
await core . draw ( 0 , 5000 ) ;
0 commit comments