Skip to content

Commit 03fb317

Browse files
committed
test: mock RPC URL module in Safe sig verifier tests
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.
1 parent 625d2e4 commit 03fb317

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

test/safe-signatures/SafeSignatureVerifier.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
import { describe, it, expect } from "vitest";
1+
import { describe, it, expect, vi } from "vitest";
22
import Verifier from "../../src/lib/safe-signature-verification/UserUpsertSignatureVerifier.js";
33

4+
// Mock the entire getRpcUrl module
5+
vi.mock("../../src/utils/getRpcUrl.js", () => ({
6+
getRpcUrl: vi.fn().mockImplementation((chainId: number) => {
7+
if (chainId === 1) {
8+
throw new Error("Unsupported chain ID: 1");
9+
}
10+
return "mock-rpc-url";
11+
}),
12+
getEvmClient: vi.fn().mockReturnValue({
13+
verifyMessage: vi.fn().mockResolvedValue(true),
14+
}),
15+
}));
16+
417
// Testing hashing of typed data via UserUpsertSignatureVerifier
518
describe("hashTypedMessage", () => {
619
it("should hash the typed message correctly", () => {

0 commit comments

Comments
 (0)