Skip to content

Commit

Permalink
fix: don't return undefined on error
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 committed Sep 3, 2024
1 parent 32b37b1 commit 13c9021
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
16 changes: 2 additions & 14 deletions packages/metrics/src/l2/l2Metrics.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { isNativeError } from "util/types";
import { BaseError } from "viem";

import { ZKChainProvider } from "@zkchainhub/chain-providers";
import { ILogger } from "@zkchainhub/shared";

Expand Down Expand Up @@ -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<number | undefined> {
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;
}
}
11 changes: 0 additions & 11 deletions packages/metrics/test/unit/l2/l2Metrics.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BaseError } from "viem";
import { beforeEach, describe, expect, it, vi } from "vitest";

import { ZKChainProvider } from "@zkchainhub/chain-providers";
Expand Down Expand Up @@ -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();
});
});
});

0 comments on commit 13c9021

Please sign in to comment.