Skip to content

Commit 2f0b670

Browse files
committed
test: fix alchemy env var missing
The tests shouldn't have to rely on Alchemy. This goes around the issue and makes it so that tests go to a fake RPC URL directly. The nice thing is that this also let's us ditch the ugly mock.
1 parent 33c976a commit 2f0b670

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

src/lib/safe/safe-rpc-urls.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ export class RandomRpcStrategy implements SafeRpcStrategy {
2525
}
2626
}
2727

28+
export class TestRpcStrategy implements SafeRpcStrategy {
29+
getUrl(): string {
30+
return "https://example.com";
31+
}
32+
}
33+
2834
export class RpcStrategyFactory {
2935
static getStrategy(
3036
chainId: number,
@@ -34,6 +40,10 @@ export class RpcStrategyFactory {
3440
if (chainId === 314 || chainId === 314159) {
3541
return new FilecoinRpcStrategy(evmClientFactory);
3642
}
43+
// Test cases should use this chain id
44+
if (chainId === 0) {
45+
return new TestRpcStrategy();
46+
}
3747
// All other chains use random selection from available RPCs
3848
return new RandomRpcStrategy(evmClientFactory);
3949
}

test/safe-signatures/SafeSignatureVerifier.test.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1-
import { describe, it, expect, vi } from "vitest";
1+
import { describe, it, expect } 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-
174
// Testing hashing of typed data via UserUpsertSignatureVerifier
185
describe("hashTypedMessage", () => {
196
it("should hash the typed message correctly", () => {
207
const verifier = new Verifier(
21-
11155111,
8+
0,
229
"0x379756bB61A632Cd3C5C5Ce4F3768f4815feaCda",
2310
{
2411
metadata: {
@@ -31,14 +18,14 @@ describe("hashTypedMessage", () => {
3118
},
3219
);
3320
expect(verifier.hashTypedData()).toBe(
34-
"0x56b9d12b9b854c0b80f253af1686aa70b14a5bc55ca94f98db6a947bd7660d7a",
21+
"0x86f0940b45a51491bd176678752b83b9b0e466c97386b543bf4e59f45f9a774a",
3522
);
3623
});
3724

3825
it("should throw with missing fields", () => {
3926
expect(() => {
4027
const verifier = new Verifier(
41-
11155111,
28+
0,
4229
"0x379756bB61A632Cd3C5C5Ce4F3768f4815feaCda",
4330
{
4431
metadata: {
@@ -53,7 +40,7 @@ describe("hashTypedMessage", () => {
5340

5441
it("should handle special characters", () => {
5542
const verifier = new Verifier(
56-
11155111,
43+
0,
5744
"0x379756bB61A632Cd3C5C5Ce4F3768f4815feaCda",
5845
{
5946
metadata: {
@@ -71,7 +58,7 @@ describe("hashTypedMessage", () => {
7158
it("should handle large data", () => {
7259
const largeMessage = "a".repeat(10000);
7360
const verifier = new Verifier(
74-
11155111,
61+
0,
7562
"0x379756bB61A632Cd3C5C5Ce4F3768f4815feaCda",
7663
{
7764
metadata: {
@@ -88,7 +75,7 @@ describe("hashTypedMessage", () => {
8875

8976
it("should handle empty strings", () => {
9077
const verifier = new Verifier(
91-
11155111,
78+
0,
9279
"0x379756bB61A632Cd3C5C5Ce4F3768f4815feaCda",
9380
{
9481
metadata: {
@@ -101,7 +88,7 @@ describe("hashTypedMessage", () => {
10188
},
10289
);
10390
expect(verifier.hashTypedData()).toBe(
104-
"0xa0752bebdb2725e200a8f2ebb6ad12f35b2566710f18c51e625276b267f623b9",
91+
"0xf6ca8a6277d5d7015160a9c28b4aca0f5cf529b8f477e94138d06983cf6e42ca",
10592
);
10693
});
10794
});

0 commit comments

Comments
 (0)