diff --git a/packages/subgraph-service/contracts/DisputeManager.sol b/packages/subgraph-service/contracts/DisputeManager.sol index 58c93a756..231688809 100644 --- a/packages/subgraph-service/contracts/DisputeManager.sol +++ b/packages/subgraph-service/contracts/DisputeManager.sol @@ -59,6 +59,9 @@ contract DisputeManager is // Maximum value for fisherman reward cut in PPM uint32 public constant MAX_FISHERMAN_REWARD_CUT = 500000; + // Minimum value for dispute deposit + uint256 public constant MIN_DISPUTE_DEPOSIT = 1e18; // 1 GRT + // -- Modifiers -- /** @@ -140,7 +143,7 @@ contract DisputeManager is */ function createIndexingDispute(address allocationId, bytes32 poi) external override returns (bytes32) { // Get funds from fisherman - _pullFishermanDeposit(); + _graphToken().pullTokens(msg.sender, disputeDeposit); // Create a dispute return _createIndexingDisputeWithAllocation(msg.sender, disputeDeposit, allocationId, poi); @@ -158,7 +161,7 @@ contract DisputeManager is */ function createQueryDispute(bytes calldata attestationData) external override returns (bytes32) { // Get funds from fisherman - _pullFishermanDeposit(); + _graphToken().pullTokens(msg.sender, disputeDeposit); // Create a dispute return @@ -174,10 +177,14 @@ contract DisputeManager is * @notice Create query disputes for two conflicting attestations. * A conflicting attestation is a proof presented by two different indexers * where for the same request on a subgraph the response is different. - * For this type of dispute the fisherman is not required to present a deposit - * as one of the attestation is considered to be right. * Two linked disputes will be created and if the arbitrator resolve one, the other - * one will be automatically resolved. + * one will be automatically resolved. Note that: + * - it's not possible to reject a conflicting query dispute as by definition at least one + * of the attestations is incorrect. + * - if both attestations are proven to be incorrect, the arbitrator can slash the indexer twice. + * Requirements: + * - fisherman must have previously approved this contract to pull `disputeDeposit` amount + * of tokens from their balance. * @param attestationData1 First attestation data submitted * @param attestationData2 Second attestation data submitted * @return DisputeId1, DisputeId2 @@ -205,10 +212,23 @@ contract DisputeManager is ) ); + // Get funds from fisherman + _graphToken().pullTokens(msg.sender, disputeDeposit); + // Create the disputes // The deposit is zero for conflicting attestations - bytes32 dId1 = _createQueryDisputeWithAttestation(fisherman, 0, attestation1, attestationData1); - bytes32 dId2 = _createQueryDisputeWithAttestation(fisherman, 0, attestation2, attestationData2); + bytes32 dId1 = _createQueryDisputeWithAttestation( + fisherman, + disputeDeposit / 2, + attestation1, + attestationData1 + ); + bytes32 dId2 = _createQueryDisputeWithAttestation( + fisherman, + disputeDeposit / 2, + attestation2, + attestationData2 + ); // Store the linked disputes to be resolved disputes[dId1].relatedDisputeId = dId2; @@ -228,54 +248,59 @@ contract DisputeManager is * @dev Accept a dispute with Id `disputeId` * @param disputeId Id of the dispute to be accepted * @param tokensSlash Amount of tokens to slash from the indexer + * @param acceptDisputeInConflict If the dispute is in conflict, draw the conflicting dispute. Otherwise + * it will be drawn automatically. Ignored if the dispute is not in conflict. */ function acceptDispute( bytes32 disputeId, - uint256 tokensSlash + uint256 tokensSlash, + bool acceptDisputeInConflict ) external override onlyArbitrator onlyPendingDispute(disputeId) { Dispute storage dispute = disputes[disputeId]; - - // store the dispute status - dispute.status = IDisputeManager.DisputeStatus.Accepted; - - // Slash - uint256 tokensToReward = _slashIndexer(dispute.indexer, tokensSlash, dispute.stakeSnapshot); - - // Give the fisherman their reward and their deposit back - _graphToken().pushTokens(dispute.fisherman, tokensToReward + dispute.deposit); + _acceptDispute(disputeId, dispute, tokensSlash); if (_isDisputeInConflict(dispute)) { - rejectDispute(dispute.relatedDisputeId); + Dispute storage relatedDispute = disputes[dispute.relatedDisputeId]; + if (acceptDisputeInConflict) { + _acceptDispute(dispute.relatedDisputeId, relatedDispute, tokensSlash); + } else { + _drawDispute(dispute.relatedDisputeId, relatedDispute); + } } + } - emit DisputeAccepted(disputeId, dispute.indexer, dispute.fisherman, dispute.deposit + tokensToReward); + /** + * @notice The arbitrator rejects a dispute as being invalid. + * Note that conflicting query disputes cannot be rejected. + * @dev Reject a dispute with Id `disputeId` + * @param disputeId Id of the dispute to be rejected + */ + function rejectDispute(bytes32 disputeId) external override onlyArbitrator onlyPendingDispute(disputeId) { + Dispute storage dispute = disputes[disputeId]; + require(!_isDisputeInConflict(dispute), DisputeManagerDisputeInConflict(disputeId)); + _rejectDispute(disputeId, dispute); } /** * @notice The arbitrator draws dispute. + * Note that drawing a conflicting query dispute should not be possible however it is allowed + * to give arbitrators greater flexibility when resolving disputes. * @dev Ignore a dispute with Id `disputeId` * @param disputeId Id of the dispute to be disregarded */ function drawDispute(bytes32 disputeId) external override onlyArbitrator onlyPendingDispute(disputeId) { Dispute storage dispute = disputes[disputeId]; + _drawDispute(disputeId, dispute); - // Return deposit to the fisherman if any - if (dispute.deposit > 0) { - _graphToken().pushTokens(dispute.fisherman, dispute.deposit); + if (_isDisputeInConflict(dispute)) { + _drawDispute(dispute.relatedDisputeId, disputes[dispute.relatedDisputeId]); } - - // resolve related dispute if any - _drawDisputeInConflict(dispute); - - // store dispute status - dispute.status = IDisputeManager.DisputeStatus.Drawn; - - emit DisputeDrawn(disputeId, dispute.indexer, dispute.fisherman, dispute.deposit); } /** * @notice Once the dispute period ends, if the dispute status remains Pending, * the fisherman can cancel the dispute and get back their initial deposit. + * Note that cancelling a conflicting query dispute will also cancel the related dispute. * @dev Cancel a dispute with Id `disputeId` * @param disputeId Id of the dispute to be cancelled */ @@ -284,19 +309,11 @@ contract DisputeManager is // Check if dispute period has finished require(dispute.createdAt + disputePeriod < block.timestamp, DisputeManagerDisputePeriodNotFinished()); + _cancelDispute(disputeId, dispute); - // Return deposit to the fisherman if any - if (dispute.deposit > 0) { - _graphToken().pushTokens(dispute.fisherman, dispute.deposit); + if (_isDisputeInConflict(dispute)) { + _cancelDispute(dispute.relatedDisputeId, disputes[dispute.relatedDisputeId]); } - - // resolve related dispute if any - _cancelDisputeInConflict(dispute); - - // store dispute status - dispute.status = IDisputeManager.DisputeStatus.Cancelled; - - emit DisputeCancelled(disputeId, dispute.indexer, dispute.fisherman, dispute.deposit); } /** @@ -401,29 +418,6 @@ contract DisputeManager is return Attestation.areConflicting(attestation1, attestation2); } - /** - * @notice The arbitrator rejects a dispute as being invalid. - * @dev Reject a dispute with Id `disputeId` - * @param disputeId Id of the dispute to be rejected - */ - function rejectDispute(bytes32 disputeId) public override onlyArbitrator onlyPendingDispute(disputeId) { - Dispute storage dispute = disputes[disputeId]; - - // store dispute status - dispute.status = IDisputeManager.DisputeStatus.Rejected; - - // For conflicting disputes, the related dispute must be accepted - require( - !_isDisputeInConflict(dispute), - DisputeManagerMustAcceptRelatedDispute(disputeId, dispute.relatedDisputeId) - ); - - // Burn the fisherman's deposit - _graphToken().burnTokens(dispute.deposit); - - emit DisputeRejected(disputeId, dispute.indexer, dispute.fisherman, dispute.deposit); - } - /** * @notice Returns the indexer that signed an attestation. * @param attestation Attestation @@ -561,42 +555,33 @@ contract DisputeManager is return disputeId; } - /** - * @notice Draw the conflicting dispute if there is any for the one passed to this function. - * @param _dispute Dispute - * @return True if resolved - */ - function _drawDisputeInConflict(Dispute memory _dispute) private returns (bool) { - if (_isDisputeInConflict(_dispute)) { - bytes32 relatedDisputeId = _dispute.relatedDisputeId; - Dispute storage relatedDispute = disputes[relatedDisputeId]; - relatedDispute.status = IDisputeManager.DisputeStatus.Drawn; - return true; - } - return false; + function _acceptDispute(bytes32 _disputeId, Dispute storage _dispute, uint256 _tokensSlashed) private { + uint256 tokensToReward = _slashIndexer(_dispute.indexer, _tokensSlashed, _dispute.stakeSnapshot); + _dispute.status = IDisputeManager.DisputeStatus.Accepted; + _graphToken().pushTokens(_dispute.fisherman, tokensToReward + _dispute.deposit); + + emit DisputeAccepted(_disputeId, _dispute.indexer, _dispute.fisherman, _dispute.deposit + tokensToReward); } - /** - * @notice Cancel the conflicting dispute if there is any for the one passed to this function. - * @param _dispute Dispute - * @return True if cancelled - */ - function _cancelDisputeInConflict(Dispute memory _dispute) private returns (bool) { - if (_isDisputeInConflict(_dispute)) { - bytes32 relatedDisputeId = _dispute.relatedDisputeId; - Dispute storage relatedDispute = disputes[relatedDisputeId]; - relatedDispute.status = IDisputeManager.DisputeStatus.Cancelled; - return true; - } - return false; + function _rejectDispute(bytes32 _disputeId, Dispute storage _dispute) private { + _dispute.status = IDisputeManager.DisputeStatus.Rejected; + _graphToken().burnTokens(_dispute.deposit); + + emit DisputeRejected(_disputeId, _dispute.indexer, _dispute.fisherman, _dispute.deposit); } - /** - * @notice Pull `disputeDeposit` from fisherman account. - */ - function _pullFishermanDeposit() private { - // Transfer tokens to deposit from fisherman to this contract - _graphToken().pullTokens(msg.sender, disputeDeposit); + function _drawDispute(bytes32 _disputeId, Dispute storage _dispute) private { + _dispute.status = IDisputeManager.DisputeStatus.Drawn; + _graphToken().pushTokens(_dispute.fisherman, _dispute.deposit); + + emit DisputeDrawn(_disputeId, _dispute.indexer, _dispute.fisherman, _dispute.deposit); + } + + function _cancelDispute(bytes32 _disputeId, Dispute storage _dispute) private { + _dispute.status = IDisputeManager.DisputeStatus.Cancelled; + _graphToken().pushTokens(_dispute.fisherman, _dispute.deposit); + + emit DisputeCancelled(_disputeId, _dispute.indexer, _dispute.fisherman, _dispute.deposit); } /** @@ -658,7 +643,7 @@ contract DisputeManager is * @param _disputeDeposit The dispute deposit in Graph Tokens */ function _setDisputeDeposit(uint256 _disputeDeposit) private { - require(_disputeDeposit != 0, DisputeManagerInvalidDisputeDeposit(_disputeDeposit)); + require(_disputeDeposit >= MIN_DISPUTE_DEPOSIT, DisputeManagerInvalidDisputeDeposit(_disputeDeposit)); disputeDeposit = _disputeDeposit; emit DisputeDepositSet(_disputeDeposit); } @@ -704,10 +689,8 @@ contract DisputeManager is * @param _dispute Dispute * @return True conflicting attestation dispute */ - function _isDisputeInConflict(Dispute memory _dispute) private view returns (bool) { - bytes32 relatedId = _dispute.relatedDisputeId; - // this is so the check returns false when rejecting the related dispute. - return relatedId != 0 && disputes[relatedId].status == IDisputeManager.DisputeStatus.Pending; + function _isDisputeInConflict(Dispute storage _dispute) private view returns (bool) { + return _dispute.relatedDisputeId != bytes32(0); } /** diff --git a/packages/subgraph-service/contracts/interfaces/IDisputeManager.sol b/packages/subgraph-service/contracts/interfaces/IDisputeManager.sol index 95511ecc2..10865a77d 100644 --- a/packages/subgraph-service/contracts/interfaces/IDisputeManager.sol +++ b/packages/subgraph-service/contracts/interfaces/IDisputeManager.sol @@ -169,6 +169,7 @@ interface IDisputeManager { error DisputeManagerDisputeNotPending(IDisputeManager.DisputeStatus status); error DisputeManagerDisputeAlreadyCreated(bytes32 disputeId); error DisputeManagerDisputePeriodNotFinished(); + error DisputeManagerDisputeInConflict(bytes32 disputeId); error DisputeManagerMustAcceptRelatedDispute(bytes32 disputeId, bytes32 relatedDisputeId); error DisputeManagerIndexerNotFound(address allocationId); error DisputeManagerNonMatchingSubgraphDeployment(bytes32 subgraphDeploymentId1, bytes32 subgraphDeploymentId2); @@ -202,7 +203,7 @@ interface IDisputeManager { function createIndexingDispute(address allocationId, bytes32 poi) external returns (bytes32); - function acceptDispute(bytes32 disputeId, uint256 tokensSlash) external; + function acceptDispute(bytes32 disputeId, uint256 tokensSlash, bool acceptDisputeInConflict) external; function rejectDispute(bytes32 disputeId) external; diff --git a/packages/subgraph-service/test/disputeManager/DisputeManager.t.sol b/packages/subgraph-service/test/disputeManager/DisputeManager.t.sol index 0d99aec0b..ce6546030 100644 --- a/packages/subgraph-service/test/disputeManager/DisputeManager.t.sol +++ b/packages/subgraph-service/test/disputeManager/DisputeManager.t.sol @@ -3,8 +3,6 @@ pragma solidity 0.8.27; import "forge-std/Test.sol"; -import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; -import { TokenUtils } from "@graphprotocol/contracts/contracts/utils/TokenUtils.sol"; import { PPMMath } from "@graphprotocol/horizon/contracts/libraries/PPMMath.sol"; import { IDisputeManager } from "../../contracts/interfaces/IDisputeManager.sol"; import { Attestation } from "../../contracts/libraries/Attestation.sol"; @@ -26,7 +24,7 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { vm.stopPrank(); } - modifier useFisherman { + modifier useFisherman() { vm.startPrank(users.fisherman); _; vm.stopPrank(); @@ -88,7 +86,7 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { // Create the indexing dispute bytes32 _disputeId = disputeManager.createIndexingDispute(_allocationId, _poi); - + // Check that the dispute was created and that it has the correct ID assertTrue(disputeManager.isDisputeCreated(_disputeId), "Dispute should be created."); assertEq(expectedDisputeId, _disputeId, "Dispute ID should match"); @@ -99,20 +97,32 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { assertEq(dispute.fisherman, fisherman, "Fisherman should match"); assertEq(dispute.deposit, disputeDeposit, "Deposit should match"); assertEq(dispute.relatedDisputeId, bytes32(0), "Related dispute ID should be empty"); - assertEq(uint8(dispute.disputeType), uint8(IDisputeManager.DisputeType.IndexingDispute), "Dispute type should be indexing"); - assertEq(uint8(dispute.status), uint8(IDisputeManager.DisputeStatus.Pending), "Dispute status should be pending"); + assertEq( + uint8(dispute.disputeType), + uint8(IDisputeManager.DisputeType.IndexingDispute), + "Dispute type should be indexing" + ); + assertEq( + uint8(dispute.status), + uint8(IDisputeManager.DisputeStatus.Pending), + "Dispute status should be pending" + ); assertEq(dispute.createdAt, block.timestamp, "Created at should match"); assertEq(dispute.stakeSnapshot, stakeSnapshot, "Stake snapshot should match"); // Check that the fisherman was charged the dispute deposit uint256 afterFishermanBalance = token.balanceOf(fisherman); - assertEq(afterFishermanBalance, beforeFishermanBalance - disputeDeposit, "Fisherman should be charged the dispute deposit"); + assertEq( + afterFishermanBalance, + beforeFishermanBalance - disputeDeposit, + "Fisherman should be charged the dispute deposit" + ); return _disputeId; } function _createQueryDispute(bytes memory _attestationData) internal returns (bytes32) { - (, address fisherman,) = vm.readCallers(); + (, address fisherman, ) = vm.readCallers(); Attestation.State memory attestation = Attestation.parse(_attestationData); address indexer = disputeManager.getAttestationIndexer(attestation); bytes32 expectedDisputeId = keccak256( @@ -130,7 +140,7 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { // Approve the dispute deposit token.approve(address(disputeManager), disputeDeposit); - + vm.expectEmit(address(disputeManager)); emit IDisputeManager.QueryDisputeCreated( expectedDisputeId, @@ -141,9 +151,9 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { _attestationData, stakeSnapshot ); - + bytes32 _disputeID = disputeManager.createQueryDispute(_attestationData); - + // Check that the dispute was created and that it has the correct ID assertTrue(disputeManager.isDisputeCreated(_disputeID), "Dispute should be created."); assertEq(expectedDisputeId, _disputeID, "Dispute ID should match"); @@ -154,15 +164,27 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { assertEq(dispute.fisherman, fisherman, "Fisherman should match"); assertEq(dispute.deposit, disputeDeposit, "Deposit should match"); assertEq(dispute.relatedDisputeId, bytes32(0), "Related dispute ID should be empty"); - assertEq(uint8(dispute.disputeType), uint8(IDisputeManager.DisputeType.QueryDispute), "Dispute type should be query"); - assertEq(uint8(dispute.status), uint8(IDisputeManager.DisputeStatus.Pending), "Dispute status should be pending"); + assertEq( + uint8(dispute.disputeType), + uint8(IDisputeManager.DisputeType.QueryDispute), + "Dispute type should be query" + ); + assertEq( + uint8(dispute.status), + uint8(IDisputeManager.DisputeStatus.Pending), + "Dispute status should be pending" + ); assertEq(dispute.createdAt, block.timestamp, "Created at should match"); assertEq(dispute.stakeSnapshot, stakeSnapshot, "Stake snapshot should match"); // Check that the fisherman was charged the dispute deposit uint256 afterFishermanBalance = token.balanceOf(fisherman); - assertEq(afterFishermanBalance, beforeFishermanBalance - disputeDeposit, "Fisherman should be charged the dispute deposit"); - + assertEq( + afterFishermanBalance, + beforeFishermanBalance - disputeDeposit, + "Fisherman should be charged the dispute deposit" + ); + return _disputeID; } @@ -174,11 +196,12 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { uint256 stakeSnapshot1; uint256 stakeSnapshot2; } + function _createQueryDisputeConflict( bytes memory attestationData1, bytes memory attestationData2 ) internal returns (bytes32, bytes32) { - (, address fisherman,) = vm.readCallers(); + (, address fisherman, ) = vm.readCallers(); BeforeValues_CreateQueryDisputeConflict memory beforeValues; beforeValues.attestation1 = Attestation.parse(attestationData1); @@ -188,6 +211,11 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { beforeValues.stakeSnapshot1 = disputeManager.getStakeSnapshot(beforeValues.indexer1); beforeValues.stakeSnapshot2 = disputeManager.getStakeSnapshot(beforeValues.indexer2); + uint256 beforeFishermanBalance = token.balanceOf(fisherman); + + // Approve the dispute deposit + token.approve(address(disputeManager), disputeDeposit); + bytes32 expectedDisputeId1 = keccak256( abi.encodePacked( beforeValues.attestation1.requestCID, @@ -213,7 +241,7 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { expectedDisputeId1, beforeValues.indexer1, fisherman, - 0, + disputeDeposit / 2, beforeValues.attestation1.subgraphDeploymentId, attestationData1, beforeValues.stakeSnapshot1 @@ -223,13 +251,16 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { expectedDisputeId2, beforeValues.indexer2, fisherman, - 0, + disputeDeposit / 2, beforeValues.attestation2.subgraphDeploymentId, attestationData2, beforeValues.stakeSnapshot2 ); - (bytes32 _disputeId1, bytes32 _disputeId2) = disputeManager.createQueryDisputeConflict(attestationData1, attestationData2); + (bytes32 _disputeId1, bytes32 _disputeId2) = disputeManager.createQueryDisputeConflict( + attestationData1, + attestationData2 + ); // Check that the disputes were created and that they have the correct IDs assertTrue(disputeManager.isDisputeCreated(_disputeId1), "Dispute 1 should be created."); @@ -241,28 +272,55 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { IDisputeManager.Dispute memory dispute1 = _getDispute(_disputeId1); assertEq(dispute1.indexer, beforeValues.indexer1, "Indexer 1 should match"); assertEq(dispute1.fisherman, fisherman, "Fisherman 1 should match"); - assertEq(dispute1.deposit, 0, "Deposit 1 should match"); + assertEq(dispute1.deposit, disputeDeposit / 2, "Deposit 1 should match"); assertEq(dispute1.relatedDisputeId, _disputeId2, "Related dispute ID 1 should be the id of the other dispute"); - assertEq(uint8(dispute1.disputeType), uint8(IDisputeManager.DisputeType.QueryDispute), "Dispute type 1 should be query"); - assertEq(uint8(dispute1.status), uint8(IDisputeManager.DisputeStatus.Pending), "Dispute status 1 should be pending"); + assertEq( + uint8(dispute1.disputeType), + uint8(IDisputeManager.DisputeType.QueryDispute), + "Dispute type 1 should be query" + ); + assertEq( + uint8(dispute1.status), + uint8(IDisputeManager.DisputeStatus.Pending), + "Dispute status 1 should be pending" + ); assertEq(dispute1.createdAt, block.timestamp, "Created at 1 should match"); assertEq(dispute1.stakeSnapshot, beforeValues.stakeSnapshot1, "Stake snapshot 1 should match"); IDisputeManager.Dispute memory dispute2 = _getDispute(_disputeId2); assertEq(dispute2.indexer, beforeValues.indexer2, "Indexer 2 should match"); assertEq(dispute2.fisherman, fisherman, "Fisherman 2 should match"); - assertEq(dispute2.deposit, 0, "Deposit 2 should match"); + assertEq(dispute2.deposit, disputeDeposit / 2, "Deposit 2 should match"); assertEq(dispute2.relatedDisputeId, _disputeId1, "Related dispute ID 2 should be the id of the other dispute"); - assertEq(uint8(dispute2.disputeType), uint8(IDisputeManager.DisputeType.QueryDispute), "Dispute type 2 should be query"); - assertEq(uint8(dispute2.status), uint8(IDisputeManager.DisputeStatus.Pending), "Dispute status 2 should be pending"); + assertEq( + uint8(dispute2.disputeType), + uint8(IDisputeManager.DisputeType.QueryDispute), + "Dispute type 2 should be query" + ); + assertEq( + uint8(dispute2.status), + uint8(IDisputeManager.DisputeStatus.Pending), + "Dispute status 2 should be pending" + ); assertEq(dispute2.createdAt, block.timestamp, "Created at 2 should match"); assertEq(dispute2.stakeSnapshot, beforeValues.stakeSnapshot2, "Stake snapshot 2 should match"); + // Check that the fisherman was charged the dispute deposit + uint256 afterFishermanBalance = token.balanceOf(fisherman); + assertEq( + afterFishermanBalance, + beforeFishermanBalance - disputeDeposit, + "Fisherman should be charged the dispute deposit" + ); + return (_disputeId1, _disputeId2); } - function _acceptDispute(bytes32 _disputeId, uint256 _tokensSlash) internal { + function _acceptDispute(bytes32 _disputeId, uint256 _tokensSlash, bool _acceptRelatedDispute) internal { IDisputeManager.Dispute memory dispute = _getDispute(_disputeId); + bool isDisputeInConflict = dispute.relatedDisputeId != bytes32(0); + IDisputeManager.Dispute memory relatedDispute; + if (isDisputeInConflict) relatedDispute = _getDispute(dispute.relatedDisputeId); address fisherman = dispute.fisherman; uint256 fishermanPreviousBalance = token.balanceOf(fisherman); uint256 indexerTokensAvailable = staking.getProviderTokensAvailable(dispute.indexer, address(subgraphService)); @@ -271,37 +329,86 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { uint256 fishermanReward = _tokensSlash.mulPPM(fishermanRewardPercentage); vm.expectEmit(address(disputeManager)); - emit IDisputeManager.DisputeAccepted(_disputeId, dispute.indexer, dispute.fisherman, dispute.deposit + fishermanReward); + emit IDisputeManager.DisputeAccepted( + _disputeId, + dispute.indexer, + dispute.fisherman, + dispute.deposit + fishermanReward + ); + + if (isDisputeInConflict) { + if (_acceptRelatedDispute) { + emit IDisputeManager.DisputeAccepted( + dispute.relatedDisputeId, + relatedDispute.indexer, + relatedDispute.fisherman, + relatedDispute.deposit + ); + } else { + emit IDisputeManager.DisputeRejected( + dispute.relatedDisputeId, + relatedDispute.indexer, + relatedDispute.fisherman, + relatedDispute.deposit + ); + } + } // Accept the dispute - disputeManager.acceptDispute(_disputeId, _tokensSlash); + disputeManager.acceptDispute(_disputeId, _tokensSlash, _acceptRelatedDispute); // Check fisherman's got their reward and their deposit (if any) back - uint256 fishermanExpectedBalance = fishermanPreviousBalance + fishermanReward + disputeDeposit; - assertEq(token.balanceOf(fisherman), fishermanExpectedBalance, "Fisherman should get their reward and deposit back"); + uint256 fishermanExpectedBalance = fishermanPreviousBalance + + fishermanReward + + disputeDeposit + + (isDisputeInConflict ? relatedDispute.deposit : 0) + + ((isDisputeInConflict && _acceptRelatedDispute) ? fishermanReward : 0); + assertEq( + token.balanceOf(fisherman), + fishermanExpectedBalance, + "Fisherman should get their reward and deposit back" + ); // Check indexer was slashed by the correct amount uint256 expectedIndexerTokensAvailable; - if (_tokensSlash > indexerTokensAvailable) { + uint256 tokensToSlash = (isDisputeInConflict && _acceptRelatedDispute) ? _tokensSlash * 2 : _tokensSlash; + if (tokensToSlash > indexerTokensAvailable) { expectedIndexerTokensAvailable = 0; } else { - expectedIndexerTokensAvailable = indexerTokensAvailable - _tokensSlash; + expectedIndexerTokensAvailable = indexerTokensAvailable - tokensToSlash; } - assertEq(staking.getProviderTokensAvailable(dispute.indexer, address(subgraphService)), expectedIndexerTokensAvailable, "Indexer should be slashed by the correct amount"); + assertEq( + staking.getProviderTokensAvailable(dispute.indexer, address(subgraphService)), + expectedIndexerTokensAvailable, + "Indexer should be slashed by the correct amount" + ); // Check dispute status dispute = _getDispute(_disputeId); - assertEq(uint8(dispute.status), uint8(IDisputeManager.DisputeStatus.Accepted), "Dispute status should be accepted"); + assertEq( + uint8(dispute.status), + uint8(IDisputeManager.DisputeStatus.Accepted), + "Dispute status should be accepted" + ); - // If there's a related dispute, check that it was rejected - if (dispute.relatedDisputeId != bytes32(0)) { - IDisputeManager.Dispute memory relatedDispute = _getDispute(dispute.relatedDisputeId); - assertEq(uint8(relatedDispute.status), uint8(IDisputeManager.DisputeStatus.Rejected), "Related dispute status should be rejected"); + // If there's a related dispute, check it + if (isDisputeInConflict) { + relatedDispute = _getDispute(dispute.relatedDisputeId); + assertEq( + uint8(relatedDispute.status), + _acceptRelatedDispute + ? uint8(IDisputeManager.DisputeStatus.Accepted) + : uint8(IDisputeManager.DisputeStatus.Drawn), + "Related dispute status should be drawn" + ); } } function _drawDispute(bytes32 _disputeId) internal { IDisputeManager.Dispute memory dispute = _getDispute(_disputeId); + bool isConflictingDispute = dispute.relatedDisputeId != bytes32(0); + IDisputeManager.Dispute memory relatedDispute; + if (isConflictingDispute) relatedDispute = _getDispute(dispute.relatedDisputeId); address fisherman = dispute.fisherman; uint256 fishermanPreviousBalance = token.balanceOf(fisherman); uint256 indexerTokensAvailable = staking.getProviderTokensAvailable(dispute.indexer, address(subgraphService)); @@ -309,15 +416,29 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { vm.expectEmit(address(disputeManager)); emit IDisputeManager.DisputeDrawn(_disputeId, dispute.indexer, dispute.fisherman, dispute.deposit); + if (isConflictingDispute) { + emit IDisputeManager.DisputeDrawn( + dispute.relatedDisputeId, + relatedDispute.indexer, + relatedDispute.fisherman, + relatedDispute.deposit + ); + } // Draw the dispute disputeManager.drawDispute(_disputeId); // Check that the fisherman got their deposit back - uint256 fishermanExpectedBalance = fishermanPreviousBalance + dispute.deposit; + uint256 fishermanExpectedBalance = fishermanPreviousBalance + + dispute.deposit + + (isConflictingDispute ? relatedDispute.deposit : 0); assertEq(token.balanceOf(fisherman), fishermanExpectedBalance, "Fisherman should receive their deposit back."); // Check that indexer was not slashed - assertEq(staking.getProviderTokensAvailable(dispute.indexer, address(subgraphService)), indexerTokensAvailable, "Indexer should not be slashed"); + assertEq( + staking.getProviderTokensAvailable(dispute.indexer, address(subgraphService)), + indexerTokensAvailable, + "Indexer should not be slashed" + ); // Check dispute status dispute = _getDispute(_disputeId); @@ -325,8 +446,12 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { // If there's a related dispute, check that it was drawn too if (dispute.relatedDisputeId != bytes32(0)) { - IDisputeManager.Dispute memory relatedDispute = _getDispute(dispute.relatedDisputeId); - assertEq(uint8(relatedDispute.status), uint8(IDisputeManager.DisputeStatus.Drawn), "Related dispute status should be drawn"); + relatedDispute = _getDispute(dispute.relatedDisputeId); + assertEq( + uint8(relatedDispute.status), + uint8(IDisputeManager.DisputeStatus.Drawn), + "Related dispute status should be drawn" + ); } } @@ -346,17 +471,28 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { assertEq(token.balanceOf(users.fisherman), fishermanPreviousBalance, "Fisherman should lose the deposit."); // Check that indexer was not slashed - assertEq(staking.getProviderTokensAvailable(dispute.indexer, address(subgraphService)), indexerTokensAvailable, "Indexer should not be slashed"); + assertEq( + staking.getProviderTokensAvailable(dispute.indexer, address(subgraphService)), + indexerTokensAvailable, + "Indexer should not be slashed" + ); // Check dispute status dispute = _getDispute(_disputeId); - assertEq(uint8(dispute.status), uint8(IDisputeManager.DisputeStatus.Rejected), "Dispute status should be rejected"); + assertEq( + uint8(dispute.status), + uint8(IDisputeManager.DisputeStatus.Rejected), + "Dispute status should be rejected" + ); // Checl related id is empty assertEq(dispute.relatedDisputeId, bytes32(0), "Related dispute ID should be empty"); } function _cancelDispute(bytes32 _disputeId) internal { IDisputeManager.Dispute memory dispute = _getDispute(_disputeId); + bool isDisputeInConflict = dispute.relatedDisputeId != bytes32(0); + IDisputeManager.Dispute memory relatedDispute; + if (isDisputeInConflict) relatedDispute = _getDispute(dispute.relatedDisputeId); address fisherman = dispute.fisherman; uint256 fishermanPreviousBalance = token.balanceOf(fisherman); uint256 disputePeriod = disputeManager.disputePeriod(); @@ -368,24 +504,50 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { vm.expectEmit(address(disputeManager)); emit IDisputeManager.DisputeCancelled(_disputeId, dispute.indexer, dispute.fisherman, dispute.deposit); + if (isDisputeInConflict) { + emit IDisputeManager.DisputeCancelled( + dispute.relatedDisputeId, + relatedDispute.indexer, + relatedDispute.fisherman, + relatedDispute.deposit + ); + } + // Cancel the dispute disputeManager.cancelDispute(_disputeId); // Check that the fisherman got their deposit back - uint256 fishermanExpectedBalance = fishermanPreviousBalance + dispute.deposit; - assertEq(token.balanceOf(users.fisherman), fishermanExpectedBalance, "Fisherman should receive their deposit back."); + uint256 fishermanExpectedBalance = fishermanPreviousBalance + + dispute.deposit + + (isDisputeInConflict ? relatedDispute.deposit : 0); + assertEq( + token.balanceOf(users.fisherman), + fishermanExpectedBalance, + "Fisherman should receive their deposit back." + ); // Check that indexer was not slashed - assertEq(staking.getProviderTokensAvailable(dispute.indexer, address(subgraphService)), indexerTokensAvailable, "Indexer should not be slashed"); + assertEq( + staking.getProviderTokensAvailable(dispute.indexer, address(subgraphService)), + indexerTokensAvailable, + "Indexer should not be slashed" + ); // Check dispute status dispute = _getDispute(_disputeId); - assertEq(uint8(dispute.status), uint8(IDisputeManager.DisputeStatus.Cancelled), "Dispute status should be cancelled"); + assertEq( + uint8(dispute.status), + uint8(IDisputeManager.DisputeStatus.Cancelled), + "Dispute status should be cancelled" + ); - // If there's a related dispute, check that it was cancelled too - if (dispute.relatedDisputeId != bytes32(0)) { - IDisputeManager.Dispute memory relatedDispute = _getDispute(dispute.relatedDisputeId); - assertEq(uint8(relatedDispute.status), uint8(IDisputeManager.DisputeStatus.Cancelled), "Related dispute status should be cancelled"); + if (isDisputeInConflict) { + relatedDispute = _getDispute(dispute.relatedDisputeId); + assertEq( + uint8(relatedDispute.status), + uint8(IDisputeManager.DisputeStatus.Cancelled), + "Related dispute status should be cancelled" + ); } } @@ -398,11 +560,12 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { bytes32 responseCID, bytes32 subgraphDeploymentId ) internal pure returns (Attestation.Receipt memory receipt) { - return Attestation.Receipt({ - requestCID: requestCID, - responseCID: responseCID, - subgraphDeploymentId: subgraphDeploymentId - }); + return + Attestation.Receipt({ + requestCID: requestCID, + responseCID: responseCID, + subgraphDeploymentId: subgraphDeploymentId + }); } function _createConflictingAttestations( @@ -446,15 +609,16 @@ contract DisputeManagerTest is SubgraphServiceSharedTest { uint256 createdAt, uint256 stakeSnapshot ) = disputeManager.disputes(_disputeId); - return IDisputeManager.Dispute({ - indexer: indexer, - fisherman: fisherman, - deposit: deposit, - relatedDisputeId: relatedDisputeId, - disputeType: disputeType, - status: status, - createdAt: createdAt, - stakeSnapshot: stakeSnapshot - }); + return + IDisputeManager.Dispute({ + indexer: indexer, + fisherman: fisherman, + deposit: deposit, + relatedDisputeId: relatedDisputeId, + disputeType: disputeType, + status: status, + createdAt: createdAt, + stakeSnapshot: stakeSnapshot + }); } } diff --git a/packages/subgraph-service/test/disputeManager/disputes/disputes.t.sol b/packages/subgraph-service/test/disputeManager/disputes/disputes.t.sol index b6b4a6890..a7ac899ef 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/disputes.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/disputes.t.sol @@ -27,7 +27,7 @@ contract DisputeManagerDisputeTest is DisputeManagerTest { IDisputeManager.DisputeManagerInvalidDispute.selector, disputeID )); - disputeManager.acceptDispute(disputeID, tokensSlash); + disputeManager.acceptDispute(disputeID, tokensSlash, false); } function test_Dispute_Accept_RevertIf_SlashZeroTokens( @@ -40,7 +40,7 @@ contract DisputeManagerDisputeTest is DisputeManagerTest { resetPrank(users.arbitrator); uint256 maxTokensToSlash = uint256(maxSlashingPercentage).mulPPM(tokens); vm.expectRevert(abi.encodeWithSelector(IDisputeManager.DisputeManagerInvalidTokensSlash.selector, 0, maxTokensToSlash)); - disputeManager.acceptDispute(disputeID, 0); + disputeManager.acceptDispute(disputeID, 0, false); } function test_Dispute_Reject_RevertIf_DisputeDoesNotExist( diff --git a/packages/subgraph-service/test/disputeManager/disputes/indexing/accept.t.sol b/packages/subgraph-service/test/disputeManager/disputes/indexing/accept.t.sol index 49bee9e26..28717a00f 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/indexing/accept.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/indexing/accept.t.sol @@ -24,7 +24,20 @@ contract DisputeManagerIndexingAcceptDisputeTest is DisputeManagerTest { bytes32 disputeID = _createIndexingDispute(allocationID, bytes32("POI1")); resetPrank(users.arbitrator); - _acceptDispute(disputeID, tokensSlash); + _acceptDispute(disputeID, tokensSlash, false); + } + + function test_Indexing_Accept_Dispute_OptParam( + uint256 tokens, + uint256 tokensSlash + ) public useIndexer useAllocation(tokens) { + tokensSlash = bound(tokensSlash, 1, uint256(maxSlashingPercentage).mulPPM(tokens)); + + resetPrank(users.fisherman); + bytes32 disputeID = _createIndexingDispute(allocationID, bytes32("POI1")); + + resetPrank(users.arbitrator); + _acceptDispute(disputeID, tokensSlash, true); } function test_Indexing_Accept_RevertIf_CallerIsNotArbitrator( @@ -39,7 +52,7 @@ contract DisputeManagerIndexingAcceptDisputeTest is DisputeManagerTest { // attempt to accept dispute as fisherman resetPrank(users.fisherman); vm.expectRevert(abi.encodeWithSelector(IDisputeManager.DisputeManagerNotArbitrator.selector)); - disputeManager.acceptDispute(disputeID, tokensSlash); + disputeManager.acceptDispute(disputeID, tokensSlash, false); } function test_Indexing_Accept_RevertWhen_SlashingOverMaxSlashPercentage( @@ -59,6 +72,6 @@ contract DisputeManagerIndexingAcceptDisputeTest is DisputeManagerTest { maxTokensToSlash ); vm.expectRevert(expectedError); - disputeManager.acceptDispute(disputeID, tokensSlash); + disputeManager.acceptDispute(disputeID, tokensSlash, false); } } diff --git a/packages/subgraph-service/test/disputeManager/disputes/query/accept.t.sol b/packages/subgraph-service/test/disputeManager/disputes/query/accept.t.sol index 7670d381e..8c63a3004 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/query/accept.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/query/accept.t.sol @@ -31,7 +31,22 @@ contract DisputeManagerQueryAcceptDisputeTest is DisputeManagerTest { bytes32 disputeID = _createQueryDispute(attestationData); resetPrank(users.arbitrator); - _acceptDispute(disputeID, tokensSlash); + _acceptDispute(disputeID, tokensSlash, false); + } + + function test_Query_Accept_Dispute_OptParam( + uint256 tokens, + uint256 tokensSlash + ) public useIndexer useAllocation(tokens) { + tokensSlash = bound(tokensSlash, 1, uint256(maxSlashingPercentage).mulPPM(tokens)); + + resetPrank(users.fisherman); + Attestation.Receipt memory receipt = _createAttestationReceipt(requestCID, responseCID, subgraphDeploymentId); + bytes memory attestationData = _createAtestationData(receipt, allocationIDPrivateKey); + bytes32 disputeID = _createQueryDispute(attestationData); + + resetPrank(users.arbitrator); + _acceptDispute(disputeID, tokensSlash, true); } function test_Query_Accept_RevertIf_CallerIsNotArbitrator( @@ -47,7 +62,7 @@ contract DisputeManagerQueryAcceptDisputeTest is DisputeManagerTest { // attempt to accept dispute as fisherman vm.expectRevert(abi.encodeWithSelector(IDisputeManager.DisputeManagerNotArbitrator.selector)); - disputeManager.acceptDispute(disputeID, tokensSlash); + disputeManager.acceptDispute(disputeID, tokensSlash, false); } function test_Query_Accept_RevertWhen_SlashingOverMaxSlashPercentage( @@ -70,6 +85,6 @@ contract DisputeManagerQueryAcceptDisputeTest is DisputeManagerTest { maxTokensToSlash ); vm.expectRevert(expectedError); - disputeManager.acceptDispute(disputeID, tokensSlash); + disputeManager.acceptDispute(disputeID, tokensSlash, false); } } diff --git a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/accept.t.sol b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/accept.t.sol index 46a6d4bdd..d44c2432a 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/accept.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/accept.t.sol @@ -18,7 +18,7 @@ contract DisputeManagerQueryConflictAcceptDisputeTest is DisputeManagerTest { * TESTS */ - function test_Query_Conflict_Accept_Dispute( + function test_Query_Conflict_Accept_Dispute_Draw_Other( uint256 tokens, uint256 tokensSlash ) public useIndexer useAllocation(tokens) { @@ -33,11 +33,49 @@ contract DisputeManagerQueryConflictAcceptDisputeTest is DisputeManagerTest { allocationIDPrivateKey ); + uint256 fishermanBalanceBefore = token.balanceOf(users.fisherman); + resetPrank(users.fisherman); - (bytes32 disputeID1,) = _createQueryDisputeConflict(attestationData1, attestationData2); + (bytes32 disputeID1, ) = _createQueryDisputeConflict(attestationData1, attestationData2); resetPrank(users.arbitrator); - _acceptDispute(disputeID1, tokensSlash); + _acceptDispute(disputeID1, tokensSlash, false); + + uint256 fishermanRewardPercentage = disputeManager.fishermanRewardCut(); + uint256 fishermanReward = tokensSlash.mulPPM(fishermanRewardPercentage); + uint256 fishermanBalanceAfter = token.balanceOf(users.fisherman); + + assertEq(fishermanBalanceAfter, fishermanBalanceBefore + fishermanReward); + } + + function test_Query_Conflict_Accept_Dispute_Accept_Other( + uint256 tokens, + uint256 tokensSlash + ) public useIndexer useAllocation(tokens) { + tokensSlash = bound(tokensSlash, 1, uint256(maxSlashingPercentage).mulPPM(tokens)); + + (bytes memory attestationData1, bytes memory attestationData2) = _createConflictingAttestations( + requestCID, + subgraphDeployment, + responseCID1, + responseCID2, + allocationIDPrivateKey, + allocationIDPrivateKey + ); + + uint256 fishermanBalanceBefore = token.balanceOf(users.fisherman); + + resetPrank(users.fisherman); + (bytes32 disputeID1, ) = _createQueryDisputeConflict(attestationData1, attestationData2); + + resetPrank(users.arbitrator); + _acceptDispute(disputeID1, tokensSlash, true); + + uint256 fishermanRewardPercentage = disputeManager.fishermanRewardCut(); + uint256 fishermanReward = tokensSlash.mulPPM(fishermanRewardPercentage); + uint256 fishermanBalanceAfter = token.balanceOf(users.fisherman); + + assertEq(fishermanBalanceAfter, fishermanBalanceBefore + fishermanReward * 2); } function test_Query_Conflict_Accept_RevertIf_CallerIsNotArbitrator( @@ -56,12 +94,12 @@ contract DisputeManagerQueryConflictAcceptDisputeTest is DisputeManagerTest { ); resetPrank(users.fisherman); - (bytes32 disputeID1,) = _createQueryDisputeConflict(attestationData1, attestationData2); + (bytes32 disputeID1, ) = _createQueryDisputeConflict(attestationData1, attestationData2); // attempt to accept dispute as fisherman resetPrank(users.fisherman); vm.expectRevert(abi.encodeWithSelector(IDisputeManager.DisputeManagerNotArbitrator.selector)); - disputeManager.acceptDispute(disputeID1, tokensSlash); + disputeManager.acceptDispute(disputeID1, tokensSlash, false); } function test_Query_Conflict_Accept_RevertWhen_SlashingOverMaxSlashPercentage( @@ -80,17 +118,17 @@ contract DisputeManagerQueryConflictAcceptDisputeTest is DisputeManagerTest { ); resetPrank(users.fisherman); - (bytes32 disputeID1,) = _createQueryDisputeConflict(attestationData1, attestationData2); + (bytes32 disputeID1, ) = _createQueryDisputeConflict(attestationData1, attestationData2); // max slashing percentage is 50% resetPrank(users.arbitrator); uint256 maxTokensToSlash = uint256(maxSlashingPercentage).mulPPM(tokens); bytes memory expectedError = abi.encodeWithSelector( - IDisputeManager.DisputeManagerInvalidTokensSlash.selector, + IDisputeManager.DisputeManagerInvalidTokensSlash.selector, tokensSlash, maxTokensToSlash ); vm.expectRevert(expectedError); - disputeManager.acceptDispute(disputeID1, tokensSlash); + disputeManager.acceptDispute(disputeID1, tokensSlash, false); } } diff --git a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/reject.t.sol b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/reject.t.sol index ff347f7d2..3b56a05d8 100644 --- a/packages/subgraph-service/test/disputeManager/disputes/queryConflict/reject.t.sol +++ b/packages/subgraph-service/test/disputeManager/disputes/queryConflict/reject.t.sol @@ -7,14 +7,11 @@ import { IDisputeManager } from "../../../../contracts/interfaces/IDisputeManage import { DisputeManagerTest } from "../../DisputeManager.t.sol"; contract DisputeManagerQueryConflictRejectDisputeTest is DisputeManagerTest { - /* * TESTS */ - function test_Query_Conflict_Reject_Revert( - uint256 tokens - ) public useIndexer useAllocation(tokens) { + function test_Query_Conflict_Reject_Revert(uint256 tokens) public useIndexer useAllocation(tokens) { bytes32 requestCID = keccak256(abi.encodePacked("Request CID")); bytes32 responseCID1 = keccak256(abi.encodePacked("Response CID 1")); bytes32 responseCID2 = keccak256(abi.encodePacked("Response CID 2")); @@ -29,14 +26,10 @@ contract DisputeManagerQueryConflictRejectDisputeTest is DisputeManagerTest { ); resetPrank(users.fisherman); - (bytes32 disputeID1, bytes32 disputeID2) = _createQueryDisputeConflict(attestationData1, attestationData2); + (bytes32 disputeID1, ) = _createQueryDisputeConflict(attestationData1, attestationData2); resetPrank(users.arbitrator); - vm.expectRevert(abi.encodeWithSelector( - IDisputeManager.DisputeManagerMustAcceptRelatedDispute.selector, - disputeID1, - disputeID2 - )); + vm.expectRevert(abi.encodeWithSelector(IDisputeManager.DisputeManagerDisputeInConflict.selector, disputeID1)); disputeManager.rejectDispute(disputeID1); } } diff --git a/packages/subgraph-service/test/disputeManager/governance/disputeDeposit.t.sol b/packages/subgraph-service/test/disputeManager/governance/disputeDeposit.t.sol index 1df13acb2..bfd97f731 100644 --- a/packages/subgraph-service/test/disputeManager/governance/disputeDeposit.t.sol +++ b/packages/subgraph-service/test/disputeManager/governance/disputeDeposit.t.sol @@ -14,12 +14,12 @@ contract DisputeManagerGovernanceDisputeDepositTest is DisputeManagerTest { */ function test_Governance_SetDisputeDeposit(uint256 disputeDeposit) public useGovernor { - vm.assume(disputeDeposit > 0); + vm.assume(disputeDeposit >= MIN_DISPUTE_DEPOSIT); _setDisputeDeposit(disputeDeposit); } - function test_Governance_RevertWhen_ZeroValue() public useGovernor { - uint256 disputeDeposit = 0; + function test_Governance_RevertWhen_DepositTooLow(uint256 disputeDeposit) public useGovernor { + vm.assume(disputeDeposit < MIN_DISPUTE_DEPOSIT); vm.expectRevert(abi.encodeWithSelector(IDisputeManager.DisputeManagerInvalidDisputeDeposit.selector, disputeDeposit)); disputeManager.setDisputeDeposit(disputeDeposit); } diff --git a/packages/subgraph-service/test/mocks/MockGRTToken.sol b/packages/subgraph-service/test/mocks/MockGRTToken.sol index 7d21fd00a..c54f4e24c 100644 --- a/packages/subgraph-service/test/mocks/MockGRTToken.sol +++ b/packages/subgraph-service/test/mocks/MockGRTToken.sol @@ -7,7 +7,9 @@ import "@graphprotocol/contracts/contracts/token/IGraphToken.sol"; contract MockGRTToken is ERC20, IGraphToken { constructor() ERC20("Graph Token", "GRT") {} - function burn(uint256 amount) external {} + function burn(uint256 amount) external { + _burn(msg.sender, amount); + } function burnFrom(address _from, uint256 amount) external { _burn(_from, amount); diff --git a/packages/subgraph-service/test/utils/Constants.sol b/packages/subgraph-service/test/utils/Constants.sol index 76f864da1..517f9991d 100644 --- a/packages/subgraph-service/test/utils/Constants.sol +++ b/packages/subgraph-service/test/utils/Constants.sol @@ -7,6 +7,7 @@ abstract contract Constants { uint256 internal constant EPOCH_LENGTH = 1; // Dispute Manager uint64 internal constant disputePeriod = 7 days; + uint256 internal constant MIN_DISPUTE_DEPOSIT = 1 ether; // 1 GRT uint256 internal constant disputeDeposit = 100 ether; // 100 GRT uint32 internal constant fishermanRewardPercentage = 500000; // 50% uint32 internal constant maxSlashingPercentage = 500000; // 50%