@@ -2,11 +2,13 @@ import { assert, describe, test, clearStore, afterEach } from 'matchstick-as'
22import { Address , Bytes , BigInt , ethereum } from '@graphprotocol/graph-ts'
33import {
44 handleIndexingAgreementAccepted ,
5+ handleIndexingAgreementCanceled ,
56 handleIndexingAgreementUpdated ,
67 handleIndexingFeesCollectedV1 ,
78} from '../src/subgraphService'
89import {
910 IndexingAgreementAccepted as AcceptedEvent ,
11+ IndexingAgreementCanceled as CanceledEvent ,
1012 IndexingAgreementUpdated as UpdatedEvent ,
1113 IndexingFeesCollectedV1 as FeesCollectedEvent ,
1214} from '../generated/SubgraphService/SubgraphService'
@@ -46,6 +48,30 @@ function createAcceptedEvent(
4648 return event
4749}
4850
51+ function createCanceledEvent (
52+ indexer : Address ,
53+ payer : Address ,
54+ agreementId : Bytes ,
55+ canceledOnBehalfOf : Address ,
56+ ) : CanceledEvent {
57+ let event = changetype < CanceledEvent > ( newMockEvent ( ) )
58+
59+ event . parameters = new Array ( )
60+ event . parameters . push ( new ethereum . EventParam ( 'indexer' , ethereum . Value . fromAddress ( indexer ) ) )
61+ event . parameters . push ( new ethereum . EventParam ( 'payer' , ethereum . Value . fromAddress ( payer ) ) )
62+ event . parameters . push (
63+ new ethereum . EventParam ( 'agreementId' , ethereum . Value . fromFixedBytes ( agreementId ) ) ,
64+ )
65+ event . parameters . push (
66+ new ethereum . EventParam (
67+ 'canceledOnBehalfOf' ,
68+ ethereum . Value . fromAddress ( canceledOnBehalfOf ) ,
69+ ) ,
70+ )
71+
72+ return event
73+ }
74+
4975function createUpdatedEvent (
5076 indexer : Address ,
5177 payer : Address ,
@@ -177,6 +203,29 @@ describe('handleIndexingAgreementAccepted', () => {
177203 )
178204 // State remains NotAccepted until RC handler fires
179205 assert . fieldEquals ( 'IndexingAgreement' , agreementId . toHexString ( ) , 'state' , 'NotAccepted' )
206+
207+ // Immutable transition log emitted for event-sourcing consumers
208+ assert . entityCount ( 'IndexingAgreementAccepted' , 1 )
209+ } )
210+ } )
211+
212+ describe ( 'handleIndexingAgreementCanceled' , ( ) => {
213+ afterEach ( ( ) => {
214+ clearStore ( )
215+ } )
216+
217+ test ( 'emits immutable IndexingAgreementCanceled log with canceledBy address' , ( ) => {
218+ let indexer = Address . fromString ( '0x0000000000000000000000000000000000000001' )
219+ let payer = Address . fromString ( '0x0000000000000000000000000000000000000002' )
220+ let agreementId = Bytes . fromHexString ( '0x0102030405060708090a0b0c0d0e0f10' )
221+ let canceledOnBehalfOf = Address . fromString ( '0x0000000000000000000000000000000000000004' )
222+
223+ let event = createCanceledEvent ( indexer , payer , agreementId , canceledOnBehalfOf )
224+ handleIndexingAgreementCanceled ( event )
225+
226+ assert . entityCount ( 'IndexingAgreementCanceled' , 1 )
227+ // Aggregated entity state is owned by the RC handler — SS handler must not create one
228+ assert . entityCount ( 'IndexingAgreement' , 0 )
180229 } )
181230} )
182231
@@ -232,6 +281,10 @@ describe('handleIndexingAgreementUpdated', () => {
232281 'tokensPerEntityPerSecond' ,
233282 '100' ,
234283 )
284+
285+ // One log per event: the accept and the update each emit their own immutable log
286+ assert . entityCount ( 'IndexingAgreementAccepted' , 1 )
287+ assert . entityCount ( 'IndexingAgreementUpdated' , 1 )
235288 } )
236289} )
237290
0 commit comments