1
1
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs" ;
2
2
import { deployments , ethers , getNamedAccounts , network } from "hardhat" ;
3
- import { BigNumber } from "ethers" ;
3
+ import { BigNumber , ContractTransaction , Wallet } from "ethers" ;
4
4
import {
5
5
PNK ,
6
6
KlerosCore ,
@@ -52,11 +52,7 @@ describe("Draw Benchmark", async () => {
52
52
let randomizer ;
53
53
54
54
beforeEach ( "Setup" , async ( ) => {
55
- deployer = ( await getNamedAccounts ( ) ) . deployer ;
56
- relayer = ( await getNamedAccounts ( ) ) . relayer ;
57
-
58
- console . log ( "deployer:%s" , deployer ) ;
59
- console . log ( "named accounts: %O" , await getNamedAccounts ( ) ) ;
55
+ ( { deployer, relayer } = await getNamedAccounts ( ) ) ;
60
56
61
57
await deployments . fixture ( [ "Arbitration" , "VeaMock" ] , {
62
58
fallbackToGlobal : true ,
@@ -70,9 +66,33 @@ describe("Draw Benchmark", async () => {
70
66
rng = ( await ethers . getContract ( "RandomizerRNG" ) ) as RandomizerRNG ;
71
67
randomizer = ( await ethers . getContract ( "RandomizerMock" ) ) as RandomizerMock ;
72
68
sortitionModule = ( await ethers . getContract ( "SortitionModule" ) ) as SortitionModule ;
69
+
70
+ // CourtId 2
71
+ const minStake = BigNumber . from ( 10 ) . pow ( 20 ) . mul ( 3 ) ; // 300 PNK
72
+ const alpha = 10000 ;
73
+ const feeForJuror = BigNumber . from ( 10 ) . pow ( 17 ) ;
74
+ await core . createCourt (
75
+ 1 ,
76
+ false ,
77
+ minStake ,
78
+ alpha ,
79
+ feeForJuror ,
80
+ 256 ,
81
+ [ 0 , 0 , 0 , 10 ] , // evidencePeriod, commitPeriod, votePeriod, appealPeriod
82
+ ethers . utils . hexlify ( 5 ) , // Extra data for sortition module will return the default value of K)
83
+ [ 1 ]
84
+ ) ;
73
85
} ) ;
74
86
75
- it ( "Draw Benchmark" , async ( ) => {
87
+ interface SetStake {
88
+ ( wallet : Wallet ) : Promise < void > ;
89
+ }
90
+
91
+ interface ExpectFromDraw {
92
+ ( drawTx : Promise < ContractTransaction > ) : Promise < void > ;
93
+ }
94
+
95
+ const draw = async ( setStake : SetStake , createDisputeCourtId : string , expectFromDraw : ExpectFromDraw ) => {
76
96
const arbitrationCost = ONE_TENTH_ETH . mul ( 3 ) ;
77
97
const [ bridger ] = await ethers . getSigners ( ) ;
78
98
@@ -90,7 +110,8 @@ describe("Draw Benchmark", async () => {
90
110
expect ( await pnk . balanceOf ( wallet . address ) ) . to . equal ( ONE_THOUSAND_PNK . mul ( 10 ) ) ;
91
111
92
112
await pnk . connect ( wallet ) . approve ( core . address , ONE_THOUSAND_PNK . mul ( 10 ) , { gasLimit : 300000 } ) ;
93
- await core . connect ( wallet ) . setStake ( 1 , ONE_THOUSAND_PNK . mul ( 10 ) , { gasLimit : 5000000 } ) ;
113
+
114
+ await setStake ( wallet ) ;
94
115
}
95
116
96
117
// Create a dispute
@@ -114,7 +135,7 @@ describe("Draw Benchmark", async () => {
114
135
templateId : 0 ,
115
136
templateUri : "" ,
116
137
choices : 2 ,
117
- extraData : "0x00" ,
138
+ extraData : `0x000000000000000000000000000000000000000000000000000000000000000 ${ createDisputeCourtId } 0000000000000000000000000000000000000000000000000000000000000003` ,
118
139
} ,
119
140
{ value : arbitrationCost }
120
141
) ;
@@ -131,12 +152,72 @@ describe("Draw Benchmark", async () => {
131
152
await randomizer . relay ( rng . address , 0 , ethers . utils . randomBytes ( 32 ) ) ;
132
153
await sortitionModule . passPhase ( ) ; // Generating -> Drawing
133
154
134
- await expect ( core . draw ( 0 , 1000 , { gasLimit : 1000000 } ) )
135
- . to . emit ( core , "Draw" )
136
- . withArgs ( anyValue , 0 , 0 , 0 )
137
- . to . emit ( core , "Draw" )
138
- . withArgs ( anyValue , 0 , 0 , 1 )
139
- . to . emit ( core , "Draw" )
140
- . withArgs ( anyValue , 0 , 0 , 2 ) ;
155
+ await expectFromDraw ( core . draw ( 0 , 1000 , { gasLimit : 1000000 } ) ) ;
156
+ } ;
157
+
158
+ it ( "Stakes in parent court and should draw jurors in parent court" , async ( ) => {
159
+ const setStake = async ( wallet : Wallet ) => {
160
+ await core . connect ( wallet ) . setStake ( 1 , ONE_THOUSAND_PNK . mul ( 5 ) , { gasLimit : 5000000 } ) ;
161
+ } ;
162
+
163
+ const expectFromDraw = async ( drawTx : Promise < ContractTransaction > ) => {
164
+ await expect ( drawTx )
165
+ . to . emit ( core , "Draw" )
166
+ . withArgs ( anyValue , 0 , 0 , 0 )
167
+ . to . emit ( core , "Draw" )
168
+ . withArgs ( anyValue , 0 , 0 , 1 )
169
+ . to . emit ( core , "Draw" )
170
+ . withArgs ( anyValue , 0 , 0 , 2 ) ;
171
+ } ;
172
+
173
+ await draw ( setStake , "1" , expectFromDraw ) ;
174
+ } ) ;
175
+
176
+ it ( "Stakes in parent court and should draw nobody in subcourt" , async ( ) => {
177
+ const setStake = async ( wallet : Wallet ) => {
178
+ await core . connect ( wallet ) . setStake ( 1 , ONE_THOUSAND_PNK . mul ( 5 ) , { gasLimit : 5000000 } ) ;
179
+ } ;
180
+
181
+ const expectFromDraw = async ( drawTx : Promise < ContractTransaction > ) => {
182
+ await expect ( drawTx ) . to . not . emit ( core , "Draw" ) ;
183
+ } ;
184
+
185
+ await draw ( setStake , "2" , expectFromDraw ) ;
186
+ } ) ;
187
+
188
+ it ( "Stakes in subcourt and should draw jurors in parent court" , async ( ) => {
189
+ const setStake = async ( wallet : Wallet ) => {
190
+ await core . connect ( wallet ) . setStake ( 2 , ONE_THOUSAND_PNK . mul ( 5 ) , { gasLimit : 5000000 } ) ;
191
+ } ;
192
+
193
+ const expectFromDraw = async ( drawTx : Promise < ContractTransaction > ) => {
194
+ await expect ( drawTx )
195
+ . to . emit ( core , "Draw" )
196
+ . withArgs ( anyValue , 0 , 0 , 0 )
197
+ . to . emit ( core , "Draw" )
198
+ . withArgs ( anyValue , 0 , 0 , 1 )
199
+ . to . emit ( core , "Draw" )
200
+ . withArgs ( anyValue , 0 , 0 , 2 ) ;
201
+ } ;
202
+
203
+ await draw ( setStake , "1" , expectFromDraw ) ;
204
+ } ) ;
205
+
206
+ it ( "Stakes in subcourt and should draw jurors in subcourt" , async ( ) => {
207
+ const setStake = async ( wallet : Wallet ) => {
208
+ await core . connect ( wallet ) . setStake ( 2 , ONE_THOUSAND_PNK . mul ( 5 ) , { gasLimit : 5000000 } ) ;
209
+ } ;
210
+
211
+ const expectFromDraw = async ( drawTx : Promise < ContractTransaction > ) => {
212
+ await expect ( drawTx )
213
+ . to . emit ( core , "Draw" )
214
+ . withArgs ( anyValue , 0 , 0 , 0 )
215
+ . to . emit ( core , "Draw" )
216
+ . withArgs ( anyValue , 0 , 0 , 1 )
217
+ . to . emit ( core , "Draw" )
218
+ . withArgs ( anyValue , 0 , 0 , 2 ) ;
219
+ } ;
220
+
221
+ await draw ( setStake , "2" , expectFromDraw ) ;
141
222
} ) ;
142
223
} ) ;
0 commit comments