Skip to content

Commit aba7ac5

Browse files
committed
feat: use poi to create dispute id
Signed-off-by: Tomás Migone <[email protected]>
1 parent 02a2fc3 commit aba7ac5

File tree

6 files changed

+40
-20
lines changed

6 files changed

+40
-20
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "packages/horizon/lib/openzeppelin-foundry-upgrades"]
88
path = packages/horizon/lib/openzeppelin-foundry-upgrades
99
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades
10+
[submodule "packages/subgraph-service/lib/openzeppelin-foundry-upgrades"]
11+
path = packages/subgraph-service/lib/openzeppelin-foundry-upgrades
12+
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades

packages/subgraph-service/contracts/SubgraphService.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ contract SubgraphService is
7474
address disputeManager,
7575
address tapCollector,
7676
address curation
77-
) DataService(graphController) Directory(address(this), tapCollector, disputeManager, curation) {
77+
) DataService(graphController) Directory(address(this), disputeManager, tapCollector, curation) {
7878
_disableInitializers();
7979
}
8080

packages/subgraph-service/remappings.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ eth-gas-reporter/=node_modules/eth-gas-reporter/
66
hardhat/=node_modules/hardhat/
77
@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/
88
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/
9+
openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src

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

+25-18
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,15 @@ contract DisputeManagerTest is Test {
9292
);
9393
disputeManager = DisputeManager(disputeManagerProxy);
9494

95-
subgraphService = new SubgraphService(address(controller), address(disputeManager), tapVerifier, curation);
96-
subgraphService.initialize(1000 ether, 16);
95+
address subgraphServiceImplementation = address(
96+
new SubgraphService(address(controller), address(disputeManager), tapVerifier, curation)
97+
);
98+
address subgraphServiceProxy = UnsafeUpgrades.deployTransparentProxy(
99+
subgraphServiceImplementation,
100+
governor,
101+
abi.encodeCall(SubgraphService.initialize, (1000 ether, 16))
102+
);
103+
subgraphService = SubgraphService(subgraphServiceProxy);
97104

98105
disputeManager.setSubgraphService(address(subgraphService));
99106
}
@@ -108,18 +115,18 @@ contract DisputeManagerTest is Test {
108115
bytes32 digest = subgraphService.encodeAllocationProof(indexer, _allocationID);
109116
(uint8 v, bytes32 r, bytes32 s) = vm.sign(allocationIDPrivateKey, digest);
110117

111-
subgraphService.register(indexer, abi.encode("url", "geoHash"));
118+
subgraphService.register(indexer, abi.encode("url", "geoHash", address(0)));
112119

113120
bytes memory data = abi.encode(subgraphDeployment, tokens, _allocationID, abi.encodePacked(r, s, v));
114121
subgraphService.startService(indexer, data);
115122
vm.stopPrank();
116123
}
117124

