@@ -118,4 +118,109 @@ contract DisputeManagerQueryAcceptDisputeTest is DisputeManagerTest {
118
118
vm.expectRevert (abi.encodeWithSelector (IDisputeManager.DisputeManagerDisputeNotInConflict.selector , disputeID));
119
119
disputeManager.acceptDisputeConflict (disputeID, tokensSlash, true , 0 );
120
120
}
121
+
122
+ function test_Query_Accept_RevertWhen_SlashingOverMaxSlashPercentage_WithDelegation (
123
+ uint256 tokens ,
124
+ uint256 tokensDelegated ,
125
+ uint256 tokensSlash
126
+ ) public useIndexer useAllocation (tokens) useDelegation (tokensDelegated) {
127
+ uint256 maxTokensToSlash = uint256 (maxSlashingPercentage).mulPPM (
128
+ _calculateStakeSnapshot (tokens, tokensDelegated)
129
+ );
130
+ tokensSlash = bound (tokensSlash, maxTokensToSlash + 1 , type (uint256 ).max);
131
+
132
+ resetPrank (users.fisherman);
133
+ Attestation.Receipt memory receipt = _createAttestationReceipt (requestCID, responseCID, subgraphDeploymentId);
134
+ bytes memory attestationData = _createAtestationData (receipt, allocationIDPrivateKey);
135
+ bytes32 disputeID = _createQueryDispute (attestationData);
136
+
137
+ // max slashing percentage is 50%
138
+ resetPrank (users.arbitrator);
139
+ bytes memory expectedError = abi.encodeWithSelector (
140
+ IDisputeManager.DisputeManagerInvalidTokensSlash.selector ,
141
+ tokensSlash,
142
+ maxTokensToSlash
143
+ );
144
+ vm.expectRevert (expectedError);
145
+ disputeManager.acceptDispute (disputeID, tokensSlash);
146
+ }
147
+
148
+
149
+ function test_Query_Accept_RevertWhen_SlashingOverMaxSlashPercentage_WithDelegation_DelegationSlashing (
150
+ uint256 tokens ,
151
+ uint256 tokensDelegated ,
152
+ uint256 tokensSlash
153
+ ) public useIndexer useAllocation (tokens) useDelegation (tokensDelegated) {
154
+ // enable delegation slashing
155
+ resetPrank (users.governor);
156
+ staking.setDelegationSlashingEnabled ();
157
+
158
+ resetPrank (users.fisherman);
159
+ uint256 maxTokensToSlash = uint256 (maxSlashingPercentage).mulPPM (
160
+ _calculateStakeSnapshot (tokens, tokensDelegated)
161
+ );
162
+ tokensSlash = bound (tokensSlash, maxTokensToSlash + 1 , type (uint256 ).max);
163
+
164
+ // Create a new dispute with delegation slashing enabled
165
+ resetPrank (users.fisherman);
166
+ Attestation.Receipt memory receipt = _createAttestationReceipt (requestCID, responseCID, subgraphDeploymentId);
167
+ bytes memory attestationData = _createAtestationData (receipt, allocationIDPrivateKey);
168
+ bytes32 disputeID = _createQueryDispute (attestationData);
169
+
170
+ // max slashing percentage is 50%
171
+ resetPrank (users.arbitrator);
172
+ bytes memory expectedError = abi.encodeWithSelector (
173
+ IDisputeManager.DisputeManagerInvalidTokensSlash.selector ,
174
+ tokensSlash,
175
+ maxTokensToSlash
176
+ );
177
+ vm.expectRevert (expectedError);
178
+ disputeManager.acceptDispute (disputeID, tokensSlash);
179
+ }
180
+
181
+ function test_Query_Accept_Dispute_AfterFishermanRewardCutIncreased (
182
+ uint256 tokens ,
183
+ uint256 tokensSlash
184
+ ) public useIndexer {
185
+ vm.assume (tokens >= minimumProvisionTokens);
186
+ vm.assume (tokens < 10_000_000_000 ether);
187
+ tokensSlash = bound (tokensSlash, 1 , uint256 (maxSlashingPercentage).mulPPM (tokens));
188
+
189
+ // Set fishermanRewardCut to 25%
190
+ resetPrank (users.governor);
191
+ uint32 oldFishermanRewardCut = 250_000 ;
192
+ disputeManager.setFishermanRewardCut (oldFishermanRewardCut);
193
+
194
+ // Create provision with maxVerifierCut == fishermanRewardCut and allocate
195
+ resetPrank (users.indexer);
196
+ _createProvision (users.indexer, tokens, oldFishermanRewardCut, disputePeriod);
197
+ _register (users.indexer, abi.encode ("url " , "geoHash " , address (0 )));
198
+ bytes memory data = _createSubgraphAllocationData (
199
+ users.indexer,
200
+ subgraphDeployment,
201
+ allocationIDPrivateKey,
202
+ tokens
203
+ );
204
+ _startService (users.indexer, data);
205
+
206
+ // Create a dispute with prov.maxVerifierCut == fishermanRewardCut
207
+ uint256 beforeFishermanBalance = token.balanceOf (users.fisherman);
208
+ resetPrank (users.fisherman);
209
+ Attestation.Receipt memory receipt = _createAttestationReceipt (requestCID, responseCID, subgraphDeploymentId);
210
+ bytes memory attestationData = _createAtestationData (receipt, allocationIDPrivateKey);
211
+ bytes32 disputeID = _createQueryDispute (attestationData);
212
+
213
+ // Now bump the fishermanRewardCut to 50%
214
+ resetPrank (users.governor);
215
+ disputeManager.setFishermanRewardCut (500_000 );
216
+
217
+ // Accept the dispute
218
+ resetPrank (users.arbitrator);
219
+ _acceptDispute (disputeID, tokensSlash);
220
+
221
+ // Check that the fisherman received the correct amount of tokens
222
+ // which should use the old fishermanRewardCut
223
+ uint256 afterFishermanBalance = token.balanceOf (users.fisherman);
224
+ assertEq (afterFishermanBalance, beforeFishermanBalance + tokensSlash.mulPPM (oldFishermanRewardCut));
225
+ }
121
226
}
0 commit comments