-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstarknet-config-validation.test.ts
More file actions
96 lines (85 loc) · 3.02 KB
/
Copy pathstarknet-config-validation.test.ts
File metadata and controls
96 lines (85 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { describe, expect, it } from "bun:test";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { buildStarknetConfigs } from "../src/starknet-config.js";
const __filename = fileURLToPath(import.meta.url);
const testsDir = resolve(__filename, "..");
const serverDir = resolve(testsDir, "..");
const E2E_PRIVATE_KEY =
"0x0000000000000000000000000000000000000000000000000000000000000001";
describe("Starknet setup validation", () => {
it("fails fast with an actionable error when sponsor is missing", () => {
const processResult = Bun.spawnSync({
cmd: ["bun", "-e", 'import "./src/setup.ts";'],
cwd: serverDir,
env: {
PATH: process.env.PATH ?? "",
HOME: process.env.HOME ?? "",
EVM_PRIVATE_KEY: E2E_PRIVATE_KEY,
EVM_NETWORKS: "base-sepolia",
STARKNET_NETWORKS: "starknet-mainnet",
STARKNET_RPC_URL_STARKNET_MAINNET: "https://starknet-mainnet.example.com",
},
stdout: "pipe",
stderr: "pipe",
});
const stdout = new TextDecoder().decode(processResult.stdout);
const stderr = new TextDecoder().decode(processResult.stderr);
const combinedOutput = `${stdout}\n${stderr}`;
expect(processResult.exitCode).not.toBe(0);
expect(combinedOutput).toContain(
"Missing Starknet sponsor address for starknet-mainnet"
);
expect(combinedOutput).toContain(
"STARKNET_SPONSOR_ADDRESS_STARKNET_MAINNET"
);
});
it("skips Starknet networks with unresolved RPC URLs", () => {
const warnings: string[] = [];
const originalWarn = console.warn;
console.warn = (...args: unknown[]) => {
warnings.push(args.map((value) => String(value)).join(" "));
};
try {
const configs = buildStarknetConfigs([
{
name: "starknet-mainnet",
caip: "starknet:SN_MAIN",
rpcUrl: undefined,
paymasterEndpoint: "https://starknet.paymaster.avnu.fi",
paymasterApiKey: "api-key",
sponsorAddress: "0xmainnet-sponsor",
},
]);
expect(configs).toEqual([]);
expect(warnings).toContain("⚠️ No RPC URL for starknet-mainnet - skipping");
} finally {
console.warn = originalWarn;
}
});
it("skips Starknet networks with unresolved paymaster endpoints", () => {
const warnings: string[] = [];
const originalWarn = console.warn;
console.warn = (...args: unknown[]) => {
warnings.push(args.map((value) => String(value)).join(" "));
};
try {
const configs = buildStarknetConfigs([
{
name: "starknet-sepolia",
caip: "starknet:SN_SEPOLIA",
rpcUrl: "https://starknet-sepolia.example.com",
paymasterEndpoint: undefined,
paymasterApiKey: "api-key",
sponsorAddress: "0xsepolia-sponsor",
},
]);
expect(configs).toEqual([]);
expect(warnings).toContain(
"⚠️ No paymaster endpoint for starknet-sepolia - skipping"
);
} finally {
console.warn = originalWarn;
}
});
});