Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: implemented base for new indexer event handling approach #590

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
fix: linting errors
hussedev committed Jul 15, 2024
commit f24fbbfe6bf44c8247d064db592c6c903df8b6f9
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -557,7 +557,7 @@ async function catchupAndWatchChain(
const changesets = await handler(args);
if (["Voted", "Allocated"].includes(eventName)) {
try {
db.applyChanges(changesets);
await db.applyChanges(changesets);
} catch (err: unknown) {
if (args.event.name === "Voted") {
indexerLogger.warn({
37 changes: 2 additions & 35 deletions src/indexer/contracts/__tests__/eventHandlers.test.ts
Original file line number Diff line number Diff line change
@@ -226,54 +226,21 @@ describe("handleEvent", () => {
});
});

test("MetadataUpdated event, NOT MIGRATED -> getEventHandler should return undefined", async () => {
test("MetadataUpdated event, NOT MIGRATED -> getEventHandler should return undefined", () => {
const contractName = "AlloV1/ProjectRegistry/V2";
const eventName = "MetadataUpdated";

const args = {
...DEFAULT_ARGS,
event: {
...DEFAULT_ARGS.event,
contractName,
name: eventName,
params: {
projectID: 1n,
metaPtr: {
pointer: "project-cid",
protocol: 0n,
},
},
},
};

const handler = getEventHandler(contractName, eventName);

expect(handler).toBeUndefined();
});
});

describe("Unknown contract name", () => {
test("getEventHandler should return undefined", async () => {
test("getEventHandler should return undefined", () => {
const contractName = "Unknown";
const eventName = "ProjectCreated";

const args = {
...DEFAULT_ARGS,
event: {
...DEFAULT_ARGS.event,
contractName,
name: eventName,
params: {
projectID: 1n,
owner: addressTwo,
},
},
context: {
...DEFAULT_ARGS.context,
rpcClient: MOCK_RPC_CLIENT(),
},
};

const handler = getEventHandler(contractName, eventName);

expect(handler).toBeUndefined();