@@ -75,7 +75,7 @@ describe("Integration tests", async () => {
7575 sortitionModule = ( await ethers . getContract ( "SortitionModule" ) ) as SortitionModule ;
7676 } ) ;
7777
78- it ( "Resolves a dispute on the home chain with no appeal" , async ( ) => {
78+ it ( "Resolves a dispute on the home chain with no appeal - Randomizer " , async ( ) => {
7979 const arbitrationCost = ONE_TENTH_ETH . mul ( 3 ) ;
8080 const [ , , relayer ] = await ethers . getSigners ( ) ;
8181
@@ -165,10 +165,118 @@ describe("Integration tests", async () => {
165165 await mineBlocks ( await sortitionModule . rngLookahead ( ) ) ; // Wait for finality
166166 expect ( await sortitionModule . phase ( ) ) . to . equal ( Phase . generating ) ;
167167 console . log ( "KC phase: %d" , await sortitionModule . phase ( ) ) ;
168- // await randomizer.relay(rng.address, 0, ethers.utils.randomBytes(32));
169- const reqId = await vrfConsumer . lastRequestId ( ) ;
170- await vrfCoordinator . fulfillRandomWords ( reqId , vrfConsumer . address ) ;
171- // await sortitionModule.passPhase(); // Generating -> Drawing
168+
169+ await randomizer . relay ( rng . address , 0 , ethers . utils . randomBytes ( 32 ) ) ;
170+ await sortitionModule . passPhase ( ) ; // Generating -> Drawing
171+ expect ( await sortitionModule . phase ( ) ) . to . equal ( Phase . drawing ) ;
172+ console . log ( "KC phase: %d" , await sortitionModule . phase ( ) ) ;
173+
174+ const tx3 = await core . draw ( 0 , 1000 ) ;
175+ console . log ( "draw successful" ) ;
176+ const events3 = ( await tx3 . wait ( ) ) . events ;
177+
178+ const roundInfo = await core . getRoundInfo ( 0 , 0 ) ;
179+ expect ( roundInfo . drawnJurors ) . deep . equal ( [ deployer , deployer , deployer ] ) ;
180+ expect ( roundInfo . tokensAtStakePerJuror ) . to . equal ( ONE_HUNDRED_PNK . mul ( 2 ) ) ;
181+ expect ( roundInfo . totalFeesForJurors ) . to . equal ( arbitrationCost ) ;
182+
183+ expect ( ( await core . disputes ( 0 ) ) . period ) . to . equal ( Period . evidence ) ;
184+
185+ await core . passPeriod ( 0 ) ;
186+ expect ( ( await core . disputes ( 0 ) ) . period ) . to . equal ( Period . vote ) ;
187+ await disputeKit . connect ( await ethers . getSigner ( deployer ) ) . castVote ( 0 , [ 0 , 1 , 2 ] , 0 , 0 , "" ) ;
188+ await core . passPeriod ( 0 ) ;
189+
190+ await network . provider . send ( "evm_increaseTime" , [ 100 ] ) ; // Wait for the appeal period
191+ await network . provider . send ( "evm_mine" ) ;
192+
193+ await core . passPeriod ( 0 ) ;
194+ expect ( ( await core . disputes ( 0 ) ) . period ) . to . equal ( Period . execution ) ;
195+ expect ( await core . execute ( 0 , 0 , 1000 ) ) . to . emit ( core , "TokenAndETHShift" ) ;
196+
197+ const tx4 = await core . executeRuling ( 0 , { gasLimit : 10000000 , gasPrice : 5000000000 } ) ;
198+ console . log ( "Ruling executed on KlerosCore" ) ;
199+ expect ( tx4 ) . to . emit ( core , "Ruling" ) . withArgs ( homeGateway . address , 0 , 0 ) ;
200+ expect ( tx4 ) . to . emit ( arbitrable , "Ruling" ) . withArgs ( foreignGateway . address , 1 , 0 ) ; // The ForeignGateway starts counting disputeID from 1.
201+ } ) ;
202+
203+ it ( "Resolves a dispute on the home chain with no appeal - Chainlink VRF v2" , async ( ) => {
204+ const arbitrationCost = ONE_TENTH_ETH . mul ( 3 ) ;
205+ const [ bridger , challenger , relayer ] = await ethers . getSigners ( ) ;
206+ const RNG_LOOKAHEAD = 20 ;
207+
208+ await sortitionModule . changeRandomNumberGenerator ( vrfConsumer . address , RNG_LOOKAHEAD ) ;
209+
210+ await pnk . approve ( core . address , ONE_THOUSAND_PNK . mul ( 100 ) ) ;
211+
212+ await core . setStake ( 1 , ONE_THOUSAND_PNK ) ;
213+ await core . getJurorBalance ( deployer , 1 ) . then ( ( result ) => {
214+ expect ( result . staked ) . to . equal ( ONE_THOUSAND_PNK ) ;
215+ expect ( result . locked ) . to . equal ( 0 ) ;
216+ logJurorBalance ( result ) ;
217+ } ) ;
218+
219+ await core . setStake ( 1 , ONE_HUNDRED_PNK . mul ( 5 ) ) ;
220+ await core . getJurorBalance ( deployer , 1 ) . then ( ( result ) => {
221+ expect ( result . staked ) . to . equal ( ONE_HUNDRED_PNK . mul ( 5 ) ) ;
222+ expect ( result . locked ) . to . equal ( 0 ) ;
223+ logJurorBalance ( result ) ;
224+ } ) ;
225+
226+ await core . setStake ( 1 , 0 ) ;
227+ await core . getJurorBalance ( deployer , 1 ) . then ( ( result ) => {
228+ expect ( result . staked ) . to . equal ( 0 ) ;
229+ expect ( result . locked ) . to . equal ( 0 ) ;
230+ logJurorBalance ( result ) ;
231+ } ) ;
232+
233+ await core . setStake ( 1 , ONE_THOUSAND_PNK . mul ( 4 ) ) ;
234+ await core . getJurorBalance ( deployer , 1 ) . then ( ( result ) => {
235+ expect ( result . staked ) . to . equal ( ONE_THOUSAND_PNK . mul ( 4 ) ) ;
236+ expect ( result . locked ) . to . equal ( 0 ) ;
237+ logJurorBalance ( result ) ;
238+ } ) ;
239+ const tx = await arbitrable . createDispute ( 2 , "0x00" , 0 , {
240+ value : arbitrationCost ,
241+ } ) ;
242+ const trace = await network . provider . send ( "debug_traceTransaction" , [ tx . hash ] ) ;
243+ const [ disputeId ] = ethers . utils . defaultAbiCoder . decode ( [ "uint" ] , `0x${ trace . returnValue } ` ) ; // get returned value from createDispute()
244+ console . log ( "Dispute Created" ) ;
245+ expect ( tx ) . to . emit ( foreignGateway , "DisputeCreation" ) ;
246+ expect ( tx ) . to . emit ( foreignGateway , "OutgoingDispute" ) ;
247+ console . log ( `disputeId: ${ disputeId } ` ) ;
248+
249+ const lastBlock = await ethers . provider . getBlock ( tx . blockNumber - 1 ) ;
250+ const disputeHash = ethers . utils . solidityKeccak256 (
251+ [ "uint" , "bytes" , "bytes" , "uint" , "uint" , "bytes" , "address" ] ,
252+ [ 31337 , lastBlock . hash , ethers . utils . toUtf8Bytes ( "createDispute" ) , disputeId , 2 , "0x00" , arbitrable . address ]
253+ ) ;
254+
255+ const events = ( await tx . wait ( ) ) . events ;
256+
257+ // Relayer tx
258+ const tx2 = await homeGateway
259+ . connect ( relayer )
260+ . relayCreateDispute ( 31337 , lastBlock . hash , disputeId , 2 , "0x00" , arbitrable . address , {
261+ value : arbitrationCost ,
262+ } ) ;
263+ expect ( tx2 ) . to . emit ( homeGateway , "Dispute" ) ;
264+ const events2 = ( await tx2 . wait ( ) ) . events ;
265+
266+ await network . provider . send ( "evm_increaseTime" , [ 2000 ] ) ; // Wait for minStakingTime
267+ await network . provider . send ( "evm_mine" ) ;
268+
269+ expect ( await sortitionModule . phase ( ) ) . to . equal ( Phase . staking ) ;
270+ expect ( await sortitionModule . disputesWithoutJurors ( ) ) . to . equal ( 1 ) ;
271+ console . log ( "KC phase: %d" , await sortitionModule . phase ( ) ) ;
272+
273+ await sortitionModule . passPhase ( ) ; // Staking -> Generating
274+ await mineBlocks ( await sortitionModule . rngLookahead ( ) ) ; // Wait for finality
275+ expect ( await sortitionModule . phase ( ) ) . to . equal ( Phase . generating ) ;
276+ console . log ( "KC phase: %d" , await sortitionModule . phase ( ) ) ;
277+
278+ const requestId = await vrfConsumer . lastRequestId ( ) ; // Needed as we emulate the vrfCoordinator manually
279+ await vrfCoordinator . fulfillRandomWords ( requestId , vrfConsumer . address ) ; // The callback calls sortitionModule.passPhase(); // Generating -> Drawing
172280 expect ( await sortitionModule . phase ( ) ) . to . equal ( Phase . drawing ) ;
173281 console . log ( "KC phase: %d" , await sortitionModule . phase ( ) ) ;
174282
0 commit comments