-
-
Notifications
You must be signed in to change notification settings - Fork 951
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
methods.{include|exclude}
on transport options (#3238)
* feat: add `methods.{include|exclude}` on transport options * docs: add * chore: changeset * u
- Loading branch information
Showing
17 changed files
with
297 additions
and
22 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 | ||
--- | ||
|
||
Added `methods` property to `http`, `ipc`, and `webSocket` transports to include or exclude RPC methods from being executed. |
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -389,6 +389,53 @@ describe('request', () => { | |
await server.close() | ||
}) | ||
|
||
test('behavior: methods.exclude', async () => { | ||
const server = await createHttpServer((_, res) => { | ||
res.end(JSON.stringify({ result: '0x1' })) | ||
}) | ||
|
||
const transport = http(server.url, { | ||
key: 'jsonRpc', | ||
name: 'JSON RPC', | ||
methods: { exclude: ['eth_a'] }, | ||
})({ chain: localhost }) | ||
|
||
await transport.request({ method: 'eth_b' }) | ||
|
||
await expect(() => | ||
transport.request({ method: 'eth_a' }), | ||
).rejects.toThrowErrorMatchingInlineSnapshot(` | ||
[MethodNotSupportedRpcError: Method "eth_a" is not supported. | ||
Details: method not supported | ||
Version: [email protected]] | ||
`) | ||
}) | ||
|
||
test('behavior: methods.include', async () => { | ||
const server = await createHttpServer((_, res) => { | ||
res.end(JSON.stringify({ result: '0x1' })) | ||
}) | ||
|
||
const transport = http(server.url, { | ||
key: 'jsonRpc', | ||
name: 'JSON RPC', | ||
methods: { include: ['eth_a', 'eth_b'] }, | ||
})({ chain: localhost }) | ||
|
||
await transport.request({ method: 'eth_a' }) | ||
await transport.request({ method: 'eth_b' }) | ||
|
||
await expect(() => | ||
transport.request({ method: 'eth_c' }), | ||
).rejects.toThrowErrorMatchingInlineSnapshot(` | ||
[MethodNotSupportedRpcError: Method "eth_c" is not supported. | ||
Details: method not supported | ||
Version: [email protected]] | ||
`) | ||
}) | ||
|
||
test('behavior: retryCount', async () => { | ||
let retryCount = -1 | ||
const server = await createHttpServer((_req, res) => { | ||
|
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
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
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
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
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
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
Oops, something went wrong.