@@ -665,6 +665,48 @@ contract KlerosCore_ExecutionTest is KlerosCore_TestBase {
665665 assertEq (ruled, true , "Should be ruled " );
666666 }
667667
668+ function test_executeRuling_arbitrableRevert () public {
669+ MaliciousArbitrableMock maliciousArbitrable = new MaliciousArbitrableMock (
670+ core,
671+ templateData,
672+ templateDataMappings,
673+ arbitratorExtraData,
674+ registry,
675+ feeToken
676+ );
677+ uint256 disputeID = 0 ;
678+
679+ vm.prank (staker1);
680+ core.setStake (GENERAL_COURT, 20000 );
681+ vm.prank (disputer);
682+ maliciousArbitrable.createDispute {value: feeForJuror * DEFAULT_NB_OF_JURORS}("Action " );
683+ vm.warp (block .timestamp + minStakingTime);
684+ sortitionModule.passPhase (); // Generating
685+ vm.warp (block .timestamp + rngLookahead);
686+ sortitionModule.passPhase (); // Drawing phase
687+
688+ core.draw (disputeID, DEFAULT_NB_OF_JURORS);
689+ vm.warp (block .timestamp + timesPerPeriod[0 ]);
690+ core.passPeriod (disputeID); // Vote
691+
692+ uint256 [] memory voteIDs = new uint256 [](3 );
693+ voteIDs[0 ] = 0 ;
694+ voteIDs[1 ] = 1 ;
695+ voteIDs[2 ] = 2 ;
696+
697+ vm.prank (staker1);
698+ disputeKit.castVote (disputeID, voteIDs, 2 , 0 , "XYZ " );
699+ core.passPeriod (disputeID); // Appeal
700+
701+ vm.warp (block .timestamp + timesPerPeriod[3 ]);
702+ core.passPeriod (disputeID); // Execution
703+
704+ vm.expectRevert (MaliciousArbitrableMock.RuleReverted.selector );
705+ core.executeRuling (disputeID); // Reverts
706+
707+ disputeKit.withdrawFeesAndRewards (disputeID, payable (staker1), 2 ); // Should not revert even if executeRuling() reverted
708+ }
709+
668710 function test_executeRuling_appealSwitch () public {
669711 // Check that the ruling switches if only one side was funded
670712 uint256 disputeID = 0 ;
@@ -780,22 +822,15 @@ contract KlerosCore_ExecutionTest is KlerosCore_TestBase {
780822 // 4. move sortition to staking phase
781823 uint256 disputeID = 0 ;
782824 uint256 amountToStake = 20000 ;
783- _stakePnk_createDispute_moveToDrawingPhase (disputeID, staker1, amountToStake);
825+ _stakePnk_createDispute_moveToDrawingPhase (staker1, amountToStake);
784826
785827 KlerosCore.Round memory round = core.getRoundInfo (disputeID, 0 );
786828 uint256 pnkAtStakePerJuror = round.pnkAtStakePerJuror;
787829 _stakeBalanceForJuror (staker1, type (uint256 ).max);
788830 _drawJurors_advancePeriodToVoting (disputeID);
789831 _vote_execute (disputeID, staker1);
790832 sortitionModule.passPhase (); // set it to staking phase
791- _assertJurorBalance (
792- disputeID,
793- staker1,
794- amountToStake,
795- pnkAtStakePerJuror * DEFAULT_NB_OF_JURORS,
796- amountToStake,
797- 1
798- );
833+ _assertJurorBalance (staker1, amountToStake, pnkAtStakePerJuror * DEFAULT_NB_OF_JURORS, amountToStake, 1 );
799834
800835 console.log ("totalStaked before: %e " , sortitionModule.totalStaked ());
801836
@@ -804,14 +839,7 @@ contract KlerosCore_ExecutionTest is KlerosCore_TestBase {
804839
805840 // post condition: inflated totalStaked
806841 console.log ("totalStaked after: %e " , sortitionModule.totalStaked ());
807- _assertJurorBalance (
808- disputeID,
809- staker1,
810- amountToStake,
811- pnkAtStakePerJuror * DEFAULT_NB_OF_JURORS,
812- amountToStake,
813- 1
814- );
842+ _assertJurorBalance (staker1, amountToStake, pnkAtStakePerJuror * DEFAULT_NB_OF_JURORS, amountToStake, 1 );
815843
816844 // new juror tries to stake but totalStaked already reached type(uint256).max
817845 // it reverts with "arithmetic underflow or overflow (0x11)"
@@ -920,19 +948,18 @@ contract KlerosCore_ExecutionTest is KlerosCore_TestBase {
920948 ///////// Internal //////////
921949
922950 function _assertJurorBalance (
923- uint256 disputeID ,
924- address juror ,
925- uint256 totalStakedPnk ,
926- uint256 totalLocked ,
927- uint256 stakedInCourt ,
928- uint256 nbCourts
929- ) internal {
951+ address _juror ,
952+ uint256 _totalStakedPnk ,
953+ uint256 _totalLocked ,
954+ uint256 _stakedInCourt ,
955+ uint256 _nbCourts
956+ ) internal view {
930957 (uint256 totalStakedPnk , uint256 totalLocked , uint256 stakedInCourt , uint256 nbCourts ) = sortitionModule
931- .getJurorBalance (juror , GENERAL_COURT);
932- assertEq (totalStakedPnk , totalStakedPnk, "Wrong totalStakedPnk " ); // jurors total staked a.k.a juror.stakedPnk
933- assertEq (totalLocked , totalLocked, "Wrong totalLocked " );
934- assertEq (stakedInCourt , stakedInCourt, "Wrong stakedInCourt " ); // juror staked in court a.k.a _stakeOf
935- assertEq (nbCourts , nbCourts, "Wrong nbCourts " );
958+ .getJurorBalance (_juror , GENERAL_COURT);
959+ assertEq (_totalStakedPnk , totalStakedPnk, "Wrong totalStakedPnk " ); // jurors total staked a.k.a juror.stakedPnk
960+ assertEq (_totalLocked , totalLocked, "Wrong totalLocked " );
961+ assertEq (_stakedInCourt , stakedInCourt, "Wrong stakedInCourt " ); // juror staked in court a.k.a _stakeOf
962+ assertEq (_nbCourts , nbCourts, "Wrong nbCourts " );
936963 }
937964
938965 function _stakeBalanceForJuror (address juror , uint256 amount ) internal {
@@ -941,7 +968,7 @@ contract KlerosCore_ExecutionTest is KlerosCore_TestBase {
941968 core.setStake (GENERAL_COURT, amount);
942969 }
943970
944- function _stakePnk_createDispute_moveToDrawingPhase (uint256 disputeID , address juror , uint256 amount ) internal {
971+ function _stakePnk_createDispute_moveToDrawingPhase (address juror , uint256 amount ) internal {
945972 vm.prank (juror);
946973 core.setStake (GENERAL_COURT, amount);
947974 vm.prank (disputer);
0 commit comments