Skip to content

Commit ec43401

Browse files
committed
test(e2e): add rpc override tests to validate environment variable functionality
1 parent 3cfb6a5 commit ec43401

File tree

2 files changed

+110
-111
lines changed

2 files changed

+110
-111
lines changed

packages/e2e/src/e2e.spec.ts

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -177,114 +177,3 @@ describe('all', () => {
177177
});
178178
});
179179
});
180-
181-
describe('rpc override', () => {
182-
const TEST_RPC = process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL;
183-
// const TEST_RPC = 'https://yellowstone-override.example';
184-
185-
// beforeAll(() => {
186-
// process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL = TEST_RPC;
187-
// });
188-
189-
// afterAll(() => {
190-
// process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL = ORIGINAL_RPC;
191-
// });
192-
193-
it('applies env rpc override to module and client', async () => {
194-
const networks = await import('@lit-protocol/networks');
195-
196-
// choose module by NETWORK env (same way init.ts does)
197-
const network = process.env.NETWORK || 'naga-dev';
198-
const importNameMap: Record<string, string> = {
199-
'naga-dev': 'nagaDev',
200-
'naga-test': 'nagaTest',
201-
'naga-local': 'nagaLocal',
202-
'naga-staging': 'nagaStaging',
203-
};
204-
const importName = importNameMap[network];
205-
const baseModule: any = (networks as any)[importName];
206-
207-
// apply override
208-
const mod =
209-
typeof baseModule.withOverrides === 'function'
210-
? baseModule.withOverrides({ rpcUrl: TEST_RPC })
211-
: baseModule;
212-
213-
// log for verification
214-
// base vs effective (when override is supported)
215-
const baseRpcUrl =
216-
typeof baseModule.getRpcUrl === 'function'
217-
? baseModule.getRpcUrl()
218-
: 'n/a';
219-
const effRpcUrl =
220-
typeof mod.getRpcUrl === 'function' ? mod.getRpcUrl() : 'n/a';
221-
// eslint-disable-next-line no-console
222-
console.log('[rpc-override] TEST_RPC:', TEST_RPC);
223-
// eslint-disable-next-line no-console
224-
console.log(
225-
'[rpc-override] module rpc (base → effective):',
226-
baseRpcUrl,
227-
'→',
228-
effRpcUrl
229-
);
230-
try {
231-
const baseChain =
232-
typeof baseModule.getChainConfig === 'function'
233-
? baseModule.getChainConfig()
234-
: null;
235-
const effChain =
236-
typeof mod.getChainConfig === 'function' ? mod.getChainConfig() : null;
237-
if (baseChain && effChain) {
238-
// eslint-disable-next-line no-console
239-
console.log(
240-
'[rpc-override] module chain id/name (base → effective):',
241-
`${baseChain.id}/${baseChain.name}`,
242-
'→',
243-
`${effChain.id}/${effChain.name}`
244-
);
245-
// eslint-disable-next-line no-console
246-
console.log(
247-
'[rpc-override] module rpcUrls.default.http (base → effective):',
248-
baseChain.rpcUrls.default.http,
249-
'→',
250-
effChain.rpcUrls.default.http
251-
);
252-
// eslint-disable-next-line no-console
253-
console.log(
254-
'[rpc-override] module rpcUrls.public.http (base → effective):',
255-
(baseChain.rpcUrls as any)['public']?.http,
256-
'→',
257-
(effChain.rpcUrls as any)['public']?.http
258-
);
259-
}
260-
} catch {}
261-
262-
// module reflects override
263-
expect(mod.getRpcUrl()).toBe(TEST_RPC);
264-
const chain = mod.getChainConfig();
265-
expect(chain.rpcUrls.default.http[0]).toBe(TEST_RPC);
266-
expect((chain.rpcUrls as any)['public'].http[0]).toBe(TEST_RPC);
267-
268-
// client reflects override
269-
const { createLitClient } = await import('@lit-protocol/lit-client');
270-
const client = await createLitClient({ network: mod });
271-
const cc = client.getChainConfig();
272-
273-
// eslint-disable-next-line no-console
274-
console.log('[rpc-override] client rpcUrl:', cc.rpcUrl);
275-
// eslint-disable-next-line no-console
276-
console.log(
277-
'[rpc-override] client viem rpcUrls.default:',
278-
cc.viemConfig.rpcUrls.default.http
279-
);
280-
// eslint-disable-next-line no-console
281-
console.log(
282-
'[rpc-override] client viem rpcUrls.public:',
283-
(cc.viemConfig.rpcUrls as any)['public']?.http
284-
);
285-
286-
expect(cc.rpcUrl).toBe(TEST_RPC);
287-
expect(cc.viemConfig.rpcUrls.default.http[0]).toBe(TEST_RPC);
288-
expect((cc.viemConfig.rpcUrls as any)['public'].http[0]).toBe(TEST_RPC);
289-
});
290-
});
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
describe('rpc override', () => {
2+
const TEST_RPC = process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL;
3+
// const TEST_RPC = 'https://yellowstone-override.example';
4+
5+
// beforeAll(() => {
6+
// process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL = TEST_RPC;
7+
// });
8+
9+
// afterAll(() => {
10+
// process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL = ORIGINAL_RPC;
11+
// });
12+
13+
it('applies env rpc override to module and client', async () => {
14+
const networks = await import('@lit-protocol/networks');
15+
16+
// choose module by NETWORK env (same way init.ts does)
17+
const network = process.env.NETWORK || 'naga-dev';
18+
const importNameMap: Record<string, string> = {
19+
'naga-dev': 'nagaDev',
20+
'naga-test': 'nagaTest',
21+
'naga-local': 'nagaLocal',
22+
'naga-staging': 'nagaStaging',
23+
};
24+
const importName = importNameMap[network];
25+
const baseModule: any = (networks as any)[importName];
26+
27+
// apply override
28+
const mod =
29+
typeof baseModule.withOverrides === 'function'
30+
? baseModule.withOverrides({ rpcUrl: TEST_RPC })
31+
: baseModule;
32+
33+
// log for verification
34+
// base vs effective (when override is supported)
35+
const baseRpcUrl =
36+
typeof baseModule.getRpcUrl === 'function'
37+
? baseModule.getRpcUrl()
38+
: 'n/a';
39+
const effRpcUrl =
40+
typeof mod.getRpcUrl === 'function' ? mod.getRpcUrl() : 'n/a';
41+
// eslint-disable-next-line no-console
42+
console.log('[rpc-override] TEST_RPC:', TEST_RPC);
43+
// eslint-disable-next-line no-console
44+
console.log(
45+
'[rpc-override] module rpc (base → effective):',
46+
baseRpcUrl,
47+
'→',
48+
effRpcUrl
49+
);
50+
try {
51+
const baseChain =
52+
typeof baseModule.getChainConfig === 'function'
53+
? baseModule.getChainConfig()
54+
: null;
55+
const effChain =
56+
typeof mod.getChainConfig === 'function' ? mod.getChainConfig() : null;
57+
if (baseChain && effChain) {
58+
// eslint-disable-next-line no-console
59+
console.log(
60+
'[rpc-override] module chain id/name (base → effective):',
61+
`${baseChain.id}/${baseChain.name}`,
62+
'→',
63+
`${effChain.id}/${effChain.name}`
64+
);
65+
// eslint-disable-next-line no-console
66+
console.log(
67+
'[rpc-override] module rpcUrls.default.http (base → effective):',
68+
baseChain.rpcUrls.default.http,
69+
'→',
70+
effChain.rpcUrls.default.http
71+
);
72+
// eslint-disable-next-line no-console
73+
console.log(
74+
'[rpc-override] module rpcUrls.public.http (base → effective):',
75+
(baseChain.rpcUrls as any)['public']?.http,
76+
'→',
77+
(effChain.rpcUrls as any)['public']?.http
78+
);
79+
}
80+
} catch {}
81+
82+
// module reflects override
83+
expect(mod.getRpcUrl()).toBe(TEST_RPC);
84+
const chain = mod.getChainConfig();
85+
expect(chain.rpcUrls.default.http[0]).toBe(TEST_RPC);
86+
expect((chain.rpcUrls as any)['public'].http[0]).toBe(TEST_RPC);
87+
88+
// client reflects override
89+
const { createLitClient } = await import('@lit-protocol/lit-client');
90+
const client = await createLitClient({ network: mod });
91+
const cc = client.getChainConfig();
92+
93+
// eslint-disable-next-line no-console
94+
console.log('[rpc-override] client rpcUrl:', cc.rpcUrl);
95+
// eslint-disable-next-line no-console
96+
console.log(
97+
'[rpc-override] client viem rpcUrls.default:',
98+
cc.viemConfig.rpcUrls.default.http
99+
);
100+
// eslint-disable-next-line no-console
101+
console.log(
102+
'[rpc-override] client viem rpcUrls.public:',
103+
(cc.viemConfig.rpcUrls as any)['public']?.http
104+
);
105+
106+
expect(cc.rpcUrl).toBe(TEST_RPC);
107+
expect(cc.viemConfig.rpcUrls.default.http[0]).toBe(TEST_RPC);
108+
expect((cc.viemConfig.rpcUrls as any)['public'].http[0]).toBe(TEST_RPC);
109+
});
110+
});

0 commit comments

Comments
 (0)