From 41a449d9cb7013dbb98ccbd5bc547cb2080abd07 Mon Sep 17 00:00:00 2001 From: nigiri <168690269+0xnigir1@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:55:20 -0300 Subject: [PATCH] test: unify createMockEvent util function --- packages/processors/test/mocks/event.mock.ts | 57 ++++++++++++++ packages/processors/test/mocks/index.ts | 1 + .../common/baseDistributed.handler.spec.ts | 43 ++++------- .../baseDistributionUpdated.handler.spec.ts | 50 +++---------- .../baseFundsDistributed.handler.spec.ts | 51 ++++--------- ...baseRecipientStatusUpdated.handler.spec.ts | 59 +++++---------- .../handlers/directAllocated.handler.spec.ts | 58 +++++---------- .../handlers/allocated.handler.spec.ts | 63 ++++++---------- .../handlers/registered.handler.spec.ts | 56 ++++---------- .../timestampsUpdated.handler.spec.ts | 41 +++------- .../updatedRegistration.handler.spec.ts | 63 ++++++---------- .../handlers/allocated.handler.spec.ts | 69 ++++++----------- .../handlers/registered.handler.spec.ts | 74 ++++++++++--------- .../timestampsUpdated.handler.spec.ts | 52 ++++--------- .../updatedRegistration.handler.spec.ts | 65 ++++++---------- 15 files changed, 300 insertions(+), 502 deletions(-) create mode 100644 packages/processors/test/mocks/event.mock.ts create mode 100644 packages/processors/test/mocks/index.ts diff --git a/packages/processors/test/mocks/event.mock.ts b/packages/processors/test/mocks/event.mock.ts new file mode 100644 index 0000000..205afa7 --- /dev/null +++ b/packages/processors/test/mocks/event.mock.ts @@ -0,0 +1,57 @@ +import { + ChainId, + ContractToEventName, + DeepPartial, + EventParams, + Hex, + mergeDeep, + ProcessorEvent, +} from "@grants-stack-indexer/shared"; + +/** + * Creates a mock event for testing. + * + * @param eventName - The name of the event. + * @param params - The parameters of the event. + * @param strategyId - The ID of the strategy. + * @param overrides - The overrides for the event. + * @returns A mock event. + * + * @default + * srcAddress: "0x1234567890123456789012345678901234567890", + * blockNumber: 118034410, + * blockTimestamp: 1000000000, + * chainId: 10 as ChainId, + * contractName: "Strategy", + * logIndex: 1, + * transactionFields: { + * hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", + * transactionIndex: 1, + * from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", + * }, + */ +export const createMockEvent = >( + eventName: T, + params: EventParams<"Strategy", T>, + strategyId: Hex, + overrides: DeepPartial> = {}, +): ProcessorEvent<"Strategy", T> => { + const defaultEvent: ProcessorEvent<"Strategy", T> = { + eventName, + params, + srcAddress: "0x1234567890123456789012345678901234567890", + blockNumber: 118034410, + blockTimestamp: 1000000000, + chainId: 10 as ChainId, + contractName: "Strategy", + logIndex: 1, + transactionFields: { + hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", + transactionIndex: 1, + from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", + }, + strategyId, + }; + + return mergeDeep(defaultEvent, overrides); +}; diff --git a/packages/processors/test/mocks/index.ts b/packages/processors/test/mocks/index.ts new file mode 100644 index 0000000..743477a --- /dev/null +++ b/packages/processors/test/mocks/index.ts @@ -0,0 +1 @@ +export * from "./event.mock.js"; diff --git a/packages/processors/test/strategy/common/baseDistributed.handler.spec.ts b/packages/processors/test/strategy/common/baseDistributed.handler.spec.ts index 53c9410..fafa9db 100644 --- a/packages/processors/test/strategy/common/baseDistributed.handler.spec.ts +++ b/packages/processors/test/strategy/common/baseDistributed.handler.spec.ts @@ -4,46 +4,29 @@ import { IRoundReadRepository, Round } from "@grants-stack-indexer/repository"; import { ChainId, ILogger, ProcessorEvent } from "@grants-stack-indexer/shared"; import { BaseDistributedHandler } from "../../../src/processors/strategy/common/baseDistributed.handler.js"; - -function createMockEvent( - overrides: Partial> = {}, -): ProcessorEvent<"Strategy", "DistributedWithRecipientAddress"> { - const defaultEvent: ProcessorEvent<"Strategy", "DistributedWithRecipientAddress"> = { - params: { - amount: "1000", - recipientAddress: "0x1234567890123456789012345678901234567890", - recipientId: "0x1234567890123456789012345678901234567890", - sender: "0x1234567890123456789012345678901234567890", - }, - eventName: "DistributedWithRecipientAddress", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 12345, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 1, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return { ...defaultEvent, ...overrides }; -} +import { createMockEvent } from "../../mocks/index.js"; describe("BaseDistributedHandler", () => { let handler: BaseDistributedHandler; let mockRoundRepository: IRoundReadRepository; let mockEvent: ProcessorEvent<"Strategy", "DistributedWithRecipientAddress">; const chainId = 10 as ChainId; + const eventName = "DistributedWithRecipientAddress"; + const defaultParams = { + amount: "1000", + recipientAddress: "0x1234567890123456789012345678901234567890", + recipientId: "0x1234567890123456789012345678901234567890", + sender: "0x1234567890123456789012345678901234567890", + } as const; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; + const logger: ILogger = { debug: vi.fn(), error: vi.fn(), info: vi.fn(), warn: vi.fn(), }; + beforeEach(() => { mockRoundRepository = { getRoundByStrategyAddress: vi.fn(), @@ -51,7 +34,7 @@ describe("BaseDistributedHandler", () => { }); it("increments round total distributed when round is found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1" } as Round; vi.spyOn(mockRoundRepository, "getRoundByStrategyAddress").mockResolvedValue(mockRound); @@ -76,7 +59,7 @@ describe("BaseDistributedHandler", () => { }); it("returns an empty array when round is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockRoundRepository, "getRoundByStrategyAddress").mockResolvedValue(undefined); diff --git a/packages/processors/test/strategy/common/baseDistributionUpdated.handler.spec.ts b/packages/processors/test/strategy/common/baseDistributionUpdated.handler.spec.ts index 7772add..c900ca7 100644 --- a/packages/processors/test/strategy/common/baseDistributionUpdated.handler.spec.ts +++ b/packages/processors/test/strategy/common/baseDistributionUpdated.handler.spec.ts @@ -3,46 +3,14 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import { IMetadataProvider } from "@grants-stack-indexer/metadata"; import { PartialRound } from "@grants-stack-indexer/repository"; -import { - Bytes32String, - ChainId, - DeepPartial, - Logger, - mergeDeep, - ProcessorEvent, -} from "@grants-stack-indexer/shared"; +import { Bytes32String, ChainId, Logger, ProcessorEvent } from "@grants-stack-indexer/shared"; import { BaseDistributionUpdatedHandler, MetadataNotFound, MetadataParsingFailed, } from "../../../src/internal.js"; - -function createMockEvent( - overrides: DeepPartial> = {}, -): ProcessorEvent<"Strategy", "DistributionUpdated"> { - const defaultEvent: ProcessorEvent<"Strategy", "DistributionUpdated"> = { - params: { - metadata: ["1", "ipfs://QmTestHash"], - merkleRoot: "0xroot" as Bytes32String, - }, - eventName: "DistributionUpdated", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 12345, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 1, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return mergeDeep(defaultEvent, overrides); -} +import { createMockEvent } from "../../mocks/index.js"; describe("BaseDistributionUpdatedHandler", () => { let handler: BaseDistributionUpdatedHandler; @@ -50,6 +18,12 @@ describe("BaseDistributionUpdatedHandler", () => { let mockLogger: Logger; let mockEvent: ProcessorEvent<"Strategy", "DistributionUpdated">; const chainId = 10 as ChainId; + const eventName = "DistributionUpdated"; + const defaultParams = { + metadata: ["1", "ipfs://QmTestHash"] as [string, string], + merkleRoot: "0xroot" as Bytes32String, + }; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; beforeEach(() => { mockMetadataProvider = { @@ -64,7 +38,7 @@ describe("BaseDistributionUpdatedHandler", () => { }); it("handles a valid distribution update event", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockDistribution = { matchingDistribution: [ { @@ -105,7 +79,7 @@ describe("BaseDistributionUpdatedHandler", () => { }); it("throws MetadataNotFound if distribution metadata is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockMetadataProvider, "getMetadata").mockResolvedValue(undefined); handler = new BaseDistributionUpdatedHandler(mockEvent, chainId, { @@ -120,7 +94,7 @@ describe("BaseDistributionUpdatedHandler", () => { }); it("throw MatchingDistributionParsingError if distribution format is invalid", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const invalidDistribution = { matchingDistribution: [ { @@ -145,7 +119,7 @@ describe("BaseDistributionUpdatedHandler", () => { }); it("handles empty matching distribution array", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const emptyDistribution = { matchingDistribution: [], }; diff --git a/packages/processors/test/strategy/common/baseFundsDistributed.handler.spec.ts b/packages/processors/test/strategy/common/baseFundsDistributed.handler.spec.ts index cc330d7..399f8c3 100644 --- a/packages/processors/test/strategy/common/baseFundsDistributed.handler.spec.ts +++ b/packages/processors/test/strategy/common/baseFundsDistributed.handler.spec.ts @@ -8,45 +8,12 @@ import { Round, RoundNotFound, } from "@grants-stack-indexer/repository"; -import { - ChainId, - DeepPartial, - Logger, - mergeDeep, - ProcessorEvent, -} from "@grants-stack-indexer/shared"; +import { ChainId, Logger, ProcessorEvent } from "@grants-stack-indexer/shared"; import "../../../src/exceptions/index.js"; import { BaseFundsDistributedHandler } from "../../../src/internal.js"; - -function createMockEvent( - overrides: DeepPartial> = {}, -): ProcessorEvent<"Strategy", "FundsDistributed"> { - const defaultEvent: ProcessorEvent<"Strategy", "FundsDistributed"> = { - params: { - recipientId: "0x1234567890123456789012345678901234567890", - amount: "1000000000000000000", - grantee: "0x1234567890123456789012345678901234567890", - token: "0x0000000000000000000000000000000000000000", - }, - eventName: "FundsDistributed", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 12345, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 1, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return mergeDeep(defaultEvent, overrides); -} +import { createMockEvent } from "../../mocks/index.js"; describe("BaseFundsDistributedHandler", () => { let handler: BaseFundsDistributedHandler; @@ -55,6 +22,14 @@ describe("BaseFundsDistributedHandler", () => { let mockLogger: Logger; let mockEvent: ProcessorEvent<"Strategy", "FundsDistributed">; const chainId = 10 as ChainId; + const eventName = "FundsDistributed"; + const defaultParams = { + recipientId: "0x1234567890123456789012345678901234567890", + amount: "1000000000000000000", + grantee: "0x1234567890123456789012345678901234567890", + token: "0x0000000000000000000000000000000000000000", + } as const; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; beforeEach(() => { mockRoundRepository = { @@ -72,7 +47,7 @@ describe("BaseFundsDistributedHandler", () => { }); it("handles a valid funds distributed event", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1" } as unknown as Round; const mockApplication = { id: "app1" } as unknown as Application; @@ -116,7 +91,7 @@ describe("BaseFundsDistributedHandler", () => { }); it("throws RoundNotFound if round is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockRoundRepository, "getRoundByStrategyAddressOrThrow").mockRejectedValue( new RoundNotFound(chainId, mockEvent.strategyId), ); @@ -131,7 +106,7 @@ describe("BaseFundsDistributedHandler", () => { }); it("throws ApplicationNotFound if application is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1" } as unknown as Round; vi.spyOn(mockRoundRepository, "getRoundByStrategyAddressOrThrow").mockResolvedValue( diff --git a/packages/processors/test/strategy/common/baseRecipientStatusUpdated.handler.spec.ts b/packages/processors/test/strategy/common/baseRecipientStatusUpdated.handler.spec.ts index 972c17b..2c65ffc 100644 --- a/packages/processors/test/strategy/common/baseRecipientStatusUpdated.handler.spec.ts +++ b/packages/processors/test/strategy/common/baseRecipientStatusUpdated.handler.spec.ts @@ -8,42 +8,10 @@ import { Round, RoundNotFound, } from "@grants-stack-indexer/repository"; -import { - ChainId, - DeepPartial, - Logger, - mergeDeep, - ProcessorEvent, -} from "@grants-stack-indexer/shared"; +import { ChainId, Logger, ProcessorEvent } from "@grants-stack-indexer/shared"; import { BaseRecipientStatusUpdatedHandler } from "../../../src/internal.js"; - -function createMockEvent( - overrides: DeepPartial> = {}, -): ProcessorEvent<"Strategy", "RecipientStatusUpdatedWithFullRow"> { - const defaultEvent: ProcessorEvent<"Strategy", "RecipientStatusUpdatedWithFullRow"> = { - params: { - rowIndex: "0", - fullRow: "801", // 001100100001 (status 1 at index 0, status 2 at index 4, status 3 at index 8) - sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - eventName: "RecipientStatusUpdatedWithFullRow", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 12345, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 1, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return mergeDeep(defaultEvent, overrides); -} +import { createMockEvent } from "../../mocks/index.js"; describe("BaseRecipientStatusUpdatedHandler", () => { let handler: BaseRecipientStatusUpdatedHandler; @@ -52,6 +20,13 @@ describe("BaseRecipientStatusUpdatedHandler", () => { let mockLogger: Logger; let mockEvent: ProcessorEvent<"Strategy", "RecipientStatusUpdatedWithFullRow">; const chainId = 10 as ChainId; + const eventName = "RecipientStatusUpdatedWithFullRow"; + const defaultParams = { + rowIndex: "0", + fullRow: "801", // 001100100001 (status 1 at index 0, status 2 at index 4, status 3 at index 8) + sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", + } as const; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; beforeEach(() => { mockRoundRepository = { @@ -69,7 +44,9 @@ describe("BaseRecipientStatusUpdatedHandler", () => { }); it("handles valid status updates for multiple applications", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { + blockNumber: 12345, + }); const mockRound = { id: "round1" } as Round; const mockApplication1 = { id: "0", @@ -175,7 +152,7 @@ describe("BaseRecipientStatusUpdatedHandler", () => { }); it("throws RoundNotFound if round is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockRoundRepository, "getRoundByStrategyAddressOrThrow").mockRejectedValue( new RoundNotFound(chainId, mockEvent.strategyId), ); @@ -190,7 +167,7 @@ describe("BaseRecipientStatusUpdatedHandler", () => { }); it("skips applications that are not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1" } as Round; vi.spyOn(mockRoundRepository, "getRoundByStrategyAddressOrThrow").mockResolvedValue( @@ -209,7 +186,7 @@ describe("BaseRecipientStatusUpdatedHandler", () => { }); it("skips invalid status values", async () => { - mockEvent = createMockEvent({ + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { params: { rowIndex: "0", fullRow: "96", // Binary: 1100000 (invalid statuses 6 and 7) @@ -232,7 +209,9 @@ describe("BaseRecipientStatusUpdatedHandler", () => { }); it("doesn't create new status snapshot if status hasn't changed", async () => { - mockEvent = createMockEvent({ params: { rowIndex: "0", fullRow: "2" } }); // Binary: 10 (status 2 at index 0) + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { + params: { rowIndex: "0", fullRow: "2" }, // Binary: 10 (status 2 at index 0) + }); const mockRound = { id: "round1" } as Round; const mockApplication = { id: "0", @@ -273,7 +252,7 @@ describe("BaseRecipientStatusUpdatedHandler", () => { }); it("handles different row indexes correctly", async () => { - mockEvent = createMockEvent({ + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { params: { rowIndex: "1", // Second row fullRow: "33", // 00100001 (status 1 at index 0, status 1 at index 4) diff --git a/packages/processors/test/strategy/directAllocation/handlers/directAllocated.handler.spec.ts b/packages/processors/test/strategy/directAllocation/handlers/directAllocated.handler.spec.ts index 24b38b2..a177e51 100644 --- a/packages/processors/test/strategy/directAllocation/handlers/directAllocated.handler.spec.ts +++ b/packages/processors/test/strategy/directAllocation/handlers/directAllocated.handler.spec.ts @@ -10,47 +10,12 @@ import { Round, RoundNotFound, } from "@grants-stack-indexer/repository"; -import { - Bytes32String, - ChainId, - DeepPartial, - ILogger, - mergeDeep, - ProcessorEvent, -} from "@grants-stack-indexer/shared"; +import { Bytes32String, ChainId, ILogger, ProcessorEvent } from "@grants-stack-indexer/shared"; import { TokenPriceNotFoundError } from "../../../../src/exceptions/index.js"; import { getDonationId } from "../../../../src/processors/strategy/helpers/index.js"; import { DirectAllocatedHandler } from "../../../../src/processors/strategy/index.js"; - -function createMockEvent( - overrides: DeepPartial> = {}, -): ProcessorEvent<"Strategy", "DirectAllocated"> { - const defaultEvent: ProcessorEvent<"Strategy", "DirectAllocated"> = { - params: { - profileId: "0x1234567890123456789012345678901234567890" as Bytes32String, - profileOwner: "0x1234567890123456789012345678901234567890", - amount: parseEther("10").toString(), - token: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", - sender: "0x1234567890123456789012345678901234567890", - }, - eventName: "DirectAllocated", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 118034410, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 92, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return mergeDeep(defaultEvent, overrides); -} +import { createMockEvent } from "../../../mocks/index.js"; describe("DirectAllocatedHandler", () => { let handler: DirectAllocatedHandler; @@ -60,6 +25,15 @@ describe("DirectAllocatedHandler", () => { let mockEvent: ProcessorEvent<"Strategy", "DirectAllocated">; let mockLogger: ILogger; const chainId = 10 as ChainId; + const eventName = "DirectAllocated"; + const defaultParams = { + profileId: "0x1234567890123456789012345678901234567890" as Bytes32String, + profileOwner: "0x1234567890123456789012345678901234567890", + amount: parseEther("10").toString(), + token: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", + sender: "0x1234567890123456789012345678901234567890", + } as const; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; beforeEach(() => { mockRoundRepository = { @@ -81,7 +55,9 @@ describe("DirectAllocatedHandler", () => { it("handles a valid direct allocation event", async () => { const amount = parseEther("10").toString(); - mockEvent = createMockEvent({ params: { amount } }); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { + params: { amount }, + }); const mockRound = { id: "round1", } as unknown as Round; @@ -136,7 +112,7 @@ describe("DirectAllocatedHandler", () => { }); it("throws RoundNotFound if round is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockRoundRepository, "getRoundByStrategyAddressOrThrow").mockRejectedValue( new RoundNotFound(chainId, mockEvent.srcAddress), ); @@ -152,7 +128,7 @@ describe("DirectAllocatedHandler", () => { }); it("throws ProjectNotFound if project is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: mockEvent.params.profileId, matchTokenAddress: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", @@ -176,7 +152,7 @@ describe("DirectAllocatedHandler", () => { }); it("throws TokenPriceNotFoundError if token price is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1", } as unknown as Round; diff --git a/packages/processors/test/strategy/directGrantsLite/handlers/allocated.handler.spec.ts b/packages/processors/test/strategy/directGrantsLite/handlers/allocated.handler.spec.ts index 1098c80..4e7afb9 100644 --- a/packages/processors/test/strategy/directGrantsLite/handlers/allocated.handler.spec.ts +++ b/packages/processors/test/strategy/directGrantsLite/handlers/allocated.handler.spec.ts @@ -10,44 +10,11 @@ import { Round, RoundNotFound, } from "@grants-stack-indexer/repository"; -import { - ChainId, - DeepPartial, - mergeDeep, - ProcessorEvent, - UnknownToken, -} from "@grants-stack-indexer/shared"; +import { ChainId, ProcessorEvent, UnknownToken } from "@grants-stack-indexer/shared"; import { TokenPriceNotFoundError } from "../../../../src/exceptions/tokenPriceNotFound.exception.js"; import { DGLiteAllocatedHandler } from "../../../../src/processors/strategy/directGrantsLite/handlers/allocated.handler.js"; - -function createMockEvent( - overrides: DeepPartial> = {}, -): ProcessorEvent<"Strategy", "AllocatedWithToken"> { - const defaultEvent: ProcessorEvent<"Strategy", "AllocatedWithToken"> = { - params: { - recipientId: "0x1234567890123456789012345678901234567890", - amount: parseEther("10").toString(), - token: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", - sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - eventName: "AllocatedWithToken", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 118034410, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 92, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return mergeDeep(defaultEvent, overrides); -} +import { createMockEvent } from "../../../mocks/index.js"; describe("DGLiteAllocatedHandler", () => { let handler: DGLiteAllocatedHandler; @@ -56,6 +23,14 @@ describe("DGLiteAllocatedHandler", () => { let mockPricingProvider: IPricingProvider; let mockEvent: ProcessorEvent<"Strategy", "AllocatedWithToken">; const chainId = 10 as ChainId; + const eventName = "AllocatedWithToken"; + const defaultParams = { + recipientId: "0x1234567890123456789012345678901234567890", + amount: parseEther("10").toString(), + token: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", + sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", + } as const; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; beforeEach(() => { mockRoundRepository = { @@ -71,7 +46,9 @@ describe("DGLiteAllocatedHandler", () => { it("handles a valid allocation event", async () => { const amount = parseEther("10").toString(); - mockEvent = createMockEvent({ params: { amount } }); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { + params: { amount }, + }); const mockRound = { id: "round1", matchTokenAddress: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", @@ -130,7 +107,7 @@ describe("DGLiteAllocatedHandler", () => { }); it("throws RoundNotFound if round is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockRoundRepository, "getRoundByStrategyAddressOrThrow").mockRejectedValue( new RoundNotFound(chainId, mockEvent.strategyId), ); @@ -145,7 +122,7 @@ describe("DGLiteAllocatedHandler", () => { }); it("throws ApplicationNotFound if application is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1", chainId, @@ -180,7 +157,7 @@ describe("DGLiteAllocatedHandler", () => { }); it("throws UnknownToken if params token is not found", async () => { - mockEvent = createMockEvent({ + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { params: { token: pad("0x1", { size: 20 }) }, }); const mockRound = { @@ -216,7 +193,7 @@ describe("DGLiteAllocatedHandler", () => { }); it("throws UnknownToken if match token is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1", matchTokenAddress: pad("0x1", { size: 20 }), @@ -250,7 +227,7 @@ describe("DGLiteAllocatedHandler", () => { }); it("throws TokenPriceNotFound if token price is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1", matchTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", @@ -286,7 +263,9 @@ describe("DGLiteAllocatedHandler", () => { it("handles different token and match token", async () => { const amount = parseEther("10").toString(); - mockEvent = createMockEvent({ params: { amount } }); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { + params: { amount }, + }); const mockRound = { id: "round1", chainId, diff --git a/packages/processors/test/strategy/directGrantsLite/handlers/registered.handler.spec.ts b/packages/processors/test/strategy/directGrantsLite/handlers/registered.handler.spec.ts index 1cffeda..3ff756f 100644 --- a/packages/processors/test/strategy/directGrantsLite/handlers/registered.handler.spec.ts +++ b/packages/processors/test/strategy/directGrantsLite/handlers/registered.handler.spec.ts @@ -11,36 +11,10 @@ import { Round, RoundNotFound, } from "@grants-stack-indexer/repository"; -import { ChainId, DeepPartial, mergeDeep, ProcessorEvent } from "@grants-stack-indexer/shared"; +import { ChainId, ProcessorEvent } from "@grants-stack-indexer/shared"; import { DGLiteRegisteredHandler } from "../../../../src/processors/strategy/directGrantsLite/handlers/registered.handler.js"; - -function createMockEvent( - overrides: DeepPartial> = {}, -): ProcessorEvent<"Strategy", "RegisteredWithSender"> { - const defaultEvent: ProcessorEvent<"Strategy", "RegisteredWithSender"> = { - params: { - recipientId: "0x1234567890123456789012345678901234567890", - data: "0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000100000000000000000000000000accc041f3d1f576198ac88ede32e58c3476710a700000000000000000000000058338e95caef17861916ef10dad5fafe20421005000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003b6261666b72656966736e77736a6c6b74746632626d6f646a6c646e76766c366677707271766a6976786b67367a6e74376a656c62786a75717a33650000000000", - sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - eventName: "RegisteredWithSender", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 12345, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 1, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return mergeDeep(defaultEvent, overrides); -} +import { createMockEvent } from "../../../mocks/index.js"; describe("DGLiteRegisteredHandler", () => { let handler: DGLiteRegisteredHandler; @@ -49,6 +23,13 @@ describe("DGLiteRegisteredHandler", () => { let mockMetadataProvider: IMetadataProvider; let mockEvent: ProcessorEvent<"Strategy", "RegisteredWithSender">; const chainId = 10 as ChainId; + const eventName = "RegisteredWithSender"; + const defaultParams = { + recipientId: "0x1234567890123456789012345678901234567890", + data: "0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000100000000000000000000000000accc041f3d1f576198ac88ede32e58c3476710a700000000000000000000000058338e95caef17861916ef10dad5fafe20421005000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003b6261666b72656966736e77736a6c6b74746632626d6f646a6c646e76766c366677707271766a6976786b67367a6e74376a656c62786a75717a33650000000000", + sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", + } as const; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; beforeEach(() => { mockRoundRepository = { @@ -63,7 +44,7 @@ describe("DGLiteRegisteredHandler", () => { }); it("handles a valid registration event", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId, @@ -88,17 +69,6 @@ describe("DGLiteRegisteredHandler", () => { const result = await handler.handle(); - // parsed data: - // { - // anchorAddress: '0xAcCC041f3D1F576198AC88eDE32E58C3476710A7', - // recipientAddress: '0x58338E95caEf17861916Ef10daD5fAFE20421005', - // metadata: { - // protocol: 1, - // pointer: 'bafkreifsnwsjlkttf2bmodjldnvvl6fwprqvjivxkg6znt7jelbxjuqz3e' - // }, - // recipientsCounter: '2' - // } - expect(result).toEqual([ { type: "InsertApplication", @@ -136,7 +106,7 @@ describe("DGLiteRegisteredHandler", () => { }); it("handles null metadata", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId, @@ -168,7 +138,7 @@ describe("DGLiteRegisteredHandler", () => { }); it("throws ProjectNotFound if project is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockProjectRepository, "getProjectByAnchorOrThrow").mockRejectedValue( new ProjectNotFound(chainId, mockEvent.params.recipientId), ); @@ -183,7 +153,7 @@ describe("DGLiteRegisteredHandler", () => { }); it("throws RoundNotFound if round is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId, diff --git a/packages/processors/test/strategy/directGrantsLite/handlers/timestampsUpdated.handler.spec.ts b/packages/processors/test/strategy/directGrantsLite/handlers/timestampsUpdated.handler.spec.ts index 02ba4a6..1032620 100644 --- a/packages/processors/test/strategy/directGrantsLite/handlers/timestampsUpdated.handler.spec.ts +++ b/packages/processors/test/strategy/directGrantsLite/handlers/timestampsUpdated.handler.spec.ts @@ -1,42 +1,23 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import { IRoundRepository, Round, RoundNotFound } from "@grants-stack-indexer/repository"; -import { ChainId, DeepPartial, mergeDeep, ProcessorEvent } from "@grants-stack-indexer/shared"; +import { ChainId, ProcessorEvent } from "@grants-stack-indexer/shared"; import { DGLiteTimestampsUpdatedHandler } from "../../../../src/processors/strategy/directGrantsLite/handlers/timestampsUpdated.handler.js"; - -function createMockEvent( - overrides: DeepPartial> = {}, -): ProcessorEvent<"Strategy", "TimestampsUpdated"> { - const defaultEvent: ProcessorEvent<"Strategy", "TimestampsUpdated"> = { - params: { - startTime: "1704067200", // 2024-01-01 00:00:00 - endTime: "1704153600", // 2024-01-02 00:00:00 - sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - eventName: "TimestampsUpdated", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 12345, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 1, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return mergeDeep(defaultEvent, overrides); -} +import { createMockEvent } from "../../../mocks/index.js"; describe("DGLiteTimestampsUpdatedHandler", () => { let handler: DGLiteTimestampsUpdatedHandler; let mockRoundRepository: IRoundRepository; let mockEvent: ProcessorEvent<"Strategy", "TimestampsUpdated">; const chainId = 10 as ChainId; + const eventName = "TimestampsUpdated"; + const defaultParams = { + startTime: "1704067200", // 2024-01-01 00:00:00 + endTime: "1704153600", // 2024-01-02 00:00:00 + sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", + } as const; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; beforeEach(() => { mockRoundRepository = { @@ -45,7 +26,7 @@ describe("DGLiteTimestampsUpdatedHandler", () => { }); it("handles a valid timestamps update event", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1" } as unknown as Round; vi.spyOn(mockRoundRepository, "getRoundByStrategyAddressOrThrow").mockResolvedValue( @@ -84,7 +65,7 @@ describe("DGLiteTimestampsUpdatedHandler", () => { }); it("throws RoundNotFound if round is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockRoundRepository, "getRoundByStrategyAddressOrThrow").mockRejectedValue( new RoundNotFound(chainId, mockEvent.strategyId), ); diff --git a/packages/processors/test/strategy/directGrantsLite/handlers/updatedRegistration.handler.spec.ts b/packages/processors/test/strategy/directGrantsLite/handlers/updatedRegistration.handler.spec.ts index 055897b..09fc0a7 100644 --- a/packages/processors/test/strategy/directGrantsLite/handlers/updatedRegistration.handler.spec.ts +++ b/packages/processors/test/strategy/directGrantsLite/handlers/updatedRegistration.handler.spec.ts @@ -13,43 +13,10 @@ import { Round, RoundNotFound, } from "@grants-stack-indexer/repository"; -import { - ChainId, - DeepPartial, - Logger, - mergeDeep, - ProcessorEvent, -} from "@grants-stack-indexer/shared"; +import { ChainId, Logger, ProcessorEvent } from "@grants-stack-indexer/shared"; import { DGLiteUpdatedRegistrationHandler } from "../../../../src/processors/strategy/directGrantsLite/handlers/updatedRegistration.handler.js"; - -function createMockEvent( - overrides: DeepPartial> = {}, -): ProcessorEvent<"Strategy", "UpdatedRegistrationWithStatus"> { - const defaultEvent: ProcessorEvent<"Strategy", "UpdatedRegistrationWithStatus"> = { - params: { - recipientId: "0x1234567890123456789012345678901234567890", - status: "2", - data: "0x0000000000000000000000002c7296a5ec0539f0a018c7176c97c92a9c44e2b4000000000000000000000000e7eb5d2b5b188777df902e89c54570e7ef4f59ce000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003b6261666b72656967796334336366696e786c6e6168713561617773676869626574763675737273376b6b78663776786d7a626a79726f37366977790000000000", - sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - eventName: "UpdatedRegistrationWithStatus", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 12345, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 1, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return mergeDeep(defaultEvent, overrides); -} +import { createMockEvent } from "../../../mocks/index.js"; describe("DGLiteUpdatedRegistrationHandler", () => { let handler: DGLiteUpdatedRegistrationHandler; @@ -60,6 +27,14 @@ describe("DGLiteUpdatedRegistrationHandler", () => { let mockLogger: Logger; let mockEvent: ProcessorEvent<"Strategy", "UpdatedRegistrationWithStatus">; const chainId = 10 as ChainId; + const eventName = "UpdatedRegistrationWithStatus"; + const defaultParams = { + recipientId: "0x1234567890123456789012345678901234567890", + status: "2", + data: "0x0000000000000000000000002c7296a5ec0539f0a018c7176c97c92a9c44e2b4000000000000000000000000e7eb5d2b5b188777df902e89c54570e7ef4f59ce000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003b6261666b72656967796334336366696e786c6e6168713561617773676869626574763675737273376b6b78663776786d7a626a79726f37366977790000000000", + sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", + } as const; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; beforeEach(() => { mockRoundRepository = { @@ -83,7 +58,7 @@ describe("DGLiteUpdatedRegistrationHandler", () => { }); it("handles a valid registration update event", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId, @@ -142,7 +117,9 @@ describe("DGLiteUpdatedRegistrationHandler", () => { }); it("returns empty array for invalid status", async () => { - mockEvent = createMockEvent({ params: { status: "4" } }); // Invalid status + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { + params: { status: "4" }, + }); // Invalid status handler = new DGLiteUpdatedRegistrationHandler(mockEvent, chainId, { roundRepository: mockRoundRepository, @@ -162,7 +139,7 @@ describe("DGLiteUpdatedRegistrationHandler", () => { }); it("throws ProjectNotFound if project is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockProjectRepository, "getProjectByAnchorOrThrow").mockRejectedValue( new ProjectNotFound(chainId, mockEvent.params.recipientId), ); @@ -179,7 +156,7 @@ describe("DGLiteUpdatedRegistrationHandler", () => { }); it("throws RoundNotFound if round is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId, @@ -201,7 +178,7 @@ describe("DGLiteUpdatedRegistrationHandler", () => { await expect(handler.handle()).rejects.toThrow(RoundNotFound); }); it("throws ApplicationNotFound if application is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId, @@ -231,7 +208,7 @@ describe("DGLiteUpdatedRegistrationHandler", () => { }); it("handles undefined metadata", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId, @@ -274,7 +251,9 @@ describe("DGLiteUpdatedRegistrationHandler", () => { }); it("doesn't add status snapshot if status hasn't changed", async () => { - mockEvent = createMockEvent({ params: { status: "1" } }); // 1 is PENDING + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { + params: { status: "1" }, + }); // 1 is PENDING const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId, diff --git a/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/allocated.handler.spec.ts b/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/allocated.handler.spec.ts index b018b5f..f7b0017 100644 --- a/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/allocated.handler.spec.ts +++ b/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/allocated.handler.spec.ts @@ -10,48 +10,14 @@ import { Round, RoundNotFound, } from "@grants-stack-indexer/repository"; -import { - ChainId, - DeepPartial, - mergeDeep, - ProcessorEvent, - UnknownToken, -} from "@grants-stack-indexer/shared"; +import { ChainId, ProcessorEvent, UnknownToken } from "@grants-stack-indexer/shared"; import { MetadataParsingFailed, TokenPriceNotFoundError, } from "../../../../src/exceptions/index.js"; import { DVMDAllocatedHandler } from "../../../../src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/allocated.handler.js"; - -function createMockEvent( - overrides: DeepPartial> = {}, -): ProcessorEvent<"Strategy", "AllocatedWithOrigin"> { - const defaultEvent: ProcessorEvent<"Strategy", "AllocatedWithOrigin"> = { - params: { - recipientId: "0x1234567890123456789012345678901234567890", - amount: "10", - token: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", - origin: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - eventName: "AllocatedWithOrigin", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 118034410, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 92, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return mergeDeep(defaultEvent, overrides); -} +import { createMockEvent } from "../../../mocks/index.js"; describe("DVMDAllocatedHandler", () => { let handler: DVMDAllocatedHandler; @@ -60,7 +26,16 @@ describe("DVMDAllocatedHandler", () => { let mockPricingProvider: IPricingProvider; let mockEvent: ProcessorEvent<"Strategy", "AllocatedWithOrigin">; const chainId = 10 as ChainId; - const expectedDonationId = "0x60077b059a7ca75483cf0651e209a0d5c14ad2afb1fd363c728f13680d24c546"; + const eventName = "AllocatedWithOrigin"; + const defaultParams = { + recipientId: "0x1234567890123456789012345678901234567890", + amount: "10", + token: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", + origin: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", + sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", + } as const; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; + const expectedDonationId = "0x86ec85686b02d646ee8a45f0770e85db890679ef7e5f962a51be056f32d54e15"; beforeEach(() => { mockRoundRepository = { @@ -76,7 +51,9 @@ describe("DVMDAllocatedHandler", () => { it("handle a valid allocated event", async () => { const amount = parseEther("10").toString(); - mockEvent = createMockEvent({ params: { amount } }); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { + params: { amount }, + }); const mockRound = { id: "round1", matchTokenAddress: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", @@ -139,7 +116,9 @@ describe("DVMDAllocatedHandler", () => { it("match token is different from event token", async () => { const amount = parseEther("1500").toString(); - mockEvent = createMockEvent({ params: { amount } }); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { + params: { amount }, + }); const mockRound = { id: "round1", matchTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", @@ -198,7 +177,7 @@ describe("DVMDAllocatedHandler", () => { }); it("throws RoundNotFound if round is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockRoundRepository, "getRoundByStrategyAddressOrThrow").mockRejectedValue( new RoundNotFound(chainId, mockEvent.strategyId), ); @@ -213,7 +192,7 @@ describe("DVMDAllocatedHandler", () => { }); it("throws ApplicationNotFound if application is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1", matchTokenAddress: "0x0987654321098765432109876543210987654321", @@ -239,7 +218,7 @@ describe("DVMDAllocatedHandler", () => { }); it("throws UnknownToken if params token is not found", async () => { - mockEvent = createMockEvent({ + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { params: { token: pad("0x1", { size: 20 }) }, }); const mockRound = { @@ -275,7 +254,7 @@ describe("DVMDAllocatedHandler", () => { }); it("throws UnknownToken if match token is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1", matchTokenAddress: pad("0x1", { size: 20 }), @@ -309,7 +288,7 @@ describe("DVMDAllocatedHandler", () => { }); it("throws TokenPriceNotFound if token price is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1", matchTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", @@ -344,7 +323,7 @@ describe("DVMDAllocatedHandler", () => { }); it("throws MetadataParsingFailed if metadata is invalid", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockRound = { id: "round1", diff --git a/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.spec.ts b/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.spec.ts index 2c9a531..608e87c 100644 --- a/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.spec.ts +++ b/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.spec.ts @@ -10,36 +10,37 @@ import { Round, RoundNotFound, } from "@grants-stack-indexer/repository"; -import { ChainId, DeepPartial, mergeDeep, ProcessorEvent } from "@grants-stack-indexer/shared"; +import { ChainId, ProcessorEvent } from "@grants-stack-indexer/shared"; import { DVMDRegisteredHandler } from "../../../../src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/index.js"; - -function createMockEvent( - overrides: DeepPartial> = {}, -): ProcessorEvent<"Strategy", "RegisteredWithSender"> { - const defaultEvent: ProcessorEvent<"Strategy", "RegisteredWithSender"> = { - params: { - recipientId: "0x1234567890123456789012345678901234567890", - sender: "0x0987654321098765432109876543210987654321", - data: "0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001000000000000000000000000002c7296a5ec0539f0a018c7176c97c92a9c44e2b4000000000000000000000000e7eb5d2b5b188777df902e89c54570e7ef4f59ce000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003b6261666b72656967796334336366696e786c6e6168713561617773676869626574763675737273376b6b78663776786d7a626a79726f37366977790000000000", - }, - eventName: "RegisteredWithSender", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 12345, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 1, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return mergeDeep(defaultEvent, overrides) as ProcessorEvent<"Strategy", "RegisteredWithSender">; -} +import { createMockEvent } from "../../../mocks/index.js"; + +// function createMockEvent( +// overrides: DeepPartial> = {}, +// ): ProcessorEvent<"Strategy", "RegisteredWithSender"> { +// const defaultEvent: ProcessorEvent<"Strategy", "RegisteredWithSender"> = { +// params: { +// recipientId: "0x1234567890123456789012345678901234567890", +// sender: "0x0987654321098765432109876543210987654321", +// data: "0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001000000000000000000000000002c7296a5ec0539f0a018c7176c97c92a9c44e2b4000000000000000000000000e7eb5d2b5b188777df902e89c54570e7ef4f59ce000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003b6261666b72656967796334336366696e786c6e6168713561617773676869626574763675737273376b6b78663776786d7a626a79726f37366977790000000000", +// }, +// eventName: "RegisteredWithSender", +// srcAddress: "0x1234567890123456789012345678901234567890", +// blockNumber: 12345, +// blockTimestamp: 1000000000, +// chainId: 10 as ChainId, +// contractName: "Strategy", +// logIndex: 1, +// transactionFields: { +// hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", +// transactionIndex: 6, +// from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", +// }, +// strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", +// }; + +// return mergeDeep(defaultEvent, overrides) as ProcessorEvent<"Strategy", "RegisteredWithSender">; +// } describe("DVMDRegisteredHandler", () => { let handler: DVMDRegisteredHandler; @@ -48,6 +49,13 @@ describe("DVMDRegisteredHandler", () => { let mockMetadataProvider: IMetadataProvider; let mockEvent: ProcessorEvent<"Strategy", "RegisteredWithSender">; const chainId = 10 as ChainId; + const eventName = "RegisteredWithSender"; + const defaultParams = { + recipientId: "0x1234567890123456789012345678901234567890", + sender: "0x0987654321098765432109876543210987654321", + data: "0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001000000000000000000000000002c7296a5ec0539f0a018c7176c97c92a9c44e2b4000000000000000000000000e7eb5d2b5b188777df902e89c54570e7ef4f59ce000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003b6261666b72656967796334336366696e786c6e6168713561617773676869626574763675737273376b6b78663776786d7a626a79726f37366977790000000000", + } as const; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; beforeEach(() => { mockRoundRepository = { @@ -62,7 +70,7 @@ describe("DVMDRegisteredHandler", () => { }); it("handle a valid registration event", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1" } as Project; const mockRound = { id: "round1" } as Round; const mockMetadata = { name: "Test Project" }; @@ -114,7 +122,7 @@ describe("DVMDRegisteredHandler", () => { }); it("throw ProjectNotFound if project is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockProjectRepository, "getProjectByAnchorOrThrow").mockRejectedValue( new ProjectNotFound(chainId, mockEvent.srcAddress), ); @@ -128,7 +136,7 @@ describe("DVMDRegisteredHandler", () => { }); it("throw RoundNotFound if round is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1" } as Project; vi.spyOn(mockProjectRepository, "getProjectByAnchorOrThrow").mockResolvedValue(mockProject); vi.spyOn(mockRoundRepository, "getRoundByStrategyAddressOrThrow").mockRejectedValue( @@ -144,7 +152,7 @@ describe("DVMDRegisteredHandler", () => { }); it("handle registration with null metadata", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1" } as Project; const mockRound = { id: "round1" } as Round; @@ -168,7 +176,7 @@ describe("DVMDRegisteredHandler", () => { it("correctly calculate application ID based on recipientsCounter", async () => { // recipientsCounter = 5 - const mockEvent = createMockEvent({ + const mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { params: { data: "0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000001000000000000000000000000002c7296a5ec0539f0a018c7176c97c92a9c44e2b4000000000000000000000000e7eb5d2b5b188777df902e89c54570e7ef4f59ce000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003b6261666b72656967796334336366696e786c6e6168713561617773676869626574763675737273376b6b78663776786d7a626a79726f37366977790000000000", }, diff --git a/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/timestampsUpdated.handler.spec.ts b/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/timestampsUpdated.handler.spec.ts index d928878..5294868 100644 --- a/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/timestampsUpdated.handler.spec.ts +++ b/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/timestampsUpdated.handler.spec.ts @@ -6,49 +6,25 @@ import { Round, RoundNotFound, } from "@grants-stack-indexer/repository"; -import { ChainId, DeepPartial, mergeDeep, ProcessorEvent } from "@grants-stack-indexer/shared"; +import { ChainId, ProcessorEvent } from "@grants-stack-indexer/shared"; import { DVMDTimestampsUpdatedHandler } from "../../../../src/internal.js"; - -function createMockEvent( - overrides: DeepPartial< - ProcessorEvent<"Strategy", "TimestampsUpdatedWithRegistrationAndAllocation"> - > = {}, -): ProcessorEvent<"Strategy", "TimestampsUpdatedWithRegistrationAndAllocation"> { - const defaultEvent: ProcessorEvent< - "Strategy", - "TimestampsUpdatedWithRegistrationAndAllocation" - > = { - params: { - registrationStartTime: "1000000000", - registrationEndTime: "1000086400", // +1 day - allocationStartTime: "1000172800", // +2 days - allocationEndTime: "1000259200", // +3 days - sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - eventName: "TimestampsUpdatedWithRegistrationAndAllocation", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 12345, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 1, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return mergeDeep(defaultEvent, overrides); -} +import { createMockEvent } from "../../../mocks/index.js"; describe("DVMDTimestampsUpdatedHandler", () => { let handler: DVMDTimestampsUpdatedHandler; let mockRoundRepository: IRoundReadRepository; let mockEvent: ProcessorEvent<"Strategy", "TimestampsUpdatedWithRegistrationAndAllocation">; const chainId = 10 as ChainId; + const eventName = "TimestampsUpdatedWithRegistrationAndAllocation"; + const defaultParams = { + registrationStartTime: "1000000000", + registrationEndTime: "1000086400", // +1 day + allocationStartTime: "1000172800", // +2 days + allocationEndTime: "1000259200", // +3 days + sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", + } as const; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; beforeEach(() => { mockRoundRepository = { @@ -64,7 +40,7 @@ describe("DVMDTimestampsUpdatedHandler", () => { allocationEndTime: "1704326400", // 2024-01-04 00:00:00 }; - mockEvent = createMockEvent({ + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { params: timestamps, }); const mockRound = { id: "round1" } as Round; @@ -99,7 +75,7 @@ describe("DVMDTimestampsUpdatedHandler", () => { }); it("throws RoundNotFound if round is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockRoundRepository, "getRoundByStrategyAddressOrThrow").mockRejectedValue( new RoundNotFound(chainId, mockEvent.strategyId), ); @@ -119,7 +95,7 @@ describe("DVMDTimestampsUpdatedHandler", () => { allocationEndTime: "1704326400", // 2024-01-04 00:00:00 }; - mockEvent = createMockEvent({ + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { params: timestamps, }); const mockRound = { id: "round1" } as Round; diff --git a/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/updatedRegistration.handler.spec.ts b/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/updatedRegistration.handler.spec.ts index 55be75a..068c7e8 100644 --- a/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/updatedRegistration.handler.spec.ts +++ b/packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/updatedRegistration.handler.spec.ts @@ -13,43 +13,10 @@ import { Round, RoundNotFound, } from "@grants-stack-indexer/repository"; -import { - ChainId, - DeepPartial, - Logger, - mergeDeep, - ProcessorEvent, -} from "@grants-stack-indexer/shared"; +import { ChainId, Logger, ProcessorEvent } from "@grants-stack-indexer/shared"; import { DVMDUpdatedRegistrationHandler } from "../../../../src/internal.js"; - -function createMockEvent( - overrides: DeepPartial> = {}, -): ProcessorEvent<"Strategy", "UpdatedRegistrationWithStatus"> { - const defaultEvent: ProcessorEvent<"Strategy", "UpdatedRegistrationWithStatus"> = { - params: { - recipientId: "0x1234567890123456789012345678901234567890", - status: "1", - data: "0x0000000000000000000000002c7296a5ec0539f0a018c7176c97c92a9c44e2b4000000000000000000000000e7eb5d2b5b188777df902e89c54570e7ef4f59ce000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003b6261666b72656967796334336366696e786c6e6168713561617773676869626574763675737273376b6b78663776786d7a626a79726f37366977790000000000", - sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - eventName: "UpdatedRegistrationWithStatus", - srcAddress: "0x1234567890123456789012345678901234567890", - blockNumber: 12345, - blockTimestamp: 1000000000, - chainId: 10 as ChainId, - contractName: "Strategy", - logIndex: 1, - transactionFields: { - hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", - transactionIndex: 6, - from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", - }, - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", - }; - - return mergeDeep(defaultEvent, overrides); -} +import { createMockEvent } from "../../../mocks/index.js"; describe("DVMDUpdatedRegistrationHandler", () => { let handler: DVMDUpdatedRegistrationHandler; @@ -60,6 +27,14 @@ describe("DVMDUpdatedRegistrationHandler", () => { let mockLogger: Logger; let mockEvent: ProcessorEvent<"Strategy", "UpdatedRegistrationWithStatus">; const chainId = 10 as ChainId; + const eventName = "UpdatedRegistrationWithStatus"; + const defaultParams = { + recipientId: "0x1234567890123456789012345678901234567890", + status: "1", + data: "0x0000000000000000000000002c7296a5ec0539f0a018c7176c97c92a9c44e2b4000000000000000000000000e7eb5d2b5b188777df902e89c54570e7ef4f59ce000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003b6261666b72656967796334336366696e786c6e6168713561617773676869626574763675737273376b6b78663776786d7a626a79726f37366977790000000000", + sender: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", + } as const; + const defaultStrategyId = "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0"; beforeEach(() => { mockRoundRepository = { @@ -83,7 +58,9 @@ describe("DVMDUpdatedRegistrationHandler", () => { }); it("handles a valid registration update event", async () => { - mockEvent = createMockEvent({ params: { status: "2" } }); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { + params: { status: "2" }, + }); const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId, @@ -146,7 +123,9 @@ describe("DVMDUpdatedRegistrationHandler", () => { it("returns empty array if status is invalid", async () => { const invalidStatuses = ["0", "4", "10"]; for (const status of invalidStatuses) { - mockEvent = createMockEvent({ params: { status } }); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { + params: { status }, + }); handler = new DVMDUpdatedRegistrationHandler(mockEvent, chainId, { roundRepository: mockRoundRepository, @@ -166,7 +145,7 @@ describe("DVMDUpdatedRegistrationHandler", () => { }); it("throws ProjectNotFound if project is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); vi.spyOn(mockProjectRepository, "getProjectByAnchorOrThrow").mockRejectedValue( new ProjectNotFound(chainId, mockEvent.params.recipientId), ); @@ -183,7 +162,7 @@ describe("DVMDUpdatedRegistrationHandler", () => { }); it("throws RoundNotFound if round is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId, @@ -206,7 +185,7 @@ describe("DVMDUpdatedRegistrationHandler", () => { }); it("throws ApplicationNotFound if application is not found", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId, @@ -236,7 +215,7 @@ describe("DVMDUpdatedRegistrationHandler", () => { }); it("handles undefined metadata", async () => { - mockEvent = createMockEvent(); + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId); const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId, @@ -279,7 +258,9 @@ describe("DVMDUpdatedRegistrationHandler", () => { }); it("doesn't add status snapshot if status hasn't changed", async () => { - mockEvent = createMockEvent({ params: { status: "1" } }); // 1 is PENDING + mockEvent = createMockEvent(eventName, defaultParams, defaultStrategyId, { + params: { status: "1" }, + }); // 1 is PENDING const mockProject = { id: "project1", anchorAddress: mockEvent.params.recipientId,