Skip to content

Commit

Permalink
more tests fixed maybe\?
Browse files Browse the repository at this point in the history
  • Loading branch information
45930 committed Dec 12, 2024
1 parent d3a6b51 commit 5e706f7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 47 deletions.
11 changes: 0 additions & 11 deletions src/db/sql/events-actions/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/services/data-adapters/database-row-adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
);

Expand Down
2 changes: 1 addition & 1 deletion src/services/events-service/events-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[][] = [];
Expand Down
64 changes: 32 additions & 32 deletions tests/resolvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,38 +222,38 @@ describe('Query Resolvers', async () => {
let lastBlockEvents: Maybe<EventData>[];
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;
Expand Down

0 comments on commit 5e706f7

Please sign in to comment.