|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity 0.8.27; |
| 3 | + |
| 4 | +import "forge-std/Test.sol"; |
| 5 | + |
| 6 | +import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGraphPayments.sol"; |
| 7 | +import { IHorizonStakingTypes } from "@graphprotocol/horizon/contracts/interfaces/internal/IHorizonStakingTypes.sol"; |
| 8 | + |
| 9 | +import { Allocation } from "../../../contracts/libraries/Allocation.sol"; |
| 10 | +import { ISubgraphService } from "../../../contracts/interfaces/ISubgraphService.sol"; |
| 11 | +import { SubgraphServiceTest } from "../SubgraphService.t.sol"; |
| 12 | + |
| 13 | +contract SubgraphServiceAllocationOverDelegatedTest is SubgraphServiceTest { |
| 14 | + |
| 15 | + /* |
| 16 | + * TESTS |
| 17 | + */ |
| 18 | + |
| 19 | + function test_SubgraphService_Allocation_OverDelegated_NotOverAllocatedAfterUndelegation( |
| 20 | + uint256 delegationTokens, |
| 21 | + uint256 undelegationTokens |
| 22 | + ) public useIndexer { |
| 23 | + // Use minimum provision tokens |
| 24 | + uint256 indexerTokens = minimumProvisionTokens; |
| 25 | + uint256 allocationTokens = indexerTokens * delegationRatio; |
| 26 | + // Bound delegation tokens to be over delegated |
| 27 | + delegationTokens = bound(delegationTokens, allocationTokens, MAX_TOKENS); |
| 28 | + // Assume undelegation tokens to still leave indexer over delegated |
| 29 | + vm.assume(undelegationTokens > 1); |
| 30 | + vm.assume(undelegationTokens < delegationTokens - allocationTokens); |
| 31 | + |
| 32 | + // Create provision |
| 33 | + token.approve(address(staking), indexerTokens); |
| 34 | + _createProvision(users.indexer, indexerTokens, maxSlashingPercentage, disputePeriod); |
| 35 | + _register(users.indexer, abi.encode("url", "geoHash", address(0))); |
| 36 | + |
| 37 | + // Delegate so that indexer is over allocated |
| 38 | + resetPrank(users.delegator); |
| 39 | + token.approve(address(staking), delegationTokens); |
| 40 | + _delegate(users.indexer, address(subgraphService), delegationTokens, 0); |
| 41 | + |
| 42 | + // Create allocation |
| 43 | + resetPrank(users.indexer); |
| 44 | + bytes memory data = _createSubgraphAllocationData( |
| 45 | + users.indexer, |
| 46 | + subgraphDeployment, |
| 47 | + allocationIDPrivateKey, |
| 48 | + allocationTokens |
| 49 | + ); |
| 50 | + _startService(users.indexer, data); |
| 51 | + |
| 52 | + // Undelegate |
| 53 | + resetPrank(users.delegator); |
| 54 | + _undelegate(users.indexer, address(subgraphService), undelegationTokens); |
| 55 | + |
| 56 | + // Check that indexer is not over allocated |
| 57 | + assertFalse(subgraphService.isOverAllocated(users.indexer)); |
| 58 | + } |
| 59 | +} |
0 commit comments