-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(SubgraphService): allow force closing over allocated allocations
- Loading branch information
Showing
6 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/subgraph-service/test/subgraphService/allocation/closeOverAllocated.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.27; | ||
|
||
import "forge-std/Test.sol"; | ||
|
||
import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGraphPayments.sol"; | ||
import { ISubgraphService } from "../../../contracts/interfaces/ISubgraphService.sol"; | ||
import { SubgraphServiceTest } from "../SubgraphService.t.sol"; | ||
|
||
contract SubgraphServiceAllocationCloseOverAllocatedTest is SubgraphServiceTest { | ||
|
||
address private permissionlessBob = makeAddr("permissionlessBob"); | ||
|
||
/* | ||
* TESTS | ||
*/ | ||
|
||
function test_SubgraphService_Allocation_CloseOverAllocated( | ||
uint256 tokens | ||
) public useIndexer useAllocation(tokens) { | ||
// thaw some tokens to become over allocated | ||
staking.thaw(users.indexer, address(subgraphService), tokens / 2); | ||
|
||
resetPrank(permissionlessBob); | ||
_closeOverAllocatedAllocation(allocationID); | ||
} | ||
|
||
function test_SubgraphService_Allocation_CloseOverAllocated_AfterCollecting( | ||
uint256 tokens | ||
) public useIndexer useAllocation(tokens) { | ||
// Simulate POIs being submitted | ||
uint8 numberOfPOIs = 5; | ||
uint256 timeBetweenPOIs = 5 days; | ||
|
||
for (uint8 i = 0; i < numberOfPOIs; i++) { | ||
// Skip forward | ||
skip(timeBetweenPOIs); | ||
|
||
bytes memory data = abi.encode(allocationID, bytes32("POI1")); | ||
_collect(users.indexer, IGraphPayments.PaymentTypes.IndexingRewards, data); | ||
} | ||
|
||
// thaw some tokens to become over allocated | ||
staking.thaw(users.indexer, address(subgraphService), tokens / 2); | ||
|
||
// Close the over allocated allocation | ||
resetPrank(permissionlessBob); | ||
_closeOverAllocatedAllocation(allocationID); | ||
} | ||
|
||
function test_SubgraphService_Allocation_CloseOverAllocated_RevertIf_NotOverAllocated( | ||
uint256 tokens | ||
) public useIndexer useAllocation(tokens) { | ||
resetPrank(permissionlessBob); | ||
vm.expectRevert( | ||
abi.encodeWithSelector( | ||
ISubgraphService.SubgraphServiceAllocationNotOverAllocated.selector, | ||
allocationID | ||
) | ||
); | ||
subgraphService.closeOverAllocatedAllocation(allocationID); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters