@@ -19,6 +19,14 @@ import {
1919} from './helper/tests' ;
2020import { init } from './init' ;
2121
22+ const RPC_OVERRIDE = process . env [ 'LIT_YELLOWSTONE_PRIVATE_RPC_URL' ] ;
23+ if ( RPC_OVERRIDE ) {
24+ console . log (
25+ '🧪 E2E: Using RPC override (LIT_YELLOWSTONE_PRIVATE_RPC_URL):' ,
26+ RPC_OVERRIDE
27+ ) ;
28+ }
29+
2230describe ( 'all' , ( ) => {
2331 // Singleton baby
2432 let ctx : Awaited < ReturnType < typeof init > > ;
@@ -178,3 +186,114 @@ describe('all', () => {
178186 } ) ;
179187 } ) ;
180188} ) ;
189+
190+ describe ( 'rpc override' , ( ) => {
191+ const TEST_RPC = process . env . LIT_YELLOWSTONE_PRIVATE_RPC_URL ;
192+ // const TEST_RPC = 'https://yellowstone-override.example';
193+
194+ // beforeAll(() => {
195+ // process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL = TEST_RPC;
196+ // });
197+
198+ // afterAll(() => {
199+ // process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL = ORIGINAL_RPC;
200+ // });
201+
202+ it ( 'applies env rpc override to module and client' , async ( ) => {
203+ const networks = await import ( '@lit-protocol/networks' ) ;
204+
205+ // choose module by NETWORK env (same way init.ts does)
206+ const network = process . env . NETWORK || 'naga-dev' ;
207+ const importNameMap : Record < string , string > = {
208+ 'naga-dev' : 'nagaDev' ,
209+ 'naga-test' : 'nagaTest' ,
210+ 'naga-local' : 'nagaLocal' ,
211+ 'naga-staging' : 'nagaStaging' ,
212+ } ;
213+ const importName = importNameMap [ network ] ;
214+ const baseModule : any = ( networks as any ) [ importName ] ;
215+
216+ // apply override
217+ const mod =
218+ typeof baseModule . withOverrides === 'function'
219+ ? baseModule . withOverrides ( { rpcUrl : TEST_RPC } )
220+ : baseModule ;
221+
222+ // log for verification
223+ // base vs effective (when override is supported)
224+ const baseRpcUrl =
225+ typeof baseModule . getRpcUrl === 'function'
226+ ? baseModule . getRpcUrl ( )
227+ : 'n/a' ;
228+ const effRpcUrl =
229+ typeof mod . getRpcUrl === 'function' ? mod . getRpcUrl ( ) : 'n/a' ;
230+ // eslint-disable-next-line no-console
231+ console . log ( '[rpc-override] TEST_RPC:' , TEST_RPC ) ;
232+ // eslint-disable-next-line no-console
233+ console . log (
234+ '[rpc-override] module rpc (base → effective):' ,
235+ baseRpcUrl ,
236+ '→' ,
237+ effRpcUrl
238+ ) ;
239+ try {
240+ const baseChain =
241+ typeof baseModule . getChainConfig === 'function'
242+ ? baseModule . getChainConfig ( )
243+ : null ;
244+ const effChain =
245+ typeof mod . getChainConfig === 'function' ? mod . getChainConfig ( ) : null ;
246+ if ( baseChain && effChain ) {
247+ // eslint-disable-next-line no-console
248+ console . log (
249+ '[rpc-override] module chain id/name (base → effective):' ,
250+ `${ baseChain . id } /${ baseChain . name } ` ,
251+ '→' ,
252+ `${ effChain . id } /${ effChain . name } `
253+ ) ;
254+ // eslint-disable-next-line no-console
255+ console . log (
256+ '[rpc-override] module rpcUrls.default.http (base → effective):' ,
257+ baseChain . rpcUrls . default . http ,
258+ '→' ,
259+ effChain . rpcUrls . default . http
260+ ) ;
261+ // eslint-disable-next-line no-console
262+ console . log (
263+ '[rpc-override] module rpcUrls.public.http (base → effective):' ,
264+ ( baseChain . rpcUrls as any ) [ 'public' ] ?. http ,
265+ '→' ,
266+ ( effChain . rpcUrls as any ) [ 'public' ] ?. http
267+ ) ;
268+ }
269+ } catch { }
270+
271+ // module reflects override
272+ expect ( mod . getRpcUrl ( ) ) . toBe ( TEST_RPC ) ;
273+ const chain = mod . getChainConfig ( ) ;
274+ expect ( chain . rpcUrls . default . http [ 0 ] ) . toBe ( TEST_RPC ) ;
275+ expect ( ( chain . rpcUrls as any ) [ 'public' ] . http [ 0 ] ) . toBe ( TEST_RPC ) ;
276+
277+ // client reflects override
278+ const { createLitClient } = await import ( '@lit-protocol/lit-client' ) ;
279+ const client = await createLitClient ( { network : mod } ) ;
280+ const cc = client . getChainConfig ( ) ;
281+
282+ // eslint-disable-next-line no-console
283+ console . log ( '[rpc-override] client rpcUrl:' , cc . rpcUrl ) ;
284+ // eslint-disable-next-line no-console
285+ console . log (
286+ '[rpc-override] client viem rpcUrls.default:' ,
287+ cc . viemConfig . rpcUrls . default . http
288+ ) ;
289+ // eslint-disable-next-line no-console
290+ console . log (
291+ '[rpc-override] client viem rpcUrls.public:' ,
292+ ( cc . viemConfig . rpcUrls as any ) [ 'public' ] ?. http
293+ ) ;
294+
295+ expect ( cc . rpcUrl ) . toBe ( TEST_RPC ) ;
296+ expect ( cc . viemConfig . rpcUrls . default . http [ 0 ] ) . toBe ( TEST_RPC ) ;
297+ expect ( ( cc . viemConfig . rpcUrls as any ) [ 'public' ] . http [ 0 ] ) . toBe ( TEST_RPC ) ;
298+ } ) ;
299+ } ) ;
0 commit comments