-
Notifications
You must be signed in to change notification settings - Fork 29
Rpc fix with json #643
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
Merged
Rpc fix with json #643
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
207fad2
Harden `fetchAndTestRpcs` parsing against DefiLlama format changes an…
Copilot 88102f6
fix: package.json formatting
L03TJ3 60fc64b
fix: simplify and make parsing of extraRpcs more direct to the chains…
L03TJ3 5241add
remove some verbosity
L03TJ3 15646ee
fix: use chainlist rpc endpoint
L03TJ3 426f3de
remove unnecessary export and const assignment
L03TJ3 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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| name: Jest Tests | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - master | ||
|
|
||
| jobs: | ||
| jest: | ||
| name: Run Jest tests | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Check out Git repository | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up Node | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 20 | ||
|
|
||
| - name: Install dependencies | ||
| run: yarn install --immutable | ||
|
|
||
| - name: Run Jest tests | ||
| run: yarn test --testPathPattern="rpcParsing" --testTimeout=30000 |
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module.exports = { | ||
| presets: [ | ||
| ['@babel/preset-env', { targets: { node: 'current' } }], | ||
| '@babel/preset-typescript', | ||
| ], | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| const nodeFetch = require('node-fetch') | ||
| const globalObject = typeof globalThis !== 'undefined' ? globalThis : global | ||
| if (!globalObject.fetch) { | ||
| globalObject.fetch = nodeFetch.default || nodeFetch | ||
| globalObject.Request = nodeFetch.Request | ||
| globalObject.Response = nodeFetch.Response | ||
| globalObject.Headers = nodeFetch.Headers | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* eslint-env jest */ | ||
|
|
||
| const CHAINLIST_RPCS_SOURCE = [ | ||
| { | ||
| chainId: 1, | ||
| name: 'Ethereum Mainnet', | ||
| rpc: [ | ||
| { url: 'https://eth.llamarpc.com' }, | ||
| { url: 'https://1rpc.io/eth' }, | ||
| { url: 'wss://ethereum-rpc.publicnode.com' }, | ||
| ], | ||
| }, | ||
| { | ||
| chainId: 122, | ||
| name: 'Fuse Mainnet', | ||
| rpc: [{ url: 'https://rpc.fuse.io' }, { url: 'https://fuse.drpc.org' }], | ||
| }, | ||
| { | ||
| chainId: 42220, | ||
| name: 'Celo Mainnet', | ||
| rpc: [{ url: 'https://forno.celo.org' }, { url: 'wss://forno.celo.org/ws' }], | ||
| }, | ||
| { | ||
| chainId: 50, | ||
| name: 'XDC Network', | ||
| rpc: [{ url: 'https://rpc.xinfin.network' }, { url: 'https://erpc.xinfin.network' }], | ||
| }, | ||
| ] | ||
|
|
||
| describe('rpcParsing', () => { | ||
| const originalEnv = process.env | ||
|
|
||
| beforeEach(() => { | ||
| process.env = { ...originalEnv } | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| process.env = originalEnv | ||
| jest.restoreAllMocks() | ||
| }) | ||
|
|
||
| it('parses HTTP(S) RPCs from chainlist json', async () => { | ||
| jest.spyOn(global, 'fetch').mockResolvedValue({ | ||
| ok: true, | ||
| json: async () => CHAINLIST_RPCS_SOURCE, | ||
| } as Response) | ||
|
|
||
| const { fetchRpcsFromChainlist } = await import('./rpcParsing') | ||
|
|
||
| await expect(fetchRpcsFromChainlist()).resolves.toEqual({ | ||
| '1': ['https://eth.llamarpc.com', 'https://1rpc.io/eth'], | ||
| '122': ['https://rpc.fuse.io', 'https://fuse.drpc.org'], | ||
| '42220': ['https://forno.celo.org'], | ||
| '50': ['https://rpc.xinfin.network', 'https://erpc.xinfin.network'], | ||
| }) | ||
| }) | ||
|
|
||
| it('returns only configured fallback chains', async () => { | ||
| process.env.REACT_APP_RPC_FALLBACK_CHAIN_IDS = '122,50' | ||
| process.env.REACT_APP_FUSE_RPC = 'https://fuse.example' | ||
|
|
||
| const { getFallbackRpcsByChain } = await import('./rpcParsing') | ||
|
|
||
| expect(getFallbackRpcsByChain()).toEqual({ | ||
| '1': [], | ||
| '122': ['https://fuse.example'], | ||
| '42220': [], | ||
| '50': ['https://rpc.xinfin.network'], | ||
| }) | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.