aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect
diff options
context:
space:
mode:
Diffstat (limited to 'packages/connect')
-rw-r--r--packages/connect/package.json2
-rw-r--r--packages/connect/src/orderbook_channel_factory.ts14
-rw-r--r--packages/connect/src/types.ts2
-rw-r--r--packages/connect/test/orderbook_channel_factory_test.ts34
-rw-r--r--packages/connect/test/ws_orderbook_channel_test.ts26
5 files changed, 54 insertions, 24 deletions
diff --git a/packages/connect/package.json b/packages/connect/package.json
index 78cb3e71d..cc68d34f4 100644
--- a/packages/connect/package.json
+++ b/packages/connect/package.json
@@ -59,6 +59,7 @@
"isomorphic-fetch": "^2.2.1",
"lodash": "^4.17.4",
"query-string": "^5.0.1",
+ "sinon": "^4.0.0",
"websocket": "^1.0.25"
},
"devDependencies": {
@@ -68,6 +69,7 @@
"@types/lodash": "4.14.104",
"@types/mocha": "^2.2.42",
"@types/query-string": "^5.0.1",
+ "@types/sinon": "^2.2.2",
"@types/websocket": "^0.0.39",
"async-child-process": "^1.1.1",
"chai": "^4.0.1",
diff --git a/packages/connect/src/orderbook_channel_factory.ts b/packages/connect/src/orderbook_channel_factory.ts
index 1b5625840..5134af323 100644
--- a/packages/connect/src/orderbook_channel_factory.ts
+++ b/packages/connect/src/orderbook_channel_factory.ts
@@ -1,21 +1,27 @@
import * as WebSocket from 'websocket';
-import { OrderbookChannel } from './types';
+import { OrderbookChannel, OrderbookChannelHandler } from './types';
import { assert } from './utils/assert';
import { WebSocketOrderbookChannel } from './ws_orderbook_channel';
export const orderbookChannelFactory = {
/**
* Instantiates a new WebSocketOrderbookChannel instance
- * @param url The relayer API base WS url you would like to interact with
+ * @param url The relayer API base WS url you would like to interact with
+ * @param handler An OrderbookChannelHandler instance that responds to various
+ * channel updates
* @return An OrderbookChannel Promise
*/
- async createWebSocketOrderbookChannelAsync(url: string): Promise<OrderbookChannel> {
+ async createWebSocketOrderbookChannelAsync(
+ url: string,
+ handler: OrderbookChannelHandler,
+ ): Promise<OrderbookChannel> {
assert.isUri('url', url);
+ assert.isOrderbookChannelHandler('handler', handler);
return new Promise<OrderbookChannel>((resolve, reject) => {
const client = new WebSocket.w3cwebsocket(url);
client.onopen = () => {
- const orderbookChannel = new WebSocketOrderbookChannel(client);
+ const orderbookChannel = new WebSocketOrderbookChannel(client, handler);
resolve(orderbookChannel);
};
client.onerror = err => {
diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts
index d7d7a96d0..7347beb0b 100644
--- a/packages/connect/src/types.ts
+++ b/packages/connect/src/types.ts
@@ -11,7 +11,7 @@ export interface Client {
}
export interface OrderbookChannel {
- subscribe: (subscriptionOpts: OrderbookChannelSubscriptionOpts, handler: OrderbookChannelHandler) => void;
+ subscribe: (subscriptionOpts: OrderbookChannelSubscriptionOpts) => void;
close: () => void;
}
diff --git a/packages/connect/test/orderbook_channel_factory_test.ts b/packages/connect/test/orderbook_channel_factory_test.ts
index fd84332cc..d2140bfa6 100644
--- a/packages/connect/test/orderbook_channel_factory_test.ts
+++ b/packages/connect/test/orderbook_channel_factory_test.ts
@@ -9,18 +9,38 @@ import { orderbookChannelFactory } from '../src/orderbook_channel_factory';
chai.config.includeStack = true;
chai.use(dirtyChai);
const expect = chai.expect;
+const emptyOrderbookChannelHandler = {
+ onSnapshot: () => {
+ _.noop();
+ },
+ onUpdate: () => {
+ _.noop();
+ },
+ onError: () => {
+ _.noop();
+ },
+ onClose: () => {
+ _.noop();
+ },
+};
describe('orderbookChannelFactory', () => {
const websocketUrl = 'ws://localhost:8080';
-
describe('#createWebSocketOrderbookChannelAsync', () => {
it('throws when input is not a url', () => {
- const badInput = 54;
- const badSubscribeCall = orderbookChannelFactory.createWebSocketOrderbookChannelAsync.bind(
- orderbookChannelFactory,
- badInput,
- );
- expect(orderbookChannelFactory.createWebSocketOrderbookChannelAsync(badInput as any)).to.be.rejected();
+ const badUrlInput = 54;
+ expect(
+ orderbookChannelFactory.createWebSocketOrderbookChannelAsync(
+ badUrlInput as any,
+ emptyOrderbookChannelHandler,
+ ),
+ ).to.be.rejected();
+ });
+ it('throws when handler has the incorrect members', () => {
+ const badHandlerInput = {};
+ expect(
+ orderbookChannelFactory.createWebSocketOrderbookChannelAsync(websocketUrl, badHandlerInput as any),
+ ).to.be.rejected();
});
});
});
diff --git a/packages/connect/test/ws_orderbook_channel_test.ts b/packages/connect/test/ws_orderbook_channel_test.ts
index f4ad67ba3..fed4f2217 100644
--- a/packages/connect/test/ws_orderbook_channel_test.ts
+++ b/packages/connect/test/ws_orderbook_channel_test.ts
@@ -2,6 +2,7 @@ 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 { WebSocketOrderbookChannel } from '../src/ws_orderbook_channel';
@@ -26,8 +27,10 @@ const emptyOrderbookChannelHandler = {
describe('WebSocketOrderbookChannel', () => {
const websocketUrl = 'ws://localhost:8080';
- const client = new WebSocket.w3cwebsocket(websocketUrl);
- const orderbookChannel = new WebSocketOrderbookChannel(client, emptyOrderbookChannelHandler);
+ const openClient = new WebSocket.w3cwebsocket(websocketUrl);
+ Sinon.stub(openClient, 'readyState').get(() => WebSocket.w3cwebsocket.OPEN);
+ Sinon.stub(openClient, 'send').callsFake(_.noop);
+ const openOrderbookChannel = new WebSocketOrderbookChannel(openClient, emptyOrderbookChannelHandler);
const subscriptionOpts = {
baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
quoteTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990',
@@ -36,22 +39,21 @@ describe('WebSocketOrderbookChannel', () => {
};
describe('#subscribe', () => {
it('throws when subscriptionOpts does not conform to schema', () => {
- const badSubscribeCall = orderbookChannel.subscribe.bind(
- orderbookChannel,
- {},
- emptyOrderbookChannelHandler,
- );
+ const badSubscribeCall = openOrderbookChannel.subscribe.bind(openOrderbookChannel, {});
expect(badSubscribeCall).throws(
'Expected subscriptionOpts to conform to schema /RelayerApiOrderbookChannelSubscribePayload\nEncountered: {}\nValidation errors: instance requires property "baseTokenAddress", instance requires property "quoteTokenAddress"',
);
});
it('does not throw when inputs are of correct types', () => {
- const goodSubscribeCall = orderbookChannel.subscribe.bind(
- orderbookChannel,
- subscriptionOpts,
- emptyOrderbookChannelHandler,
- );
+ const goodSubscribeCall = openOrderbookChannel.subscribe.bind(openOrderbookChannel, 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 closedOrderbookChannel = new WebSocketOrderbookChannel(closedClient, emptyOrderbookChannelHandler);
+ const badSubscribeCall = closedOrderbookChannel.subscribe.bind(closedOrderbookChannel, subscriptionOpts);
+ expect(badSubscribeCall).throws('WebSocket connection is closed');
+ });
});
});
8 03:52:13 +0800'>2012-06-281-6/+6 * - reset MAINTAINERdinoex2012-06-261-1/+1 * s/X11BASE/LOCALBASE/, or equivalent.dougb2012-06-255-8/+8 * Style fix: include bsd.port.pre.mk before using SRC_BASE.hrs2012-06-201-2/+4 * - Update MASTER_SITES and WWW: linesylvio2012-06-182-7/+12 * KDE/FreeBSD team presents KDE SC 4.8.4, probably the last release in 4.8.x se...makc2012-06-153-4/+2 * Update to 7.0.5p3 and convert to OptionsNG.ale2012-06-134-142/+12 * Update to 9.5.1.hrs2012-06-132-3/+3 * 2012-05-10 print/cups-magicolor: BROKEN for more than 6 monthbapt2012-06-136-110/+0 * Style fix.hrs2012-06-131-7/+4 * - Add LICENSE.hrs2012-06-136-396/+990 * Update to 2.1.9 release.ale2012-06-124-49/+3 * - Add LICENSE.hrs2012-06-125-391/+953 * - fix option GHOSTSCRIPTdinoex2012-06-111-6/+9 * - use OPTIONS_DEFINEdinoex2012-06-113-51/+36 * - Convert all remaining instances of BUILD_DEPENDS=${RUN_DEPENDS} orswills2012-06-114-4/+4 * - Mark BROKEN: incorrect plist (%%DATADIR%% followed with literal value ofpav2012-06-101-0/+2 * - update to 0.5dinoex2012-06-082-3/+3 * - Convert USE_QT_VER=4 and QT_COMPONETS to USE_QT4miwi2012-06-068-16/+8 * - Update to 0.9.1.11swills2012-06-062-3/+3 * - Remove SITE_PERL from *_DEPENDSaz2012-06-061-1/+1 * - Remove obsoleted Haskell ports:pgj2012-06-043-30/+0 * - Update The Glorious Glasgow Haskell Compiler to version 7.4.1pgj2012-06-042-2/+9 * - do not drop spool on updatedinoex2012-06-011-1/+1 * - update png to 1.5.10dinoex2012-06-01158-144/+293 * - Fix problem of duplicate LATEST_LINK values with scribus-devel port.sylvio2012-05-311-0/+1 * Avoid namespace collisions between the embedded (modified) png libraryale2012-05-292-0/+128 * New options framework for the portsbapt2012-05-292-1/+10 * - Update to 1.5.0beech2012-05-296-1658/+3057 * - Update to 6.6.15.araujo2012-05-282-3/+3 * - Update to 1.2.9sylvio2012-05-263-14/+3 * Fix brokenness caused by graphics/xpdf r1.102.cy2012-05-251-3/+5 * KDE/FreeBSD team presents long awaited KDE SC 4.8.3!makc2012-05-255-15/+9 * Chase PyQT updatemakc2012-05-252-1/+2 * - Mark BROKEN: xpdf port no longer installs anything under bin/pav2012-05-241-0/+2 * - Update to version 4miwi2012-05-224-52/+31 * - Update to 2.0.1jgh2012-05-225-134/+28 * - Update texinfo to latest version (16 May)johans2012-05-212-5/+6 * Remove the auto-check dependency and able to use OPTIONS now.mezz2012-05-211-8/+3 * Mark IGNORE with php 5.4 and set 5.3 as default.ale2012-05-201-1/+2 * This is a beginning-of-page hook for LaTeX.pawel2012-05-194-0/+54 * The examplep LaTeX package provides sophisticated featurespawel2012-05-194-0/+58 * Remove expired unmaintained ports:rene2012-05-189-149/+0 * - Update to 1.0.3miwi2012-05-172-5/+4 * Fix for PHP 5.4.ale2012-05-162-0/+45 * - Update to 1.4.1sylvio2012-05-163-325/+663 * Update autoconf to 2.69 and automake to 1.12ade2012-05-121-0/+3 * - Follow the upstream change for the download location [1]rene2012-05-091-3/+3 * - Update to 1.2.18nivit2012-05-032-4/+9 * Add missing run dependency on ghostscriptpawel2012-04-281-1/+2 * Update to 4.2.0 .nox2012-04-252-3/+3 * - Update to 4.31jgh2012-04-213-11/+18 * No more used in the ports tree, no more upstreambapt2012-04-191-0/+3 * - Remove MD5.araujo2012-04-181-1/+0 * - Update to 6.6.9.araujo2012-04-152-6/+6 * Mark as deprecated and set expiration to 2012-05-10 for ports that are mark a...bapt2012-04-101-0/+3 * Fix build. FT_BRIDGE=1 no longer needs FT_* variables, and the freetypehrs2012-04-071-13/+2 * Fix ghostscript 9 runtime. By adding 2 upstream commits.kwm2012-04-072-0/+102 * Update to latest texinfo.tex and texi2dvi versions (6 April)johans2012-04-072-6/+5 * Update to 2.4.9.kwm2012-04-072-3/+3 * - Reassign to the heaptabthorpe2012-04-031-1/+1 * Add a patch to allow specifying remote printer by IP-address, rathermi2012-04-034-7/+25 * Mark as broken: it overwrites files owned by one of its dependenciesbapt2012-04-021-0/+1 * - Update to 0.6.1wen2012-04-012-3/+3 * Stop installing empty ppd files due to a forgotten " ; \" in the upstreamcrees2012-03-222-14/+15 * Update to 2.0.3rakuco2012-03-215-184/+15 * - rename broken option DNSSD to AVAHIdinoex2012-03-202-5/+17 * - Update to 2.4.9miwi2012-03-182-4/+4 * Fix MASTERDIR.hrs2012-03-181-1/+1 * Add etc/papersize.{a4,letter}.hrs2012-03-172-0/+12 * Use libpaper for default paper size configuration. It is no longer hardcodedhrs2012-03-171-2/+7 * Add print/papersize-default-{a4,letter}, which install default paper sizehrs2012-03-175-0/+51 * - Set / Update Portscout flagsmiwi2012-03-171-1/+3 * Policy "at_console" work in Linux, but don't work in FreeBSD so changed itmezz2012-03-142-1/+11 * - Revert ports/165605 as requested by portmgr@pgollucci2012-03-142-2/+16 * - Update to 1.9.61sunpoet2012-03-122-3/+3 * - Remove ports that only work with < perl 5.12 (devel/p5-B-Size, devel/p5-Dev...pgollucci2012-03-092-16/+2 * Update MASTER_SITESak2012-03-041-1/+3 * Update maintainer email in my portsak2012-03-031-1/+1 * Disable libpaper by default because it can override the A4SIZE optionhrs2012-02-291-4/+10 * Take maintainership.hrs2012-02-291-1/+1 * - Remove .aux and .log files in PORTDOCS.hrs2012-02-292-11/+4 * Fix implicit dependency.hrs2012-02-291-0/+5 * Mark BROKEN: does not build with gifliberwin2012-02-281-0/+2 * Return maintainership back to poolmm2012-02-261-1/+1 * - Switch from libungif to giflib to avoid conflictswills2012-02-261-1/+1 * - Update to 0.5.6wen2012-02-252-3/+3 * - Chase Emacs updatesashish2012-02-221-1/+1 * - build with giflibdinoex2012-02-211-1/+2 * - Mark MAKE_JOBS_UNSAFE since this failed with MAKE_JOBS for meswills2012-02-211-0/+1 * - fix build for FreeBSD 7.xdinoex2012-02-201-0/+6 * - Switch to giflibswills2012-02-201-2/+2 * - Update to version 1.0b7miwi2012-02-206-74/+54 * - replace `YES' with `yes' in USE_PYTHON/USE_PYDISTUTILS (mostly)rm2012-02-191-5/+5 * Update to 3.12.2makc2012-02-193-3/+9 * - add USE_ICONV to cups-clientdinoex2012-02-171-0/+3 * - Bump PORTREVISION to chase the update of multimedia/libvpxashish2012-02-163-0/+3 * Update mime and desktop databases via @exec and @unexec at pkg-plist.bsam2012-02-162-0/+5 * Update to version 1.4.0. The new version uses QT4.bsam2012-02-157-750/+2220 * Fix build on systems which already have graphics/openjpeg in LOCALBASE.hrs2012-02-142-3/+5 * - update to 1.5.2dinoex2012-02-141-1/+1 * - update to 1.5.2dinoex2012-02-144-38/+161 * Fix a URL in MASTER_SITES.hrs2012-02-132-2/+2 * - Please welcome GHC 7.0.4pgj2012-02-132-2/+2 * Add missing patches. This should fix build on !amd64 platforms.hrs2012-02-135-2/+44 * - Update MASTER_SITES.hrs2012-02-133-7/+15 * Update to 9.05. Changes include:hrs2012-02-1311-144/+105 * - convert to using PYTHON_SITELIBDIR (non-functional change)rm2012-02-131-2/+2 * Update to 0.23.1makc2012-02-093-13/+20 * Remove whitespace after b.p.m to help reduce false postives when searching fo...eadler2012-02-081-1/+0 * The variable is USE_PERL5 not USE_PERLeadler2012-02-072-2/+2 * Upgrade to 1.7.thierry2012-02-063-111/+108 * - update maintainer addressjgh2012-02-051-1/+1 * Add the last two ports I added to buildeadler2012-02-041-0/+1 * pdfcolorsplit - a Python program that drives pdftk to split a PDF file intoeadler2012-02-043-0/+42 * Add a .desktop file for the port. An upstream version will show up in the 2.1.xrakuco2012-01-293-0/+31 * The KDE/FreeBSD team is pleased to announce KDE SC 4.7.4, whichavilla2012-01-252-1/+13 * Create a missing directory for the manual page in the German and French version.hrs2012-01-242-2/+7 * - Add LICENSE.hrs2012-01-231-2/+7 * - Update to 9.4.7 (English version only)hrs2012-01-223-9/+22 * At the moment 1385 ports use BUILD_DEPENDS= ${RUN_DEPENDS} and 450eadler2012-01-226-6/+6 * - Update to 1.3.6.araujo2012-01-202-3/+3 * - Reset ports due to maintainer timeouts and lack of response to emailstabthorpe2012-01-191-1/+1 * Update to 3.11.12makc2012-01-164-11/+44 * Update to 9.04.hrs2012-01-1510-97/+74 * - Update to 2.92miwi2012-01-152-3/+3 * - escape shell namesdinoex2012-01-141-5/+5 * In the rc.d scripts, change assignments to rcvar to use thedougb2012-01-144-4/+4 * Add the missing dependency to gnutls.netchild2012-01-141-0/+2 * Fix port.ale2012-01-131-2/+2 * - Add forgotten patchale2012-01-134-10/+47 * Update to 2.0.2.rakuco2012-01-125-9/+171 * Chase pdflib.so version and bump PORTREVISION accordingly.ale2012-01-101-1/+2 * Update to 7.0.5 release and remove unneeded libtool hacks.ale2012-01-104-20/+6 * - The proper acronym for Apache Software License 2 is really AL2tabthorpe2012-01-091-1/+1 * Add a symlink so ldconfig can find the shared object.jlaffaye2012-01-032-1/+10 * - Update to version 0.7 [1]pawel2011-12-295-21/+57 * - Unbreak and update to 0.0.4-betalwhsu2011-12-222-6/+4 * - Fix PLIST when building WITHOUT_NLSgahr2011-12-202-16/+23 * - Builds on 9.x nowscheidell2011-12-151-8/+3 * Avoid Makefile, our implicit rules (in sys.mk) are better.sanpei2011-12-131-0/+2 * update to 3.7.3bf2011-12-063-15/+9 * Remove these ports as they are no longer included in the upstreamswills2011-12-064-70/+0 * Fix build with fltk-1.3.0.cy2011-12-044-1/+43 * Update to 2.6.1jlaffaye2011-12-012-5/+5 * Fix build errors due to cups 1.5.0.cy2011-11-303-5/+22 * - Update to 2.4.7miwi2011-11-262-3/+3 * - fix case problems with PAPERSIZEdinoex2011-11-192-10/+13 * Update to 0.9.1 official release.ale2011-11-173-5/+35 * - Change gcc dep from 4.5+ to 4.6+glarkin2011-11-161-1/+2 * Remove CMAKE_USE_PTHREAD from the ports using it.rakuco2011-11-142-2/+0 * - Fix buildtabthorpe2011-11-122-2/+10 * Mark as broken on latest -9: fails to compile.linimon2011-11-111-1/+7 * - Remove WITH_FBSD10_FIX, is no longer neededmiwi2011-11-092-2/+0 * Add EXPIRATION_DATE= 2011-11-30 to recently BROKEN ports that do notdougb2011-11-021-0/+1 * Update to 2.4.7.kwm2011-11-022-4/+4 * Update poppler to 0.18.0.kwm2011-10-311-1/+3 * - Fix build with FreeBSD 10miwi2011-10-291-0/+1 * - Fix build on FreeBSD 10miwi2011-10-291-0/+1 * Consistify spelling of "Xfce", and some other projects while there.rene2011-10-271-1/+1 * update print/flpsed to 0.7.0, and www/dillo2 to 3.0.1,bf2011-10-263-27/+15 * The vast majority of pkg-descr files had the following format when theydougb2011-10-246-15/+1 * Remove more tags from pkg-descr files fo the form:dougb2011-10-2413-32/+0 * - Return my ports back to the pool. I was unable to make any fixes tostas2011-10-241-1/+1 * Re-assign to the Xfce team.rene2011-10-231-1/+1 * - Add p5-PostScript-PPD 0.0203sunpoet2011-10-215-0/+44 * - add some hooksdinoex2011-10-201-3/+3 * - Chase editors/emacs updateashish2011-10-171-1/+1 * - Unbreak and update to version 5.2.7pawel2011-10-1713-31/+337 * The KDE/FreeBSD team is pleased to announce KDE Software Compilationavilla2011-10-174-17/+25 * - Update to 1.9.60sunpoet2011-10-152-4/+3 * - Unbreakpav2011-10-153-2/+20 * - Mark BROKEN: does not compilepav2011-10-151-0/+2 * - Fix buildpav2011-10-151-0/+10 * - Mark BROKEN: does not compilepav2011-10-151-0/+2 * Fix the build with cups 1.5.0.kwm2011-10-141-0/+21 * - Fix build with new cupspav2011-10-142-0/+20 * Update to 3.11.10makc2011-10-144-15/+15 * Fix build after cups updatemakc2011-10-121-0/+10 * - Mark BROKEN after cups update: does not compilepav2011-10-091-0/+2 * - Mark BROKEN: does not compilepav2011-10-091-0/+2 * Remove ports maintainted by ports@ which have passed their EXPIRATION_DATEdougb2011-10-096-81/+0 * Remove print/lyx14.rakuco2011-10-069-1366/+0 * - force build with same cups client installeddinoex2011-10-061-3/+6 * - update to 1.5.0dinoex2011-10-051-1/+1 * - update to 1.5.0dinoex2011-10-054-76/+62 * - Update to 1.9.59sunpoet2011-10-052-3/+3 * - Unbreak, update to 2.5lwhsu2011-09-295-38/+126 * - use cups-clientdinoex2011-09-272-1/+3 * - Add LDFLAGS to CONFIGURE_ENV and MAKE_ENV (as it was done with LDFLAGS)amdmi32011-09-24