diff --git a/src/db/sql/events-actions/queries.ts b/src/db/sql/events-actions/queries.ts index d17ff0e..0de23c4 100644 --- a/src/db/sql/events-actions/queries.ts +++ b/src/db/sql/events-actions/queries.ts @@ -348,17 +348,6 @@ export function getEventsQuery( `; } -async function logQuery(strings: TemplateStringsArray, ...values: any[]) { - const resolvedValues = await Promise.all(values); - - let query = ''; - strings.forEach((string, i) => { - query += string + (values[i] !== undefined ? values[i] : ''); - }); - console.log('Interpolated Query:', query); - return query; -} - export function getActionsQuery( db_client: postgres.Sql, address: string, diff --git a/src/services/data-adapters/database-row-adapters.ts b/src/services/data-adapters/database-row-adapters.ts index 17ee353..0516cd7 100644 --- a/src/services/data-adapters/database-row-adapters.ts +++ b/src/services/data-adapters/database-row-adapters.ts @@ -123,8 +123,8 @@ function removeRedundantEmittedFields( for (let i = 0; i < archiveNodeRow.length; i++) { const currentRow = archiveNodeRow[i]; const { - event_field_elements_id, // The unique id for the event/action emitted - event_field_element_ids, // The list of field ids that make up the event/action + event_field_elements_id, // The unique id for the field array in the current row + event_element_ids, // The list of element ids in the event (list of event_field_elements_id) zkapp_account_update_id, // The unique id for the account update that emitted the event/action zkapp_account_updates_ids, // List of all account update ids inside the transaction } = currentRow; @@ -140,7 +140,7 @@ function removeRedundantEmittedFields( // Since multiple events/actions can be emitted in a single account update, we want to put back the event/action // in the correct place. To do this, we need to know the index of the event array id in the list of event array ids (these stored in order by the Archive Node) const emittedEventOrActionIndexes = findAllIndexes( - event_field_element_ids, + event_element_ids, event_field_elements_id ); diff --git a/src/services/events-service/events-service.ts b/src/services/events-service/events-service.ts index 940ff6e..eeff1b4 100644 --- a/src/services/events-service/events-service.ts +++ b/src/services/events-service/events-service.ts @@ -88,7 +88,7 @@ class EventsService implements IEventsService { const blockMapEntries = Array.from(blocksWithTransactions.entries()); for (let i = 0; i < blockMapEntries.length; i++) { const transactions = blockMapEntries[i][1]; - const transaction = transactions.values().next().value[0]; + const transaction = transactions.values().next().value![0]; const blockInfo = createBlockInfo(transaction); const eventsData: Event[][] = []; diff --git a/tests/resolvers.test.ts b/tests/resolvers.test.ts index 4372104..90bafa5 100644 --- a/tests/resolvers.test.ts +++ b/tests/resolvers.test.ts @@ -222,38 +222,38 @@ describe('Query Resolvers', async () => { let lastBlockEvents: Maybe[]; let results: EventQueryResult; - // test('Fetching events with a valid address but no emitted events should not throw', async () => { - // assert.doesNotThrow(async () => { - // await executeEventsQuery({ - // address: zkAppKeypair.publicKey.toBase58(), - // }); - // }); - // }); - - // test('Fetching events with a empty address should return empty list', async () => { - // results = await executeEventsQuery({ - // address: '', - // }); - // assert.strictEqual(results.data.events.length, 0); - // }); - - // describe('After emitting an event with a single field once', async () => { - // before(async () => { - // await emitSingleEvent(zkApp, senderKeypair); - // results = await executeEventsQuery({ - // address: zkApp.address.toBase58(), - // }); - // eventsResponse = results.data.events; - // lastBlockEvents = eventsResponse[eventsResponse.length - 1].eventData!; - // }); - // test('GQL response contains one event in the latest block', async () => { - // assert.strictEqual(lastBlockEvents.length, 1); - // }); - // test('The event has the correct data', async () => { - // const eventData = lastBlockEvents[0]!; - // assert.deepStrictEqual(eventData.data, ['0', '2']); // event type enum = 0 and event data = 2 - // }); - // }); + test('Fetching events with a valid address but no emitted events should not throw', async () => { + assert.doesNotThrow(async () => { + await executeEventsQuery({ + address: zkAppKeypair.publicKey.toBase58(), + }); + }); + }); + + test('Fetching events with a empty address should return empty list', async () => { + results = await executeEventsQuery({ + address: '', + }); + assert.strictEqual(results.data.events.length, 0); + }); + + describe('After emitting an event with a single field once', async () => { + before(async () => { + await emitSingleEvent(zkApp, senderKeypair); + results = await executeEventsQuery({ + address: zkApp.address.toBase58(), + }); + eventsResponse = results.data.events; + lastBlockEvents = eventsResponse[eventsResponse.length - 1].eventData!; + }); + test('GQL response contains one event in the latest block', async () => { + assert.strictEqual(lastBlockEvents.length, 1); + }); + test('The event has the correct data', async () => { + const eventData = lastBlockEvents[0]!; + assert.deepStrictEqual(eventData.data, ['0', '2']); // event type enum = 0 and event data = 2 + }); + }); describe('After emitting an event with a single field multiple times', async () => { let results: EventQueryResult;