From 7031d72a7e2f2b062ae9dbb26826f33fc40ad08b Mon Sep 17 00:00:00 2001 From: Miguel de Elias Date: Thu, 2 Jan 2025 11:16:06 -0300 Subject: [PATCH] fix: add whenNotPaused to closeStaleAllocation --- .../subgraph-service/contracts/SubgraphService.sol | 2 +- packages/subgraph-service/test/SubgraphBaseTest.t.sol | 4 +++- .../test/shared/SubgraphServiceShared.t.sol | 2 +- .../test/subgraphService/allocation/forceClose.t.sol | 10 ++++++++++ packages/subgraph-service/test/utils/Users.sol | 1 + 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/subgraph-service/contracts/SubgraphService.sol b/packages/subgraph-service/contracts/SubgraphService.sol index a4c6596e8..69f6fb6df 100644 --- a/packages/subgraph-service/contracts/SubgraphService.sol +++ b/packages/subgraph-service/contracts/SubgraphService.sol @@ -313,7 +313,7 @@ contract SubgraphService is /** * @notice See {ISubgraphService.closeStaleAllocation} */ - function closeStaleAllocation(address allocationId) external override { + function closeStaleAllocation(address allocationId) external override whenNotPaused { Allocation.State memory allocation = allocations.get(allocationId); require(allocation.isStale(maxPOIStaleness), SubgraphServiceCannotForceCloseAllocation(allocationId)); require(!allocation.isAltruistic(), SubgraphServiceAllocationIsAltruistic(allocationId)); diff --git a/packages/subgraph-service/test/SubgraphBaseTest.t.sol b/packages/subgraph-service/test/SubgraphBaseTest.t.sol index 663442e1f..878d341b0 100644 --- a/packages/subgraph-service/test/SubgraphBaseTest.t.sol +++ b/packages/subgraph-service/test/SubgraphBaseTest.t.sol @@ -75,7 +75,8 @@ abstract contract SubgraphBaseTest is Utils, Constants { delegator: createUser("delegator"), arbitrator: createUser("arbitrator"), fisherman: createUser("fisherman"), - rewardsDestination: createUser("rewardsDestination") + rewardsDestination: createUser("rewardsDestination"), + pauseGuardian: createUser("pauseGuardian") }); deployProtocolContracts(); @@ -191,6 +192,7 @@ abstract contract SubgraphBaseTest is Utils, Constants { epochManager.setEpochLength(EPOCH_LENGTH); subgraphService.setMaxPOIStaleness(maxPOIStaleness); subgraphService.setCurationCut(curationCut); + subgraphService.setPauseGuardian(users.pauseGuardian, true); } function unpauseProtocol() private { diff --git a/packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol b/packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol index e3258a09e..fa9d420fb 100644 --- a/packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol +++ b/packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol @@ -31,7 +31,7 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest { } modifier useAllocation(uint256 tokens) { - vm.assume(tokens > minimumProvisionTokens); + vm.assume(tokens >= minimumProvisionTokens); vm.assume(tokens < 10_000_000_000 ether); _createProvision(users.indexer, tokens, maxSlashingPercentage, disputePeriod); _register(users.indexer, abi.encode("url", "geoHash", address(0))); diff --git a/packages/subgraph-service/test/subgraphService/allocation/forceClose.t.sol b/packages/subgraph-service/test/subgraphService/allocation/forceClose.t.sol index 5b35f8d4e..1ac1383ab 100644 --- a/packages/subgraph-service/test/subgraphService/allocation/forceClose.t.sol +++ b/packages/subgraph-service/test/subgraphService/allocation/forceClose.t.sol @@ -3,6 +3,7 @@ pragma solidity 0.8.27; import "forge-std/Test.sol"; +import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGraphPayments.sol"; import { Allocation } from "../../../contracts/libraries/Allocation.sol"; @@ -91,4 +92,13 @@ contract SubgraphServiceAllocationForceCloseTest is SubgraphServiceTest { ); subgraphService.closeStaleAllocation(allocationID); } + + function test_SubgraphService_Allocation_ForceClose_RevertIf_Paused() public useIndexer useAllocation(1000 ether) { + resetPrank(users.pauseGuardian); + subgraphService.pause(); + + resetPrank(permissionlessBob); + vm.expectRevert(abi.encodeWithSelector(PausableUpgradeable.EnforcedPause.selector)); + subgraphService.closeStaleAllocation(allocationID); + } } diff --git a/packages/subgraph-service/test/utils/Users.sol b/packages/subgraph-service/test/utils/Users.sol index 69c3e411e..0d11fae9e 100644 --- a/packages/subgraph-service/test/utils/Users.sol +++ b/packages/subgraph-service/test/utils/Users.sol @@ -12,4 +12,5 @@ struct Users { address arbitrator; address fisherman; address rewardsDestination; + address pauseGuardian; } \ No newline at end of file