@@ -12,9 +12,9 @@ import {
1212 PNK__factory ,
1313} from "../../typechain-types" ;
1414import { expectGoverned , getSortitionSumTreeLibrary , randomInt } from "../shared" ;
15- import type { BigNumberish } from "ethers" ;
16- import { generateSubcourts , getDisputeExtraData } from "../shared/arbitration" ;
15+ import { bitfieldDisputeKits , generateSubcourts , getDisputeExtraData } from "../shared/arbitration" ;
1716import { SignerWithAddress } from "hardhat-deploy-ethers/signers" ;
17+ import type { BigNumberish } from "ethers" ;
1818
1919const JUROR_PROSECUTION_MODULE_ADDRESS = AddressZero ;
2020const HIDDEN_VOTES = false ;
@@ -166,6 +166,78 @@ describe("KlerosCore", function () {
166166 expect ( randomCourt . jurorsForCourtJump ) . to . equal ( subcourts [ randomCourtID ] . jurorsForCourtJump ) ;
167167 expect ( randomCourt . minStake ) . to . equal ( subcourts [ randomCourtID ] . minStake ) ;
168168 } ) ;
169+
170+ // TODO should not set court stake higher than parent and smaller than children
171+
172+ it ( "Should not allow creating subcourts with parents that have a higher minimum stake" , async ( ) => {
173+ await expect (
174+ core
175+ . connect ( deployer )
176+ . createSubcourt (
177+ 0 ,
178+ HIDDEN_VOTES ,
179+ MIN_STAKE - 1 ,
180+ ALPHA ,
181+ FEE_FOR_JUROR ,
182+ JURORS_FOR_COURT_JUMP ,
183+ TIMES_PER_PERIOD ,
184+ SORTITION_SUM_TREE_K ,
185+ disputeKit . address
186+ )
187+ ) . to . be . revertedWith ( "A subcourt cannot be a child of a subcourt with a higher minimum stake." ) ;
188+ } ) ;
189+
190+ it ( "Should add/remove disputekits from subcourt" , async ( ) => {
191+ const otherDisputeKit = await new DisputeKitClassic__factory ( deployer ) . deploy (
192+ deployer . address ,
193+ core . address ,
194+ rng . address
195+ ) ;
196+ await core . addNewDisputeKit ( otherDisputeKit . address , 21 ) ;
197+ await core . addNewDisputeKit ( innocentBystander . address , 57 ) ;
198+ await core
199+ . connect ( deployer )
200+ . createSubcourt (
201+ 0 ,
202+ HIDDEN_VOTES ,
203+ MIN_STAKE ,
204+ ALPHA ,
205+ FEE_FOR_JUROR ,
206+ JURORS_FOR_COURT_JUMP ,
207+ TIMES_PER_PERIOD ,
208+ SORTITION_SUM_TREE_K ,
209+ 0
210+ ) ;
211+
212+ await core . connect ( deployer ) . setDisputeKits ( 0 , [ 0 ] , false ) ;
213+ expect ( ( await core . courts ( 0 ) ) . supportedDisputeKits ) . to . equal ( bitfieldDisputeKits ( ) ) ;
214+
215+ expect ( ( await core . courts ( 1 ) ) . supportedDisputeKits ) . to . equal ( bitfieldDisputeKits ( ) ) ;
216+ await core . connect ( deployer ) . setDisputeKits ( 1 , [ 0 ] , true ) ;
217+ expect ( ( await core . courts ( 1 ) ) . supportedDisputeKits ) . to . equal ( bitfieldDisputeKits ( 0 ) ) ;
218+
219+ await core . connect ( deployer ) . setDisputeKits ( 1 , [ 21 , 57 ] , true ) ;
220+
221+ expect ( ( await core . courts ( 1 ) ) . supportedDisputeKits ) . to . equal ( bitfieldDisputeKits ( 0 , 21 , 57 ) ) ;
222+ await expect ( core . connect ( deployer ) . setDisputeKits ( 1 , [ 57 ] , true ) ) . to . be . revertedWith (
223+ "Dispute kit already supported"
224+ ) ;
225+
226+ await core . connect ( deployer ) . setDisputeKits ( 1 , [ 0 ] , false ) ;
227+ expect ( ( await core . courts ( 1 ) ) . supportedDisputeKits ) . to . equal ( bitfieldDisputeKits ( 21 , 57 ) ) ;
228+ await expect ( core . connect ( deployer ) . setDisputeKits ( 1 , [ 0 , 57 ] , true ) ) . to . be . revertedWith (
229+ "Dispute kit already supported"
230+ ) ;
231+ await expect ( core . connect ( deployer ) . setDisputeKits ( 1 , [ 0 ] , false ) ) . to . be . revertedWith (
232+ "Dispute kit is not supported"
233+ ) ;
234+
235+ await core . connect ( deployer ) . setDisputeKits ( 1 , [ 21 ] , false ) ;
236+ await expect ( core . connect ( deployer ) . setDisputeKits ( 1 , [ 21 , 57 ] , false ) ) . to . be . revertedWith (
237+ "Dispute kit is not supported"
238+ ) ;
239+ expect ( ( await core . courts ( 1 ) ) . supportedDisputeKits ) . to . equal ( bitfieldDisputeKits ( 57 ) ) ;
240+ } ) ;
169241 } ) ;
170242
171243 it ( "Should set stake correctly" , async ( ) => {
@@ -178,14 +250,18 @@ describe("KlerosCore", function () {
178250
179251 await expect ( core . connect ( aspiringJuror ) . setStake ( 0 , MIN_STAKE - 1 ) ) . to . be . revertedWith ( "Staking failed" ) ;
180252
181- await core . connect ( aspiringJuror ) . setStake ( 0 , MIN_STAKE ) ;
253+ await expect ( core . connect ( aspiringJuror ) . setStake ( 0 , MIN_STAKE ) )
254+ . to . emit ( core , "StakeSet" )
255+ . withArgs ( aspiringJuror . address , 0 , MIN_STAKE , MIN_STAKE ) ;
182256 expect ( await pnk . balanceOf ( aspiringJuror . address ) ) . to . equal ( 1000 - MIN_STAKE ) ;
183257
184258 let jurorBalance = await core . getJurorBalance ( aspiringJuror . address , 0 ) ;
185259 expect ( jurorBalance . staked ) . to . equal ( MIN_STAKE ) ;
186260 expect ( jurorBalance . locked ) . to . equal ( 0 ) ;
187261
188- await core . connect ( aspiringJuror ) . setStake ( 0 , 0 ) ;
262+ await expect ( core . connect ( aspiringJuror ) . setStake ( 0 , 0 ) )
263+ . to . emit ( core , "StakeSet" )
264+ . withArgs ( aspiringJuror . address , 0 , 0 , 0 ) ;
189265 expect ( await pnk . balanceOf ( aspiringJuror . address ) ) . to . equal ( 1000 ) ;
190266
191267 jurorBalance = await core . getJurorBalance ( aspiringJuror . address , 0 ) ;
0 commit comments