@@ -1393,6 +1393,7 @@ contract KlerosCoreTest is Test {
13931393 assertEq (jumped, false , "jumped should be false " );
13941394 assertEq (extraData, newExtraData, "Wrong extra data " );
13951395 assertEq (disputeKit.coreDisputeIDToLocal (0 ), disputeID, "Wrong local disputeID " );
1396+ assertEq (disputeKit.coreDisputeIDToDisputeLength (0 ), 1 , "Wrong disputes length " );
13961397
13971398 (
13981399 uint256 winningChoice ,
@@ -1783,7 +1784,7 @@ contract KlerosCoreTest is Test {
17831784 (address account , bytes32 commit , uint256 choice , bool voted ) = disputeKit.getVoteInfo (0 , 0 , 0 ); // Dispute - Round - VoteID
17841785 assertEq (account, staker1, "Wrong drawn account " );
17851786 assertEq (commit, bytes32 (0 ), "Commit should be empty " );
1786- assertEq (choice, 2 , "Choice should be empty " );
1787+ assertEq (choice, 2 , "Choice should be 2 " );
17871788 assertEq (voted, true , "Voted should be true " );
17881789
17891790 assertEq (disputeKit.isVoteActive (0 , 0 , 0 ), true , "Vote should be active " ); // Dispute - Round - VoteID
@@ -2827,4 +2828,98 @@ contract KlerosCoreTest is Test {
28272828 assertEq (crowdfunder2.balance, 10 ether, "Wrong balance of the crowdfunder2 " );
28282829 assertEq (address (disputeKit).balance, 0 , "Wrong balance of the DK " );
28292830 }
2831+
2832+ function test_castVote_differentDK () public {
2833+ DisputeKitClassic dkLogic = new DisputeKitClassic ();
2834+ // Create a new DK to check castVote.
2835+ bytes memory initDataDk = abi.encodeWithSignature ("initialize(address,address) " , governor, address (core));
2836+
2837+ UUPSProxy proxyDk = new UUPSProxy (address (dkLogic), initDataDk);
2838+ DisputeKitClassic newDisputeKit = DisputeKitClassic (address (proxyDk));
2839+
2840+ vm.prank (governor);
2841+ core.addNewDisputeKit (newDisputeKit);
2842+
2843+ uint256 newDkID = 2 ;
2844+ uint256 [] memory supportedDK = new uint256 [](1 );
2845+ bytes memory newExtraData = abi.encodePacked (uint256 (GENERAL_COURT), DEFAULT_NB_OF_JURORS, newDkID);
2846+
2847+ vm.prank (governor);
2848+ vm.expectEmit (true , true , true , true );
2849+ emit KlerosCoreBase.DisputeKitEnabled (GENERAL_COURT, newDkID, true );
2850+ supportedDK[0 ] = newDkID;
2851+ core.enableDisputeKits (GENERAL_COURT, supportedDK, true );
2852+ assertEq (core.isSupported (GENERAL_COURT, newDkID), true , "New DK should be supported by General court " );
2853+
2854+ vm.prank (staker1);
2855+ core.setStake (GENERAL_COURT, 20000 );
2856+
2857+ // Create one dispute for the old DK and two disputes for the new DK.
2858+ vm.prank (disputer);
2859+ arbitrable.createDispute {value: feeForJuror * DEFAULT_NB_OF_JURORS}("Action " );
2860+
2861+ arbitrable.changeArbitratorExtraData (newExtraData);
2862+
2863+ vm.prank (disputer);
2864+ arbitrable.createDispute {value: feeForJuror * DEFAULT_NB_OF_JURORS}("Action " );
2865+
2866+ vm.prank (disputer);
2867+ arbitrable.createDispute {value: feeForJuror * DEFAULT_NB_OF_JURORS}("Action " );
2868+
2869+ uint256 disputeID = 2 ; // Use the latest dispute for reference. This is the ID in the core contract
2870+
2871+ vm.warp (block .timestamp + minStakingTime);
2872+ sortitionModule.passPhase (); // Generating
2873+ vm.roll (block .number + rngLookahead + 1 );
2874+ sortitionModule.passPhase (); // Drawing phase
2875+
2876+ KlerosCoreBase.Round memory round = core.getRoundInfo (disputeID, 0 );
2877+ assertEq (round.disputeKitID, newDkID, "Wrong DK ID " );
2878+
2879+ core.draw (disputeID, DEFAULT_NB_OF_JURORS);
2880+ // Draw jurors for the old DK as well to prepare round.votes array
2881+ core.draw (0 , DEFAULT_NB_OF_JURORS);
2882+
2883+ vm.warp (block .timestamp + timesPerPeriod[0 ]);
2884+ core.passPeriod (disputeID); // Vote
2885+
2886+ // Check that the new DK has the info but not the old one.
2887+
2888+ assertEq (disputeKit.coreDisputeIDToDisputeLength (disputeID), 0 , "Should be 0 for old DK " );
2889+
2890+ // This is the DK where dispute was created. Core dispute points to index 1 because new DK has two disputes.
2891+ assertEq (newDisputeKit.coreDisputeIDToLocal (disputeID), 1 , "Wrong local dispute ID for new DK " );
2892+ assertEq (newDisputeKit.coreDisputeIDToDisputeLength (disputeID), 2 , "Wrong disputes length for new DK " );
2893+ (uint256 numberOfChoices , , bytes memory extraData ) = newDisputeKit.disputes (1 );
2894+ assertEq (numberOfChoices, 2 , "Wrong numberOfChoices in new DK " );
2895+ assertEq (extraData, newExtraData, "Wrong extra data " );
2896+
2897+ uint256 [] memory voteIDs = new uint256 [](3 );
2898+ voteIDs[0 ] = 0 ;
2899+ voteIDs[1 ] = 1 ;
2900+ voteIDs[2 ] = 2 ;
2901+
2902+ // Deliberately cast votes using the old DK to see if the exception will be caught.
2903+ vm.prank (staker1);
2904+ vm.expectRevert (bytes ("No local dispute for core ID " ));
2905+ disputeKit.castVote (disputeID, voteIDs, 2 , 0 , "XYZ " );
2906+
2907+ // And check the new DK.
2908+ vm.prank (staker1);
2909+ newDisputeKit.castVote (disputeID, voteIDs, 2 , 0 , "XYZ " );
2910+
2911+ (
2912+ uint256 winningChoice ,
2913+ bool tied ,
2914+ uint256 totalVoted ,
2915+ uint256 totalCommited ,
2916+ ,
2917+ uint256 choiceCount
2918+ ) = newDisputeKit.getRoundInfo (disputeID, 0 , 2 );
2919+ assertEq (winningChoice, 2 , "Wrong winning choice " );
2920+ assertEq (tied, false , "tied should be false " );
2921+ assertEq (totalVoted, 3 , "totalVoted should be 3 " );
2922+ assertEq (totalCommited, 0 , "totalCommited should be 0 " );
2923+ assertEq (choiceCount, 3 , "choiceCount should be 3 " );
2924+ }
28302925}
0 commit comments