cleaning for ws tests
This commit is contained in:
@@ -68,12 +68,10 @@ describe('Private Inverse Perps Websocket Client', () => {
|
||||
it('should open a ws connection', async () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.inverse,
|
||||
});
|
||||
|
||||
await Promise.all([wsOpenPromise]);
|
||||
});
|
||||
|
||||
it('should subscribe to private wallet events', async () => {
|
||||
|
||||
@@ -30,12 +30,14 @@ describe('Public Inverse Perps Websocket Client', () => {
|
||||
it('should open a public ws connection', async () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.inverse,
|
||||
});
|
||||
|
||||
await Promise.all([wsOpenPromise]);
|
||||
try {
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.inverse,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
});
|
||||
|
||||
it('should subscribe to public orderBookL2_25 events', async () => {
|
||||
|
||||
@@ -71,12 +71,14 @@ describe('Private Linear Perps Websocket Client', () => {
|
||||
it('should open a ws connection', async () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.linearPrivate,
|
||||
});
|
||||
|
||||
await Promise.all([wsOpenPromise]);
|
||||
try {
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.linearPrivate,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
});
|
||||
|
||||
it('should subscribe to private wallet events', async () => {
|
||||
|
||||
@@ -23,17 +23,16 @@ describe('Public Linear Perps Websocket Client', () => {
|
||||
|
||||
afterAll(() => {
|
||||
wsClient.closeAll();
|
||||
wsClient.removeAllListeners();
|
||||
});
|
||||
|
||||
it('should open a public ws connection', async () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.linearPublic,
|
||||
});
|
||||
|
||||
await Promise.all([wsOpenPromise]);
|
||||
});
|
||||
|
||||
it('should subscribe to public orderBookL2_25 events', async () => {
|
||||
@@ -41,33 +40,27 @@ describe('Public Linear Perps Websocket Client', () => {
|
||||
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
const wsTopic = 'orderBookL2_25.BTCUSDT';
|
||||
expect(wsResponsePromise).resolves.toMatchObject({
|
||||
request: {
|
||||
args: [wsTopic],
|
||||
op: 'subscribe',
|
||||
},
|
||||
success: true,
|
||||
});
|
||||
expect(wsUpdatePromise).resolves.toMatchObject({
|
||||
topic: wsTopic,
|
||||
data: {
|
||||
order_book: expect.any(Array),
|
||||
},
|
||||
});
|
||||
|
||||
wsClient.subscribe(wsTopic);
|
||||
|
||||
try {
|
||||
await wsResponsePromise;
|
||||
expect(await wsResponsePromise).toMatchObject({
|
||||
request: {
|
||||
args: [wsTopic],
|
||||
op: 'subscribe',
|
||||
},
|
||||
success: true,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(
|
||||
`Wait for "${wsTopic}" subscription response exception: `,
|
||||
e
|
||||
);
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
|
||||
try {
|
||||
await wsUpdatePromise;
|
||||
expect(await wsUpdatePromise).toMatchObject({
|
||||
topic: wsTopic,
|
||||
data: {
|
||||
order_book: expect.any(Array),
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(`Wait for "${wsTopic}" event exception: `, e);
|
||||
}
|
||||
@@ -78,13 +71,6 @@ describe('Public Linear Perps Websocket Client', () => {
|
||||
// const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
const wsTopic = 'wallet';
|
||||
expect(wsResponsePromise).resolves.toMatchObject({
|
||||
request: {
|
||||
args: [wsTopic],
|
||||
op: 'subscribe',
|
||||
},
|
||||
success: true,
|
||||
});
|
||||
|
||||
// No easy way to trigger a private event (other than executing trades)
|
||||
// expect(wsUpdatePromise).resolves.toMatchObject({
|
||||
@@ -95,9 +81,15 @@ describe('Public Linear Perps Websocket Client', () => {
|
||||
wsClient.subscribe(wsTopic);
|
||||
|
||||
try {
|
||||
await Promise.all([wsResponsePromise]);
|
||||
expect(await wsResponsePromise).toBeFalsy();
|
||||
} catch (e) {
|
||||
//
|
||||
expect(e).toMatchObject({
|
||||
request: {
|
||||
args: [wsTopic],
|
||||
op: 'subscribe',
|
||||
},
|
||||
success: false,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -46,15 +46,20 @@ describe('Private Spot V1 Websocket Client', () => {
|
||||
|
||||
wsClient.connectPrivate();
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.spotPrivate,
|
||||
});
|
||||
try {
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
// wsKey: WS_KEY_MAP.spotPrivate,
|
||||
// also opens public conn automatically, which can confuse the test
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
// expect(wsUpdatePromise).resolves.toMatchObject({
|
||||
// topic: 'wsTopic',
|
||||
// data: expect.any(Array),
|
||||
// });
|
||||
await Promise.all([wsOpenPromise]);
|
||||
|
||||
// await Promise.all([wsUpdatePromise]);
|
||||
// await promiseSleep(4000);
|
||||
});
|
||||
|
||||
@@ -79,13 +79,11 @@ describe('Private Spot V3 Websocket Client', () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.spotV3Private,
|
||||
});
|
||||
|
||||
try {
|
||||
await Promise.all([wsOpenPromise]);
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.spotV3Private,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
|
||||
@@ -34,12 +34,14 @@ describe('Public Spot V1 Websocket Client', () => {
|
||||
it('should open a public ws connection', async () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.spotPublic,
|
||||
});
|
||||
|
||||
await Promise.all([wsOpenPromise]);
|
||||
try {
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.spotPublic,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
});
|
||||
|
||||
it('should subscribe to public orderbook events', async () => {
|
||||
|
||||
@@ -34,12 +34,14 @@ describe('Public Spot V3 Websocket Client', () => {
|
||||
it('should open a public ws connection', async () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.spotV3Public,
|
||||
});
|
||||
|
||||
await Promise.all([wsOpenPromise]);
|
||||
try {
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.spotV3Public,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
});
|
||||
|
||||
it('should subscribe to public orderbook events', async () => {
|
||||
|
||||
@@ -77,7 +77,6 @@ describe('Private USDC Option Websocket Client', () => {
|
||||
wsClientOptions,
|
||||
getSilentLogger('expectSuccess')
|
||||
);
|
||||
wsClient.connectPrivate();
|
||||
// logAllEvents(wsClient);
|
||||
});
|
||||
|
||||
@@ -86,16 +85,15 @@ describe('Private USDC Option Websocket Client', () => {
|
||||
});
|
||||
|
||||
it('should open a private ws connection', async () => {
|
||||
wsClient.connectPrivate();
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.usdcOptionPrivate,
|
||||
});
|
||||
|
||||
try {
|
||||
await Promise.all([wsOpenPromise]);
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.usdcOptionPrivate,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
@@ -113,6 +111,7 @@ describe('Private USDC Option Websocket Client', () => {
|
||||
});
|
||||
|
||||
it(`should subscribe to private "${wsTopic}" events`, async () => {
|
||||
wsClient.connectPrivate();
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
|
||||
@@ -31,13 +31,14 @@ describe('Public USDC Option Websocket Client', () => {
|
||||
|
||||
it('should open a public ws connection', async () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.usdcOptionPublic,
|
||||
});
|
||||
|
||||
await Promise.all([wsOpenPromise]);
|
||||
try {
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.usdcOptionPublic,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
});
|
||||
|
||||
it('should subscribe to public trade events', async () => {
|
||||
|
||||
@@ -89,13 +89,11 @@ describe('Private USDC Perp Websocket Client', () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.usdcPerpPrivate,
|
||||
});
|
||||
|
||||
try {
|
||||
await Promise.all([wsOpenPromise]);
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.usdcPerpPrivate,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
|
||||
@@ -33,12 +33,10 @@ describe('Public USDC Perp Websocket Client', () => {
|
||||
it('should open a public ws connection', async () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.usdcPerpPublic,
|
||||
});
|
||||
|
||||
await Promise.all([wsOpenPromise]);
|
||||
});
|
||||
|
||||
it('should subscribe to public trade events', async () => {
|
||||
|
||||
Reference in New Issue
Block a user