diff --git a/src/utils.spec.ts b/src/utils.spec.ts index ded6da8..892f2f1 100644 --- a/src/utils.spec.ts +++ b/src/utils.spec.ts @@ -1,5 +1,6 @@ import { expect, test } from "bun:test"; -import { parseBlockId, parseTimestamp } from "./utils.js"; +import { parseBlockId, parseLimit, parseTimestamp } from "./utils.js"; +import { config } from "./config.js"; test("parseBlockId", () => { expect(parseBlockId("0x123") as string).toBe("123"); @@ -11,3 +12,10 @@ test("parseTimestamp", () => { expect(parseTimestamp("awdawd")).toBeNaN(); expect(parseTimestamp(null)).toBeUndefined(); }); + +test("parseLimit", () => { + expect(parseLimit("1")).toBe(1); + expect(parseLimit("0")).toBe(1); + expect(parseLimit(10)).toBe(10); + expect(parseLimit(config.maxLimit + 1)).toBe(config.maxLimit); +}); \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index 531d675..6b33936 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,6 +13,7 @@ export function parseLimit(limit?: string | null | number, defaultLimit?: number if (typeof limit === "number") value = limit; } // limit must be between 1 and maxLimit + if (value <= 0) value = 1; if (value > config.maxLimit) value = config.maxLimit; return value; }