-
-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 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 |
---|---|---|
|
@@ -1567,4 +1567,34 @@ describe('subscribe', () => { | |
unwatch() | ||
}) | ||
}) | ||
|
||
test( | ||
'https://github.com/wevm/viem/issues/2563', | ||
async () => { | ||
let error: Error | undefined | ||
const unwatch = watchContractEvent(webSocketClient, { | ||
...usdcContractConfig, | ||
onError: (error_) => { | ||
error = error_ | ||
}, | ||
onLogs: () => {}, | ||
}) | ||
|
||
await wait(100) | ||
const { socket } = await webSocketClient.transport.getRpcClient() | ||
socket.close() | ||
await wait(100) | ||
|
||
expect(error).toMatchInlineSnapshot(` | ||
[SocketClosedError: The socket has been closed. | ||
URL: http://localhost | ||
Version: [email protected]] | ||
`) | ||
|
||
unwatch() | ||
}, | ||
{ timeout: 10_000 }, | ||
) | ||
}) |
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 |
---|---|---|
|
@@ -185,6 +185,39 @@ test('subscribe', async () => { | |
expect(blocks.length).toBe(1) | ||
}) | ||
|
||
test('throws on socket closure', async () => { | ||
const transport = webSocket(anvilMainnet.rpcUrl.ws, { | ||
key: 'jsonRpc', | ||
name: 'JSON RPC', | ||
})({}) | ||
if (!transport.value) return | ||
|
||
let error: Error | undefined | ||
const { subscriptionId } = await transport.value.subscribe({ | ||
params: ['newHeads'], | ||
onData: () => {}, | ||
onError: (error_) => { | ||
error = error_ | ||
}, | ||
}) | ||
|
||
// Make sure we are subscribed. | ||
expect(subscriptionId).toBeDefined() | ||
|
||
await wait(100) | ||
const { socket } = await transport.value.getRpcClient() | ||
socket.close() | ||
await wait(100) | ||
|
||
expect(error).toMatchInlineSnapshot(` | ||
[SocketClosedError: The socket has been closed. | ||
URL: http://localhost | ||
Version: [email protected]] | ||
`) | ||
}) | ||
|
||
test('throws on bogus subscription', async () => { | ||
const transport = webSocket(anvilMainnet.rpcUrl.ws, { | ||
key: 'jsonRpc', | ||
|
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