aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/test/ws_orders_channel_test.ts
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-08-21 02:42:29 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-08-21 02:42:29 +0800
commit075e3a41c876797907e3ad98f20940e32e8d0762 (patch)
treed1f9db70ee1a56b500a3293a9ee962fd08f7abec /packages/connect/test/ws_orders_channel_test.ts
parentf2d1d953553adfa59f0a39bf2cf98817fae0a4ff (diff)
downloaddexon-0x-contracts-075e3a41c876797907e3ad98f20940e32e8d0762.tar
dexon-0x-contracts-075e3a41c876797907e3ad98f20940e32e8d0762.tar.gz
dexon-0x-contracts-075e3a41c876797907e3ad98f20940e32e8d0762.tar.bz2
dexon-0x-contracts-075e3a41c876797907e3ad98f20940e32e8d0762.tar.lz
dexon-0x-contracts-075e3a41c876797907e3ad98f20940e32e8d0762.tar.xz
dexon-0x-contracts-075e3a41c876797907e3ad98f20940e32e8d0762.tar.zst
dexon-0x-contracts-075e3a41c876797907e3ad98f20940e32e8d0762.zip
Update websocket for SRA v2
Diffstat (limited to 'packages/connect/test/ws_orders_channel_test.ts')
-rw-r--r--packages/connect/test/ws_orders_channel_test.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/packages/connect/test/ws_orders_channel_test.ts b/packages/connect/test/ws_orders_channel_test.ts
new file mode 100644
index 000000000..98eb24e6e
--- /dev/null
+++ b/packages/connect/test/ws_orders_channel_test.ts
@@ -0,0 +1,49 @@
+import * as chai from 'chai';
+import * as dirtyChai from 'dirty-chai';
+import * as _ from 'lodash';
+import 'mocha';
+import * as Sinon from 'sinon';
+import * as WebSocket from 'websocket';
+
+import { WebSocketOrdersChannel } from '../src/ws_orders_channel';
+
+chai.config.includeStack = true;
+chai.use(dirtyChai);
+const expect = chai.expect;
+const emptyOrdersChannelHandler = {
+ onUpdate: _.noop,
+ onError: _.noop,
+ onClose: _.noop,
+};
+
+describe('WebSocketOrdersChannel', () => {
+ const websocketUrl = 'ws://localhost:8080';
+ const openClient = new WebSocket.w3cwebsocket(websocketUrl);
+ Sinon.stub(openClient, 'readyState').get(() => WebSocket.w3cwebsocket.OPEN);
+ Sinon.stub(openClient, 'send').callsFake(_.noop.bind(_));
+ const openOrdersChannel = new WebSocketOrdersChannel(openClient, emptyOrdersChannelHandler);
+ const subscriptionOpts = {
+ baseAssetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ quoteAssetData: '0xef7fff64389b814a946f3e92105513705ca6b990',
+ limit: 100,
+ };
+ describe('#subscribe', () => {
+ it('throws when subscriptionOpts does not conform to schema', () => {
+ const badSubscribeCall = openOrdersChannel.subscribe.bind(openOrdersChannel, {
+ makerAssetData: 5,
+ });
+ expect(badSubscribeCall).throws();
+ });
+ it('does not throw when inputs are of correct types', () => {
+ const goodSubscribeCall = openOrdersChannel.subscribe.bind(openOrdersChannel, subscriptionOpts);
+ expect(goodSubscribeCall).to.not.throw();
+ });
+ it('throws when client is closed', () => {
+ const closedClient = new WebSocket.w3cwebsocket(websocketUrl);
+ Sinon.stub(closedClient, 'readyState').get(() => WebSocket.w3cwebsocket.CLOSED);
+ const closedOrdersChannel = new WebSocketOrdersChannel(closedClient, emptyOrdersChannelHandler);
+ const badSubscribeCall = closedOrdersChannel.subscribe.bind(closedOrdersChannel, subscriptionOpts);
+ expect(badSubscribeCall).throws('WebSocket connection is closed');
+ });
+ });
+});