From d5824664dd35643ea1b2923f038eaf881e2e3d68 Mon Sep 17 00:00:00 2001 From: Pierre Seznec Date: Thu, 29 Aug 2024 12:27:52 +0200 Subject: [PATCH] fix event poller --- src/events/eventsPoller.ts | 2 -- test/integration/events.spec.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/events/eventsPoller.ts b/src/events/eventsPoller.ts index f6285ee8..363dbfff 100644 --- a/src/events/eventsPoller.ts +++ b/src/events/eventsPoller.ts @@ -46,8 +46,6 @@ export class EventPoller extends EventEmitter { try { if (this.lastSlot) { this.eventsFilter.start = nextSlot(this.lastSlot) - } else { - this.lastSlot = this.eventsFilter.start || nextSlot(this.lastSlot) } const events = await this.provider.getEvents(this.eventsFilter) diff --git a/test/integration/events.spec.ts b/test/integration/events.spec.ts index 8f2167ab..6a963147 100644 --- a/test/integration/events.spec.ts +++ b/test/integration/events.spec.ts @@ -67,4 +67,30 @@ describe('SC Event tests', () => { }) stopPolling() }) + + test('poll transfer event without start slot', async () => { + const amount = 1_000n + + const operation = await usdcContract.transfer( + 'AU1wN8rn4SkwYSTDF3dHFY4U28KtsqKL1NnEjDZhHnHEy6cEQm53', + amount + ) + await operation.waitSpeculativeExecution() + + let events: SCEvent[] = [] + + const filter: EventFilter = { + operationId: operation.id, + } + + const { stopPolling } = EventPoller.start(provider, filter, (data) => { + events = data + }) + + await waitForExpect(() => { + expect(events.length).toEqual(1) + expect(events[0].data).toEqual('TRANSFER SUCCESS') + }) + stopPolling() + }) })