Skip to content

Commit ca2ef4f

Browse files
authored
chore: add over delegated test for SubgraphService (#1082)
1 parent 51d0f7f commit ca2ef4f

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

packages/subgraph-service/test/shared/HorizonStakingShared.t.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ abstract contract HorizonStakingSharedTest is SubgraphBaseTest {
3333
staking.delegate(_indexer, _verifier, _tokens, _minSharesOut);
3434
}
3535

36+
function _undelegate(address _indexer, address _verifier, uint256 _shares) internal {
37+
staking.undelegate(_indexer, _verifier, _shares);
38+
}
39+
3640
function _setDelegationFeeCut(
3741
address _indexer,
3842
address _verifier,
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

Comments
 (0)