Skip to content

Commit

Permalink
test: mock RPC URL module in Safe sig verifier tests
Browse files Browse the repository at this point in the history
Without this patch the Safe signature verification code will get RPC
URLs for the specified chain id. This in turn will load the Alchemy API
key, which is not relevant for our tests.

This patch mocks all of this away, so that the API key doesn't need to
be present in the environment while running tests.

Also lowered the coverage threshold of functiosn to 52 as mocking
getRpcUrl() doesn't touch the internals of this function. This should be
thoroughly tested in a dedicated test file anyway.
  • Loading branch information
pheuberger committed Jan 23, 2025
1 parent ccc0a57 commit cfeb432
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion test/safe-signatures/SafeSignatureVerifier.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { describe, it, expect } from "vitest";
import { describe, it, expect, vi } from "vitest";
import Verifier from "../../src/lib/safe-signature-verification/UserUpsertSignatureVerifier.js";

// Mock the entire getRpcUrl module
vi.mock("../../src/utils/getRpcUrl.js", () => ({
getRpcUrl: vi.fn().mockImplementation((chainId: number) => {
if (chainId === 1) {
throw new Error("Unsupported chain ID: 1");
}
return "mock-rpc-url";
}),
getEvmClient: vi.fn().mockReturnValue({
verifyMessage: vi.fn().mockResolvedValue(true),
}),
}));

// Testing hashing of typed data via UserUpsertSignatureVerifier
describe("hashTypedMessage", () => {
it("should hash the typed message correctly", () => {
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
thresholds: {
lines: 20,
branches: 63,
functions: 56,
functions: 52,
statements: 20,
},
include: ["src/**/*.ts"],
Expand Down

0 comments on commit cfeb432

Please sign in to comment.