-
Notifications
You must be signed in to change notification settings - Fork 88
[Feature] Overwrite RPC URL #883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Ansonhkg
merged 4 commits into
naga_add_hardcoded_keysets-3
from
feature/jss-81-naga-bug-overwrite-rpc-url-based-880
Sep 16, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
689e557
feat(rpc): implement RPC URL override functionality in various modules
Ansonhkg c922755
fix(auth-server): `initSystemContext` to override RPC URL
Ansonhkg 18cc2c2
fix(private-rpc): withOverrides no longer monkey-patches methods nor …
Ansonhkg 249d8ac
fix(e2e): rpc override test
Ansonhkg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,14 @@ import { | |
| } from './helper/tests'; | ||
| import { init } from './init'; | ||
|
|
||
| const RPC_OVERRIDE = process.env['LIT_YELLOWSTONE_PRIVATE_RPC_URL']; | ||
| if (RPC_OVERRIDE) { | ||
| console.log( | ||
| '🧪 E2E: Using RPC override (LIT_YELLOWSTONE_PRIVATE_RPC_URL):', | ||
| RPC_OVERRIDE | ||
| ); | ||
| } | ||
|
|
||
| describe('all', () => { | ||
| // Singleton baby | ||
| let ctx: Awaited<ReturnType<typeof init>>; | ||
|
|
@@ -161,3 +169,114 @@ describe('all', () => { | |
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('rpc override', () => { | ||
| const TEST_RPC = process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL; | ||
| // const TEST_RPC = 'https://yellowstone-override.example'; | ||
|
|
||
| // beforeAll(() => { | ||
| // process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL = TEST_RPC; | ||
| // }); | ||
|
|
||
| // afterAll(() => { | ||
| // process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL = ORIGINAL_RPC; | ||
| // }); | ||
|
|
||
| it('applies env rpc override to module and client', async () => { | ||
| const networks = await import('@lit-protocol/networks'); | ||
|
|
||
| // choose module by NETWORK env (same way init.ts does) | ||
| const network = process.env.NETWORK || 'naga-dev'; | ||
| const importNameMap: Record<string, string> = { | ||
| 'naga-dev': 'nagaDev', | ||
| 'naga-test': 'nagaTest', | ||
| 'naga-local': 'nagaLocal', | ||
| 'naga-staging': 'nagaStaging', | ||
| }; | ||
| const importName = importNameMap[network]; | ||
| const baseModule: any = (networks as any)[importName]; | ||
|
|
||
| // apply override | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks confusing but purely for observability / checking the logs to see if they are correctly applied. |
||
| const mod = | ||
| typeof baseModule.withOverrides === 'function' | ||
| ? baseModule.withOverrides({ rpcUrl: TEST_RPC }) | ||
| : baseModule; | ||
|
|
||
| // log for verification | ||
| // base vs effective (when override is supported) | ||
| const baseRpcUrl = | ||
| typeof baseModule.getRpcUrl === 'function' | ||
| ? baseModule.getRpcUrl() | ||
| : 'n/a'; | ||
| const effRpcUrl = | ||
| typeof mod.getRpcUrl === 'function' ? mod.getRpcUrl() : 'n/a'; | ||
| // eslint-disable-next-line no-console | ||
| console.log('[rpc-override] TEST_RPC:', TEST_RPC); | ||
| // eslint-disable-next-line no-console | ||
| console.log( | ||
| '[rpc-override] module rpc (base → effective):', | ||
| baseRpcUrl, | ||
| '→', | ||
| effRpcUrl | ||
| ); | ||
| try { | ||
| const baseChain = | ||
| typeof baseModule.getChainConfig === 'function' | ||
| ? baseModule.getChainConfig() | ||
| : null; | ||
| const effChain = | ||
| typeof mod.getChainConfig === 'function' ? mod.getChainConfig() : null; | ||
| if (baseChain && effChain) { | ||
| // eslint-disable-next-line no-console | ||
| console.log( | ||
| '[rpc-override] module chain id/name (base → effective):', | ||
| `${baseChain.id}/${baseChain.name}`, | ||
| '→', | ||
| `${effChain.id}/${effChain.name}` | ||
| ); | ||
| // eslint-disable-next-line no-console | ||
| console.log( | ||
| '[rpc-override] module rpcUrls.default.http (base → effective):', | ||
| baseChain.rpcUrls.default.http, | ||
| '→', | ||
| effChain.rpcUrls.default.http | ||
| ); | ||
| // eslint-disable-next-line no-console | ||
| console.log( | ||
| '[rpc-override] module rpcUrls.public.http (base → effective):', | ||
| (baseChain.rpcUrls as any)['public']?.http, | ||
| '→', | ||
| (effChain.rpcUrls as any)['public']?.http | ||
| ); | ||
| } | ||
| } catch {} | ||
|
|
||
| // module reflects override | ||
| expect(mod.getRpcUrl()).toBe(TEST_RPC); | ||
| const chain = mod.getChainConfig(); | ||
| expect(chain.rpcUrls.default.http[0]).toBe(TEST_RPC); | ||
| expect((chain.rpcUrls as any)['public'].http[0]).toBe(TEST_RPC); | ||
|
|
||
| // client reflects override | ||
| const { createLitClient } = await import('@lit-protocol/lit-client'); | ||
| const client = await createLitClient({ network: mod }); | ||
| const cc = client.getChainConfig(); | ||
|
|
||
| // eslint-disable-next-line no-console | ||
| console.log('[rpc-override] client rpcUrl:', cc.rpcUrl); | ||
| // eslint-disable-next-line no-console | ||
| console.log( | ||
| '[rpc-override] client viem rpcUrls.default:', | ||
| cc.viemConfig.rpcUrls.default.http | ||
| ); | ||
| // eslint-disable-next-line no-console | ||
| console.log( | ||
| '[rpc-override] client viem rpcUrls.public:', | ||
| (cc.viemConfig.rpcUrls as any)['public']?.http | ||
| ); | ||
|
|
||
| expect(cc.rpcUrl).toBe(TEST_RPC); | ||
| expect(cc.viemConfig.rpcUrls.default.http[0]).toBe(TEST_RPC); | ||
| expect((cc.viemConfig.rpcUrls as any)['public'].http[0]).toBe(TEST_RPC); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several places that do this, we will optimise in a follow up PR.