Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Add a failing test that verifies we can subscribe to an RPC subscript…
Browse files Browse the repository at this point in the history
…ion method (#3506)

In rc2 there's a bug where `await rpcSubscriptions.anyNotifications().subscribe()` hangs. Unlike `rpc-api` [all tests in `rpc-subscriptions-api` are currently commented out.  ](https://github.com/solana-labs/solana-web3.js/blob/master/packages/rpc-subscriptions-api/src/__tests__/account-notifications-test.ts)

This PR adds a (currently failing) test to subscribe to notifications against the localhost test validator.

Notes:

- I've put this test in `rpc-subscriptions` rather than `rpc-subscriptions-api` because it relies on transport functions from `rpc-subscriptions`. If we wanted to build a full suite of `rpc-subscriptions-api` tests later then we should probably move these transport functions to a different package where they could be a dependency of `rpc-subscriptions-api`. We currently have `rpc-transport-http` for this on the `rpc-api` side. 

- I used `it.skip` instead of `it.failing` because the test times out rather than failing, and Jest doesn't treat that as a pass for `it.failing`. Anyway I don't plan to leave it failing long!
  • Loading branch information
mcintyre94 authored Oct 31, 2024
1 parent f802b8e commit bd1cd50
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/rpc-subscriptions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
"@solana/rpc-types": "workspace:*",
"@solana/subscribable": "workspace:*"
},
"devDependencies": {
"@solana/addresses": "workspace:*"
},
"peerDependencies": {
"typescript": ">=5"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Address } from '@solana/addresses';
import { AccountNotificationsApi, SolanaRpcSubscriptionsApi } from '@solana/rpc-subscriptions-api';
import { createSubscriptionRpc, RpcSubscriptions } from '@solana/rpc-subscriptions-spec';

import {
createDefaultRpcSubscriptionsTransport,
createDefaultSolanaRpcSubscriptionsChannelCreator,
createSolanaRpcSubscriptionsApi,
} from '..';

function createLocalhostSolanaRpcSubscriptions(): RpcSubscriptions<SolanaRpcSubscriptionsApi> {
return createSubscriptionRpc({
api: createSolanaRpcSubscriptionsApi(),
transport: createDefaultRpcSubscriptionsTransport({
createChannel: createDefaultSolanaRpcSubscriptionsChannelCreator({ url: 'ws://localhost:8900' }),
}),
});
}

describe('accountNotifications', () => {
let rpcSubscriptions: RpcSubscriptions<AccountNotificationsApi>;
beforeEach(() => {
rpcSubscriptions = createLocalhostSolanaRpcSubscriptions();
});

// eslint-disable-next-line jest/no-disabled-tests
it.skip('can subscribe to account notifications', async () => {
expect.hasAssertions();
const abortSignal = new AbortController().signal;
const subscriptionPromise = rpcSubscriptions
.accountNotifications('4nTLDQiSTRHbngKZWPMfYnZdWTbKiNeuuPcX7yFUpSAc' as Address)
.subscribe({ abortSignal });

await expect(subscriptionPromise).resolves.toEqual(
expect.objectContaining({
[Symbol.asyncIterator]: expect.any(Function),
}),
);
});
});
4 changes: 4 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd1cd50

Please sign in to comment.