118-
function createIndexingDispute(address _allocationID, uint256 tokens) private returns (bytes32 disputeID) {
125+
function createIndexingDispute(address _allocationID, bytes32 _poi, uint256 tokens) private returns (bytes32 disputeID) {
119126
vm.startPrank(fisherman);
120127
graphToken.mint(fisherman, tokens);
121128
graphToken.approve(address(disputeManager), tokens);
122-
bytes32 _disputeID = disputeManager.createIndexingDispute(_allocationID, bytes32("POI1234"), tokens);
129+
bytes32 _disputeID = disputeManager.createIndexingDispute(_allocationID, _poi, tokens);
123130
vm.stopPrank();
124131
return _disputeID;
125132
}
@@ -181,7 +188,7 @@ contract DisputeManagerTest is Test {
181188
function testCreateIndexingDispute() public {
182189
createProvisionAndAllocate(allocationID, 10000 ether);
183190

184-
bytes32 disputeID = createIndexingDispute(allocationID, 200 ether);
191+
bytes32 disputeID = createIndexingDispute(allocationID, bytes32("POI1"), 200 ether);
185192
assertTrue(disputeManager.isDisputeCreated(disputeID), "Dispute should be created.");
186193
}
187194

@@ -217,7 +224,7 @@ contract DisputeManagerTest is Test {
217224

218225
function test_RevertWhen_DisputeAlreadyCreated() public {
219226
createProvisionAndAllocate(allocationID, 10000 ether);
220-
bytes32 disputeID = createIndexingDispute(allocationID, 200 ether);
227+
bytes32 disputeID = createIndexingDispute(allocationID, bytes32("POI1"), 200 ether);
221228

222229
// Create another dispute with different fisherman
223230
address otherFisherman = address(0x5);
@@ -227,7 +234,7 @@ contract DisputeManagerTest is Test {
227234
graphToken.approve(address(disputeManager), tokens);
228235
bytes memory expectedError = abi.encodeWithSignature("DisputeManagerDisputeAlreadyCreated(bytes32)", disputeID);
229236
vm.expectRevert(expectedError);
230-
disputeManager.createIndexingDispute(allocationID, bytes32("POI1234"), tokens);
237+
disputeManager.createIndexingDispute(allocationID, bytes32("POI1"), tokens);
231238
vm.stopPrank();
232239
}
233240

@@ -241,7 +248,7 @@ contract DisputeManagerTest is Test {
241248
100 ether
242249
);
243250
vm.expectRevert(expectedError);
244-
disputeManager.createIndexingDispute(allocationID, bytes32("POI1234"), 50 ether);
251+
disputeManager.createIndexingDispute(allocationID, bytes32("POI3"), 50 ether);
245252
vm.stopPrank();
246253
}
247254

@@ -253,7 +260,7 @@ contract DisputeManagerTest is Test {
253260
graphToken.approve(address(disputeManager), tokens);
254261
bytes memory expectedError = abi.encodeWithSignature("DisputeManagerIndexerNotFound(address)", allocationID);
255262
vm.expectRevert(expectedError);
256-
disputeManager.createIndexingDispute(allocationID, bytes32("POI1234"), tokens);
263+
disputeManager.createIndexingDispute(allocationID, bytes32("POI4"), tokens);
257264
vm.stopPrank();
258265
}
259266

@@ -316,7 +323,7 @@ contract DisputeManagerTest is Test {
316323

317324
function testAcceptIndexingDispute() public {
318325
createProvisionAndAllocate(allocationID, 10000 ether);
319-
bytes32 disputeID = createIndexingDispute(allocationID, 200 ether);
326+
bytes32 disputeID = createIndexingDispute(allocationID, bytes32("POI1"), 200 ether);
320327

321328
vm.prank(arbitrator);
322329
disputeManager.acceptDispute(disputeID, 5000 ether);
@@ -371,7 +378,7 @@ contract DisputeManagerTest is Test {
371378
function test_RevertIf_CallerIsNotArbitrator_AcceptDispute() public {
372379
createProvisionAndAllocate(allocationID, 10000 ether);
373380

374-
bytes32 disputeID = createIndexingDispute(allocationID, 200 ether);
381+
bytes32 disputeID = createIndexingDispute(allocationID, bytes32("POI1"), 200 ether);
375382

376383
// attempt to accept dispute as fisherman
377384
vm.prank(fisherman);
@@ -381,11 +388,11 @@ contract DisputeManagerTest is Test {
381388

382389
function test_RevertIf_SlashingOverMaxSlashPercentage() public {
383390
createProvisionAndAllocate(allocationID, 10000 ether);
384-
bytes32 disputeID = createIndexingDispute(allocationID, 200 ether);
391+
bytes32 disputeID = createIndexingDispute(allocationID, bytes32("POI101"), 200 ether);
385392

386393
// max slashing percentage is 50%
387394
vm.prank(arbitrator);
388-
bytes memory expectedError = abi.encodeWithSignature("DisputeManagerInvalidSlashAmount(uint256)", 6000 ether);
395+
bytes memory expectedError = abi.encodeWithSignature("DisputeManagerInvalidTokensSlash(uint256)", 6000 ether);
389396
vm.expectRevert(expectedError);
390397
disputeManager.acceptDispute(disputeID, 6000 ether);
391398
}
@@ -394,7 +401,7 @@ contract DisputeManagerTest is Test {
394401

395402
function testCancelDispute() public {
396403
createProvisionAndAllocate(allocationID, 10000 ether);
397-
bytes32 disputeID = createIndexingDispute(allocationID, 200 ether);
404+
bytes32 disputeID = createIndexingDispute(allocationID, bytes32("POI1"), 200 ether);
398405

399406
// skip to end of dispute period
400407
skip(disputePeriod + 1);
@@ -442,7 +449,7 @@ contract DisputeManagerTest is Test {
442449

443450
function test_RevertIf_CallerIsNotFisherman_CancelDispute() public {
444451
createProvisionAndAllocate(allocationID, 10000 ether);
445-
bytes32 disputeID = createIndexingDispute(allocationID, 200 ether);
452+
bytes32 disputeID = createIndexingDispute(allocationID, bytes32("POI1"), 200 ether);
446453

447454
vm.prank(arbitrator);
448455
vm.expectRevert(bytes4(keccak256("DisputeManagerNotFisherman()")));
@@ -453,7 +460,7 @@ contract DisputeManagerTest is Test {
453460

454461
function testDrawDispute() public {
455462
createProvisionAndAllocate(allocationID, 10000 ether);
456-
bytes32 disputeID = createIndexingDispute(allocationID, 200 ether);
463+
bytes32 disputeID = createIndexingDispute(allocationID, bytes32("POI32"), 200 ether);
457464

458465
vm.prank(arbitrator);
459466
disputeManager.drawDispute(disputeID);
@@ -495,7 +502,7 @@ contract DisputeManagerTest is Test {
495502

496503
function test_RevertIf_CallerIsNotArbitrator_DrawDispute() public {
497504
createProvisionAndAllocate(allocationID, 10000 ether);
498-
bytes32 disputeID = createIndexingDispute(allocationID, 200 ether);
505+
bytes32 disputeID = createIndexingDispute(allocationID,bytes32("POI1"), 200 ether);
499506

500507
// attempt to draw dispute as fisherman
501508
vm.prank(fisherman);

packages/subgraph-service/test/mocks/MockHorizonStaking.sol

+9-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ contract MockHorizonStaking {
8383

8484
// provisioned tokens that are not being used
8585
// `Provision.tokens - Provision.tokensThawing`
86-
function getTokensAvailable(address serviceProvider, address verifier) external view returns (uint256 tokens) {
86+
function getTokensAvailable(address serviceProvider, address verifier, uint32 delegationRatio) external view returns (uint256 tokens) {
8787
return _provisions[verifier][serviceProvider].tokens;
8888
}
8989

@@ -97,6 +97,14 @@ contract MockHorizonStaking {
9797
return true;
9898
}
9999

100+
function getDelegationPool(address serviceProvider, address verifier) external view returns (IHorizonStakingTypes.DelegationPool memory) {
101+
return IHorizonStakingTypes.DelegationPool({
102+
tokens: 0,
103+
shares: 0,
104+
tokensThawing: 0,
105+
sharesThawing: 0
106+
});
107+
}
100108
function getDelegationCut(address serviceProvider, uint8 paymentType) external view returns (uint256 delegationCut) {}
101109
function addToDelegationPool(address serviceProvider, uint256 tokens) external {}
102110
function stakeToProvision(address _serviceProvider, address _verifier, uint256 _tokens) external {}

0 commit comments

Comments
 (0)