-
-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
fallback
fall through behavior when allowlist is set
- Loading branch information
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"viem": patch | ||
--- | ||
|
||
Fixed issue where `fallback` transports would fall through when other transports do not support the JSON-RPC method (has set up a method allowlist on the transport). |
This file contains 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 |
---|---|---|
|
@@ -79,6 +79,7 @@ export function createTransport< | |
return { | ||
config: { | ||
key, | ||
methods, | ||
name, | ||
request, | ||
retryCount, | ||
|
This file contains 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import { createHttpServer } from '~test/src/utils.js' | |
import { getBlockNumber } from '../../actions/public/getBlockNumber.js' | ||
import { localhost } from '../../chains/index.js' | ||
import { | ||
InternalRpcError, | ||
MethodNotSupportedRpcError, | ||
UserRejectedRequestError, | ||
} from '../../errors/rpc.js' | ||
|
@@ -31,6 +32,7 @@ test('default', () => { | |
{ | ||
"config": { | ||
"key": "fallback", | ||
"methods": undefined, | ||
"name": "Fallback", | ||
"request": [Function], | ||
"retryCount": 3, | ||
|
@@ -45,6 +47,7 @@ test('default', () => { | |
{ | ||
"config": { | ||
"key": "http", | ||
"methods": undefined, | ||
"name": "HTTP JSON-RPC", | ||
"request": [Function], | ||
"retryCount": 0, | ||
|
@@ -61,6 +64,7 @@ test('default', () => { | |
{ | ||
"config": { | ||
"key": "http", | ||
"methods": undefined, | ||
"name": "HTTP JSON-RPC", | ||
"request": [Function], | ||
"retryCount": 0, | ||
|
@@ -267,6 +271,46 @@ describe('request', () => { | |
expect(await transport.request({ method: 'eth_c' })).toBe('0x2') | ||
}) | ||
|
||
test('methods.include (error)', async () => { | ||
const server1 = await createHttpServer((_req, res) => { | ||
res.writeHead(200, { | ||
'Content-Type': 'application/json', | ||
}) | ||
res.end( | ||
JSON.stringify({ | ||
error: { code: InternalRpcError.code, message: 'sad times' }, | ||
}), | ||
) | ||
}) | ||
const server2 = await createHttpServer((_req, res) => { | ||
res.writeHead(200, { | ||
'Content-Type': 'application/json', | ||
}) | ||
res.end(JSON.stringify({ result: '0x2' })) | ||
}) | ||
|
||
const transport = fallback([ | ||
http(server1.url, { methods: { include: ['eth_a', 'eth_b'] } }), | ||
http(server2.url, { methods: { exclude: ['eth_a'] } }), | ||
http(server2.url, { methods: { include: ['eth_b'] } }), | ||
])({ | ||
chain: localhost, | ||
}) | ||
|
||
await expect(() => | ||
transport.request({ method: 'eth_a' }), | ||
).rejects.toThrowErrorMatchingInlineSnapshot(` | ||
[InternalRpcError: An internal error was received. | ||
URL: http://localhost | ||
Request body: {"method":"eth_a"} | ||
Details: sad times | ||
Version: [email protected]] | ||
`) | ||
expect(await transport.request({ method: 'eth_b' })).toBe('0x2') | ||
}) | ||
|
||
test('error (rpc)', async () => { | ||
let count = 0 | ||
const server1 = await createHttpServer((_req, res) => { | ||
|
@@ -556,6 +600,7 @@ describe('client', () => { | |
"request": [Function], | ||
"transport": { | ||
"key": "fallback", | ||
"methods": undefined, | ||
"name": "Fallback", | ||
"onResponse": [Function], | ||
"request": [Function], | ||
|
@@ -566,6 +611,7 @@ describe('client', () => { | |
{ | ||
"config": { | ||
"key": "http", | ||
"methods": undefined, | ||
"name": "HTTP JSON-RPC", | ||
"request": [Function], | ||
"retryCount": 0, | ||
|
@@ -582,6 +628,7 @@ describe('client', () => { | |
{ | ||
"config": { | ||
"key": "http", | ||
"methods": undefined, | ||
"name": "HTTP JSON-RPC", | ||
"request": [Function], | ||
"retryCount": 0, | ||
|
This file contains 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