Skip to content

Commit 63d2ba4

Browse files
authored
Subgraph Service - Unit tests (#1022)
* chore: add unit tests * fix: rebase cleanup * chore: dispute manager tests fixes * chore: dispute manager test fixes * chore: refactoring subgraph service unit tests * chore: subgraph service test fixes
1 parent ddbc4d2 commit 63d2ba4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2943
-1183
lines changed

packages/subgraph-service/contracts/DisputeManager.sol

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,15 @@ contract DisputeManager is
128128
* The disputes are created in reference to an allocationId and specifically
129129
* a POI for that allocation.
130130
* This function is called by a challenger and it will pull `disputeDeposit` GRT tokens.
131-
*
131+
*
132132
* Requirements:
133-
* - Challenger must have previously approved this contract to pull `disputeDeposit` amount
133+
* - Challenger must have previously approved this contract to pull `disputeDeposit` amount
134134
* of tokens from their balance.
135-
*
135+
*
136136
* @param allocationId The allocation to dispute
137137
* @param poi The Proof of Indexing (POI) being disputed
138138
*/
139-
function createIndexingDispute(
140-
address allocationId,
141-
bytes32 poi
142-
) external override returns (bytes32) {
139+
function createIndexingDispute(address allocationId, bytes32 poi) external override returns (bytes32) {
143140
// Get funds from submitter
144141
_pullSubmitterDeposit();
145142

@@ -150,11 +147,11 @@ contract DisputeManager is
150147
/**
151148
* @notice Create a query dispute for the arbitrator to resolve.
152149
* This function is called by a challenger and it will pull `disputeDeposit` GRT tokens.
153-
*
150+
*
154151
* * Requirements:
155-
* - Challenger must have previously approved this contract to pull `disputeDeposit` amount
152+
* - Challenger must have previously approved this contract to pull `disputeDeposit` amount
156153
* of tokens from their balance.
157-
*
154+
*
158155
* @param attestationData Attestation bytes submitted by the challenger
159156
*/
160157
function createQueryDispute(bytes calldata attestationData) external override returns (bytes32) {
@@ -296,6 +293,8 @@ contract DisputeManager is
296293

297294
// store dispute status
298295
dispute.status = IDisputeManager.DisputeStatus.Cancelled;
296+
297+
emit DisputeCancelled(disputeId, dispute.indexer, dispute.fisherman, dispute.deposit);
299298
}
300299

301300
/**
@@ -668,7 +667,10 @@ contract DisputeManager is
668667
* @param _fishermanRewardCut Reward as a percentage of indexer stake
669668
*/
670669
function _setFishermanRewardCut(uint32 _fishermanRewardCut) private {
671-
require(_fishermanRewardCut <= MAX_FISHERMAN_REWARD_CUT, DisputeManagerInvalidFishermanReward(_fishermanRewardCut));
670+
require(
671+
_fishermanRewardCut <= MAX_FISHERMAN_REWARD_CUT,
672+
DisputeManagerInvalidFishermanReward(_fishermanRewardCut)
673+
);
672674
fishermanRewardCut = _fishermanRewardCut;
673675
emit FishermanRewardCutSet(_fishermanRewardCut);
674676
}

packages/subgraph-service/contracts/interfaces/IDisputeManager.sol

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ interface IDisputeManager {
143143
*/
144144
event DisputeLinked(bytes32 indexed disputeId1, bytes32 indexed disputeId2);
145145

146+
/**
147+
* @dev Emitted when a dispute is cancelled by the fisherman.
148+
* The event emits the amount `tokens` returned to the fisherman.
149+
*/
150+
event DisputeCancelled(
151+
bytes32 indexed disputeId,
152+
address indexed indexer,
153+
address indexed fisherman,
154+
uint256 tokens
155+
);
156+
146157
// -- Errors --
147158

148159
error DisputeManagerNotArbitrator();
@@ -213,10 +224,10 @@ interface IDisputeManager {
213224

214225
function getAttestationIndexer(Attestation.State memory attestation) external view returns (address);
215226

227+
function getStakeSnapshot(address indexer) external view returns (uint256);
228+
216229
function areConflictingAttestations(
217230
Attestation.State memory attestation1,
218231
Attestation.State memory attestation2
219232
) external pure returns (bool);
220-
221-
function getStakeSnapshot(address indexer) external view returns (uint256);
222233
}

packages/subgraph-service/contracts/libraries/Attestation.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ library Attestation {
3333
uint256 private constant SIG_S_OFFSET = RECEIPT_SIZE_BYTES + SIG_R_LENGTH;
3434
uint256 private constant SIG_V_OFFSET = RECEIPT_SIZE_BYTES + SIG_R_LENGTH + SIG_S_LENGTH;
3535
uint256 private constant SIG_SIZE_BYTES = SIG_R_LENGTH + SIG_S_LENGTH + SIG_V_LENGTH;
36-
36+
3737
uint256 private constant ATTESTATION_SIZE_BYTES = RECEIPT_SIZE_BYTES + SIG_SIZE_BYTES;
3838

3939
uint256 private constant UINT8_BYTE_LENGTH = 1;

packages/subgraph-service/test/SubgraphBaseTest.t.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ abstract contract SubgraphBaseTest is Utils, Constants {
4040
SubgraphService subgraphService;
4141
DisputeManager disputeManager;
4242
IHorizonStaking staking;
43-
IGraphPayments graphPayments;
43+
GraphPayments graphPayments;
4444
IPaymentsEscrow escrow;
45-
ITAPCollector tapCollector;
45+
TAPCollector tapCollector;
4646

4747
HorizonStaking private stakingBase;
4848
HorizonStakingExtension private stakingExtension;
@@ -196,7 +196,7 @@ abstract contract SubgraphBaseTest is Utils, Constants {
196196
controller.setPaused(false);
197197
}
198198

199-
function createUser(string memory name) private returns (address) {
199+
function createUser(string memory name) internal returns (address) {
200200
address user = makeAddr(name);
201201
vm.deal({ account: user, newBalance: 100 ether });
202202
deal({ token: address(token), to: user, give: 10_000_000_000 ether });

0 commit comments

Comments
 (0)