From 986fdc6f8fb383014fd859c60bcc460f45c2d341 Mon Sep 17 00:00:00 2001 From: Dev M Date: Wed, 9 Sep 2026 21:06:23 +0000 Subject: [PATCH] fix(sdk): return undefined from parseFillLogs on empty logs Guard against reading logs[0] when the caller passes an empty array so parseFillLogs returns undefined instead of throwing a TypeError. Fixes #268 --- packages/sdk/src/actions/waitForFillTx.ts | 4 +++ .../test/unit/actions/parseFillLogs.test.ts | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 packages/sdk/test/unit/actions/parseFillLogs.test.ts 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(); + }); +});