Skip to content

Commit

Permalink
Merge branch 'master' into update-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 authored Jan 24, 2025
2 parents 3fe7840 + 2b44dff commit 0f368a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 20, 22]
node-version: [20, 22]
fail-fast: false
steps:
- uses: actions/checkout@v4
Expand Down
36 changes: 17 additions & 19 deletions packages/client/test/rpc/websocket.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ describe('JSON-RPC call', () => {
//@ts-ignore -- `isomorphic-ws` types aren't perfectly mapped to jayson.WebSocketClient but works fine for this test
ws: socket,
})
while ((rpc as any).ws.readyState !== WebSocket.OPEN) {
await new Promise((resolve) => setTimeout(resolve, 100))
}
try {
await new Promise((resolve) => {
;(rpc as any).ws.on('open', async () => {
const res = await rpc.request('METHOD_DOES_NOT_EXIST', ['0x1', true])
assert.equal(res.error.code, METHOD_NOT_FOUND)
resolve(undefined)
})
})
const res = await rpc.request('METHOD_DOES_NOT_EXIST', ['0x1', true])
assert.equal(res.error.code, METHOD_NOT_FOUND)
} catch (err: any) {
assert.fail(err)
}
Expand All @@ -44,32 +42,32 @@ describe('JSON-RPC call', () => {
it('auth protected server without any auth headers', async () => {
const server = startRPC({}, { wsServer: true }, { jwtSecret })
server.listen(1236, 'localhost')
const rpc = Client.websocket({
url: 'ws://localhost:1236/',
})

await new Promise((resolve) => {
;(rpc as any).ws.on('error', async (err: any) => {
const socket = new WebSocket('ws://localhost:1236', undefined, {})
socket.onerror = (err) => {
assert.ok(err.message.includes('401'), 'Unauthorized')
resolve(undefined)
}
Client.websocket({
// @ts-ignore -- see above test
ws: socket,
})
})
}, 30000)
})

it('server without any auth headers', async () => {
const server = startRPC({}, { wsServer: true })
server.listen(12345, 'localhost')
const rpc = Client.websocket({
url: 'ws://localhost:12345/',
})
while ((rpc as any).ws.readyState !== WebSocket.OPEN) {
await new Promise((resolve) => setTimeout(resolve, 100))
}
try {
await new Promise((resolve) => {
;(rpc as any).ws.on('open', async () => {
const res = await rpc.request('METHOD_DOES_NOT_EXIST', ['0x1', true])
assert.equal(res.error.code, METHOD_NOT_FOUND)
resolve(undefined)
})
})
const res = await rpc.request('METHOD_DOES_NOT_EXIST', ['0x1', true])
assert.equal(res.error.code, METHOD_NOT_FOUND)
} catch (err: any) {
assert.fail(err)
}
Expand Down

0 comments on commit 0f368a3

Please sign in to comment.