Skip to content

Commit

Permalink
refactor(experimental): a transport that coalesces multiple subscript…
Browse files Browse the repository at this point in the history
…ions behind a single subscription
  • Loading branch information
steveluscher committed Sep 29, 2023
1 parent 38ab0c7 commit c913f59
Show file tree
Hide file tree
Showing 6 changed files with 459 additions and 78 deletions.
3 changes: 1 addition & 2 deletions packages/library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
"@solana/keys": "workspace:*",
"@solana/rpc-core": "workspace:*",
"@solana/rpc-transport": "workspace:*",
"@solana/transactions": "workspace:*",
"fast-stable-stringify": "^1.0.0"
"@solana/transactions": "workspace:*"
},
"devDependencies": {
"@solana/eslint-config-solana": "^1.0.2",
Expand Down
68 changes: 1 addition & 67 deletions packages/library/src/__tests__/rpc-request-deduplication-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
getSolanaRpcPayloadDeduplicationKey,
getSolanaRpcSubscriptionPayloadDeduplicationKey,
} from '../rpc-request-deduplication';
import { getSolanaRpcPayloadDeduplicationKey } from '../rpc-request-deduplication';

describe('getSolanaRpcPayloadDeduplicationKey', () => {
it('produces no key for undefined payloads', () => {
Expand Down Expand Up @@ -55,66 +52,3 @@ describe('getSolanaRpcPayloadDeduplicationKey', () => {
);
});
});

describe('getSolanaRpcSubscriptionPayloadDeduplicationKey', () => {
it('produces no key for undefined payloads', () => {
expect(getSolanaRpcSubscriptionPayloadDeduplicationKey(undefined)).toBeUndefined();
});
it('produces no key for null payloads', () => {
expect(getSolanaRpcSubscriptionPayloadDeduplicationKey(null)).toBeUndefined();
});
it('produces no key for array payloads', () => {
expect(getSolanaRpcSubscriptionPayloadDeduplicationKey([])).toBeUndefined();
});
it('produces no key for string payloads', () => {
expect(getSolanaRpcSubscriptionPayloadDeduplicationKey('o hai')).toBeUndefined();
});
it('produces no key for numeric payloads', () => {
expect(getSolanaRpcSubscriptionPayloadDeduplicationKey(123)).toBeUndefined();
});
it('produces no key for bigint payloads', () => {
expect(getSolanaRpcSubscriptionPayloadDeduplicationKey(123n)).toBeUndefined();
});
it('produces no key for object payloads that are not JSON-RPC payloads', () => {
expect(getSolanaRpcSubscriptionPayloadDeduplicationKey({})).toBeUndefined();
});
it("produces a key for a JSON-RPC payload whose method ends in 'Subscribe'", () => {
expect(
getSolanaRpcSubscriptionPayloadDeduplicationKey({
id: 1,
jsonrpc: '2.0',
method: 'fooSubscribe',
params: 'foo',
})
).toMatchInlineSnapshot(`"["fooSubscribe","foo"]"`);
});
it("produces no key for a JSON-RPC payload whose method does not end in 'Subscribe'", () => {
expect(
getSolanaRpcSubscriptionPayloadDeduplicationKey({
id: 1,
jsonrpc: '2.0',
method: 'getFoo',
params: 'foo',
})
).toBeUndefined();
});
it('produces identical keys for two materially identical JSON-RPC payloads', () => {
expect(
getSolanaRpcSubscriptionPayloadDeduplicationKey({
id: 1,
jsonrpc: '2.0',
method: 'fooSubscribe',
params: { a: 1, b: { c: [2, 3], d: 4 } },
})
).toEqual(
/* eslint-disable sort-keys-fix/sort-keys-fix */
getSolanaRpcSubscriptionPayloadDeduplicationKey({
jsonrpc: '2.0',
method: 'fooSubscribe',
params: { b: { d: 4, c: [2, 3] }, a: 1 },
id: 2,
})
/* eslint-enable sort-keys-fix/sort-keys-fix */
);
});
});
Loading

0 comments on commit c913f59

Please sign in to comment.