diff --git a/packages/sdk/src/actions/waitForFillTx.ts b/packages/sdk/src/actions/waitForFillTx.ts index 200b24c..82e37bc 100644 --- a/packages/sdk/src/actions/waitForFillTx.ts +++ b/packages/sdk/src/actions/waitForFillTx.ts @@ -161,6 +161,10 @@ export function parseFillLogs( depositId: bigint | number; }>, ) { + if (logs.length === 0) { + return undefined; + } + const blockData = { depositTxHash: logs[0]!.blockHash!, depositTxBlock: logs[0]!.blockNumber!, diff --git a/packages/sdk/test/unit/actions/parseFillLogs.test.ts b/packages/sdk/test/unit/actions/parseFillLogs.test.ts new file mode 100644 index 0000000..b1edca7 --- /dev/null +++ b/packages/sdk/test/unit/actions/parseFillLogs.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, test } from "vitest"; +import { parseFillLogs } from "../../../src/actions/waitForFillTx.js"; + +describe("parseFillLogs", () => { + test("returns undefined for an empty logs array", () => { + expect(parseFillLogs([])).toBeUndefined(); + }); + + test("returns undefined when logs contain no fill events", () => { + const unrelatedLog = { + address: "0x0000000000000000000000000000000000000001", + blockHash: + "0x1111111111111111111111111111111111111111111111111111111111111111", + blockNumber: 1n, + data: "0x", + logIndex: 0, + transactionHash: + "0x2222222222222222222222222222222222222222222222222222222222222222", + transactionIndex: 0, + removed: false, + topics: [], + } as const; + + expect(parseFillLogs([unrelatedLog])).toBeUndefined(); + }); +});