Skip to content

Commit

Permalink
Merge pull request #986 from graphprotocol/mde/subgraph-service-tests
Browse files Browse the repository at this point in the history
Subgraph Service: unit tests
  • Loading branch information
Maikol authored Jun 27, 2024
2 parents b4f3285 + 19cb287 commit f47cf91
Show file tree
Hide file tree
Showing 24 changed files with 1,486 additions and 627 deletions.
23 changes: 23 additions & 0 deletions packages/subgraph-service/contracts/SubgraphService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,29 @@ contract SubgraphService is
_setDelegationRatio(delegationRatio);
}

/**
* @notice See {ISubgraphService.setStakeToFeesRatio}
*/
function setStakeToFeesRatio(uint256 _stakeToFeesRatio) external override onlyOwner {
stakeToFeesRatio = _stakeToFeesRatio;
emit StakeToFeesRatioSet(_stakeToFeesRatio);
}

/**
* @notice See {ISubgraphService.setMaxPOIStaleness}
*/
function setMaxPOIStaleness(uint256 maxPOIStaleness) external override onlyOwner {
_setMaxPOIStaleness(maxPOIStaleness);
}

/**
* @notice See {ISubgraphService.setPaymentCuts}
*/
function setPaymentCuts(IGraphPayments.PaymentTypes paymentType, uint128 serviceCut, uint128 curationCut) external override onlyOwner {
paymentCuts[paymentType] = PaymentCuts(serviceCut, curationCut);
emit PaymentCutsSet(paymentType, serviceCut, curationCut);
}

/**
* @notice See {ISubgraphService.getAllocation}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ interface ISubgraphService is IDataServiceFees {
uint256 tokensSubgraphService
);

/**
* @notice Emitted when the stake to fees ratio is set.
* @param ratio The stake to fees ratio
*/
event StakeToFeesRatioSet(uint256 ratio);

/**
* @notice Emmited when payment cuts are set for a payment type
* @param paymentType The payment type
* @param serviceCut The service cut for the payment type
* @param curationCut The curation cut for the payment type
*/
event PaymentCutsSet(IGraphPayments.PaymentTypes paymentType, uint128 serviceCut, uint128 curationCut);

/**
* @notice Thrown when an indexer tries to register with an empty URL
*/
Expand Down Expand Up @@ -133,6 +147,28 @@ interface ISubgraphService is IDataServiceFees {
*/
function setDelegationRatio(uint32 delegationRatio) external;

/**
* @notice Sets the stake to fees ratio
* @param stakeToFeesRatio The stake to fees ratio
*/
function setStakeToFeesRatio(uint256 stakeToFeesRatio) external;

/**
* @notice Sets the max POI staleness
* See {AllocationManagerV1Storage-maxPOIStaleness} for more details.
* @param maxPOIStaleness The max POI staleness in seconds
*/
function setMaxPOIStaleness(uint256 maxPOIStaleness) external;

/**
* @notice Sets the payment cuts for a payment type
* @dev Emits a {PaymentCutsSet} event
* @param paymentType The payment type
* @param serviceCut The service cut for the payment type
* @param curationCut The curation cut for the payment type
*/
function setPaymentCuts(IGraphPayments.PaymentTypes paymentType, uint128 serviceCut, uint128 curationCut) external;

/**
* @notice Sets the rewards destination for an indexer to receive indexing rewards
* @dev Emits a {RewardsDestinationSet} event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca
*/
event RewardsDestinationSet(address indexed indexer, address indexed rewardsDestination);

/**
* @notice Emitted when the maximum POI staleness is updated
* @param maxPOIStaleness The max POI staleness in seconds
*/
event MaxPOIStalenessSet(uint256 maxPOIStaleness);

/**
* @notice Thrown when an allocation proof is invalid
* Both `signer` and `allocationId` should match for a valid proof.
Expand Down Expand Up @@ -384,15 +390,15 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca
function _closeAllocation(address _allocationId) internal returns (Allocation.State memory) {
Allocation.State memory allocation = allocations.get(_allocationId);

allocations.close(_allocationId);
allocationProvisionTracker.release(allocation.indexer, allocation.tokens);

// Take rewards snapshot to prevent other allos from counting tokens from this allo
allocations.snapshotRewards(
_allocationId,
_graphRewardsManager().onSubgraphAllocationUpdate(allocation.subgraphDeploymentId)
);

allocations.close(_allocationId);
allocationProvisionTracker.release(allocation.indexer, allocation.tokens);

// Update total allocated tokens for the subgraph deployment
subgraphAllocatedTokens[allocation.subgraphDeploymentId] =
subgraphAllocatedTokens[allocation.subgraphDeploymentId] -
Expand All @@ -412,6 +418,16 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca
emit RewardsDestinationSet(_indexer, _rewardsDestination);
}

/**
* @notice Sets the maximum amount of time, in seconds, allowed between presenting POIs to qualify for indexing rewards
* @dev Emits a {MaxPOIStalenessSet} event
* @param _maxPOIStaleness The max POI staleness in seconds
*/
function _setMaxPOIStaleness(uint256 _maxPOIStaleness) internal {
maxPOIStaleness = _maxPOIStaleness;
emit MaxPOIStalenessSet(_maxPOIStaleness);
}

/**
* @notice Gets the details of an allocation
* @param _allocationId The id of the allocation
Expand Down
1 change: 1 addition & 0 deletions packages/subgraph-service/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cache_path = 'cache_forge'
optimizer = true
optimizer-runs = 200
via_ir = true
fs_permissions = [{ access = "read", path = "./"}]

[profile.lite]
optimizer = false
Expand Down
Loading

0 comments on commit f47cf91

Please sign in to comment.