feat(web3): add ability to pass different websocket endpoint #17387 (#17556)

This commit is contained in:
Alexey Elizarov
2021-05-28 00:57:32 +03:00
committed by GitHub
parent ec1a307a7c
commit 94fffee158
4 changed files with 57 additions and 24 deletions

View File

@ -4,7 +4,7 @@ import {expect, use} from 'chai';
import chaiAsPromised from 'chai-as-promised';
import {Connection} from '../src';
import {url} from './url';
import {url, wsUrl} from './url';
import {sleep} from '../src/util/sleep';
use(chaiAsPromised);
@ -63,5 +63,21 @@ if (process.env.TEST_LIVE) {
await sleep(1100);
expect(connection._rpcWebSocketIdleTimeout).to.eq(null);
});
it('connect by websocket endpoint from options', async () => {
let connection = new Connection('', {
wsEndpoint: wsUrl,
});
const testSignature = bs58.encode(Buffer.alloc(64));
const id = connection.onSignature(testSignature, () => {});
// wait for websocket to connect
await sleep(100);
expect(connection._rpcWebSocketConnected).to.be.true;
expect(connection._rpcWebSocketHeartbeat).not.to.eq(null);
await connection.removeSignatureListener(id);
});
});
}