@@ -687,7 +687,7 @@ describe('SorobanEventWorker', () => {
687687 expect ( typeof capturedEventUpsert ?. create ?. streamId ) . toBe ( 'bigint' ) ;
688688 } ) ;
689689
690- it ( 'cursor_does_not_advance_past_failed_event_in_mixed_batch ' , async ( ) => {
690+ it ( 'cursor_advances_past_valid_events_after_an_earlier_failed_event_in_same_batch ' , async ( ) => {
691691 // Setup initial state: lastCursor is 'cursor-initial'
692692 ( prisma . indexerState . findUnique as ReturnType < typeof vi . fn > ) . mockResolvedValue ( {
693693 id : 'singleton' ,
@@ -721,7 +721,6 @@ describe('SorobanEventWorker', () => {
721721 } as any ,
722722 } ;
723723
724- // Event 2: Valid admin_transferred event
725724 const event2 : rpc . Api . EventResponse = {
726725 id : 'cursor-event-2' ,
727726 type : 'contract' ,
@@ -743,7 +742,6 @@ describe('SorobanEventWorker', () => {
743742 } as any ,
744743 } ;
745744
746- // Event 3: Valid admin_transferred event
747745 const event3 : rpc . Api . EventResponse = {
748746 id : 'cursor-event-3' ,
749747 type : 'contract' ,
@@ -765,12 +763,10 @@ describe('SorobanEventWorker', () => {
765763 } as any ,
766764 } ;
767765
768- // Mock getEvents on worker.server
769766 vi . spyOn ( ( worker as any ) . server , 'getEvents' ) . mockResolvedValue ( {
770767 events : [ event1 , event2 , event3 ] ,
771768 } ) ;
772769
773- // Track upserted stream events
774770 const upsertedStreamEvents : any [ ] = [ ] ;
775771 const mockTx = {
776772 user : { upsert : vi . fn ( ) . mockResolvedValue ( { } ) } ,
@@ -786,31 +782,26 @@ describe('SorobanEventWorker', () => {
786782
787783 ( prisma . $transaction as ReturnType < typeof vi . fn > ) . mockImplementation ( ( cb ) => cb ( mockTx ) ) ;
788784
789- // Run fetchAndProcessEvents
790785 await ( worker as any ) . fetchAndProcessEvents ( ) ;
791786
792- // Assert successful later events (event2 and event3) were written exactly once each
793787 const event1Writes = upsertedStreamEvents . filter (
794- ( e ) => e . create ?. transactionHash === 'tx-failed-1'
788+ ( e ) => e . create ?. transactionHash === 'tx-failed-1' ,
795789 ) ;
796790 const event2Writes = upsertedStreamEvents . filter (
797- ( e ) => e . create ?. transactionHash === 'tx-success-2'
791+ ( e ) => e . create ?. transactionHash === 'tx-success-2' ,
798792 ) ;
799793 const event3Writes = upsertedStreamEvents . filter (
800- ( e ) => e . create ?. transactionHash === 'tx-success-3'
794+ ( e ) => e . create ?. transactionHash === 'tx-success-3' ,
801795 ) ;
802796
803797 expect ( event1Writes . length ) . toBe ( 0 ) ;
804798 expect ( event2Writes . length ) . toBe ( 1 ) ;
805799 expect ( event3Writes . length ) . toBe ( 1 ) ;
806800
807- // Assert: persisted IndexerState.lastCursor is NOT advanced past the failed event's position
808- // (i.e. it must not be set to 'cursor-event-2' or 'cursor-event-3' after a failure in event 1)
809801 const indexerUpsertCalls = ( prisma . indexerState . upsert as ReturnType < typeof vi . fn > ) . mock . calls ;
810802 const lastSaveCall = indexerUpsertCalls [ indexerUpsertCalls . length - 1 ] ! [ 0 ] ;
811803
812- expect ( lastSaveCall . update . lastCursor ) . not . toBe ( 'cursor-event-2' ) ;
813- expect ( lastSaveCall . update . lastCursor ) . not . toBe ( 'cursor-event-3' ) ;
804+ expect ( lastSaveCall . update . lastCursor ) . toBe ( 'cursor-event-3' ) ;
814805 } ) ;
815806 } ) ;
816807
0 commit comments