Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xkenj1 committed Oct 9, 2024
1 parent e869159 commit 22d1c1a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/data-flow/src/eventsFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class EventsFetcher implements IEventsFetcher {
logIndex: number,
limit: number = 100,
): Promise<AnyProtocolEvent[]> {
return await this.indexerClient.getEventsByBlockNumberAndLogIndex(
return await this.indexerClient.getEventsAfterBlockNumberAndLogIndex(
chainId,
blockNumber,
logIndex,
Expand Down
12 changes: 6 additions & 6 deletions packages/data-flow/test/unit/eventsFetcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("EventsFetcher", () => {

beforeEach(() => {
indexerClientMock = {
getEventsByBlockNumberAndLogIndex: vi.fn(),
getEventsAfterBlockNumberAndLogIndex: vi.fn(),
};

eventsFetcher = new EventsFetcher(indexerClientMock);
Expand Down Expand Up @@ -46,15 +46,15 @@ describe("EventsFetcher", () => {
const logIndex = 0;
const limit = 100;

indexerClientMock.getEventsByBlockNumberAndLogIndex.mockResolvedValue(mockEvents);
indexerClientMock.getEventsAfterBlockNumberAndLogIndex.mockResolvedValue(mockEvents);

const result = await eventsFetcher.fetcEventsByBlockNumberAndLogIndex(
const result = await eventsFetcher.fetchEventsByBlockNumberAndLogIndex(
chainId,
blockNumber,
logIndex,
);

expect(indexerClientMock.getEventsByBlockNumberAndLogIndex).toHaveBeenCalledWith(
expect(indexerClientMock.getEventsAfterBlockNumberAndLogIndex).toHaveBeenCalledWith(
chainId,
blockNumber,
logIndex,
Expand All @@ -68,12 +68,12 @@ describe("EventsFetcher", () => {
const blockNumber = 1000;
const logIndex = 0;

indexerClientMock.getEventsByBlockNumberAndLogIndex.mockRejectedValue(
indexerClientMock.getEventsAfterBlockNumberAndLogIndex.mockRejectedValue(
new Error("Network error"),
);

await expect(
eventsFetcher.fetcEventsByBlockNumberAndLogIndex(chainId, blockNumber, logIndex),
eventsFetcher.fetchEventsByBlockNumberAndLogIndex(chainId, blockNumber, logIndex),
).rejects.toThrow("Network error");
});
});
20 changes: 12 additions & 8 deletions packages/indexer-client/test/unit/envioIndexerClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("EnvioIndexerClient", () => {
});
});

describe("getEventsByBlockNumberAndLogIndex", () => {
describe("getEventsAfterBlockNumberAndLogIndex", () => {
const mockEvents: AnyProtocolEvent[] = [
{
chain_id: 1,
Expand All @@ -65,7 +65,7 @@ describe("EnvioIndexerClient", () => {
};
graphqlClient.rawRequest.mockResolvedValue(mockedResponse);

const result = await envioIndexerClient.getEventsByBlockNumberAndLogIndex(
const result = await envioIndexerClient.getEventsAfterBlockNumberAndLogIndex(
1,
12345,
0,
Expand All @@ -84,7 +84,7 @@ describe("EnvioIndexerClient", () => {
};
graphqlClient.rawRequest.mockResolvedValue(mockedResponse);

await envioIndexerClient.getEventsByBlockNumberAndLogIndex(1, 12345, 0);
await envioIndexerClient.getEventsAfterBlockNumberAndLogIndex(1, 12345, 0);
expect(graphqlClient.rawRequest).toHaveBeenCalledWith(
expect.stringContaining("limit: 100"),
);
Expand All @@ -100,7 +100,7 @@ describe("EnvioIndexerClient", () => {
};
graphqlClient.rawRequest.mockResolvedValue(mockedResponse);

await envioIndexerClient.getEventsByBlockNumberAndLogIndex(1, 12345, 0, 50);
await envioIndexerClient.getEventsAfterBlockNumberAndLogIndex(1, 12345, 0, 50);
expect(graphqlClient.rawRequest).toHaveBeenCalledWith(
expect.stringContaining("limit: 50"),
);
Expand All @@ -117,7 +117,7 @@ describe("EnvioIndexerClient", () => {
graphqlClient.rawRequest.mockResolvedValue(mockedResponse);

await expect(
envioIndexerClient.getEventsByBlockNumberAndLogIndex(1, 12345, 0),
envioIndexerClient.getEventsAfterBlockNumberAndLogIndex(1, 12345, 0),
).rejects.toThrow(InvalidIndexerResponse);
});

Expand All @@ -126,7 +126,7 @@ describe("EnvioIndexerClient", () => {
graphqlClient.rawRequest.mockRejectedValue(error);

await expect(
envioIndexerClient.getEventsByBlockNumberAndLogIndex(1, 12345, 0),
envioIndexerClient.getEventsAfterBlockNumberAndLogIndex(1, 12345, 0),
).rejects.toThrow(IndexerClientError);
});

Expand All @@ -140,7 +140,7 @@ describe("EnvioIndexerClient", () => {
};
graphqlClient.rawRequest.mockResolvedValue(mockedResponse);

await envioIndexerClient.getEventsByBlockNumberAndLogIndex(1, 12345, 0);
await envioIndexerClient.getEventsAfterBlockNumberAndLogIndex(1, 12345, 0);
expect(graphqlClient.rawRequest).toHaveBeenCalledWith(
expect.stringContaining("chain_id: { _eq: 1 }"),
);
Expand All @@ -162,7 +162,11 @@ describe("EnvioIndexerClient", () => {
};
graphqlClient.rawRequest.mockResolvedValue(mockedResponse);

const result = await envioIndexerClient.getEventsByBlockNumberAndLogIndex(1, 12345, 0);
const result = await envioIndexerClient.getEventsAfterBlockNumberAndLogIndex(
1,
12345,
0,
);
expect(result).toEqual([]);
});
});
Expand Down

0 comments on commit 22d1c1a

Please sign in to comment.