diff --git a/.changeset/funny-weeks-smash.md b/.changeset/funny-weeks-smash.md new file mode 100644 index 000000000000..4972aa0a8445 --- /dev/null +++ b/.changeset/funny-weeks-smash.md @@ -0,0 +1,7 @@ +--- +'@solana/rpc-subscriptions': patch +'@solana/rpc-spec-types': patch +'@solana/rpc-spec': patch +--- + +Fixed a bug where the subcription server's response would not be detected, because of a mismatch in the format of the `id`. Now all RPC message ids are strings, for avoidance of doubt. diff --git a/packages/rpc-spec-types/src/__tests__/rpc-message-test.ts b/packages/rpc-spec-types/src/__tests__/rpc-message-test.ts index 671c8e66ec12..a4a90b6a4d2f 100644 --- a/packages/rpc-spec-types/src/__tests__/rpc-message-test.ts +++ b/packages/rpc-spec-types/src/__tests__/rpc-message-test.ts @@ -5,12 +5,12 @@ describe('createRpcMessage', () => { const request = { methodName: 'foo', params: 'bar' }; const { id: firstId } = createRpcMessage(request); const { id: secondId } = createRpcMessage(request); - expect(secondId - firstId).toBe(1); + expect(Number(secondId) - Number(firstId)).toBe(1); }); it('returns a well-formed JSON-RPC 2.0 message', () => { const request = { methodName: 'someMethod', params: [1, 2, 3] }; expect(createRpcMessage(request)).toStrictEqual({ - id: expect.any(Number), + id: expect.any(String), jsonrpc: '2.0', method: 'someMethod', params: [1, 2, 3], diff --git a/packages/rpc-spec-types/src/rpc-message.ts b/packages/rpc-spec-types/src/rpc-message.ts index 2cc05c7e9a0f..86586fe946c4 100644 --- a/packages/rpc-spec-types/src/rpc-message.ts +++ b/packages/rpc-spec-types/src/rpc-message.ts @@ -1,10 +1,10 @@ import { RpcRequest } from './rpc-request'; -let _nextMessageId = 0; -function getNextMessageId() { +let _nextMessageId = 0n; +function getNextMessageId(): string { const id = _nextMessageId; - _nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER; - return id; + _nextMessageId++; + return id.toString(); } export function createRpcMessage(request: RpcRequest) { diff --git a/packages/rpc-spec-types/src/rpc-response.ts b/packages/rpc-spec-types/src/rpc-response.ts index 7efba62a60a7..545ec649c587 100644 --- a/packages/rpc-spec-types/src/rpc-response.ts +++ b/packages/rpc-spec-types/src/rpc-response.ts @@ -7,7 +7,7 @@ export type RpcResponseTransformer = { }; interface IHasIdentifier { - readonly id: number; + readonly id: string; } type RpcErrorResponsePayload = Readonly<{ diff --git a/packages/rpc-spec/src/__tests__/rpc-test.ts b/packages/rpc-spec/src/__tests__/rpc-test.ts index 3bbe178b434d..9da0d9a483cd 100644 --- a/packages/rpc-spec/src/__tests__/rpc-test.ts +++ b/packages/rpc-spec/src/__tests__/rpc-test.ts @@ -59,7 +59,7 @@ describe('JSON-RPC 2.0', () => { .send() .catch(() => {}); expect(makeHttpRequest).toHaveBeenCalledWith({ - payload: { ...createRpcMessage({ methodName: 'someMethod', params: [123] }), id: expect.any(Number) }, + payload: { ...createRpcMessage({ methodName: 'someMethod', params: [123] }), id: expect.any(String) }, }); }); it('returns results from the transport', async () => { @@ -99,7 +99,7 @@ describe('JSON-RPC 2.0', () => { expect(makeHttpRequest).toHaveBeenCalledWith({ payload: { ...createRpcMessage({ methodName: 'someMethodAugmented', params: [123, 'augmented', 'params'] }), - id: expect.any(Number), + id: expect.any(String), }, }); }); diff --git a/packages/rpc-subscriptions/src/__tests__/rpc-subscriptions-functional-test.ts b/packages/rpc-subscriptions/src/__tests__/rpc-subscriptions-functional-test.ts index 12fb04a89fcb..61d47e22d5d0 100644 --- a/packages/rpc-subscriptions/src/__tests__/rpc-subscriptions-functional-test.ts +++ b/packages/rpc-subscriptions/src/__tests__/rpc-subscriptions-functional-test.ts @@ -23,8 +23,7 @@ describe('accountNotifications', () => { rpcSubscriptions = createLocalhostSolanaRpcSubscriptions(); }); - // eslint-disable-next-line jest/no-disabled-tests - it.skip('can subscribe to account notifications', async () => { + it('can subscribe to account notifications', async () => { expect.hasAssertions(); const abortSignal = new AbortController().signal; const subscriptionPromise = rpcSubscriptions