Skip to content

Commit e071a73

Browse files
fix: [TRST-L-6] Proper agreement version check
1 parent 54747b8 commit e071a73

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ library IndexingAgreement {
390390
signedRCAU.rcau.metadata
391391
);
392392

393-
wrapper.agreement.version = metadata.version;
394-
393+
require(wrapper.agreement.version == IndexingAgreementVersion.V1, "internal: invalid version");
395394
require(metadata.version == IndexingAgreementVersion.V1, IndexingAgreementInvalidVersion(metadata.version));
396395
_setTermsV1(self, signedRCAU.rcau.agreementId, metadata.terms);
397396

packages/subgraph-service/test/unit/subgraphService/indexing-agreement/accept.t.sol

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,38 @@ contract SubgraphServiceIndexingAgreementAcceptTest is SubgraphServiceIndexingAg
226226
subgraphService.acceptIndexingAgreement(ctx.indexers[0].allocationId, accepted);
227227
}
228228

229-
function test_SubgraphService_AcceptIndexingAgreement_Revert_WhenAgreementAlreadyAllocated() public {}
229+
function test_SubgraphService_AcceptIndexingAgreement_Revert_WhenAgreementAlreadyAllocated(
230+
Seed memory seed,
231+
uint256 alternativeNonce
232+
) public {
233+
Context storage ctx = _newCtx(seed);
234+
IndexerState memory indexerState = _withIndexer(ctx);
235+
236+
// First, accept an indexing agreement on the allocation
237+
(IRecurringCollector.SignedRCA memory accepted, ) = _withAcceptedIndexingAgreement(ctx, indexerState);
238+
vm.assume(accepted.rca.nonce != alternativeNonce);
239+
240+
// Now try to accept a different agreement on the same allocation
241+
// Create a new agreement with different nonce to ensure different agreement ID
242+
IRecurringCollector.RecurringCollectionAgreement
243+
memory newRCA = _generateAcceptableRecurringCollectionAgreement(ctx, indexerState.addr);
244+
newRCA.nonce = alternativeNonce; // Different nonce to ensure different agreement ID
245+
246+
// Sign the new agreement
247+
IRecurringCollector.SignedRCA memory newSignedRCA = _recurringCollectorHelper.generateSignedRCA(
248+
newRCA,
249+
ctx.payer.signerPrivateKey
250+
);
251+
252+
// Expect the error when trying to accept a second agreement on the same allocation
253+
bytes memory expectedErr = abi.encodeWithSelector(
254+
IndexingAgreement.AllocationAlreadyHasIndexingAgreement.selector,
255+
indexerState.allocationId
256+
);
257+
vm.expectRevert(expectedErr);
258+
resetPrank(indexerState.addr);
259+
subgraphService.acceptIndexingAgreement(indexerState.allocationId, newSignedRCA);
260+
}
230261

231262
function test_SubgraphService_AcceptIndexingAgreement_Revert_WhenInvalidTermsData(Seed memory seed) public {
232263
Context storage ctx = _newCtx(seed);

0 commit comments

Comments
 (0)