From 13c9021fc94633de5acf5470fd4f96ff7f1f47c1 Mon Sep 17 00:00:00 2001 From: nigiri <168690269+0xnigir1@users.noreply.github.com> Date: Tue, 3 Sep 2024 15:54:57 -0300 Subject: [PATCH] fix: don't return undefined on error --- packages/metrics/src/l2/l2Metrics.service.ts | 16 ++-------------- .../test/unit/l2/l2Metrics.service.spec.ts | 11 ----------- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/packages/metrics/src/l2/l2Metrics.service.ts b/packages/metrics/src/l2/l2Metrics.service.ts index 2f7dc7a..24dd87b 100644 --- a/packages/metrics/src/l2/l2Metrics.service.ts +++ b/packages/metrics/src/l2/l2Metrics.service.ts @@ -1,6 +1,3 @@ -import { isNativeError } from "util/types"; -import { BaseError } from "viem"; - import { ZKChainProvider } from "@zkchainhub/chain-providers"; import { ILogger } from "@zkchainhub/shared"; @@ -47,16 +44,7 @@ export class L2MetricsService { * @returns A Promise that resolves to the number of the last verified block, or undefined if an error occurs. */ async getLastVerifiedBlock(lastVerifiedBatch: number): Promise { - try { - const [, endBlock] = await this.provider.getL1BatchBlockRange(lastVerifiedBatch); - return endBlock; - } catch (error) { - if (error instanceof BaseError) { - this.logger.error(error.message); - } else if (isNativeError(error)) { - this.logger.error(error); - } - return undefined; - } + const [, endBlock] = await this.provider.getL1BatchBlockRange(lastVerifiedBatch); + return endBlock; } } diff --git a/packages/metrics/test/unit/l2/l2Metrics.service.spec.ts b/packages/metrics/test/unit/l2/l2Metrics.service.spec.ts index ed5d9bb..07a83eb 100644 --- a/packages/metrics/test/unit/l2/l2Metrics.service.spec.ts +++ b/packages/metrics/test/unit/l2/l2Metrics.service.spec.ts @@ -1,4 +1,3 @@ -import { BaseError } from "viem"; import { beforeEach, describe, expect, it, vi } from "vitest"; import { ZKChainProvider } from "@zkchainhub/chain-providers"; @@ -78,15 +77,5 @@ describe("L2MetricsService", () => { expect(result).toBe(expectedEndBlock); expect(provider.getL1BatchBlockRange).toHaveBeenCalledWith(lastVerifiedBatch); }); - it("return undefined if an error occurs", async () => { - const lastVerifiedBatch = 500; - vi.spyOn(provider, "getL1BatchBlockRange").mockRejectedValue( - new BaseError("Invalid batch number"), - ); - - const result = await service.getLastVerifiedBlock(lastVerifiedBatch); - - expect(result).toBeUndefined(); - }); }); });