Skip to content

Commit

Permalink
fix: Don't remove entries from AnchorRequestStore if applying the anc…
Browse files Browse the repository at this point in the history
…hor commit fails (#3277)
  • Loading branch information
stbrody authored Sep 16, 2024
1 parent a342f20 commit c2282b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/core/src/state-management/__tests__/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,26 @@ describeIfV3('handleAnchorEvent', () => {
expect(shouldRemove).toBeTruthy()
expect(nextSpy).not.toBeCalled()
})

test('Throw error if unable to handle anchor commit APPLY_ANCHOR_COMMIT_ATTEMPTS times', async () => {
const tile = await TileDocument.create(ceramic, { text: 1 }, undefined, { anchor: true })
const state$ = await repository.load(tile.id)
const witnessCar = new CARFactory().build()
witnessCar.put('root', { isRoot: true })
const event: AnchorEvent = {
status: AnchorRequestStatusName.COMPLETED,
message: 'Last COMPLETED',
streamId: tile.id,
cid: tile.tip,
witnessCar,
}
const dispatcherImportCarSpy = jest.spyOn(ceramic.dispatcher as any, 'importCAR')
dispatcherImportCarSpy.mockImplementation(async () => {
throw new Error('Fake error')
})
await expect(repository.handleAnchorEvent(state$, event)).rejects.toThrow('Fake error')
expect(dispatcherImportCarSpy).toBeCalledTimes(3)
})
})
})

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/state-management/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,8 @@ export class Repository {
if (tip.equals(state$.tip)) {
state$.next({ ...state$.value, anchorStatus: AnchorStatus.FAILED })
}

throw error
}
}
}
Expand Down

0 comments on commit c2282b7

Please sign in to comment.