From c1cc92a46f9ebfa4408a5dc515f1e100fe3a7054 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 14 Aug 2018 14:00:16 -0700 Subject: Change names of basic types in Client interface --- packages/connect/src/http_client.ts | 8 ++++---- packages/connect/src/index.ts | 2 +- packages/connect/src/schemas/schemas.ts | 4 ++-- .../src/schemas/token_pairs_request_opts_schema.ts | 4 ++-- packages/connect/src/types.ts | 13 ++++++++++--- packages/connect/test/http_client_test.ts | 18 +++++++++--------- 6 files changed, 28 insertions(+), 21 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 03cc590e4..1b51ee429 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -7,6 +7,7 @@ import * as queryString from 'query-string'; import { schemas as clientSchemas } from './schemas/schemas'; import { + AssetPairsRequestOpts, Client, FeesRequest, FeesResponse, @@ -17,7 +18,6 @@ import { OrdersRequestOpts, PagedRequestOpts, TokenPairsItem, - TokenPairsRequestOpts, } from './types'; import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers'; @@ -69,9 +69,9 @@ export class HttpClient implements Client { * @param requestOpts Options specifying token information to retrieve and page information, defaults to { page: 1, perPage: 100 } * @return The resulting TokenPairsItems that match the request */ - public async getTokenPairsAsync(requestOpts?: TokenPairsRequestOpts & PagedRequestOpts): Promise { + public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise { if (!_.isUndefined(requestOpts)) { - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.tokenPairsRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.AssetPairsRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); } const httpRequestOpts = { @@ -135,7 +135,7 @@ export class HttpClient implements Client { * @param request A FeesRequest instance describing the specific fees to retrieve * @return The resulting FeesResponse that matches the request */ - public async getFeesAsync(request: FeesRequest): Promise { + public async getOrderConfigAsync(request: FeesRequest): Promise { assert.doesConformToSchema('request', request, clientSchemas.feesRequestSchema); const httpRequestOpts = { payload: request, diff --git a/packages/connect/src/index.ts b/packages/connect/src/index.ts index 7f5eb8ed3..a4fc39425 100644 --- a/packages/connect/src/index.ts +++ b/packages/connect/src/index.ts @@ -12,7 +12,7 @@ export { OrdersRequestOpts, PagedRequestOpts, TokenPairsItem, - TokenPairsRequestOpts, + AssetPairsRequestOpts, TokenTradeInfo, } from './types'; diff --git a/packages/connect/src/schemas/schemas.ts b/packages/connect/src/schemas/schemas.ts index 0b8b798a9..e6ca010ae 100644 --- a/packages/connect/src/schemas/schemas.ts +++ b/packages/connect/src/schemas/schemas.ts @@ -2,12 +2,12 @@ import { feesRequestSchema } from './fees_request_schema'; import { orderBookRequestSchema } from './orderbook_request_schema'; import { ordersRequestOptsSchema } from './orders_request_opts_schema'; import { pagedRequestOptsSchema } from './paged_request_opts_schema'; -import { tokenPairsRequestOptsSchema } from './token_pairs_request_opts_schema'; +import { AssetPairsRequestOptsSchema } from './token_pairs_request_opts_schema'; export const schemas = { feesRequestSchema, orderBookRequestSchema, ordersRequestOptsSchema, pagedRequestOptsSchema, - tokenPairsRequestOptsSchema, + AssetPairsRequestOptsSchema, }; diff --git a/packages/connect/src/schemas/token_pairs_request_opts_schema.ts b/packages/connect/src/schemas/token_pairs_request_opts_schema.ts index 9b73a917b..dffd063d0 100644 --- a/packages/connect/src/schemas/token_pairs_request_opts_schema.ts +++ b/packages/connect/src/schemas/token_pairs_request_opts_schema.ts @@ -1,5 +1,5 @@ -export const tokenPairsRequestOptsSchema = { - id: '/TokenPairsRequestOpts', +export const AssetPairsRequestOptsSchema = { + id: '/AssetPairsRequestOpts', type: 'object', properties: { tokenA: { $ref: '/Address' }, diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index fc7a4b24d..ca56d251b 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -2,11 +2,11 @@ import { SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; export interface Client { - getTokenPairsAsync: (requestOpts?: TokenPairsRequestOpts & PagedRequestOpts) => Promise; + getAssetPairsAsync: (requestOpts?: AssetPairsRequestOpts & PagedRequestOpts) => Promise; getOrdersAsync: (requestOpts?: OrdersRequestOpts & PagedRequestOpts) => Promise; getOrderAsync: (orderHash: string) => Promise; getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise; - getFeesAsync: (request: FeesRequest) => Promise; + getOrderConfigAsync: (request: FeesRequest) => Promise; submitOrderAsync: (signedOrder: SignedOrder) => Promise; } @@ -83,7 +83,7 @@ export enum WebsocketClientEventType { ConnectFailed = 'connectFailed', } -export interface TokenPairsRequestOpts { +export interface AssetPairsRequestOpts { tokenA?: string; tokenB?: string; } @@ -121,6 +121,13 @@ export interface OrderbookResponse { asks: SignedOrder[]; } +export interface PaginatedCollectionResponse { + total: number; + page: number; + perPage: number; + records: T[]; +} + export interface FeesRequest { exchangeContractAddress: string; maker: string; diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 311dc96e6..38327b090 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -38,29 +38,29 @@ describe('HttpClient', () => { expect(sanitizedUrl).to.be.deep.equal(urlWithoutTrailingSlash); }); }); - describe('#getTokenPairsAsync', () => { + describe('#getAssetPairsAsync', () => { const url = `${relayUrl}/token_pairs`; it('gets token pairs with default options when none are provided', async () => { const urlWithQuery = `${url}?page=1&per_page=100`; fetchMock.get(urlWithQuery, tokenPairsResponseJSON); - const tokenPairs = await relayerClient.getTokenPairsAsync(); + const tokenPairs = await relayerClient.getAssetPairsAsync(); expect(tokenPairs).to.be.deep.equal(tokenPairsResponse); }); it('gets token pairs with specified request options', async () => { const tokenAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d'; - const tokenPairsRequestOpts = { + const AssetPairsRequestOpts = { tokenA: tokenAddress, page: 3, perPage: 50, }; const urlWithQuery = `${url}?page=3&per_page=50&tokenA=${tokenAddress}`; fetchMock.get(urlWithQuery, tokenPairsResponseJSON); - const tokenPairs = await relayerClient.getTokenPairsAsync(tokenPairsRequestOpts); + const tokenPairs = await relayerClient.getAssetPairsAsync(AssetPairsRequestOpts); expect(tokenPairs).to.be.deep.equal(tokenPairsResponse); }); it('throws an error for invalid JSON response', async () => { fetchMock.get(url, { test: 'dummy' }); - expect(relayerClient.getTokenPairsAsync()).to.be.rejected(); + expect(relayerClient.getAssetPairsAsync()).to.be.rejected(); }); }); describe('#getOrdersAsync', () => { @@ -132,7 +132,7 @@ describe('HttpClient', () => { expect(relayerClient.getOrderbookAsync(request)).to.be.rejected(); }); }); - describe('#getFeesAsync', () => { + describe('#getOrderConfigAsync', () => { const request = { exchangeContractAddress: '0x12459c951127e0c374ff9105dda097662a027093', maker: '0x9e56625509c2f60af937f23b7b532600390e8c8b', @@ -147,7 +147,7 @@ describe('HttpClient', () => { const url = `${relayUrl}/fees`; it('gets fees', async () => { fetchMock.post(url, feesResponseJSON); - const fees = await relayerClient.getFeesAsync(request); + const fees = await relayerClient.getOrderConfigAsync(request); expect(fees).to.be.deep.equal(feesResponse); }); it('does not mutate input', async () => { @@ -156,7 +156,7 @@ describe('HttpClient', () => { const takerTokenAmountBefore = new BigNumber(request.takerTokenAmount); const saltBefore = new BigNumber(request.salt); const expirationUnixTimestampSecBefore = new BigNumber(request.expirationUnixTimestampSec); - await relayerClient.getFeesAsync(request); + await relayerClient.getOrderConfigAsync(request); expect(makerTokenAmountBefore).to.be.deep.equal(request.makerTokenAmount); expect(takerTokenAmountBefore).to.be.deep.equal(request.takerTokenAmount); expect(saltBefore).to.be.deep.equal(request.salt); @@ -164,7 +164,7 @@ describe('HttpClient', () => { }); it('throws an error for invalid JSON response', async () => { fetchMock.post(url, { test: 'dummy' }); - expect(relayerClient.getFeesAsync(request)).to.be.rejected(); + expect(relayerClient.getOrderConfigAsync(request)).to.be.rejected(); }); }); }); -- cgit v1.2.3 From ce88086e080e05ed71c1ef4e31f2d0ce530af67f Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 14 Aug 2018 14:40:52 -0700 Subject: Update types to reflect v2 --- packages/connect/src/http_client.ts | 22 +++--- packages/connect/src/index.ts | 6 +- .../connect/src/schemas/fees_request_schema.ts | 18 ++--- .../src/schemas/orderbook_request_schema.ts | 6 +- .../src/schemas/orders_request_opts_schema.ts | 6 +- .../src/schemas/token_pairs_request_opts_schema.ts | 4 +- packages/connect/src/types.ts | 91 ++++++++++------------ .../src/utils/orderbook_channel_message_parser.ts | 10 +-- .../src/utils/relayer_response_json_parsers.ts | 20 ++--- packages/connect/src/utils/type_converters.ts | 6 +- packages/connect/src/ws_orderbook_channel.ts | 8 +- .../test/fixtures/standard_relayer_api/fees.ts | 4 +- ...77fa9ac94a50f016026fd13f42990861238897721f.json | 8 +- ...f977fa9ac94a50f016026fd13f42990861238897721f.ts | 8 +- .../fixtures/standard_relayer_api/orderbook.json | 16 ++-- .../fixtures/standard_relayer_api/orderbook.ts | 16 ++-- .../test/fixtures/standard_relayer_api/orders.json | 8 +- .../test/fixtures/standard_relayer_api/orders.ts | 8 +- .../snapshot_orderbook_channel_message.ts | 17 ---- .../fixtures/standard_relayer_api/token_pairs.json | 4 +- .../fixtures/standard_relayer_api/token_pairs.ts | 6 +- .../unknown_orderbook_channel_message.ts | 2 +- .../update_orderbook_channel_message.ts | 4 +- packages/connect/test/http_client_test.ts | 70 ++++++++--------- .../test/orderbook_channel_message_parsers_test.ts | 22 +++--- packages/connect/test/ws_orderbook_channel_test.ts | 6 +- 26 files changed, 186 insertions(+), 210 deletions(-) delete mode 100644 packages/connect/test/fixtures/standard_relayer_api/snapshot_orderbook_channel_message.ts (limited to 'packages/connect') diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 1b51ee429..b2e15775e 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -9,8 +9,8 @@ import { schemas as clientSchemas } from './schemas/schemas'; import { AssetPairsRequestOpts, Client, - FeesRequest, - FeesResponse, + OrderConfigRequest, + OrderConfigResponse, HttpRequestOptions, HttpRequestType, OrderbookRequest, @@ -65,8 +65,8 @@ export class HttpClient implements Client { this._apiEndpointUrl = url.replace(TRAILING_SLASHES_REGEX, ''); // remove trailing slashes } /** - * Retrieve token pair info from the API - * @param requestOpts Options specifying token information to retrieve and page information, defaults to { page: 1, perPage: 100 } + * Retrieve assetData pair info from the API + * @param requestOpts Options specifying assetData information to retrieve and page information, defaults to { page: 1, perPage: 100 } * @return The resulting TokenPairsItems that match the request */ public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise { @@ -77,9 +77,9 @@ export class HttpClient implements Client { const httpRequestOpts = { params: _.defaults({}, requestOpts, DEFAULT_PAGED_REQUEST_OPTS), }; - const responseJson = await this._requestAsync('/token_pairs', HttpRequestType.Get, httpRequestOpts); - const tokenPairs = relayerResponseJsonParsers.parseTokenPairsJson(responseJson); - return tokenPairs; + const responseJson = await this._requestAsync('/assetData_pairs', HttpRequestType.Get, httpRequestOpts); + const assetDataPairs = relayerResponseJsonParsers.parseTokenPairsJson(responseJson); + return assetDataPairs; } /** * Retrieve orders from the API @@ -132,16 +132,16 @@ export class HttpClient implements Client { } /** * Retrieve fee information from the API - * @param request A FeesRequest instance describing the specific fees to retrieve - * @return The resulting FeesResponse that matches the request + * @param request A OrderConfigRequest instance describing the specific fees to retrieve + * @return The resulting OrderConfigResponse that matches the request */ - public async getOrderConfigAsync(request: FeesRequest): Promise { + public async getOrderConfigAsync(request: OrderConfigRequest): Promise { assert.doesConformToSchema('request', request, clientSchemas.feesRequestSchema); const httpRequestOpts = { payload: request, }; const responseJson = await this._requestAsync('/fees', HttpRequestType.Post, httpRequestOpts); - const fees = relayerResponseJsonParsers.parseFeesResponseJson(responseJson); + const fees = relayerResponseJsonParsers.parseOrderConfigResponseJson(responseJson); return fees; } /** diff --git a/packages/connect/src/index.ts b/packages/connect/src/index.ts index a4fc39425..e57967714 100644 --- a/packages/connect/src/index.ts +++ b/packages/connect/src/index.ts @@ -2,8 +2,8 @@ export { HttpClient } from './http_client'; export { orderbookChannelFactory } from './orderbook_channel_factory'; export { Client, - FeesRequest, - FeesResponse, + OrderConfigRequest, + OrderConfigResponse, OrderbookChannel, OrderbookChannelHandler, OrderbookChannelSubscriptionOpts, @@ -13,7 +13,7 @@ export { PagedRequestOpts, TokenPairsItem, AssetPairsRequestOpts, - TokenTradeInfo, + Asset, } from './types'; export { Order, SignedOrder } from '@0xproject/types'; diff --git a/packages/connect/src/schemas/fees_request_schema.ts b/packages/connect/src/schemas/fees_request_schema.ts index ff3d7b9d3..e41e49e09 100644 --- a/packages/connect/src/schemas/fees_request_schema.ts +++ b/packages/connect/src/schemas/fees_request_schema.ts @@ -1,26 +1,26 @@ export const feesRequestSchema = { - id: '/FeesRequest', + id: '/OrderConfigRequest', type: 'object', properties: { - exchangeContractAddress: { $ref: '/Address' }, + exchangeAddress: { $ref: '/Address' }, maker: { $ref: '/Address' }, taker: { $ref: '/Address' }, makerTokenAddress: { $ref: '/Address' }, takerTokenAddress: { $ref: '/Address' }, - makerTokenAmount: { $ref: '/Number' }, - takerTokenAmount: { $ref: '/Number' }, - expirationUnixTimestampSec: { $ref: '/Number' }, + makerAssetAmount: { $ref: '/Number' }, + takerAssetAmount: { $ref: '/Number' }, + expirationTimeSeconds: { $ref: '/Number' }, salt: { $ref: '/Number' }, }, required: [ - 'exchangeContractAddress', + 'exchangeAddress', 'maker', 'taker', 'makerTokenAddress', 'takerTokenAddress', - 'makerTokenAmount', - 'takerTokenAmount', - 'expirationUnixTimestampSec', + 'makerAssetAmount', + 'takerAssetAmount', + 'expirationTimeSeconds', 'salt', ], }; diff --git a/packages/connect/src/schemas/orderbook_request_schema.ts b/packages/connect/src/schemas/orderbook_request_schema.ts index 5f3463242..cc75ada5c 100644 --- a/packages/connect/src/schemas/orderbook_request_schema.ts +++ b/packages/connect/src/schemas/orderbook_request_schema.ts @@ -2,8 +2,8 @@ export const orderBookRequestSchema = { id: '/OrderBookRequest', type: 'object', properties: { - baseTokenAddress: { $ref: '/Address' }, - quoteTokenAddress: { $ref: '/Address' }, + baseAssetData: { $ref: '/Address' }, + quoteAssetData: { $ref: '/Address' }, }, - required: ['baseTokenAddress', 'quoteTokenAddress'], + required: ['baseAssetData', 'quoteAssetData'], }; diff --git a/packages/connect/src/schemas/orders_request_opts_schema.ts b/packages/connect/src/schemas/orders_request_opts_schema.ts index 5facbc959..1a9f74f7f 100644 --- a/packages/connect/src/schemas/orders_request_opts_schema.ts +++ b/packages/connect/src/schemas/orders_request_opts_schema.ts @@ -2,12 +2,12 @@ export const ordersRequestOptsSchema = { id: '/OrdersRequestOpts', type: 'object', properties: { - exchangeContractAddress: { $ref: '/Address' }, + exchangeAddress: { $ref: '/Address' }, tokenAddress: { $ref: '/Address' }, makerTokenAddress: { $ref: '/Address' }, takerTokenAddress: { $ref: '/Address' }, - tokenA: { $ref: '/Address' }, - tokenB: { $ref: '/Address' }, + assetDataA: { $ref: '/Address' }, + assetDataB: { $ref: '/Address' }, maker: { $ref: '/Address' }, taker: { $ref: '/Address' }, trader: { $ref: '/Address' }, diff --git a/packages/connect/src/schemas/token_pairs_request_opts_schema.ts b/packages/connect/src/schemas/token_pairs_request_opts_schema.ts index dffd063d0..bf1caa20d 100644 --- a/packages/connect/src/schemas/token_pairs_request_opts_schema.ts +++ b/packages/connect/src/schemas/token_pairs_request_opts_schema.ts @@ -2,7 +2,7 @@ export const AssetPairsRequestOptsSchema = { id: '/AssetPairsRequestOpts', type: 'object', properties: { - tokenA: { $ref: '/Address' }, - tokenB: { $ref: '/Address' }, + assetDataA: { $ref: '/Address' }, + assetDataB: { $ref: '/Address' }, }, }; diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index ca56d251b..0f2242329 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -2,11 +2,12 @@ import { SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; export interface Client { - getAssetPairsAsync: (requestOpts?: AssetPairsRequestOpts & PagedRequestOpts) => Promise; - getOrdersAsync: (requestOpts?: OrdersRequestOpts & PagedRequestOpts) => Promise; - getOrderAsync: (orderHash: string) => Promise; + getAssetPairsAsync: (requestOpts?: AssetPairsRequestOpts & PagedRequestOpts) => Promise>; + getOrdersAsync: (requestOpts?: OrdersRequestOpts & PagedRequestOpts) => Promise>; + getOrderAsync: (orderHash: string) => Promise; getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise; - getOrderConfigAsync: (request: FeesRequest) => Promise; + getOrderConfigAsync: (request: OrderConfigRequest) => Promise; + getFeeRecipients: () => Promise>; submitOrderAsync: (signedOrder: SignedOrder) => Promise; } @@ -16,58 +17,45 @@ export interface OrderbookChannel { } /** - * baseTokenAddress: The address of token designated as the baseToken in the currency pair calculation of price - * quoteTokenAddress: The address of token designated as the quoteToken in the currency pair calculation of price + * baseAssetData: The address of assetData designated as the baseToken in the currency pair calculation of price + * quoteAssetData: The address of assetData designated as the quoteToken in the currency pair calculation of price * snapshot: If true, a snapshot of the orderbook will be sent before the updates to the orderbook * limit: Maximum number of bids and asks in orderbook snapshot */ export interface OrderbookChannelSubscriptionOpts { - baseTokenAddress: string; - quoteTokenAddress: string; + baseAssetData: string; + quoteAssetData: string; snapshot: boolean; limit: number; } export interface OrderbookChannelHandler { - onSnapshot: ( - channel: OrderbookChannel, - subscriptionOpts: OrderbookChannelSubscriptionOpts, - snapshot: OrderbookResponse, - ) => void; onUpdate: ( channel: OrderbookChannel, subscriptionOpts: OrderbookChannelSubscriptionOpts, - order: SignedOrder, + order: APIOrder, ) => void; onError: (channel: OrderbookChannel, err: Error, subscriptionOpts?: OrderbookChannelSubscriptionOpts) => void; onClose: (channel: OrderbookChannel) => void; } -export type OrderbookChannelMessage = - | SnapshotOrderbookChannelMessage - | UpdateOrderbookChannelMessage - | UnknownOrderbookChannelMessage; +export type OrdersChannelMessage = + | UpdateOrdersChannelMessage + | UnknownOrdersChannelMessage; -export enum OrderbookChannelMessageTypes { - Snapshot = 'snapshot', +export enum OrdersChannelMessageTypes { Update = 'update', Unknown = 'unknown', } -export interface SnapshotOrderbookChannelMessage { - type: OrderbookChannelMessageTypes.Snapshot; - requestId: number; - payload: OrderbookResponse; -} - -export interface UpdateOrderbookChannelMessage { - type: OrderbookChannelMessageTypes.Update; +export interface UpdateOrdersChannelMessage { + type: OrdersChannelMessageTypes.Update; requestId: number; - payload: SignedOrder; + payload: APIOrder; } -export interface UnknownOrderbookChannelMessage { - type: OrderbookChannelMessageTypes.Unknown; +export interface UnknownOrdersChannelMessage { + type: OrdersChannelMessageTypes.Unknown; requestId: number; payload: undefined; } @@ -83,25 +71,30 @@ export enum WebsocketClientEventType { ConnectFailed = 'connectFailed', } +export interface APIOrder { + order: SignedOrder; + metaData: object; +} + export interface AssetPairsRequestOpts { - tokenA?: string; - tokenB?: string; + assetDataA?: string; + assetDataB?: string; } export interface TokenPairsItem { - tokenA: TokenTradeInfo; - tokenB: TokenTradeInfo; + assetDataA: Asset; + assetDataB: Asset; } -export interface TokenTradeInfo { - address: string; +export interface Asset { + assetData: string; minAmount: BigNumber; maxAmount: BigNumber; precision: number; } export interface OrdersRequestOpts { - exchangeContractAddress?: string; + exchangeAddress?: string; tokenAddress?: string; makerTokenAddress?: string; takerTokenAddress?: string; @@ -112,35 +105,35 @@ export interface OrdersRequestOpts { } export interface OrderbookRequest { - baseTokenAddress: string; - quoteTokenAddress: string; + baseAssetData: string; + quoteAssetData: string; } export interface OrderbookResponse { - bids: SignedOrder[]; - asks: SignedOrder[]; + bids: PaginatedCollection; + asks: PaginatedCollection; } -export interface PaginatedCollectionResponse { +export interface PaginatedCollection { total: number; page: number; perPage: number; records: T[]; } -export interface FeesRequest { - exchangeContractAddress: string; +export interface OrderConfigRequest { + exchangeAddress: string; maker: string; taker: string; makerTokenAddress: string; takerTokenAddress: string; - makerTokenAmount: BigNumber; - takerTokenAmount: BigNumber; - expirationUnixTimestampSec: BigNumber; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + expirationTimeSeconds: BigNumber; salt: BigNumber; } -export interface FeesResponse { +export interface OrderConfigResponse { feeRecipient: string; makerFee: BigNumber; takerFee: BigNumber; diff --git a/packages/connect/src/utils/orderbook_channel_message_parser.ts b/packages/connect/src/utils/orderbook_channel_message_parser.ts index 593288078..ca739e587 100644 --- a/packages/connect/src/utils/orderbook_channel_message_parser.ts +++ b/packages/connect/src/utils/orderbook_channel_message_parser.ts @@ -2,12 +2,12 @@ import { assert } from '@0xproject/assert'; import { schemas } from '@0xproject/json-schemas'; import * as _ from 'lodash'; -import { OrderbookChannelMessage, OrderbookChannelMessageTypes } from '../types'; +import { OrdersChannelMessage, OrdersChannelMessageTypes } from '../types'; import { relayerResponseJsonParsers } from './relayer_response_json_parsers'; export const orderbookChannelMessageParser = { - parse(utf8Data: string): OrderbookChannelMessage { + parse(utf8Data: string): OrdersChannelMessage { // parse the message const messageObj = JSON.parse(utf8Data); // ensure we have a type parameter to switch on @@ -19,13 +19,13 @@ export const orderbookChannelMessageParser = { assert.assert(!_.isUndefined(requestId), `Message is missing a requestId parameter: ${utf8Data}`); assert.isNumber('requestId', requestId); switch (type) { - case OrderbookChannelMessageTypes.Snapshot: { + case OrdersChannelMessageTypes.Snapshot: { assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrderbookChannelSnapshotSchema); const orderbookJson = messageObj.payload; const orderbook = relayerResponseJsonParsers.parseOrderbookResponseJson(orderbookJson); return _.assign(messageObj, { payload: orderbook }); } - case OrderbookChannelMessageTypes.Update: { + case OrdersChannelMessageTypes.Update: { assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrderbookChannelUpdateSchema); const orderJson = messageObj.payload; const order = relayerResponseJsonParsers.parseOrderJson(orderJson); @@ -33,7 +33,7 @@ export const orderbookChannelMessageParser = { } default: { return { - type: OrderbookChannelMessageTypes.Unknown, + type: OrdersChannelMessageTypes.Unknown, requestId, payload: undefined, }; diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts index ccae8b115..55f787820 100644 --- a/packages/connect/src/utils/relayer_response_json_parsers.ts +++ b/packages/connect/src/utils/relayer_response_json_parsers.ts @@ -2,19 +2,19 @@ import { assert } from '@0xproject/assert'; import { schemas } from '@0xproject/json-schemas'; import { SignedOrder } from '@0xproject/types'; -import { FeesResponse, OrderbookResponse, TokenPairsItem } from '../types'; +import { OrderConfigResponse, OrderbookResponse, TokenPairsItem } from '../types'; import { typeConverters } from './type_converters'; export const relayerResponseJsonParsers = { parseTokenPairsJson(json: any): TokenPairsItem[] { - assert.doesConformToSchema('tokenPairs', json, schemas.relayerApiTokenPairsResponseSchema); - return json.map((tokenPair: any) => { - return typeConverters.convertStringsFieldsToBigNumbers(tokenPair, [ - 'tokenA.minAmount', - 'tokenA.maxAmount', - 'tokenB.minAmount', - 'tokenB.maxAmount', + assert.doesConformToSchema('assetDataPairs', json, schemas.relayerApiTokenPairsResponseSchema); + return json.map((assetDataPair: any) => { + return typeConverters.convertStringsFieldsToBigNumbers(assetDataPair, [ + 'assetDataA.minAmount', + 'assetDataA.maxAmount', + 'assetDataB.minAmount', + 'assetDataB.maxAmount', ]); }); }, @@ -30,8 +30,8 @@ export const relayerResponseJsonParsers = { assert.doesConformToSchema('orderBook', json, schemas.relayerApiOrderBookResponseSchema); return typeConverters.convertOrderbookStringFieldsToBigNumber(json); }, - parseFeesResponseJson(json: any): FeesResponse { - assert.doesConformToSchema('fees', json, schemas.relayerApiFeesResponseSchema); + parseOrderConfigResponseJson(json: any): OrderConfigResponse { + assert.doesConformToSchema('fees', json, schemas.relayerApiOrderConfigResponseSchema); return typeConverters.convertStringsFieldsToBigNumbers(json, ['makerFee', 'takerFee']); }, }; diff --git a/packages/connect/src/utils/type_converters.ts b/packages/connect/src/utils/type_converters.ts index 210d452b9..513f9b39f 100644 --- a/packages/connect/src/utils/type_converters.ts +++ b/packages/connect/src/utils/type_converters.ts @@ -12,11 +12,11 @@ export const typeConverters = { }, convertOrderStringFieldsToBigNumber(order: any): any { return typeConverters.convertStringsFieldsToBigNumbers(order, [ - 'makerTokenAmount', - 'takerTokenAmount', + 'makerAssetAmount', + 'takerAssetAmount', 'makerFee', 'takerFee', - 'expirationUnixTimestampSec', + 'expirationTimeSeconds', 'salt', ]); }, diff --git a/packages/connect/src/ws_orderbook_channel.ts b/packages/connect/src/ws_orderbook_channel.ts index fa9f5e37f..d09fd375d 100644 --- a/packages/connect/src/ws_orderbook_channel.ts +++ b/packages/connect/src/ws_orderbook_channel.ts @@ -4,8 +4,8 @@ import * as WebSocket from 'websocket'; import { OrderbookChannel, OrderbookChannelHandler, - OrderbookChannelMessageTypes, OrderbookChannelSubscriptionOpts, + OrdersChannelMessageTypes, } from './types'; import { assert } from './utils/assert'; import { orderbookChannelMessageParser } from './utils/orderbook_channel_message_parser'; @@ -44,7 +44,7 @@ export class WebSocketOrderbookChannel implements OrderbookChannel { /** * Subscribe to orderbook snapshots and updates from the websocket * @param subscriptionOpts An OrderbookChannelSubscriptionOpts instance describing which - * token pair to subscribe to + * assetData pair to subscribe to */ public subscribe(subscriptionOpts: OrderbookChannelSubscriptionOpts): void { assert.isOrderbookChannelSubscriptionOpts('subscriptionOpts', subscriptionOpts); @@ -82,11 +82,11 @@ export class WebSocketOrderbookChannel implements OrderbookChannel { return; } switch (parserResult.type) { - case OrderbookChannelMessageTypes.Snapshot: { + case OrdersChannelMessageTypes.Snapshot: { this._handler.onSnapshot(this, subscriptionOpts, parserResult.payload); break; } - case OrderbookChannelMessageTypes.Update: { + case OrdersChannelMessageTypes.Update: { this._handler.onUpdate(this, subscriptionOpts, parserResult.payload); break; } diff --git a/packages/connect/test/fixtures/standard_relayer_api/fees.ts b/packages/connect/test/fixtures/standard_relayer_api/fees.ts index fecbaacff..7a526b491 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/fees.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/fees.ts @@ -1,8 +1,8 @@ import { BigNumber } from '@0xproject/utils'; -import { FeesResponse } from '../../../src/types'; +import { OrderConfigResponse } from '../../../src/types'; -export const feesResponse: FeesResponse = { +export const feesResponse: OrderConfigResponse = { feeRecipient: '0x323b5d4c32345ced77393b3530b1eed0f346429d', makerFee: new BigNumber('10000000000000000'), takerFee: new BigNumber('30000000000000000'), diff --git a/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json b/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json index e84954b0d..23e4fb327 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json +++ b/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json @@ -3,14 +3,14 @@ "taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", "makerFee": "100000000000000", "takerFee": "200000000000000", - "makerTokenAmount": "10000000000000000", - "takerTokenAmount": "20000000000000000", + "makerAssetAmount": "10000000000000000", + "takerAssetAmount": "20000000000000000", "makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d", "takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990", "salt": "256", "feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da", - "exchangeContractAddress": "0x12459c951127e0c374ff9105dda097662a027093", - "expirationUnixTimestampSec": "42", + "exchangeAddress": "0x12459c951127e0c374ff9105dda097662a027093", + "expirationTimeSeconds": "42", "ecSignature": { "v": 27, "r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33", diff --git a/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.ts b/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.ts index 5a03a2ff6..68446c83a 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.ts @@ -5,14 +5,14 @@ export const orderResponse = { taker: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', makerFee: new BigNumber('100000000000000'), takerFee: new BigNumber('200000000000000'), - makerTokenAmount: new BigNumber('10000000000000000'), - takerTokenAmount: new BigNumber('20000000000000000'), + makerAssetAmount: new BigNumber('10000000000000000'), + takerAssetAmount: new BigNumber('20000000000000000'), makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', salt: new BigNumber('256'), feeRecipient: '0xb046140686d052fff581f63f8136cce132e857da', - exchangeContractAddress: '0x12459c951127e0c374ff9105dda097662a027093', - expirationUnixTimestampSec: new BigNumber('42'), + exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', + expirationTimeSeconds: new BigNumber('42'), ecSignature: { v: 27, r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', diff --git a/packages/connect/test/fixtures/standard_relayer_api/orderbook.json b/packages/connect/test/fixtures/standard_relayer_api/orderbook.json index 825be34c2..2dec4b0fe 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/orderbook.json +++ b/packages/connect/test/fixtures/standard_relayer_api/orderbook.json @@ -5,14 +5,14 @@ "taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", "makerFee": "100000000000000", "takerFee": "200000000000000", - "makerTokenAmount": "10000000000000000", - "takerTokenAmount": "20000000000000000", + "makerAssetAmount": "10000000000000000", + "takerAssetAmount": "20000000000000000", "makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d", "takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990", "salt": "256", "feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da", - "exchangeContractAddress": "0x12459c951127e0c374ff9105dda097662a027093", - "expirationUnixTimestampSec": "42", + "exchangeAddress": "0x12459c951127e0c374ff9105dda097662a027093", + "expirationTimeSeconds": "42", "ecSignature": { "v": 27, "r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33", @@ -26,14 +26,14 @@ "taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", "makerFee": "100000000000000", "takerFee": "200000000000000", - "makerTokenAmount": "10000000000000000", - "takerTokenAmount": "20000000000000000", + "makerAssetAmount": "10000000000000000", + "takerAssetAmount": "20000000000000000", "makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d", "takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990", "salt": "256", "feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da", - "exchangeContractAddress": "0x12459c951127e0c374ff9105dda097662a027093", - "expirationUnixTimestampSec": "42", + "exchangeAddress": "0x12459c951127e0c374ff9105dda097662a027093", + "expirationTimeSeconds": "42", "ecSignature": { "v": 27, "r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33", diff --git a/packages/connect/test/fixtures/standard_relayer_api/orderbook.ts b/packages/connect/test/fixtures/standard_relayer_api/orderbook.ts index 6684ac2e5..9f80988ce 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/orderbook.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/orderbook.ts @@ -7,14 +7,14 @@ export const orderbookResponse = { taker: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', makerFee: new BigNumber('100000000000000'), takerFee: new BigNumber('200000000000000'), - makerTokenAmount: new BigNumber('10000000000000000'), - takerTokenAmount: new BigNumber('20000000000000000'), + makerAssetAmount: new BigNumber('10000000000000000'), + takerAssetAmount: new BigNumber('20000000000000000'), makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', salt: new BigNumber('256'), feeRecipient: '0xb046140686d052fff581f63f8136cce132e857da', - exchangeContractAddress: '0x12459c951127e0c374ff9105dda097662a027093', - expirationUnixTimestampSec: new BigNumber('42'), + exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', + expirationTimeSeconds: new BigNumber('42'), ecSignature: { v: 27, r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', @@ -28,14 +28,14 @@ export const orderbookResponse = { taker: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', makerFee: new BigNumber('100000000000000'), takerFee: new BigNumber('200000000000000'), - makerTokenAmount: new BigNumber('10000000000000000'), - takerTokenAmount: new BigNumber('20000000000000000'), + makerAssetAmount: new BigNumber('10000000000000000'), + takerAssetAmount: new BigNumber('20000000000000000'), makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', salt: new BigNumber('256'), feeRecipient: '0xb046140686d052fff581f63f8136cce132e857da', - exchangeContractAddress: '0x12459c951127e0c374ff9105dda097662a027093', - expirationUnixTimestampSec: new BigNumber('42'), + exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', + expirationTimeSeconds: new BigNumber('42'), ecSignature: { v: 27, r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', diff --git a/packages/connect/test/fixtures/standard_relayer_api/orders.json b/packages/connect/test/fixtures/standard_relayer_api/orders.json index cfa780dc4..929dde4a8 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/orders.json +++ b/packages/connect/test/fixtures/standard_relayer_api/orders.json @@ -4,14 +4,14 @@ "taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", "makerFee": "100000000000000", "takerFee": "200000000000000", - "makerTokenAmount": "10000000000000000", - "takerTokenAmount": "20000000000000000", + "makerAssetAmount": "10000000000000000", + "takerAssetAmount": "20000000000000000", "makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d", "takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990", "salt": "256", "feeRecipient": "0x9e56625509c2f60af937f23b7b532600390e8c8b", - "exchangeContractAddress": "0x9e56625509c2f60af937f23b7b532600390e8c8b", - "expirationUnixTimestampSec": "42", + "exchangeAddress": "0x9e56625509c2f60af937f23b7b532600390e8c8b", + "expirationTimeSeconds": "42", "ecSignature": { "v": 27, "r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33", diff --git a/packages/connect/test/fixtures/standard_relayer_api/orders.ts b/packages/connect/test/fixtures/standard_relayer_api/orders.ts index 5044777bd..6d32fd3f3 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/orders.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/orders.ts @@ -6,14 +6,14 @@ export const ordersResponse = [ taker: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', makerFee: new BigNumber('100000000000000'), takerFee: new BigNumber('200000000000000'), - makerTokenAmount: new BigNumber('10000000000000000'), - takerTokenAmount: new BigNumber('20000000000000000'), + makerAssetAmount: new BigNumber('10000000000000000'), + takerAssetAmount: new BigNumber('20000000000000000'), makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', salt: new BigNumber('256'), feeRecipient: '0x9e56625509c2f60af937f23b7b532600390e8c8b', - exchangeContractAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b', - expirationUnixTimestampSec: new BigNumber('42'), + exchangeAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b', + expirationTimeSeconds: new BigNumber('42'), ecSignature: { v: 27, r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', diff --git a/packages/connect/test/fixtures/standard_relayer_api/snapshot_orderbook_channel_message.ts b/packages/connect/test/fixtures/standard_relayer_api/snapshot_orderbook_channel_message.ts deleted file mode 100644 index 1d7e67055..000000000 --- a/packages/connect/test/fixtures/standard_relayer_api/snapshot_orderbook_channel_message.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as orderbookJSON from './orderbook.json'; - -const orderbookJsonString = JSON.stringify(orderbookJSON); - -export const snapshotOrderbookChannelMessage = `{ - "type": "snapshot", - "channel": "orderbook", - "requestId": 1, - "payload": ${orderbookJsonString} -}`; - -export const malformedSnapshotOrderbookChannelMessage = `{ - "type": "snapshot", - "channel": "orderbook", - "requestId": 1, - "payload": {} -}`; diff --git a/packages/connect/test/fixtures/standard_relayer_api/token_pairs.json b/packages/connect/test/fixtures/standard_relayer_api/token_pairs.json index 90f57a974..2d9610e3d 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/token_pairs.json +++ b/packages/connect/test/fixtures/standard_relayer_api/token_pairs.json @@ -1,12 +1,12 @@ [ { - "tokenA": { + "assetDataA": { "address": "0x323b5d4c32345ced77393b3530b1eed0f346429d", "minAmount": "0", "maxAmount": "10000000000000000000", "precision": 5 }, - "tokenB": { + "assetDataB": { "address": "0xef7fff64389b814a946f3e92105513705ca6b990", "minAmount": "0", "maxAmount": "50000000000000000000", diff --git a/packages/connect/test/fixtures/standard_relayer_api/token_pairs.ts b/packages/connect/test/fixtures/standard_relayer_api/token_pairs.ts index f48b1e877..1225ac4fc 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/token_pairs.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/token_pairs.ts @@ -2,15 +2,15 @@ import { BigNumber } from '@0xproject/utils'; import { TokenPairsItem } from '../../../src/types'; -export const tokenPairsResponse: TokenPairsItem[] = [ +export const assetDataPairsResponse: TokenPairsItem[] = [ { - tokenA: { + assetDataA: { address: '0x323b5d4c32345ced77393b3530b1eed0f346429d', minAmount: new BigNumber(0), maxAmount: new BigNumber('10000000000000000000'), precision: 5, }, - tokenB: { + assetDataB: { address: '0xef7fff64389b814a946f3e92105513705ca6b990', minAmount: new BigNumber(0), maxAmount: new BigNumber('50000000000000000000'), diff --git a/packages/connect/test/fixtures/standard_relayer_api/unknown_orderbook_channel_message.ts b/packages/connect/test/fixtures/standard_relayer_api/unknown_orderbook_channel_message.ts index cbedff60e..c0e924a4b 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/unknown_orderbook_channel_message.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/unknown_orderbook_channel_message.ts @@ -2,7 +2,7 @@ import * as orderResponseJSON from './order/0xabc67323774bdbd24d94f977fa9ac94a50 const orderJSONString = JSON.stringify(orderResponseJSON); -export const unknownOrderbookChannelMessage = `{ +export const unknownOrdersChannelMessage = `{ "type": "superGoodUpdate", "channel": "orderbook", "requestId": 1, diff --git a/packages/connect/test/fixtures/standard_relayer_api/update_orderbook_channel_message.ts b/packages/connect/test/fixtures/standard_relayer_api/update_orderbook_channel_message.ts index 0e2c7523b..daab20368 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/update_orderbook_channel_message.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/update_orderbook_channel_message.ts @@ -2,14 +2,14 @@ import * as orderResponseJSON from './order/0xabc67323774bdbd24d94f977fa9ac94a50 const orderJSONString = JSON.stringify(orderResponseJSON); -export const updateOrderbookChannelMessage = `{ +export const updateOrdersChannelMessage = `{ "type": "update", "channel": "orderbook", "requestId": 1, "payload": ${orderJSONString} }`; -export const malformedUpdateOrderbookChannelMessage = `{ +export const malformedUpdateOrdersChannelMessage = `{ "type": "update", "channel": "orderbook", "requestId": 1, diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 38327b090..ea5717327 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -15,8 +15,8 @@ import { orderbookResponse } from './fixtures/standard_relayer_api/orderbook'; import * as orderbookJSON from './fixtures/standard_relayer_api/orderbook.json'; import { ordersResponse } from './fixtures/standard_relayer_api/orders'; import * as ordersResponseJSON from './fixtures/standard_relayer_api/orders.json'; -import { tokenPairsResponse } from './fixtures/standard_relayer_api/token_pairs'; -import * as tokenPairsResponseJSON from './fixtures/standard_relayer_api/token_pairs.json'; +import { assetDataPairsResponse } from './fixtures/standard_relayer_api/assetData_pairs'; +import * as assetDataPairsResponseJSON from './fixtures/standard_relayer_api/assetData_pairs.json'; chai.config.includeStack = true; chai.use(dirtyChai); @@ -39,24 +39,24 @@ describe('HttpClient', () => { }); }); describe('#getAssetPairsAsync', () => { - const url = `${relayUrl}/token_pairs`; - it('gets token pairs with default options when none are provided', async () => { + const url = `${relayUrl}/assetData_pairs`; + it('gets assetData pairs with default options when none are provided', async () => { const urlWithQuery = `${url}?page=1&per_page=100`; - fetchMock.get(urlWithQuery, tokenPairsResponseJSON); - const tokenPairs = await relayerClient.getAssetPairsAsync(); - expect(tokenPairs).to.be.deep.equal(tokenPairsResponse); + fetchMock.get(urlWithQuery, assetDataPairsResponseJSON); + const assetDataPairs = await relayerClient.getAssetPairsAsync(); + expect(assetDataPairs).to.be.deep.equal(assetDataPairsResponse); }); - it('gets token pairs with specified request options', async () => { - const tokenAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d'; + it('gets assetData pairs with specified request options', async () => { + const assetDataAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d'; const AssetPairsRequestOpts = { - tokenA: tokenAddress, + assetDataA: assetDataAddress, page: 3, perPage: 50, }; - const urlWithQuery = `${url}?page=3&per_page=50&tokenA=${tokenAddress}`; - fetchMock.get(urlWithQuery, tokenPairsResponseJSON); - const tokenPairs = await relayerClient.getAssetPairsAsync(AssetPairsRequestOpts); - expect(tokenPairs).to.be.deep.equal(tokenPairsResponse); + const urlWithQuery = `${url}?page=3&per_page=50&assetDataA=${assetDataAddress}`; + fetchMock.get(urlWithQuery, assetDataPairsResponseJSON); + const assetDataPairs = await relayerClient.getAssetPairsAsync(AssetPairsRequestOpts); + expect(assetDataPairs).to.be.deep.equal(assetDataPairsResponse); }); it('throws an error for invalid JSON response', async () => { fetchMock.get(url, { test: 'dummy' }); @@ -72,13 +72,13 @@ describe('HttpClient', () => { expect(orders).to.be.deep.equal(ordersResponse); }); it('gets orders with specified request options', async () => { - const tokenAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d'; + const assetDataAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d'; const ordersRequest = { - tokenAddress, + assetDataAddress, page: 3, perPage: 50, }; - const urlWithQuery = `${url}?page=3&per_page=50&tokenAddress=${tokenAddress}`; + const urlWithQuery = `${url}?page=3&per_page=50&assetDataAddress=${assetDataAddress}`; fetchMock.get(urlWithQuery, ordersResponseJSON); const orders = await relayerClient.getOrdersAsync(ordersRequest); expect(orders).to.be.deep.equal(ordersResponse); @@ -103,22 +103,22 @@ describe('HttpClient', () => { }); describe('#getOrderBookAsync', () => { const request = { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', + baseAssetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + quoteAssetData: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', }; const url = `${relayUrl}/orderbook`; it('gets orderbook with default page options when none are provided', async () => { - const urlWithQuery = `${url}?baseTokenAddress=${ - request.baseTokenAddress - }&page=1&per_page=100"eTokenAddress=${request.quoteTokenAddress}`; + const urlWithQuery = `${url}?baseAssetData=${ + request.baseAssetData + }&page=1&per_page=100"eAssetData=${request.quoteAssetData}`; fetchMock.get(urlWithQuery, orderbookJSON); const orderbook = await relayerClient.getOrderbookAsync(request); expect(orderbook).to.be.deep.equal(orderbookResponse); }); it('gets orderbook with specified page options', async () => { - const urlWithQuery = `${url}?baseTokenAddress=${ - request.baseTokenAddress - }&page=3&per_page=50"eTokenAddress=${request.quoteTokenAddress}`; + const urlWithQuery = `${url}?baseAssetData=${ + request.baseAssetData + }&page=3&per_page=50"eAssetData=${request.quoteAssetData}`; fetchMock.get(urlWithQuery, orderbookJSON); const pagedRequestOptions = { page: 3, @@ -134,15 +134,15 @@ describe('HttpClient', () => { }); describe('#getOrderConfigAsync', () => { const request = { - exchangeContractAddress: '0x12459c951127e0c374ff9105dda097662a027093', + exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', maker: '0x9e56625509c2f60af937f23b7b532600390e8c8b', taker: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - makerTokenAmount: new BigNumber('10000000000000000000'), - takerTokenAmount: new BigNumber('30000000000000000000'), + makerAssetAmount: new BigNumber('10000000000000000000'), + takerAssetAmount: new BigNumber('30000000000000000000'), salt: new BigNumber('256'), - expirationUnixTimestampSec: new BigNumber('42'), + expirationTimeSeconds: new BigNumber('42'), }; const url = `${relayUrl}/fees`; it('gets fees', async () => { @@ -152,15 +152,15 @@ describe('HttpClient', () => { }); it('does not mutate input', async () => { fetchMock.post(url, feesResponseJSON); - const makerTokenAmountBefore = new BigNumber(request.makerTokenAmount); - const takerTokenAmountBefore = new BigNumber(request.takerTokenAmount); + const makerAssetAmountBefore = new BigNumber(request.makerAssetAmount); + const takerAssetAmountBefore = new BigNumber(request.takerAssetAmount); const saltBefore = new BigNumber(request.salt); - const expirationUnixTimestampSecBefore = new BigNumber(request.expirationUnixTimestampSec); + const expirationTimeSecondsBefore = new BigNumber(request.expirationTimeSeconds); await relayerClient.getOrderConfigAsync(request); - expect(makerTokenAmountBefore).to.be.deep.equal(request.makerTokenAmount); - expect(takerTokenAmountBefore).to.be.deep.equal(request.takerTokenAmount); + expect(makerAssetAmountBefore).to.be.deep.equal(request.makerAssetAmount); + expect(takerAssetAmountBefore).to.be.deep.equal(request.takerAssetAmount); expect(saltBefore).to.be.deep.equal(request.salt); - expect(expirationUnixTimestampSecBefore).to.be.deep.equal(request.expirationUnixTimestampSec); + expect(expirationTimeSecondsBefore).to.be.deep.equal(request.expirationTimeSeconds); }); it('throws an error for invalid JSON response', async () => { fetchMock.post(url, { test: 'dummy' }); diff --git a/packages/connect/test/orderbook_channel_message_parsers_test.ts b/packages/connect/test/orderbook_channel_message_parsers_test.ts index 3e1f44384..ce881e627 100644 --- a/packages/connect/test/orderbook_channel_message_parsers_test.ts +++ b/packages/connect/test/orderbook_channel_message_parsers_test.ts @@ -7,13 +7,13 @@ import { orderbookChannelMessageParser } from '../src/utils/orderbook_channel_me import { orderResponse } from './fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f'; import { orderbookResponse } from './fixtures/standard_relayer_api/orderbook'; import { - malformedSnapshotOrderbookChannelMessage, - snapshotOrderbookChannelMessage, + malformedSnapshotOrdersChannelMessage, + snapshotOrdersChannelMessage, } from './fixtures/standard_relayer_api/snapshot_orderbook_channel_message'; -import { unknownOrderbookChannelMessage } from './fixtures/standard_relayer_api/unknown_orderbook_channel_message'; +import { unknownOrdersChannelMessage } from './fixtures/standard_relayer_api/unknown_orderbook_channel_message'; import { - malformedUpdateOrderbookChannelMessage, - updateOrderbookChannelMessage, + malformedUpdateOrdersChannelMessage, + updateOrdersChannelMessage, } from './fixtures/standard_relayer_api/update_orderbook_channel_message'; chai.config.includeStack = true; @@ -23,17 +23,17 @@ const expect = chai.expect; describe('orderbookChannelMessageParser', () => { describe('#parser', () => { it('parses snapshot messages', () => { - const snapshotMessage = orderbookChannelMessageParser.parse(snapshotOrderbookChannelMessage); + const snapshotMessage = orderbookChannelMessageParser.parse(snapshotOrdersChannelMessage); expect(snapshotMessage.type).to.be.equal('snapshot'); expect(snapshotMessage.payload).to.be.deep.equal(orderbookResponse); }); it('parses update messages', () => { - const updateMessage = orderbookChannelMessageParser.parse(updateOrderbookChannelMessage); + const updateMessage = orderbookChannelMessageParser.parse(updateOrdersChannelMessage); expect(updateMessage.type).to.be.equal('update'); expect(updateMessage.payload).to.be.deep.equal(orderResponse); }); it('returns unknown message for messages with unsupported types', () => { - const unknownMessage = orderbookChannelMessageParser.parse(unknownOrderbookChannelMessage); + const unknownMessage = orderbookChannelMessageParser.parse(unknownOrdersChannelMessage); expect(unknownMessage.type).to.be.equal('unknown'); expect(unknownMessage.payload).to.be.undefined(); }); @@ -57,20 +57,20 @@ describe('orderbookChannelMessageParser', () => { expect(badCall).throws('Expected type to be of type string, encountered: 1'); }); it('throws when snapshot message has malformed payload', () => { - const badCall = () => orderbookChannelMessageParser.parse(malformedSnapshotOrderbookChannelMessage); + const badCall = () => orderbookChannelMessageParser.parse(malformedSnapshotOrdersChannelMessage); // tslint:disable-next-line:max-line-length const errMsg = 'Validation errors: instance.payload requires property "bids", instance.payload requires property "asks"'; expect(badCall).throws(errMsg); }); it('throws when update message has malformed payload', () => { - const badCall = () => orderbookChannelMessageParser.parse(malformedUpdateOrderbookChannelMessage); + const badCall = () => orderbookChannelMessageParser.parse(malformedUpdateOrdersChannelMessage); expect(badCall).throws(/^Expected message to conform to schema/); }); it('throws when input message is not valid JSON', () => { const nonJsonString = 'h93b{sdfs9fsd f'; const badCall = () => orderbookChannelMessageParser.parse(nonJsonString); - expect(badCall).throws('Unexpected token h in JSON at position 0'); + expect(badCall).throws('Unexpected assetData h in JSON at position 0'); }); }); }); diff --git a/packages/connect/test/ws_orderbook_channel_test.ts b/packages/connect/test/ws_orderbook_channel_test.ts index 5a63cbdcc..b5682af36 100644 --- a/packages/connect/test/ws_orderbook_channel_test.ts +++ b/packages/connect/test/ws_orderbook_channel_test.ts @@ -32,8 +32,8 @@ describe('WebSocketOrderbookChannel', () => { Sinon.stub(openClient, 'send').callsFake(_.noop.bind(_)); const openOrderbookChannel = new WebSocketOrderbookChannel(openClient, emptyOrderbookChannelHandler); const subscriptionOpts = { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', + baseAssetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + quoteAssetData: '0xef7fff64389b814a946f3e92105513705ca6b990', snapshot: true, limit: 100, }; @@ -41,7 +41,7 @@ describe('WebSocketOrderbookChannel', () => { it('throws when subscriptionOpts does not conform to schema', () => { 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"', + 'Expected subscriptionOpts to conform to schema /RelayerApiOrderbookChannelSubscribePayload\nEncountered: {}\nValidation errors: instance requires property "baseAssetData", instance requires property "quoteAssetData"', ); }); it('does not throw when inputs are of correct types', () => { -- cgit v1.2.3 From 5c40c466f6e9f690afa86f23dd5ba240691dceb8 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 14 Aug 2018 14:59:53 -0700 Subject: Update json-schemas, update HTTPClient types --- packages/connect/package.json | 2 +- packages/connect/src/http_client.ts | 36 ++++++++++------------ packages/connect/src/index.ts | 2 +- packages/connect/src/types.ts | 6 ++-- .../src/utils/orderbook_channel_message_parser.ts | 10 ++---- .../src/utils/relayer_response_json_parsers.ts | 8 ++--- packages/connect/src/ws_orderbook_channel.ts | 8 ++--- .../fixtures/standard_relayer_api/token_pairs.ts | 4 +-- packages/connect/test/http_client_test.ts | 4 +-- .../test/orderbook_channel_message_parsers_test.ts | 20 ++++++------ 10 files changed, 44 insertions(+), 56 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/package.json b/packages/connect/package.json index 4ab5cec64..39376a9a6 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -52,7 +52,7 @@ "homepage": "https://github.com/0xProject/0x-monorepo/packages/connect/README.md", "dependencies": { "@0xproject/assert": "^0.2.14", - "@0xproject/json-schemas": "^0.8.3", + "@0xproject/json-schemas": "^1.0.1-rc.4", "@0xproject/types": "^0.8.2", "@0xproject/typescript-typings": "^1.0.4", "@0xproject/utils": "^1.0.5", diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index b2e15775e..20a2f9cc0 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -7,17 +7,19 @@ import * as queryString from 'query-string'; import { schemas as clientSchemas } from './schemas/schemas'; import { + APIOrder, + AssetPairsItem, AssetPairsRequestOpts, Client, - OrderConfigRequest, - OrderConfigResponse, HttpRequestOptions, HttpRequestType, OrderbookRequest, OrderbookResponse, + OrderConfigRequest, + OrderConfigResponse, OrdersRequestOpts, PagedRequestOpts, - TokenPairsItem, + PaginatedCollection, } from './types'; import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers'; @@ -26,12 +28,6 @@ const DEFAULT_PAGED_REQUEST_OPTS: PagedRequestOpts = { page: 1, perPage: 100, }; -/** - * This mapping defines how an option property name gets converted into an HTTP request query field - */ -const OPTS_TO_QUERY_FIELD_MAP = { - perPage: 'per_page', -}; /** * This class includes all the functionality related to interacting with a set of HTTP endpoints @@ -47,12 +43,8 @@ export class HttpClient implements Client { if (_.isUndefined(params) || _.isEmpty(params)) { return ''; } - // format params into a form the api expects - const formattedParams = _.mapKeys(params, (_value: any, key: string) => { - return _.get(OPTS_TO_QUERY_FIELD_MAP, key, key); - }); // stringify the formatted object - const stringifiedParams = queryString.stringify(formattedParams); + const stringifiedParams = queryString.stringify(params); return `?${stringifiedParams}`; } /** @@ -67,9 +59,9 @@ export class HttpClient implements Client { /** * Retrieve assetData pair info from the API * @param requestOpts Options specifying assetData information to retrieve and page information, defaults to { page: 1, perPage: 100 } - * @return The resulting TokenPairsItems that match the request + * @return The resulting AssetPairsItems that match the request */ - public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise { + public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise> { if (!_.isUndefined(requestOpts)) { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.AssetPairsRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); @@ -78,7 +70,7 @@ export class HttpClient implements Client { params: _.defaults({}, requestOpts, DEFAULT_PAGED_REQUEST_OPTS), }; const responseJson = await this._requestAsync('/assetData_pairs', HttpRequestType.Get, httpRequestOpts); - const assetDataPairs = relayerResponseJsonParsers.parseTokenPairsJson(responseJson); + const assetDataPairs = relayerResponseJsonParsers.parseAssetDataPairsJson(responseJson); return assetDataPairs; } /** @@ -86,7 +78,7 @@ export class HttpClient implements Client { * @param requestOpts Options specifying orders to retrieve and page information, defaults to { page: 1, perPage: 100 } * @return The resulting SignedOrders that match the request */ - public async getOrdersAsync(requestOpts?: OrdersRequestOpts & PagedRequestOpts): Promise { + public async getOrdersAsync(requestOpts?: OrdersRequestOpts & PagedRequestOpts): Promise> { if (!_.isUndefined(requestOpts)) { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.ordersRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); @@ -103,7 +95,7 @@ export class HttpClient implements Client { * @param orderHash An orderHash generated from the desired order * @return The SignedOrder that matches the supplied orderHash */ - public async getOrderAsync(orderHash: string): Promise { + public async getOrderAsync(orderHash: string): Promise { assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get); const order = relayerResponseJsonParsers.parseOrderJson(responseJson); @@ -144,6 +136,12 @@ export class HttpClient implements Client { const fees = relayerResponseJsonParsers.parseOrderConfigResponseJson(responseJson); return fees; } + + public async getFeeRecipientsAsync(): Promise> { + // TODO + return; + } + /** * Submit a signed order to the API * @param signedOrder A SignedOrder instance to submit diff --git a/packages/connect/src/index.ts b/packages/connect/src/index.ts index e57967714..e0c4293d9 100644 --- a/packages/connect/src/index.ts +++ b/packages/connect/src/index.ts @@ -11,7 +11,7 @@ export { OrderbookResponse, OrdersRequestOpts, PagedRequestOpts, - TokenPairsItem, + AssetPairsItem, AssetPairsRequestOpts, Asset, } from './types'; diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index 0f2242329..fb51dca98 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -2,12 +2,12 @@ import { SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; export interface Client { - getAssetPairsAsync: (requestOpts?: AssetPairsRequestOpts & PagedRequestOpts) => Promise>; + getAssetPairsAsync: (requestOpts?: AssetPairsRequestOpts & PagedRequestOpts) => Promise>; getOrdersAsync: (requestOpts?: OrdersRequestOpts & PagedRequestOpts) => Promise>; getOrderAsync: (orderHash: string) => Promise; getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise; getOrderConfigAsync: (request: OrderConfigRequest) => Promise; - getFeeRecipients: () => Promise>; + getFeeRecipientsAsync: () => Promise>; submitOrderAsync: (signedOrder: SignedOrder) => Promise; } @@ -81,7 +81,7 @@ export interface AssetPairsRequestOpts { assetDataB?: string; } -export interface TokenPairsItem { +export interface AssetPairsItem { assetDataA: Asset; assetDataB: Asset; } diff --git a/packages/connect/src/utils/orderbook_channel_message_parser.ts b/packages/connect/src/utils/orderbook_channel_message_parser.ts index ca739e587..986209c54 100644 --- a/packages/connect/src/utils/orderbook_channel_message_parser.ts +++ b/packages/connect/src/utils/orderbook_channel_message_parser.ts @@ -6,7 +6,7 @@ import { OrdersChannelMessage, OrdersChannelMessageTypes } from '../types'; import { relayerResponseJsonParsers } from './relayer_response_json_parsers'; -export const orderbookChannelMessageParser = { +export const ordersChannelMessageParser = { parse(utf8Data: string): OrdersChannelMessage { // parse the message const messageObj = JSON.parse(utf8Data); @@ -19,14 +19,8 @@ export const orderbookChannelMessageParser = { assert.assert(!_.isUndefined(requestId), `Message is missing a requestId parameter: ${utf8Data}`); assert.isNumber('requestId', requestId); switch (type) { - case OrdersChannelMessageTypes.Snapshot: { - assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrderbookChannelSnapshotSchema); - const orderbookJson = messageObj.payload; - const orderbook = relayerResponseJsonParsers.parseOrderbookResponseJson(orderbookJson); - return _.assign(messageObj, { payload: orderbook }); - } case OrdersChannelMessageTypes.Update: { - assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrderbookChannelUpdateSchema); + assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrdersChannelUpdateSchema); const orderJson = messageObj.payload; const order = relayerResponseJsonParsers.parseOrderJson(orderJson); return _.assign(messageObj, { payload: order }); diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts index 55f787820..6463aefb0 100644 --- a/packages/connect/src/utils/relayer_response_json_parsers.ts +++ b/packages/connect/src/utils/relayer_response_json_parsers.ts @@ -2,13 +2,13 @@ import { assert } from '@0xproject/assert'; import { schemas } from '@0xproject/json-schemas'; import { SignedOrder } from '@0xproject/types'; -import { OrderConfigResponse, OrderbookResponse, TokenPairsItem } from '../types'; +import { AssetPairsItem, OrderbookResponse, OrderConfigResponse } from '../types'; import { typeConverters } from './type_converters'; export const relayerResponseJsonParsers = { - parseTokenPairsJson(json: any): TokenPairsItem[] { - assert.doesConformToSchema('assetDataPairs', json, schemas.relayerApiTokenPairsResponseSchema); + parseAssetDataPairsJson(json: any): AssetPairsItem[] { + assert.doesConformToSchema('assetDataPairs', json, schemas.relayerApiAssetDataPairsResponseSchema); return json.map((assetDataPair: any) => { return typeConverters.convertStringsFieldsToBigNumbers(assetDataPair, [ 'assetDataA.minAmount', @@ -27,7 +27,7 @@ export const relayerResponseJsonParsers = { return typeConverters.convertOrderStringFieldsToBigNumber(json); }, parseOrderbookResponseJson(json: any): OrderbookResponse { - assert.doesConformToSchema('orderBook', json, schemas.relayerApiOrderBookResponseSchema); + assert.doesConformToSchema('orderBook', json, schemas.relayerApiOrdersResponseSchema); return typeConverters.convertOrderbookStringFieldsToBigNumber(json); }, parseOrderConfigResponseJson(json: any): OrderConfigResponse { diff --git a/packages/connect/src/ws_orderbook_channel.ts b/packages/connect/src/ws_orderbook_channel.ts index d09fd375d..3d9230792 100644 --- a/packages/connect/src/ws_orderbook_channel.ts +++ b/packages/connect/src/ws_orderbook_channel.ts @@ -8,7 +8,7 @@ import { OrdersChannelMessageTypes, } from './types'; import { assert } from './utils/assert'; -import { orderbookChannelMessageParser } from './utils/orderbook_channel_message_parser'; +import { ordersChannelMessageParser } from './utils/orderbook_channel_message_parser'; /** * This class includes all the functionality related to interacting with a websocket endpoint @@ -72,7 +72,7 @@ export class WebSocketOrderbookChannel implements OrderbookChannel { } try { const data = message.data; - const parserResult = orderbookChannelMessageParser.parse(data); + const parserResult = ordersChannelMessageParser.parse(data); const subscriptionOpts = this._subscriptionOptsList[parserResult.requestId]; if (_.isUndefined(subscriptionOpts)) { this._handler.onError( @@ -82,10 +82,6 @@ export class WebSocketOrderbookChannel implements OrderbookChannel { return; } switch (parserResult.type) { - case OrdersChannelMessageTypes.Snapshot: { - this._handler.onSnapshot(this, subscriptionOpts, parserResult.payload); - break; - } case OrdersChannelMessageTypes.Update: { this._handler.onUpdate(this, subscriptionOpts, parserResult.payload); break; diff --git a/packages/connect/test/fixtures/standard_relayer_api/token_pairs.ts b/packages/connect/test/fixtures/standard_relayer_api/token_pairs.ts index 1225ac4fc..03cce8444 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/token_pairs.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/token_pairs.ts @@ -1,8 +1,8 @@ import { BigNumber } from '@0xproject/utils'; -import { TokenPairsItem } from '../../../src/types'; +import { AssetPairsItem } from '../../../src/types'; -export const assetDataPairsResponse: TokenPairsItem[] = [ +export const assetDataPairsResponse: AssetPairsItem[] = [ { assetDataA: { address: '0x323b5d4c32345ced77393b3530b1eed0f346429d', diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index ea5717327..866cf7b2f 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -7,6 +7,8 @@ import 'mocha'; import { HttpClient } from '../src/index'; +import { assetDataPairsResponse } from './fixtures/standard_relayer_api/assetData_pairs'; +import * as assetDataPairsResponseJSON from './fixtures/standard_relayer_api/assetData_pairs.json'; import { feesResponse } from './fixtures/standard_relayer_api/fees'; import * as feesResponseJSON from './fixtures/standard_relayer_api/fees.json'; import { orderResponse } from './fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f'; @@ -15,8 +17,6 @@ import { orderbookResponse } from './fixtures/standard_relayer_api/orderbook'; import * as orderbookJSON from './fixtures/standard_relayer_api/orderbook.json'; import { ordersResponse } from './fixtures/standard_relayer_api/orders'; import * as ordersResponseJSON from './fixtures/standard_relayer_api/orders.json'; -import { assetDataPairsResponse } from './fixtures/standard_relayer_api/assetData_pairs'; -import * as assetDataPairsResponseJSON from './fixtures/standard_relayer_api/assetData_pairs.json'; chai.config.includeStack = true; chai.use(dirtyChai); diff --git a/packages/connect/test/orderbook_channel_message_parsers_test.ts b/packages/connect/test/orderbook_channel_message_parsers_test.ts index ce881e627..9960ad1df 100644 --- a/packages/connect/test/orderbook_channel_message_parsers_test.ts +++ b/packages/connect/test/orderbook_channel_message_parsers_test.ts @@ -2,7 +2,7 @@ import * as chai from 'chai'; import * as dirtyChai from 'dirty-chai'; import 'mocha'; -import { orderbookChannelMessageParser } from '../src/utils/orderbook_channel_message_parser'; +import { ordersChannelMessageParser } from '../src/utils/orderbook_channel_message_parser'; import { orderResponse } from './fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f'; import { orderbookResponse } from './fixtures/standard_relayer_api/orderbook'; @@ -20,20 +20,20 @@ chai.config.includeStack = true; chai.use(dirtyChai); const expect = chai.expect; -describe('orderbookChannelMessageParser', () => { +describe('ordersChannelMessageParser', () => { describe('#parser', () => { it('parses snapshot messages', () => { - const snapshotMessage = orderbookChannelMessageParser.parse(snapshotOrdersChannelMessage); + const snapshotMessage = ordersChannelMessageParser.parse(snapshotOrdersChannelMessage); expect(snapshotMessage.type).to.be.equal('snapshot'); expect(snapshotMessage.payload).to.be.deep.equal(orderbookResponse); }); it('parses update messages', () => { - const updateMessage = orderbookChannelMessageParser.parse(updateOrdersChannelMessage); + const updateMessage = ordersChannelMessageParser.parse(updateOrdersChannelMessage); expect(updateMessage.type).to.be.equal('update'); expect(updateMessage.payload).to.be.deep.equal(orderResponse); }); it('returns unknown message for messages with unsupported types', () => { - const unknownMessage = orderbookChannelMessageParser.parse(unknownOrdersChannelMessage); + const unknownMessage = ordersChannelMessageParser.parse(unknownOrdersChannelMessage); expect(unknownMessage.type).to.be.equal('unknown'); expect(unknownMessage.payload).to.be.undefined(); }); @@ -43,7 +43,7 @@ describe('orderbookChannelMessageParser', () => { "requestId": 1, "payload": {} }`; - const badCall = () => orderbookChannelMessageParser.parse(typelessMessage); + const badCall = () => ordersChannelMessageParser.parse(typelessMessage); expect(badCall).throws(`Message is missing a type parameter: ${typelessMessage}`); }); it('throws when type is not a string', () => { @@ -53,23 +53,23 @@ describe('orderbookChannelMessageParser', () => { "requestId": 1, "payload": {} }`; - const badCall = () => orderbookChannelMessageParser.parse(messageWithBadType); + const badCall = () => ordersChannelMessageParser.parse(messageWithBadType); expect(badCall).throws('Expected type to be of type string, encountered: 1'); }); it('throws when snapshot message has malformed payload', () => { - const badCall = () => orderbookChannelMessageParser.parse(malformedSnapshotOrdersChannelMessage); + const badCall = () => ordersChannelMessageParser.parse(malformedSnapshotOrdersChannelMessage); // tslint:disable-next-line:max-line-length const errMsg = 'Validation errors: instance.payload requires property "bids", instance.payload requires property "asks"'; expect(badCall).throws(errMsg); }); it('throws when update message has malformed payload', () => { - const badCall = () => orderbookChannelMessageParser.parse(malformedUpdateOrdersChannelMessage); + const badCall = () => ordersChannelMessageParser.parse(malformedUpdateOrdersChannelMessage); expect(badCall).throws(/^Expected message to conform to schema/); }); it('throws when input message is not valid JSON', () => { const nonJsonString = 'h93b{sdfs9fsd f'; - const badCall = () => orderbookChannelMessageParser.parse(nonJsonString); + const badCall = () => ordersChannelMessageParser.parse(nonJsonString); expect(badCall).throws('Unexpected assetData h in JSON at position 0'); }); }); -- cgit v1.2.3 From 80e5127a469a0f38cddc18a45a4a7e019191760c Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 14 Aug 2018 17:16:03 -0700 Subject: Update types and add missing param to SRA spec --- packages/connect/package.json | 2 +- packages/connect/src/types.ts | 36 ++++++++++++++++++++---------------- packages/connect/src/utils/assert.ts | 3 +-- 3 files changed, 22 insertions(+), 19 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/package.json b/packages/connect/package.json index 39376a9a6..336cb85fc 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -53,7 +53,7 @@ "dependencies": { "@0xproject/assert": "^0.2.14", "@0xproject/json-schemas": "^1.0.1-rc.4", - "@0xproject/types": "^0.8.2", + "@0xproject/types": "^1.0.1-rc.4", "@0xproject/typescript-typings": "^1.0.4", "@0xproject/utils": "^1.0.5", "lodash": "^4.17.5", diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index fb51dca98..dab01c935 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -94,14 +94,18 @@ export interface Asset { } export interface OrdersRequestOpts { + makerAssetProxyId?: string; + takerAssetProxyId?: string; + makerAssetAddress?: string; + takerAssetAddress?: string; exchangeAddress?: string; - tokenAddress?: string; - makerTokenAddress?: string; - takerTokenAddress?: string; - maker?: string; - taker?: string; - trader?: string; - feeRecipient?: string; + senderAddress?: string; + makerAssetData?: string; + takerAssetData?: string; + makerAddress?: string; + takerAddress?: string; + traderAddress?: string; + feeRecipientAddress?: string; } export interface OrderbookRequest { @@ -122,21 +126,21 @@ export interface PaginatedCollection { } export interface OrderConfigRequest { + makerAddress: string; + takerAddress: string; + makerAssetAmount: string; + takerAssetAmount: string; + makerAssetData: string; + takerAssetData: string; exchangeAddress: string; - maker: string; - taker: string; - makerTokenAddress: string; - takerTokenAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; + expirationTimeSeconds: string; } export interface OrderConfigResponse { - feeRecipient: string; makerFee: BigNumber; takerFee: BigNumber; + feeRecipientAddress: string; + senderAddress: string; } export interface PagedRequestOpts { diff --git a/packages/connect/src/utils/assert.ts b/packages/connect/src/utils/assert.ts index a0fd12fbd..353b7f29f 100644 --- a/packages/connect/src/utils/assert.ts +++ b/packages/connect/src/utils/assert.ts @@ -14,11 +14,10 @@ export const assert = { sharedAssert.doesConformToSchema( variableName, subscriptionOpts, - schemas.relayerApiOrderbookChannelSubscribePayload, + schemas.relayerApiOrdersChannelSubscribePayload, ); }, isOrderbookChannelHandler(variableName: string, handler: any): void { - sharedAssert.isFunction(`${variableName}.onSnapshot`, _.get(handler, 'onSnapshot')); sharedAssert.isFunction(`${variableName}.onUpdate`, _.get(handler, 'onUpdate')); sharedAssert.isFunction(`${variableName}.onError`, _.get(handler, 'onError')); sharedAssert.isFunction(`${variableName}.onClose`, _.get(handler, 'onClose')); -- cgit v1.2.3 From 3eeb9ddfa6440d9287c0b2e6c6c51847cedf8b96 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 14 Aug 2018 17:31:19 -0700 Subject: Update connect json-schemas --- .../src/schemas/asset_pairs_request_opts_schema.ts | 8 +++++++ .../connect/src/schemas/fees_request_schema.ts | 26 ---------------------- .../src/schemas/order_config_request_schema.ts | 24 ++++++++++++++++++++ .../src/schemas/orderbook_request_schema.ts | 4 ++-- .../src/schemas/orders_request_opts_schema.ts | 23 ++++++++++--------- packages/connect/src/schemas/schemas.ts | 8 +++---- .../src/schemas/token_pairs_request_opts_schema.ts | 8 ------- 7 files changed, 51 insertions(+), 50 deletions(-) create mode 100644 packages/connect/src/schemas/asset_pairs_request_opts_schema.ts delete mode 100644 packages/connect/src/schemas/fees_request_schema.ts create mode 100644 packages/connect/src/schemas/order_config_request_schema.ts delete mode 100644 packages/connect/src/schemas/token_pairs_request_opts_schema.ts (limited to 'packages/connect') diff --git a/packages/connect/src/schemas/asset_pairs_request_opts_schema.ts b/packages/connect/src/schemas/asset_pairs_request_opts_schema.ts new file mode 100644 index 000000000..f224503cc --- /dev/null +++ b/packages/connect/src/schemas/asset_pairs_request_opts_schema.ts @@ -0,0 +1,8 @@ +export const assetPairsRequestOptsSchema = { + id: '/AssetPairsRequestOpts', + type: 'object', + properties: { + assetDataA: { $ref: '/Address' }, + assetDataB: { $ref: '/Address' }, + }, +}; diff --git a/packages/connect/src/schemas/fees_request_schema.ts b/packages/connect/src/schemas/fees_request_schema.ts deleted file mode 100644 index e41e49e09..000000000 --- a/packages/connect/src/schemas/fees_request_schema.ts +++ /dev/null @@ -1,26 +0,0 @@ -export const feesRequestSchema = { - id: '/OrderConfigRequest', - type: 'object', - properties: { - exchangeAddress: { $ref: '/Address' }, - maker: { $ref: '/Address' }, - taker: { $ref: '/Address' }, - makerTokenAddress: { $ref: '/Address' }, - takerTokenAddress: { $ref: '/Address' }, - makerAssetAmount: { $ref: '/Number' }, - takerAssetAmount: { $ref: '/Number' }, - expirationTimeSeconds: { $ref: '/Number' }, - salt: { $ref: '/Number' }, - }, - required: [ - 'exchangeAddress', - 'maker', - 'taker', - 'makerTokenAddress', - 'takerTokenAddress', - 'makerAssetAmount', - 'takerAssetAmount', - 'expirationTimeSeconds', - 'salt', - ], -}; diff --git a/packages/connect/src/schemas/order_config_request_schema.ts b/packages/connect/src/schemas/order_config_request_schema.ts new file mode 100644 index 000000000..8f6b19500 --- /dev/null +++ b/packages/connect/src/schemas/order_config_request_schema.ts @@ -0,0 +1,24 @@ +export const orderConfigRequestSchema = { + id: '/OrderConfigRequest', + type: 'object', + properties: { + makerAddress: { $ref: '/addressSchema' }, + takerAddress: { $ref: '/addressSchema' }, + makerAssetAmount: { $ref: '/numberSchema' }, + takerAssetAmount: { $ref: '/numberSchema' }, + makerAssetData: { $ref: '/hexSchema'}, + takerAssetData: { $ref: '/hexSchema' }, + exchangeAddress: { $ref: '/addressSchema' }, + expirationTimeSeconds: { $ref: '/numberSchema' }, + }, + required: [ + 'makerAddress', + 'takerAddress', + 'makerAssetAmount', + 'takerAssetAmount', + 'makerAssetData', + 'takerAssetData', + 'exchangeAddress', + 'expirationTimeSeconds', + ], +}; diff --git a/packages/connect/src/schemas/orderbook_request_schema.ts b/packages/connect/src/schemas/orderbook_request_schema.ts index cc75ada5c..0c9389d50 100644 --- a/packages/connect/src/schemas/orderbook_request_schema.ts +++ b/packages/connect/src/schemas/orderbook_request_schema.ts @@ -2,8 +2,8 @@ export const orderBookRequestSchema = { id: '/OrderBookRequest', type: 'object', properties: { - baseAssetData: { $ref: '/Address' }, - quoteAssetData: { $ref: '/Address' }, + baseAssetData: { $ref: '/hexSchema' }, + quoteAssetData: { $ref: '/hexSchema' }, }, required: ['baseAssetData', 'quoteAssetData'], }; diff --git a/packages/connect/src/schemas/orders_request_opts_schema.ts b/packages/connect/src/schemas/orders_request_opts_schema.ts index 1a9f74f7f..71ce3d06f 100644 --- a/packages/connect/src/schemas/orders_request_opts_schema.ts +++ b/packages/connect/src/schemas/orders_request_opts_schema.ts @@ -2,15 +2,18 @@ export const ordersRequestOptsSchema = { id: '/OrdersRequestOpts', type: 'object', properties: { - exchangeAddress: { $ref: '/Address' }, - tokenAddress: { $ref: '/Address' }, - makerTokenAddress: { $ref: '/Address' }, - takerTokenAddress: { $ref: '/Address' }, - assetDataA: { $ref: '/Address' }, - assetDataB: { $ref: '/Address' }, - maker: { $ref: '/Address' }, - taker: { $ref: '/Address' }, - trader: { $ref: '/Address' }, - feeRecipient: { $ref: '/Address' }, + makerAssetProxyId: { $ref: '/hexSchema' }, + takerAssetProxyId: { $ref: '/hexSchema' }, + makerAssetAddress: { $ref: '/addressSchema' }, + takerAssetAddress: { $ref: '/addressSchema' }, + exchangeAddress: { $ref: '/addressSchema' }, + senderAddress: { $ref: '/addressSchema' }, + makerAssetData: { $ref: '/hexSchema' }, + takerAssetData: { $ref: '/hexSchema' }, + traderAssetData: { $ref: '/hexSchema' }, + makerAddress: { $ref: '/addressSchema' }, + takerAddress: { $ref: '/addressSchema' }, + traderAddress: { $ref: '/addressSchema' }, + feeRecipientAddress: { $ref: '/addressSchema' }, }, }; diff --git a/packages/connect/src/schemas/schemas.ts b/packages/connect/src/schemas/schemas.ts index e6ca010ae..a7e968a01 100644 --- a/packages/connect/src/schemas/schemas.ts +++ b/packages/connect/src/schemas/schemas.ts @@ -1,13 +1,13 @@ -import { feesRequestSchema } from './fees_request_schema'; +import { assetPairsRequestOptsSchema } from './asset_pairs_request_opts_schema'; +import { orderConfigRequestSchema } from './order_config_request_schema'; import { orderBookRequestSchema } from './orderbook_request_schema'; import { ordersRequestOptsSchema } from './orders_request_opts_schema'; import { pagedRequestOptsSchema } from './paged_request_opts_schema'; -import { AssetPairsRequestOptsSchema } from './token_pairs_request_opts_schema'; export const schemas = { - feesRequestSchema, + orderConfigRequestSchema, orderBookRequestSchema, ordersRequestOptsSchema, pagedRequestOptsSchema, - AssetPairsRequestOptsSchema, + assetPairsRequestOptsSchema, }; diff --git a/packages/connect/src/schemas/token_pairs_request_opts_schema.ts b/packages/connect/src/schemas/token_pairs_request_opts_schema.ts deleted file mode 100644 index bf1caa20d..000000000 --- a/packages/connect/src/schemas/token_pairs_request_opts_schema.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const AssetPairsRequestOptsSchema = { - id: '/AssetPairsRequestOpts', - type: 'object', - properties: { - assetDataA: { $ref: '/Address' }, - assetDataB: { $ref: '/Address' }, - }, -}; -- cgit v1.2.3 From bb992f8a49b42a1cd50d5bcc868f6d69fcd1a7ae Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 14 Aug 2018 19:16:36 -0700 Subject: Update parsing code --- packages/connect/src/http_client.ts | 22 ++++++++++++---------- packages/connect/src/types.ts | 4 ++++ .../src/utils/relayer_response_json_parsers.ts | 22 ++++++++++++---------- packages/connect/src/utils/type_converters.ts | 17 +++++++++++++++-- 4 files changed, 43 insertions(+), 22 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 20a2f9cc0..10c956ff8 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -8,8 +8,8 @@ import * as queryString from 'query-string'; import { schemas as clientSchemas } from './schemas/schemas'; import { APIOrder, - AssetPairsItem, AssetPairsRequestOpts, + AssetPairsResponse, Client, HttpRequestOptions, HttpRequestType, @@ -18,6 +18,7 @@ import { OrderConfigRequest, OrderConfigResponse, OrdersRequestOpts, + OrdersResponse, PagedRequestOpts, PaginatedCollection, } from './types'; @@ -61,9 +62,9 @@ export class HttpClient implements Client { * @param requestOpts Options specifying assetData information to retrieve and page information, defaults to { page: 1, perPage: 100 } * @return The resulting AssetPairsItems that match the request */ - public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise> { + public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise { if (!_.isUndefined(requestOpts)) { - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.AssetPairsRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.assetPairsRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); } const httpRequestOpts = { @@ -78,7 +79,7 @@ export class HttpClient implements Client { * @param requestOpts Options specifying orders to retrieve and page information, defaults to { page: 1, perPage: 100 } * @return The resulting SignedOrders that match the request */ - public async getOrdersAsync(requestOpts?: OrdersRequestOpts & PagedRequestOpts): Promise> { + public async getOrdersAsync(requestOpts?: OrdersRequestOpts & PagedRequestOpts): Promise { if (!_.isUndefined(requestOpts)) { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.ordersRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); @@ -98,7 +99,7 @@ export class HttpClient implements Client { public async getOrderAsync(orderHash: string): Promise { assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get); - const order = relayerResponseJsonParsers.parseOrderJson(responseJson); + const order = relayerResponseJsonParsers.parseAPIOrderJson(responseJson); return order; } /** @@ -128,18 +129,19 @@ export class HttpClient implements Client { * @return The resulting OrderConfigResponse that matches the request */ public async getOrderConfigAsync(request: OrderConfigRequest): Promise { - assert.doesConformToSchema('request', request, clientSchemas.feesRequestSchema); + assert.doesConformToSchema('request', request, clientSchemas.orderConfigRequestSchema); const httpRequestOpts = { payload: request, }; - const responseJson = await this._requestAsync('/fees', HttpRequestType.Post, httpRequestOpts); + const responseJson = await this._requestAsync('/order_config', HttpRequestType.Post, httpRequestOpts); const fees = relayerResponseJsonParsers.parseOrderConfigResponseJson(responseJson); return fees; } - + /** + * Retrieve the list of fee recipient addresses used by + */ public async getFeeRecipientsAsync(): Promise> { - // TODO - return; + return this._requestAsync('/fee_recipients', HttpRequestType.Get); } /** diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index dab01c935..8c2eaff7d 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -71,6 +71,8 @@ export enum WebsocketClientEventType { ConnectFailed = 'connectFailed', } +export type OrdersResponse = PaginatedCollection; + export interface APIOrder { order: SignedOrder; metaData: object; @@ -81,6 +83,8 @@ export interface AssetPairsRequestOpts { assetDataB?: string; } +export type AssetPairsResponse = PaginatedCollection; + export interface AssetPairsItem { assetDataA: Asset; assetDataB: Asset; diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts index 6463aefb0..9a17b23d3 100644 --- a/packages/connect/src/utils/relayer_response_json_parsers.ts +++ b/packages/connect/src/utils/relayer_response_json_parsers.ts @@ -1,14 +1,16 @@ import { assert } from '@0xproject/assert'; import { schemas } from '@0xproject/json-schemas'; -import { SignedOrder } from '@0xproject/types'; -import { AssetPairsItem, OrderbookResponse, OrderConfigResponse } from '../types'; +import { APIOrder, AssetPairsItem, AssetPairsResponse, OrderbookResponse, OrderConfigResponse, OrdersResponse } from '../types'; import { typeConverters } from './type_converters'; export const relayerResponseJsonParsers = { - parseAssetDataPairsJson(json: any): AssetPairsItem[] { + parseAssetDataPairsJson(json: any): AssetPairsResponse { assert.doesConformToSchema('assetDataPairs', json, schemas.relayerApiAssetDataPairsResponseSchema); + return { ...json, records: relayerResponseJsonParsers.parseAssetDataPairsJson(json.records) }; + }, + parseAssetPairsItemJson(json: any): AssetPairsItem[] { return json.map((assetDataPair: any) => { return typeConverters.convertStringsFieldsToBigNumbers(assetDataPair, [ 'assetDataA.minAmount', @@ -18,20 +20,20 @@ export const relayerResponseJsonParsers = { ]); }); }, - parseOrdersJson(json: any): SignedOrder[] { - assert.doesConformToSchema('orders', json, schemas.signedOrdersSchema); - return json.map((order: object) => typeConverters.convertOrderStringFieldsToBigNumber(order)); + parseOrdersJson(json: any): OrdersResponse { + assert.doesConformToSchema('relayerApiOrdersResponse', json, schemas.relayerApiOrdersResponseSchema); + return { ...json, records: json.records.map(relayerResponseJsonParsers.parseAPIOrderJson.bind(relayerResponseJsonParsers)) }; }, - parseOrderJson(json: any): SignedOrder { - assert.doesConformToSchema('order', json, schemas.signedOrderSchema); + parseAPIOrderJson(json: any): APIOrder { + assert.doesConformToSchema('relayerApiOrder', json, schemas.relayerApiOrderSchema); return typeConverters.convertOrderStringFieldsToBigNumber(json); }, parseOrderbookResponseJson(json: any): OrderbookResponse { - assert.doesConformToSchema('orderBook', json, schemas.relayerApiOrdersResponseSchema); + assert.doesConformToSchema('orderBook', json, schemas.relayerApiOrderbookResponseSchema); return typeConverters.convertOrderbookStringFieldsToBigNumber(json); }, parseOrderConfigResponseJson(json: any): OrderConfigResponse { - assert.doesConformToSchema('fees', json, schemas.relayerApiOrderConfigResponseSchema); + assert.doesConformToSchema('orderConfig', json, schemas.relayerApiOrderConfigResponseSchema); return typeConverters.convertStringsFieldsToBigNumbers(json, ['makerFee', 'takerFee']); }, }; diff --git a/packages/connect/src/utils/type_converters.ts b/packages/connect/src/utils/type_converters.ts index 513f9b39f..c28cba0e1 100644 --- a/packages/connect/src/utils/type_converters.ts +++ b/packages/connect/src/utils/type_converters.ts @@ -1,15 +1,28 @@ import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; +import { APIOrder } from '../types'; + export const typeConverters = { convertOrderbookStringFieldsToBigNumber(orderbook: any): any { const bids = _.get(orderbook, 'bids', []); const asks = _.get(orderbook, 'asks', []); + const convertedBids = { + ...bids, + records: bids.records.map((order: any) => typeConverters.convertAPIOrderStringFieldsToBigNumber(order)), + }; + const convertedAsks = { + ...asks, + records: asks.records.map((order: any) => typeConverters.convertAPIOrderStringFieldsToBigNumber(order)), + }; return { - bids: bids.map((order: any) => typeConverters.convertOrderStringFieldsToBigNumber(order)), - asks: asks.map((order: any) => typeConverters.convertOrderStringFieldsToBigNumber(order)), + bids: convertedBids, + asks: convertedAsks, }; }, + convertAPIOrderStringFieldsToBigNumber(apiOrder: any): APIOrder { + return { ...apiOrder, order: typeConverters.convertOrderStringFieldsToBigNumber(apiOrder.order) }; + }, convertOrderStringFieldsToBigNumber(order: any): any { return typeConverters.convertStringsFieldsToBigNumbers(order, [ 'makerAssetAmount', -- cgit v1.2.3 From 41768617a9130828339f3c231322c176ce19fd1d Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 15 Aug 2018 14:41:09 -0700 Subject: Update test fixtures --- packages/connect/src/http_client.ts | 3 +- packages/connect/src/types.ts | 4 +- .../src/utils/orderbook_channel_message_parser.ts | 2 +- .../fixtures/standard_relayer_api/asset_pairs.json | 21 +++++ .../fixtures/standard_relayer_api/asset_pairs.ts | 25 ++++++ .../standard_relayer_api/fee_recipients.json | 10 +++ .../standard_relayer_api/fee_recipients.ts | 14 ++++ .../test/fixtures/standard_relayer_api/fees.json | 5 -- .../test/fixtures/standard_relayer_api/fees.ts | 9 --- ...77fa9ac94a50f016026fd13f42990861238897721f.json | 35 ++++---- ...f977fa9ac94a50f016026fd13f42990861238897721f.ts | 34 ++++---- .../standard_relayer_api/order_config.json | 6 ++ .../fixtures/standard_relayer_api/order_config.ts | 10 +++ .../fixtures/standard_relayer_api/orderbook.json | 92 +++++++++++---------- .../fixtures/standard_relayer_api/orderbook.ts | 94 ++++++++++++---------- .../test/fixtures/standard_relayer_api/orders.json | 46 ++++++----- .../test/fixtures/standard_relayer_api/orders.ts | 47 ++++++----- .../fixtures/standard_relayer_api/token_pairs.json | 16 ---- .../fixtures/standard_relayer_api/token_pairs.ts | 20 ----- 19 files changed, 284 insertions(+), 209 deletions(-) create mode 100644 packages/connect/test/fixtures/standard_relayer_api/asset_pairs.json create mode 100644 packages/connect/test/fixtures/standard_relayer_api/asset_pairs.ts create mode 100644 packages/connect/test/fixtures/standard_relayer_api/fee_recipients.json create mode 100644 packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts delete mode 100644 packages/connect/test/fixtures/standard_relayer_api/fees.json delete mode 100644 packages/connect/test/fixtures/standard_relayer_api/fees.ts create mode 100644 packages/connect/test/fixtures/standard_relayer_api/order_config.json create mode 100644 packages/connect/test/fixtures/standard_relayer_api/order_config.ts delete mode 100644 packages/connect/test/fixtures/standard_relayer_api/token_pairs.json delete mode 100644 packages/connect/test/fixtures/standard_relayer_api/token_pairs.ts (limited to 'packages/connect') diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 10c956ff8..7783af876 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -21,6 +21,7 @@ import { OrdersResponse, PagedRequestOpts, PaginatedCollection, + FeeRecipientsResponse, } from './types'; import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers'; @@ -140,7 +141,7 @@ export class HttpClient implements Client { /** * Retrieve the list of fee recipient addresses used by */ - public async getFeeRecipientsAsync(): Promise> { + public async getFeeRecipientsAsync(): Promise { return this._requestAsync('/fee_recipients', HttpRequestType.Get); } diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index 8c2eaff7d..42417f709 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -7,7 +7,7 @@ export interface Client { getOrderAsync: (orderHash: string) => Promise; getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise; getOrderConfigAsync: (request: OrderConfigRequest) => Promise; - getFeeRecipientsAsync: () => Promise>; + getFeeRecipientsAsync: () => Promise; submitOrderAsync: (signedOrder: SignedOrder) => Promise; } @@ -147,6 +147,8 @@ export interface OrderConfigResponse { senderAddress: string; } +export type FeeRecipientsResponse = PaginatedCollection; + export interface PagedRequestOpts { page?: number; perPage?: number; diff --git a/packages/connect/src/utils/orderbook_channel_message_parser.ts b/packages/connect/src/utils/orderbook_channel_message_parser.ts index 986209c54..97d8f2d6a 100644 --- a/packages/connect/src/utils/orderbook_channel_message_parser.ts +++ b/packages/connect/src/utils/orderbook_channel_message_parser.ts @@ -22,7 +22,7 @@ export const ordersChannelMessageParser = { case OrdersChannelMessageTypes.Update: { assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrdersChannelUpdateSchema); const orderJson = messageObj.payload; - const order = relayerResponseJsonParsers.parseOrderJson(orderJson); + const order = relayerResponseJsonParsers.parseAPIOrderJson(orderJson); return _.assign(messageObj, { payload: order }); } default: { diff --git a/packages/connect/test/fixtures/standard_relayer_api/asset_pairs.json b/packages/connect/test/fixtures/standard_relayer_api/asset_pairs.json new file mode 100644 index 000000000..603e9f67e --- /dev/null +++ b/packages/connect/test/fixtures/standard_relayer_api/asset_pairs.json @@ -0,0 +1,21 @@ +{ + "total": 43, + "page": 1, + "perPage": 100, + "records": [ + { + "assetDataA": { + "minAmount": "0", + "maxAmount": "10000000000000000000", + "precision": 5, + "assetData": "0xf47261b04c32345ced77393b3530b1eed0f346429d" + }, + "assetDataB": { + "minAmount": "0", + "maxAmount": "50000000000000000000", + "precision": 5, + "assetData": "0x0257179264389b814a946f3e92105513705ca6b990" + } + } + ] +} diff --git a/packages/connect/test/fixtures/standard_relayer_api/asset_pairs.ts b/packages/connect/test/fixtures/standard_relayer_api/asset_pairs.ts new file mode 100644 index 000000000..8fc6435ec --- /dev/null +++ b/packages/connect/test/fixtures/standard_relayer_api/asset_pairs.ts @@ -0,0 +1,25 @@ +import { BigNumber } from '@0xproject/utils'; + +import { AssetPairsResponse } from '../../../src/types'; + +export const assetDataPairsResponse: AssetPairsResponse = { + total: 43, + page: 1, + perPage: 100, + records: [ + { + assetDataA: { + minAmount: new BigNumber('0'), + maxAmount: new BigNumber('10000000000000000000'), + precision: 5, + assetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d', + }, + assetDataB: { + minAmount: new BigNumber('0'), + maxAmount: new BigNumber('50000000000000000000'), + precision: 5, + assetData: '0x0257179264389b814a946f3e92105513705ca6b990', + }, + }, + ], +}; \ No newline at end of file diff --git a/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.json b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.json new file mode 100644 index 000000000..1ea3dcc0e --- /dev/null +++ b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.json @@ -0,0 +1,10 @@ +{ + "total": 3, + "page": 1, + "perPage": 10, + "records": [ + "0x6eC92694ea172ebC430C30fa31De87620967A082", + "0x9e56625509c2f60af937f23b7b532600390e8c8b", + "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32" + ] +} \ No newline at end of file diff --git a/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts new file mode 100644 index 000000000..84ea4cd6c --- /dev/null +++ b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts @@ -0,0 +1,14 @@ +import { BigNumber } from '@0xproject/utils'; + +import { FeeRecipientsResponse } from '../../../src/types'; + +export const feeRecipientsResponse: FeeRecipientsResponse = { + total: 3, + page: 1, + perPage: 10, + records: [ + '0x6eC92694ea172ebC430C30fa31De87620967A082', + '0x9e56625509c2f60af937f23b7b532600390e8c8b', + '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', + ], +}; \ No newline at end of file diff --git a/packages/connect/test/fixtures/standard_relayer_api/fees.json b/packages/connect/test/fixtures/standard_relayer_api/fees.json deleted file mode 100644 index 483a74254..000000000 --- a/packages/connect/test/fixtures/standard_relayer_api/fees.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "feeRecipient": "0x323b5d4c32345ced77393b3530b1eed0f346429d", - "makerFee": "10000000000000000", - "takerFee": "30000000000000000" -} diff --git a/packages/connect/test/fixtures/standard_relayer_api/fees.ts b/packages/connect/test/fixtures/standard_relayer_api/fees.ts deleted file mode 100644 index 7a526b491..000000000 --- a/packages/connect/test/fixtures/standard_relayer_api/fees.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { BigNumber } from '@0xproject/utils'; - -import { OrderConfigResponse } from '../../../src/types'; - -export const feesResponse: OrderConfigResponse = { - feeRecipient: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - makerFee: new BigNumber('10000000000000000'), - takerFee: new BigNumber('30000000000000000'), -}; diff --git a/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json b/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json index 23e4fb327..4a2ab6914 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json +++ b/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json @@ -1,19 +1,20 @@ { - "maker": "0x9e56625509c2f60af937f23b7b532600390e8c8b", - "taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", - "makerFee": "100000000000000", - "takerFee": "200000000000000", - "makerAssetAmount": "10000000000000000", - "takerAssetAmount": "20000000000000000", - "makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d", - "takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990", - "salt": "256", - "feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da", - "exchangeAddress": "0x12459c951127e0c374ff9105dda097662a027093", - "expirationTimeSeconds": "42", - "ecSignature": { - "v": 27, - "r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33", - "s": "0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254" - } + "order": { + "makerAddress": "0x9e56625509c2f60af937f23b7b532600390e8c8b", + "takerAddress": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", + "feeRecipientAddress": "0xb046140686d052fff581f63f8136cce132e857da", + "senderAddress": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", + "makerAssetAmount": "10000000000000000", + "takerAssetAmount": "20000000000000000", + "makerFee": "100000000000000", + "takerFee": "200000000000000", + "expirationTimeSeconds": "1532560590", + "salt": "1532559225", + "makerAssetData": "0xf47261b04c32345ced77393b3530b1eed0f346429d", + "takerAssetData": "0x0257179264389b814a946f3e92105513705ca6b990", + "exchangeAddress": "0x12459c951127e0c374ff9105dda097662a027093", + "signature": "0x012761a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33" + }, + "metaData": {} } + diff --git a/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.ts b/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.ts index 68446c83a..d4f056d3e 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.ts @@ -1,21 +1,21 @@ import { BigNumber } from '@0xproject/utils'; -export const orderResponse = { - maker: '0x9e56625509c2f60af937f23b7b532600390e8c8b', - taker: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', - makerFee: new BigNumber('100000000000000'), - takerFee: new BigNumber('200000000000000'), - makerAssetAmount: new BigNumber('10000000000000000'), - takerAssetAmount: new BigNumber('20000000000000000'), - makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - salt: new BigNumber('256'), - feeRecipient: '0xb046140686d052fff581f63f8136cce132e857da', - exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', - expirationTimeSeconds: new BigNumber('42'), - ecSignature: { - v: 27, - r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', +export const apiOrderResponse = { + order: { + makerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b', + takerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', + feeRecipientAddress: '0xb046140686d052fff581f63f8136cce132e857da', + senderAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', + makerAssetAmount: new BigNumber('10000000000000000'), + takerAssetAmount: new BigNumber('20000000000000000'), + makerFee: new BigNumber('100000000000000'), + takerFee: new BigNumber('200000000000000'), + expirationTimeSeconds: new BigNumber('1532560590'), + salt: new BigNumber('1532559225'), + makerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d', + takerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990', + exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', + signature: '0x012761a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', }, + metaData: {}, }; diff --git a/packages/connect/test/fixtures/standard_relayer_api/order_config.json b/packages/connect/test/fixtures/standard_relayer_api/order_config.json new file mode 100644 index 000000000..39da91e6d --- /dev/null +++ b/packages/connect/test/fixtures/standard_relayer_api/order_config.json @@ -0,0 +1,6 @@ +{ + "senderAddress": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", + "feeRecipientAddress": "0xb046140686d052fff581f63f8136cce132e857da", + "makerFee": "100000000000000", + "takerFee": "200000000000000" +} diff --git a/packages/connect/test/fixtures/standard_relayer_api/order_config.ts b/packages/connect/test/fixtures/standard_relayer_api/order_config.ts new file mode 100644 index 000000000..36f01a009 --- /dev/null +++ b/packages/connect/test/fixtures/standard_relayer_api/order_config.ts @@ -0,0 +1,10 @@ +import { BigNumber } from '@0xproject/utils'; + +import { OrderConfigResponse } from '../../../src/types'; + +export const orderConfigResponse: OrderConfigResponse = { + senderAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', + feeRecipientAddress: '0xb046140686d052fff581f63f8136cce132e857da', + makerFee: new BigNumber('100000000000000'), + takerFee: new BigNumber('200000000000000'), +}; diff --git a/packages/connect/test/fixtures/standard_relayer_api/orderbook.json b/packages/connect/test/fixtures/standard_relayer_api/orderbook.json index 2dec4b0fe..b14d12e57 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/orderbook.json +++ b/packages/connect/test/fixtures/standard_relayer_api/orderbook.json @@ -1,44 +1,54 @@ { - "bids": [ - { - "maker": "0x9e56625509c2f60af937f23b7b532600390e8c8b", - "taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", - "makerFee": "100000000000000", - "takerFee": "200000000000000", - "makerAssetAmount": "10000000000000000", - "takerAssetAmount": "20000000000000000", - "makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d", - "takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990", - "salt": "256", - "feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da", - "exchangeAddress": "0x12459c951127e0c374ff9105dda097662a027093", - "expirationTimeSeconds": "42", - "ecSignature": { - "v": 27, - "r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33", - "s": "0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254" + "bids": { + "total": 325, + "page": 2, + "perPage": 100, + "records": [ + { + "order": { + "makerAddress": "0x9e56625509c2f60af937f23b7b532600390e8c8b", + "takerAddress": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", + "feeRecipientAddress": "0xb046140686d052fff581f63f8136cce132e857da", + "senderAddress": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", + "makerAssetAmount": "10000000000000000", + "takerAssetAmount": "20000000000000000", + "makerFee": "100000000000000", + "takerFee": "200000000000000", + "expirationTimeSeconds": "1532560590", + "salt": "1532559225", + "makerAssetData": "0xf47261b04c32345ced77393b3530b1eed0f346429d", + "takerAssetData": "0x0257179264389b814a946f3e92105513705ca6b990", + "exchangeAddress": "0x12459c951127e0c374ff9105dda097662a027093", + "signature": "0x012761a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33" + }, + "metaData": {} } - } - ], - "asks": [ - { - "maker": "0x9e56625509c2f60af937f23b7b532600390e8c8b", - "taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", - "makerFee": "100000000000000", - "takerFee": "200000000000000", - "makerAssetAmount": "10000000000000000", - "takerAssetAmount": "20000000000000000", - "makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d", - "takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990", - "salt": "256", - "feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da", - "exchangeAddress": "0x12459c951127e0c374ff9105dda097662a027093", - "expirationTimeSeconds": "42", - "ecSignature": { - "v": 27, - "r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33", - "s": "0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254" + ] + }, + "asks": { + "total": 500, + "page": 2, + "perPage": 100, + "records": [ + { + "order": { + "makerAddress": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", + "takerAddress": "0x9e56625509c2f60af937f23b7b532600390e8c8b", + "feeRecipientAddress": "0xb046140686d052fff581f63f8136cce132e857da", + "senderAddress": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", + "makerAssetAmount": "20000000000000000", + "takerAssetAmount": "10000000000000000", + "makerFee": "200000000000000", + "takerFee": "100000000000000", + "expirationTimeSeconds": "1532560590", + "salt": "1532559225", + "makerAssetData": "0x0257179264389b814a946f3e92105513705ca6b990", + "takerAssetData": "0xf47261b04c32345ced77393b3530b1eed0f346429d", + "exchangeAddress": "0x12459c951127e0c374ff9105dda097662a027093", + "signature": "0x013842a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b3518891" + }, + "metaData": {} } - } - ] -} + ] + } +} \ No newline at end of file diff --git a/packages/connect/test/fixtures/standard_relayer_api/orderbook.ts b/packages/connect/test/fixtures/standard_relayer_api/orderbook.ts index 9f80988ce..d5f39a51f 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/orderbook.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/orderbook.ts @@ -1,46 +1,58 @@ import { BigNumber } from '@0xproject/utils'; -export const orderbookResponse = { - bids: [ - { - maker: '0x9e56625509c2f60af937f23b7b532600390e8c8b', - taker: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', - makerFee: new BigNumber('100000000000000'), - takerFee: new BigNumber('200000000000000'), - makerAssetAmount: new BigNumber('10000000000000000'), - takerAssetAmount: new BigNumber('20000000000000000'), - makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - salt: new BigNumber('256'), - feeRecipient: '0xb046140686d052fff581f63f8136cce132e857da', - exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', - expirationTimeSeconds: new BigNumber('42'), - ecSignature: { - v: 27, - r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', +import { OrderbookResponse } from '../../../src/types'; + +export const orderbookResponse: OrderbookResponse = { + bids: { + total: 325, + page: 2, + perPage: 100, + records: [ + { + order: { + makerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b', + takerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', + feeRecipientAddress: '0xb046140686d052fff581f63f8136cce132e857da', + senderAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', + makerAssetAmount: new BigNumber('10000000000000000'), + takerAssetAmount: new BigNumber('20000000000000000'), + makerFee: new BigNumber('100000000000000'), + takerFee: new BigNumber('200000000000000'), + expirationTimeSeconds: new BigNumber('1532560590'), + salt: new BigNumber('1532559225'), + makerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d', + takerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990', + exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', + signature: '0x012761a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', + }, + metaData: {}, }, - }, - ], - asks: [ - { - maker: '0x9e56625509c2f60af937f23b7b532600390e8c8b', - taker: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', - makerFee: new BigNumber('100000000000000'), - takerFee: new BigNumber('200000000000000'), - makerAssetAmount: new BigNumber('10000000000000000'), - takerAssetAmount: new BigNumber('20000000000000000'), - makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - salt: new BigNumber('256'), - feeRecipient: '0xb046140686d052fff581f63f8136cce132e857da', - exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', - expirationTimeSeconds: new BigNumber('42'), - ecSignature: { - v: 27, - r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', + ], + }, + asks: { + total: 500, + page: 2, + perPage: 100, + records: [ + { + order: { + makerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', + takerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b', + feeRecipientAddress: '0xb046140686d052fff581f63f8136cce132e857da', + senderAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', + makerAssetAmount: new BigNumber('20000000000000000'), + takerAssetAmount: new BigNumber('10000000000000000'), + makerFee: new BigNumber('200000000000000'), + takerFee: new BigNumber('100000000000000'), + expirationTimeSeconds: new BigNumber('1532560590'), + salt: new BigNumber('1532559225'), + makerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990', + takerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d', + exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', + signature: '0x013842a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b3518891', + }, + metaData: {}, }, - }, - ], + ], + }, }; diff --git a/packages/connect/test/fixtures/standard_relayer_api/orders.json b/packages/connect/test/fixtures/standard_relayer_api/orders.json index 929dde4a8..e4fb3a3dd 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/orders.json +++ b/packages/connect/test/fixtures/standard_relayer_api/orders.json @@ -1,21 +1,27 @@ -[ - { - "maker": "0x9e56625509c2f60af937f23b7b532600390e8c8b", - "taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", - "makerFee": "100000000000000", - "takerFee": "200000000000000", - "makerAssetAmount": "10000000000000000", - "takerAssetAmount": "20000000000000000", - "makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d", - "takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990", - "salt": "256", - "feeRecipient": "0x9e56625509c2f60af937f23b7b532600390e8c8b", - "exchangeAddress": "0x9e56625509c2f60af937f23b7b532600390e8c8b", - "expirationTimeSeconds": "42", - "ecSignature": { - "v": 27, - "r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33", - "s": "0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254" +{ + "total": 984, + "page": 1, + "perPage": 100, + "records": [ + { + "order": { + "makerAddress": "0x9e56625509c2f60af937f23b7b532600390e8c8b", + "takerAddress": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", + "feeRecipientAddress": "0xb046140686d052fff581f63f8136cce132e857da", + "senderAddress": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32", + "makerAssetAmount": "10000000000000000", + "takerAssetAmount": "20000000000000000", + "makerFee": "100000000000000", + "takerFee": "200000000000000", + "expirationTimeSeconds": "1532560590", + "salt": "1532559225", + "makerAssetData": "0xf47261b04c32345ced77393b3530b1eed0f346429d", + "takerAssetData": "0x0257179264389b814a946f3e92105513705ca6b990", + "exchangeAddress": "0x12459c951127e0c374ff9105dda097662a027093", + "signature": "0x012761a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33" + }, + "metaData": {} } - } -] + ] +} + diff --git a/packages/connect/test/fixtures/standard_relayer_api/orders.ts b/packages/connect/test/fixtures/standard_relayer_api/orders.ts index 6d32fd3f3..01f8974b8 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/orders.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/orders.ts @@ -1,23 +1,30 @@ import { BigNumber } from '@0xproject/utils'; -export const ordersResponse = [ - { - maker: '0x9e56625509c2f60af937f23b7b532600390e8c8b', - taker: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', - makerFee: new BigNumber('100000000000000'), - takerFee: new BigNumber('200000000000000'), - makerAssetAmount: new BigNumber('10000000000000000'), - takerAssetAmount: new BigNumber('20000000000000000'), - makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - salt: new BigNumber('256'), - feeRecipient: '0x9e56625509c2f60af937f23b7b532600390e8c8b', - exchangeAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b', - expirationTimeSeconds: new BigNumber('42'), - ecSignature: { - v: 27, - r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', +import { OrdersResponse } from '../../../src/types'; + +export const ordersResponse: OrdersResponse = { + total: 984, + page: 1, + perPage: 100, + records: [ + { + order: { + makerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b', + takerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', + feeRecipientAddress: '0xb046140686d052fff581f63f8136cce132e857da', + senderAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', + makerAssetAmount: new BigNumber('10000000000000000'), + takerAssetAmount: new BigNumber('20000000000000000'), + makerFee: new BigNumber('100000000000000'), + takerFee: new BigNumber('200000000000000'), + expirationTimeSeconds: new BigNumber('1532560590'), + salt: new BigNumber('1532559225'), + makerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d', + takerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990', + exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', + signature: '0x012761a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', + }, + metaData: {}, }, - }, -]; + ], +}; diff --git a/packages/connect/test/fixtures/standard_relayer_api/token_pairs.json b/packages/connect/test/fixtures/standard_relayer_api/token_pairs.json deleted file mode 100644 index 2d9610e3d..000000000 --- a/packages/connect/test/fixtures/standard_relayer_api/token_pairs.json +++ /dev/null @@ -1,16 +0,0 @@ -[ - { - "assetDataA": { - "address": "0x323b5d4c32345ced77393b3530b1eed0f346429d", - "minAmount": "0", - "maxAmount": "10000000000000000000", - "precision": 5 - }, - "assetDataB": { - "address": "0xef7fff64389b814a946f3e92105513705ca6b990", - "minAmount": "0", - "maxAmount": "50000000000000000000", - "precision": 5 - } - } -] diff --git a/packages/connect/test/fixtures/standard_relayer_api/token_pairs.ts b/packages/connect/test/fixtures/standard_relayer_api/token_pairs.ts deleted file mode 100644 index 03cce8444..000000000 --- a/packages/connect/test/fixtures/standard_relayer_api/token_pairs.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { BigNumber } from '@0xproject/utils'; - -import { AssetPairsItem } from '../../../src/types'; - -export const assetDataPairsResponse: AssetPairsItem[] = [ - { - assetDataA: { - address: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - minAmount: new BigNumber(0), - maxAmount: new BigNumber('10000000000000000000'), - precision: 5, - }, - assetDataB: { - address: '0xef7fff64389b814a946f3e92105513705ca6b990', - minAmount: new BigNumber(0), - maxAmount: new BigNumber('50000000000000000000'), - precision: 5, - }, - }, -]; -- cgit v1.2.3 From e7f19e350ed9374729e73320d569294e88fde236 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 15 Aug 2018 15:10:39 -0700 Subject: Project now builds --- packages/connect/src/http_client.ts | 3 +- .../fixtures/standard_relayer_api/asset_pairs.ts | 2 +- .../standard_relayer_api/fee_recipients.ts | 3 +- ...f977fa9ac94a50f016026fd13f42990861238897721f.ts | 2 +- packages/connect/test/http_client_test.ts | 33 ++++++++++------------ .../test/orderbook_channel_message_parsers_test.ts | 17 ----------- 6 files changed, 19 insertions(+), 41 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 7783af876..e8b82f0b2 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -11,6 +11,7 @@ import { AssetPairsRequestOpts, AssetPairsResponse, Client, + FeeRecipientsResponse, HttpRequestOptions, HttpRequestType, OrderbookRequest, @@ -20,8 +21,6 @@ import { OrdersRequestOpts, OrdersResponse, PagedRequestOpts, - PaginatedCollection, - FeeRecipientsResponse, } from './types'; import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers'; diff --git a/packages/connect/test/fixtures/standard_relayer_api/asset_pairs.ts b/packages/connect/test/fixtures/standard_relayer_api/asset_pairs.ts index 8fc6435ec..5ce703317 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/asset_pairs.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/asset_pairs.ts @@ -22,4 +22,4 @@ export const assetDataPairsResponse: AssetPairsResponse = { }, }, ], -}; \ No newline at end of file +}; diff --git a/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts index 84ea4cd6c..9da2703df 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts @@ -1,4 +1,3 @@ -import { BigNumber } from '@0xproject/utils'; import { FeeRecipientsResponse } from '../../../src/types'; @@ -11,4 +10,4 @@ export const feeRecipientsResponse: FeeRecipientsResponse = { '0x9e56625509c2f60af937f23b7b532600390e8c8b', '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', ], -}; \ No newline at end of file +}; diff --git a/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.ts b/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.ts index d4f056d3e..c8a669b3b 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.ts @@ -1,6 +1,6 @@ import { BigNumber } from '@0xproject/utils'; -export const apiOrderResponse = { +export const orderResponse = { order: { makerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b', takerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 866cf7b2f..fc5d01706 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -7,12 +7,12 @@ import 'mocha'; import { HttpClient } from '../src/index'; -import { assetDataPairsResponse } from './fixtures/standard_relayer_api/assetData_pairs'; -import * as assetDataPairsResponseJSON from './fixtures/standard_relayer_api/assetData_pairs.json'; -import { feesResponse } from './fixtures/standard_relayer_api/fees'; -import * as feesResponseJSON from './fixtures/standard_relayer_api/fees.json'; +import { assetDataPairsResponse } from './fixtures/standard_relayer_api/asset_pairs'; +import * as assetDataPairsResponseJSON from './fixtures/standard_relayer_api/asset_pairs.json'; import { orderResponse } from './fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f'; import * as orderResponseJSON from './fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json'; +import { orderConfigResponse } from './fixtures/standard_relayer_api/order_config'; +import * as orderConfigResponseJSON from './fixtures/standard_relayer_api/order_config.json'; import { orderbookResponse } from './fixtures/standard_relayer_api/orderbook'; import * as orderbookJSON from './fixtures/standard_relayer_api/orderbook.json'; import { ordersResponse } from './fixtures/standard_relayer_api/orders'; @@ -39,7 +39,7 @@ describe('HttpClient', () => { }); }); describe('#getAssetPairsAsync', () => { - const url = `${relayUrl}/assetData_pairs`; + const url = `${relayUrl}/asset_pairs`; it('gets assetData pairs with default options when none are provided', async () => { const urlWithQuery = `${url}?page=1&per_page=100`; fetchMock.get(urlWithQuery, assetDataPairsResponseJSON); @@ -134,32 +134,29 @@ describe('HttpClient', () => { }); describe('#getOrderConfigAsync', () => { const request = { + makerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b', + takerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', + makerAssetAmount: '10000000000000000', + takerAssetAmount: '20000000000000000', + expirationTimeSeconds: '1532560590', + makerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d', + takerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990', exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', - maker: '0x9e56625509c2f60af937f23b7b532600390e8c8b', - taker: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', - makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - makerAssetAmount: new BigNumber('10000000000000000000'), - takerAssetAmount: new BigNumber('30000000000000000000'), - salt: new BigNumber('256'), - expirationTimeSeconds: new BigNumber('42'), }; const url = `${relayUrl}/fees`; it('gets fees', async () => { - fetchMock.post(url, feesResponseJSON); + fetchMock.post(url, orderConfigResponseJSON); const fees = await relayerClient.getOrderConfigAsync(request); - expect(fees).to.be.deep.equal(feesResponse); + expect(fees).to.be.deep.equal(orderConfigResponse); }); it('does not mutate input', async () => { - fetchMock.post(url, feesResponseJSON); + fetchMock.post(url, orderConfigResponseJSON); const makerAssetAmountBefore = new BigNumber(request.makerAssetAmount); const takerAssetAmountBefore = new BigNumber(request.takerAssetAmount); - const saltBefore = new BigNumber(request.salt); const expirationTimeSecondsBefore = new BigNumber(request.expirationTimeSeconds); await relayerClient.getOrderConfigAsync(request); expect(makerAssetAmountBefore).to.be.deep.equal(request.makerAssetAmount); expect(takerAssetAmountBefore).to.be.deep.equal(request.takerAssetAmount); - expect(saltBefore).to.be.deep.equal(request.salt); expect(expirationTimeSecondsBefore).to.be.deep.equal(request.expirationTimeSeconds); }); it('throws an error for invalid JSON response', async () => { diff --git a/packages/connect/test/orderbook_channel_message_parsers_test.ts b/packages/connect/test/orderbook_channel_message_parsers_test.ts index 9960ad1df..b5a91330d 100644 --- a/packages/connect/test/orderbook_channel_message_parsers_test.ts +++ b/packages/connect/test/orderbook_channel_message_parsers_test.ts @@ -5,11 +5,6 @@ import 'mocha'; import { ordersChannelMessageParser } from '../src/utils/orderbook_channel_message_parser'; import { orderResponse } from './fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f'; -import { orderbookResponse } from './fixtures/standard_relayer_api/orderbook'; -import { - malformedSnapshotOrdersChannelMessage, - snapshotOrdersChannelMessage, -} from './fixtures/standard_relayer_api/snapshot_orderbook_channel_message'; import { unknownOrdersChannelMessage } from './fixtures/standard_relayer_api/unknown_orderbook_channel_message'; import { malformedUpdateOrdersChannelMessage, @@ -22,11 +17,6 @@ const expect = chai.expect; describe('ordersChannelMessageParser', () => { describe('#parser', () => { - it('parses snapshot messages', () => { - const snapshotMessage = ordersChannelMessageParser.parse(snapshotOrdersChannelMessage); - expect(snapshotMessage.type).to.be.equal('snapshot'); - expect(snapshotMessage.payload).to.be.deep.equal(orderbookResponse); - }); it('parses update messages', () => { const updateMessage = ordersChannelMessageParser.parse(updateOrdersChannelMessage); expect(updateMessage.type).to.be.equal('update'); @@ -56,13 +46,6 @@ describe('ordersChannelMessageParser', () => { const badCall = () => ordersChannelMessageParser.parse(messageWithBadType); expect(badCall).throws('Expected type to be of type string, encountered: 1'); }); - it('throws when snapshot message has malformed payload', () => { - const badCall = () => ordersChannelMessageParser.parse(malformedSnapshotOrdersChannelMessage); - // tslint:disable-next-line:max-line-length - const errMsg = - 'Validation errors: instance.payload requires property "bids", instance.payload requires property "asks"'; - expect(badCall).throws(errMsg); - }); it('throws when update message has malformed payload', () => { const badCall = () => ordersChannelMessageParser.parse(malformedUpdateOrdersChannelMessage); expect(badCall).throws(/^Expected message to conform to schema/); -- cgit v1.2.3 From c325d638c98a990f2d0e991f2e03287183ba292f Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 15 Aug 2018 17:18:19 -0700 Subject: getAssetPairsAsync tests passing --- packages/connect/package.json | 2 +- packages/connect/src/http_client.ts | 2 +- .../src/schemas/asset_pairs_request_opts_schema.ts | 4 ++-- .../src/utils/relayer_response_json_parsers.ts | 10 +++++----- .../standard_relayer_api/fee_recipients.ts | 1 - ...77fa9ac94a50f016026fd13f42990861238897721f.json | 1 - packages/connect/test/http_client_test.ts | 22 +++++++++++----------- 7 files changed, 20 insertions(+), 22 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/package.json b/packages/connect/package.json index 336cb85fc..de262a5c2 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -51,7 +51,7 @@ }, "homepage": "https://github.com/0xProject/0x-monorepo/packages/connect/README.md", "dependencies": { - "@0xproject/assert": "^0.2.14", + "@0xproject/assert": "^1.0.5", "@0xproject/json-schemas": "^1.0.1-rc.4", "@0xproject/types": "^1.0.1-rc.4", "@0xproject/typescript-typings": "^1.0.4", diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index e8b82f0b2..35d7ee77e 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -70,7 +70,7 @@ export class HttpClient implements Client { const httpRequestOpts = { params: _.defaults({}, requestOpts, DEFAULT_PAGED_REQUEST_OPTS), }; - const responseJson = await this._requestAsync('/assetData_pairs', HttpRequestType.Get, httpRequestOpts); + const responseJson = await this._requestAsync('/asset_pairs', HttpRequestType.Get, httpRequestOpts); const assetDataPairs = relayerResponseJsonParsers.parseAssetDataPairsJson(responseJson); return assetDataPairs; } diff --git a/packages/connect/src/schemas/asset_pairs_request_opts_schema.ts b/packages/connect/src/schemas/asset_pairs_request_opts_schema.ts index f224503cc..a9e3942a4 100644 --- a/packages/connect/src/schemas/asset_pairs_request_opts_schema.ts +++ b/packages/connect/src/schemas/asset_pairs_request_opts_schema.ts @@ -2,7 +2,7 @@ export const assetPairsRequestOptsSchema = { id: '/AssetPairsRequestOpts', type: 'object', properties: { - assetDataA: { $ref: '/Address' }, - assetDataB: { $ref: '/Address' }, + assetDataA: { $ref: '/hexSchema' }, + assetDataB: { $ref: '/hexSchema' }, }, }; diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts index 9a17b23d3..37099384f 100644 --- a/packages/connect/src/utils/relayer_response_json_parsers.ts +++ b/packages/connect/src/utils/relayer_response_json_parsers.ts @@ -7,10 +7,10 @@ import { typeConverters } from './type_converters'; export const relayerResponseJsonParsers = { parseAssetDataPairsJson(json: any): AssetPairsResponse { - assert.doesConformToSchema('assetDataPairs', json, schemas.relayerApiAssetDataPairsResponseSchema); - return { ...json, records: relayerResponseJsonParsers.parseAssetDataPairsJson(json.records) }; + assert.doesConformToSchema('assetDataPairsResponse', json, schemas.relayerApiAssetDataPairsResponseSchema); + return { ...json, records: relayerResponseJsonParsers.parseAssetPairsItemsJson(json.records) }; }, - parseAssetPairsItemJson(json: any): AssetPairsItem[] { + parseAssetPairsItemsJson(json: any): AssetPairsItem[] { return json.map((assetDataPair: any) => { return typeConverters.convertStringsFieldsToBigNumbers(assetDataPair, [ 'assetDataA.minAmount', @@ -29,11 +29,11 @@ export const relayerResponseJsonParsers = { return typeConverters.convertOrderStringFieldsToBigNumber(json); }, parseOrderbookResponseJson(json: any): OrderbookResponse { - assert.doesConformToSchema('orderBook', json, schemas.relayerApiOrderbookResponseSchema); + assert.doesConformToSchema('orderBookResponse', json, schemas.relayerApiOrderbookResponseSchema); return typeConverters.convertOrderbookStringFieldsToBigNumber(json); }, parseOrderConfigResponseJson(json: any): OrderConfigResponse { - assert.doesConformToSchema('orderConfig', json, schemas.relayerApiOrderConfigResponseSchema); + assert.doesConformToSchema('orderConfigResponse', json, schemas.relayerApiOrderConfigResponseSchema); return typeConverters.convertStringsFieldsToBigNumbers(json, ['makerFee', 'takerFee']); }, }; diff --git a/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts index 9da2703df..a95bd25dd 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts @@ -1,4 +1,3 @@ - import { FeeRecipientsResponse } from '../../../src/types'; export const feeRecipientsResponse: FeeRecipientsResponse = { diff --git a/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json b/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json index 4a2ab6914..8d2cdd8ed 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json +++ b/packages/connect/test/fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json @@ -17,4 +17,3 @@ }, "metaData": {} } - diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index fc5d01706..9cdcde71e 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -26,7 +26,7 @@ const expect = chai.expect; describe('HttpClient', () => { const relayUrl = 'https://example.com'; const relayerClient = new HttpClient(relayUrl); - afterEach(() => { + beforeEach(() => { fetchMock.restore(); }); describe('#constructor', () => { @@ -41,21 +41,21 @@ describe('HttpClient', () => { describe('#getAssetPairsAsync', () => { const url = `${relayUrl}/asset_pairs`; it('gets assetData pairs with default options when none are provided', async () => { - const urlWithQuery = `${url}?page=1&per_page=100`; + const urlWithQuery = `${url}?page=1&perPage=100`; fetchMock.get(urlWithQuery, assetDataPairsResponseJSON); const assetDataPairs = await relayerClient.getAssetPairsAsync(); expect(assetDataPairs).to.be.deep.equal(assetDataPairsResponse); }); it('gets assetData pairs with specified request options', async () => { - const assetDataAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d'; - const AssetPairsRequestOpts = { - assetDataA: assetDataAddress, + const assetData = '0xf47261b04c32345ced77393b3530b1eed0f346429d'; + const assetPairsRequestOpts = { + assetDataA: assetData, page: 3, perPage: 50, }; - const urlWithQuery = `${url}?page=3&per_page=50&assetDataA=${assetDataAddress}`; + const urlWithQuery = `${url}?assetDataA=${assetData}&page=3&perPage=50`; fetchMock.get(urlWithQuery, assetDataPairsResponseJSON); - const assetDataPairs = await relayerClient.getAssetPairsAsync(AssetPairsRequestOpts); + const assetDataPairs = await relayerClient.getAssetPairsAsync(assetPairsRequestOpts); expect(assetDataPairs).to.be.deep.equal(assetDataPairsResponse); }); it('throws an error for invalid JSON response', async () => { @@ -66,7 +66,7 @@ describe('HttpClient', () => { describe('#getOrdersAsync', () => { const url = `${relayUrl}/orders`; it('gets orders with default options when none are provided', async () => { - const urlWithQuery = `${url}?page=1&per_page=100`; + const urlWithQuery = `${url}?page=1&perPage=100`; fetchMock.get(urlWithQuery, ordersResponseJSON); const orders = await relayerClient.getOrdersAsync(); expect(orders).to.be.deep.equal(ordersResponse); @@ -78,7 +78,7 @@ describe('HttpClient', () => { page: 3, perPage: 50, }; - const urlWithQuery = `${url}?page=3&per_page=50&assetDataAddress=${assetDataAddress}`; + const urlWithQuery = `${url}?page=3&perPage=50&assetDataAddress=${assetDataAddress}`; fetchMock.get(urlWithQuery, ordersResponseJSON); const orders = await relayerClient.getOrdersAsync(ordersRequest); expect(orders).to.be.deep.equal(ordersResponse); @@ -110,7 +110,7 @@ describe('HttpClient', () => { it('gets orderbook with default page options when none are provided', async () => { const urlWithQuery = `${url}?baseAssetData=${ request.baseAssetData - }&page=1&per_page=100"eAssetData=${request.quoteAssetData}`; + }&page=1&perPage=100"eAssetData=${request.quoteAssetData}`; fetchMock.get(urlWithQuery, orderbookJSON); const orderbook = await relayerClient.getOrderbookAsync(request); expect(orderbook).to.be.deep.equal(orderbookResponse); @@ -118,7 +118,7 @@ describe('HttpClient', () => { it('gets orderbook with specified page options', async () => { const urlWithQuery = `${url}?baseAssetData=${ request.baseAssetData - }&page=3&per_page=50"eAssetData=${request.quoteAssetData}`; + }&page=3&perPage=50"eAssetData=${request.quoteAssetData}`; fetchMock.get(urlWithQuery, orderbookJSON); const pagedRequestOptions = { page: 3, -- cgit v1.2.3 From 1c87e5f69809954add5e76de520e8ef4f405c1c0 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 15 Aug 2018 17:31:39 -0700 Subject: Get orders async tests passing --- packages/connect/src/utils/relayer_response_json_parsers.ts | 2 +- packages/connect/src/utils/type_converters.ts | 7 ++++++- packages/connect/test/http_client_test.ts | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts index 37099384f..2b2e1efe7 100644 --- a/packages/connect/src/utils/relayer_response_json_parsers.ts +++ b/packages/connect/src/utils/relayer_response_json_parsers.ts @@ -26,7 +26,7 @@ export const relayerResponseJsonParsers = { }, parseAPIOrderJson(json: any): APIOrder { assert.doesConformToSchema('relayerApiOrder', json, schemas.relayerApiOrderSchema); - return typeConverters.convertOrderStringFieldsToBigNumber(json); + return typeConverters.convertAPIOrderStringFieldsToBigNumber(json); }, parseOrderbookResponseJson(json: any): OrderbookResponse { assert.doesConformToSchema('orderBookResponse', json, schemas.relayerApiOrderbookResponseSchema); diff --git a/packages/connect/src/utils/type_converters.ts b/packages/connect/src/utils/type_converters.ts index c28cba0e1..4b211a0b2 100644 --- a/packages/connect/src/utils/type_converters.ts +++ b/packages/connect/src/utils/type_converters.ts @@ -36,7 +36,12 @@ export const typeConverters = { convertStringsFieldsToBigNumbers(obj: any, fields: string[]): any { const result = _.assign({}, obj); _.each(fields, field => { - _.update(result, field, (value: string) => new BigNumber(value)); + _.update(result, field, (value: string) => { + if (_.isUndefined(value)) { + throw new Error(`Could not find field '${field}' while converting string fields to BigNumber.`); + } + return new BigNumber(value); + }); }); return result; }, diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 9cdcde71e..7a1781131 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -78,7 +78,7 @@ describe('HttpClient', () => { page: 3, perPage: 50, }; - const urlWithQuery = `${url}?page=3&perPage=50&assetDataAddress=${assetDataAddress}`; + const urlWithQuery = `${url}?assetDataAddress=${assetDataAddress}&page=3&perPage=50`; fetchMock.get(urlWithQuery, ordersResponseJSON); const orders = await relayerClient.getOrdersAsync(ordersRequest); expect(orders).to.be.deep.equal(ordersResponse); -- cgit v1.2.3 From 30dfb7511dc695b2dc7514c2908e632e0969ddfd Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 15 Aug 2018 17:36:54 -0700 Subject: All previous tests passing --- packages/connect/test/http_client_test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 7a1781131..6d5ab288a 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -143,7 +143,7 @@ describe('HttpClient', () => { takerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990', exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', }; - const url = `${relayUrl}/fees`; + const url = `${relayUrl}/order_config`; it('gets fees', async () => { fetchMock.post(url, orderConfigResponseJSON); const fees = await relayerClient.getOrderConfigAsync(request); @@ -151,9 +151,9 @@ describe('HttpClient', () => { }); it('does not mutate input', async () => { fetchMock.post(url, orderConfigResponseJSON); - const makerAssetAmountBefore = new BigNumber(request.makerAssetAmount); - const takerAssetAmountBefore = new BigNumber(request.takerAssetAmount); - const expirationTimeSecondsBefore = new BigNumber(request.expirationTimeSeconds); + const makerAssetAmountBefore = request.makerAssetAmount; + const takerAssetAmountBefore = request.takerAssetAmount; + const expirationTimeSecondsBefore = request.expirationTimeSeconds; await relayerClient.getOrderConfigAsync(request); expect(makerAssetAmountBefore).to.be.deep.equal(request.makerAssetAmount); expect(takerAssetAmountBefore).to.be.deep.equal(request.takerAssetAmount); -- cgit v1.2.3 From ca5e52920d5fd8388fc1f62f0a98908adfc69c08 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 15 Aug 2018 17:52:13 -0700 Subject: Add fee recipients test --- packages/connect/src/http_client.ts | 10 +++++++--- packages/connect/src/types.ts | 2 +- packages/connect/test/http_client_test.ts | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 35d7ee77e..5aeba19dd 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -140,10 +140,14 @@ export class HttpClient implements Client { /** * Retrieve the list of fee recipient addresses used by */ - public async getFeeRecipientsAsync(): Promise { - return this._requestAsync('/fee_recipients', HttpRequestType.Get); + public async getFeeRecipientsAsync(requestOpts?: PagedRequestOpts): Promise { + if (!_.isUndefined(requestOpts)) { + assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); + } + const feeRecipients = await this._requestAsync('/fee_recipients', HttpRequestType.Get); + assert.doesConformToSchema('feeRecipients', feeRecipients, schemas.relayerApiFeeRecipientsResponseSchema); + return feeRecipients; } - /** * Submit a signed order to the API * @param signedOrder A SignedOrder instance to submit diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index 42417f709..44ea4abd6 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -7,7 +7,7 @@ export interface Client { getOrderAsync: (orderHash: string) => Promise; getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise; getOrderConfigAsync: (request: OrderConfigRequest) => Promise; - getFeeRecipientsAsync: () => Promise; + getFeeRecipientsAsync: (requestOpts?: PagedRequestOpts) => Promise; submitOrderAsync: (signedOrder: SignedOrder) => Promise; } diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 6d5ab288a..cdff00a61 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -17,6 +17,8 @@ import { orderbookResponse } from './fixtures/standard_relayer_api/orderbook'; import * as orderbookJSON from './fixtures/standard_relayer_api/orderbook.json'; import { ordersResponse } from './fixtures/standard_relayer_api/orders'; import * as ordersResponseJSON from './fixtures/standard_relayer_api/orders.json'; +import { feeRecipientsResponse } from './fixtures/standard_relayer_api/fee_recipients'; +import * as feeRecipientsResponseJSON from './fixtures/standard_relayer_api/fee_recipients.json'; chai.config.includeStack = true; chai.use(dirtyChai); @@ -164,4 +166,26 @@ describe('HttpClient', () => { expect(relayerClient.getOrderConfigAsync(request)).to.be.rejected(); }); }); + describe('#getFeeRecipientsAsync', () => { + const url = `${relayUrl}/fee_recipients`; + it('gets orderbook with default page options when none are provided', async () => { + fetchMock.get(url, feeRecipientsResponseJSON); + const feeRecipients = await relayerClient.getFeeRecipientsAsync(); + expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse); + }); + it('gets orderbook with specified page options', async () => { + const urlWithQuery = `${url}?&page=3&perPage=50`; + fetchMock.get(url, feeRecipientsResponseJSON); + const pagedRequestOptions = { + page: 3, + perPage: 50, + }; + const feeRecipients = await relayerClient.getFeeRecipientsAsync(pagedRequestOptions); + expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse); + }); + it('throws an error for invalid JSON response', async () => { + fetchMock.get(url, { test: 'dummy' }); + expect(relayerClient.getFeeRecipientsAsync()).to.be.rejected(); + }); + }); }); -- cgit v1.2.3 From e079790f7fe82452471fc69fa9583c07848f801d Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 16 Aug 2018 16:51:55 -0700 Subject: Use uuid as string for requestId --- packages/connect/package.json | 2 ++ packages/connect/src/ws_orderbook_channel.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/package.json b/packages/connect/package.json index 798f839b5..ee08104cf 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -59,6 +59,7 @@ "lodash": "^4.17.5", "query-string": "^5.0.1", "sinon": "^4.0.0", + "uuid": "^3.3.2", "websocket": "^1.0.25" }, "devDependencies": { @@ -69,6 +70,7 @@ "@types/mocha": "^2.2.42", "@types/query-string": "^5.0.1", "@types/sinon": "^2.2.2", + "@types/uuid": "^3.4.3", "@types/websocket": "^0.0.39", "async-child-process": "^1.1.1", "chai": "^4.0.1", diff --git a/packages/connect/src/ws_orderbook_channel.ts b/packages/connect/src/ws_orderbook_channel.ts index 3d9230792..425ba8afb 100644 --- a/packages/connect/src/ws_orderbook_channel.ts +++ b/packages/connect/src/ws_orderbook_channel.ts @@ -1,4 +1,5 @@ import * as _ from 'lodash'; +import { v4 as uuid } from 'uuid'; import * as WebSocket from 'websocket'; import { @@ -50,11 +51,10 @@ export class WebSocketOrderbookChannel implements OrderbookChannel { assert.isOrderbookChannelSubscriptionOpts('subscriptionOpts', subscriptionOpts); assert.assert(this._client.readyState === WebSocket.w3cwebsocket.OPEN, 'WebSocket connection is closed'); this._subscriptionOptsList.push(subscriptionOpts); - // TODO: update requestId management to use UUIDs for v2 const subscribeMessage = { type: 'subscribe', channel: 'orderbook', - requestId: this._subscriptionOptsList.length - 1, + requestId: uuid(), payload: subscriptionOpts, }; this._client.send(JSON.stringify(subscribeMessage)); -- cgit v1.2.3 From 64a85dfb9cc60212dcf1c70ca7be4874936dd332 Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 16 Aug 2018 17:03:11 -0700 Subject: Rename websocket files and types --- packages/connect/src/orderbook_channel_factory.ts | 32 ------- packages/connect/src/orders_channel_factory.ts | 32 +++++++ packages/connect/src/types.ts | 18 ++-- packages/connect/src/utils/assert.ts | 4 +- packages/connect/src/ws_orderbook_channel.ts | 101 ---------------------- packages/connect/src/ws_orders_channel.ts | 101 ++++++++++++++++++++++ 6 files changed, 143 insertions(+), 145 deletions(-) delete mode 100644 packages/connect/src/orderbook_channel_factory.ts create mode 100644 packages/connect/src/orders_channel_factory.ts delete mode 100644 packages/connect/src/ws_orderbook_channel.ts create mode 100644 packages/connect/src/ws_orders_channel.ts (limited to 'packages/connect') diff --git a/packages/connect/src/orderbook_channel_factory.ts b/packages/connect/src/orderbook_channel_factory.ts deleted file mode 100644 index 5134af323..000000000 --- a/packages/connect/src/orderbook_channel_factory.ts +++ /dev/null @@ -1,32 +0,0 @@ -import * as WebSocket from 'websocket'; - -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 handler An OrderbookChannelHandler instance that responds to various - * channel updates - * @return An OrderbookChannel Promise - */ - async createWebSocketOrderbookChannelAsync( - url: string, - handler: OrderbookChannelHandler, - ): Promise { - assert.isUri('url', url); - assert.isOrderbookChannelHandler('handler', handler); - return new Promise((resolve, reject) => { - const client = new WebSocket.w3cwebsocket(url); - client.onopen = () => { - const orderbookChannel = new WebSocketOrderbookChannel(client, handler); - resolve(orderbookChannel); - }; - client.onerror = err => { - reject(err); - }; - }); - }, -}; diff --git a/packages/connect/src/orders_channel_factory.ts b/packages/connect/src/orders_channel_factory.ts new file mode 100644 index 000000000..4e9b74b2c --- /dev/null +++ b/packages/connect/src/orders_channel_factory.ts @@ -0,0 +1,32 @@ +import * as WebSocket from 'websocket'; + +import { OrdersChannel, OrdersChannelHandler } from './types'; +import { assert } from './utils/assert'; +import { WebSocketOrdersChannel } from './ws_orders_channel'; + +export const ordersChannelFactory = { + /** + * Instantiates a new WebSocketOrdersChannel instance + * @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 createWebSocketOrdersChannelAsync( + url: string, + handler: OrdersChannelHandler, + ): Promise { + assert.isUri('url', url); + assert.isOrderbookChannelHandler('handler', handler); + return new Promise((resolve, reject) => { + const client = new WebSocket.w3cwebsocket(url); + client.onopen = () => { + const orderbookChannel = new WebSocketOrdersChannel(client, handler); + resolve(orderbookChannel); + }; + client.onerror = err => { + reject(err); + }; + }); + }, +}; diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index 44ea4abd6..e85a0542c 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -11,32 +11,30 @@ export interface Client { submitOrderAsync: (signedOrder: SignedOrder) => Promise; } -export interface OrderbookChannel { - subscribe: (subscriptionOpts: OrderbookChannelSubscriptionOpts) => void; +export interface OrdersChannel { + subscribe: (subscriptionOpts: OrdersChannelSubscriptionOpts) => void; close: () => void; } /** * baseAssetData: The address of assetData designated as the baseToken in the currency pair calculation of price * quoteAssetData: The address of assetData designated as the quoteToken in the currency pair calculation of price - * snapshot: If true, a snapshot of the orderbook will be sent before the updates to the orderbook * limit: Maximum number of bids and asks in orderbook snapshot */ -export interface OrderbookChannelSubscriptionOpts { +export interface OrdersChannelSubscriptionOpts { baseAssetData: string; quoteAssetData: string; - snapshot: boolean; limit: number; } -export interface OrderbookChannelHandler { +export interface OrdersChannelHandler { onUpdate: ( - channel: OrderbookChannel, - subscriptionOpts: OrderbookChannelSubscriptionOpts, + channel: OrdersChannel, + subscriptionOpts: OrdersChannelSubscriptionOpts, order: APIOrder, ) => void; - onError: (channel: OrderbookChannel, err: Error, subscriptionOpts?: OrderbookChannelSubscriptionOpts) => void; - onClose: (channel: OrderbookChannel) => void; + onError: (channel: OrdersChannel, err: Error, subscriptionOpts?: OrdersChannelSubscriptionOpts) => void; + onClose: (channel: OrdersChannel) => void; } export type OrdersChannelMessage = diff --git a/packages/connect/src/utils/assert.ts b/packages/connect/src/utils/assert.ts index 353b7f29f..3d8f1c799 100644 --- a/packages/connect/src/utils/assert.ts +++ b/packages/connect/src/utils/assert.ts @@ -10,14 +10,14 @@ import * as _ from 'lodash'; export const assert = { ...sharedAssert, - isOrderbookChannelSubscriptionOpts(variableName: string, subscriptionOpts: any): void { + isOrdersChannelSubscriptionOpts(variableName: string, subscriptionOpts: any): void { sharedAssert.doesConformToSchema( variableName, subscriptionOpts, schemas.relayerApiOrdersChannelSubscribePayload, ); }, - isOrderbookChannelHandler(variableName: string, handler: any): void { + isOrdersChannelHandler(variableName: string, handler: any): void { sharedAssert.isFunction(`${variableName}.onUpdate`, _.get(handler, 'onUpdate')); sharedAssert.isFunction(`${variableName}.onError`, _.get(handler, 'onError')); sharedAssert.isFunction(`${variableName}.onClose`, _.get(handler, 'onClose')); diff --git a/packages/connect/src/ws_orderbook_channel.ts b/packages/connect/src/ws_orderbook_channel.ts deleted file mode 100644 index 425ba8afb..000000000 --- a/packages/connect/src/ws_orderbook_channel.ts +++ /dev/null @@ -1,101 +0,0 @@ -import * as _ from 'lodash'; -import { v4 as uuid } from 'uuid'; -import * as WebSocket from 'websocket'; - -import { - OrderbookChannel, - OrderbookChannelHandler, - OrderbookChannelSubscriptionOpts, - OrdersChannelMessageTypes, -} from './types'; -import { assert } from './utils/assert'; -import { ordersChannelMessageParser } from './utils/orderbook_channel_message_parser'; - -/** - * This class includes all the functionality related to interacting with a websocket endpoint - * that implements the standard relayer API v0 - */ -export class WebSocketOrderbookChannel implements OrderbookChannel { - private readonly _client: WebSocket.w3cwebsocket; - private readonly _handler: OrderbookChannelHandler; - private readonly _subscriptionOptsList: OrderbookChannelSubscriptionOpts[] = []; - /** - * Instantiates a new WebSocketOrderbookChannel instance - * @param client A WebSocket client - * @param handler An OrderbookChannelHandler instance that responds to various - * channel updates - * @return An instance of WebSocketOrderbookChannel - */ - constructor(client: WebSocket.w3cwebsocket, handler: OrderbookChannelHandler) { - assert.isOrderbookChannelHandler('handler', handler); - // set private members - this._client = client; - this._handler = handler; - // attach client callbacks - this._client.onerror = err => { - this._handler.onError(this, err); - }; - this._client.onclose = () => { - this._handler.onClose(this); - }; - this._client.onmessage = message => { - this._handleWebSocketMessage(message); - }; - } - /** - * Subscribe to orderbook snapshots and updates from the websocket - * @param subscriptionOpts An OrderbookChannelSubscriptionOpts instance describing which - * assetData pair to subscribe to - */ - public subscribe(subscriptionOpts: OrderbookChannelSubscriptionOpts): void { - assert.isOrderbookChannelSubscriptionOpts('subscriptionOpts', subscriptionOpts); - assert.assert(this._client.readyState === WebSocket.w3cwebsocket.OPEN, 'WebSocket connection is closed'); - this._subscriptionOptsList.push(subscriptionOpts); - const subscribeMessage = { - type: 'subscribe', - channel: 'orderbook', - requestId: uuid(), - payload: subscriptionOpts, - }; - this._client.send(JSON.stringify(subscribeMessage)); - } - /** - * Close the websocket and stop receiving updates - */ - public close(): void { - this._client.close(); - } - private _handleWebSocketMessage(message: any): void { - if (_.isUndefined(message.data)) { - this._handler.onError(this, new Error(`Message does not contain data. Url: ${this._client.url}`)); - return; - } - try { - const data = message.data; - const parserResult = ordersChannelMessageParser.parse(data); - const subscriptionOpts = this._subscriptionOptsList[parserResult.requestId]; - if (_.isUndefined(subscriptionOpts)) { - this._handler.onError( - this, - new Error(`Message has unknown requestId. Url: ${this._client.url} Message: ${data}`), - ); - return; - } - switch (parserResult.type) { - case OrdersChannelMessageTypes.Update: { - this._handler.onUpdate(this, subscriptionOpts, parserResult.payload); - break; - } - default: { - this._handler.onError( - this, - new Error(`Message has unknown type parameter. Url: ${this._client.url} Message: ${data}`), - subscriptionOpts, - ); - } - } - } catch (error) { - this._handler.onError(this, error); - } - } -} diff --git a/packages/connect/src/ws_orders_channel.ts b/packages/connect/src/ws_orders_channel.ts new file mode 100644 index 000000000..9d45b6570 --- /dev/null +++ b/packages/connect/src/ws_orders_channel.ts @@ -0,0 +1,101 @@ +import * as _ from 'lodash'; +import { v4 as uuid } from 'uuid'; +import * as WebSocket from 'websocket'; + +import { + OrdersChannel, + OrdersChannelHandler, + OrdersChannelMessageTypes, + OrdersChannelSubscriptionOpts, +} from './types'; +import { assert } from './utils/assert'; +import { ordersChannelMessageParser } from './utils/orderbook_channel_message_parser'; + +/** + * This class includes all the functionality related to interacting with a websocket endpoint + * that implements the standard relayer API v0 + */ +export class WebSocketOrdersChannel implements OrdersChannel { + private readonly _client: WebSocket.w3cwebsocket; + private readonly _handler: OrdersChannelHandler; + private readonly _subscriptionOptsList: OrdersChannelSubscriptionOpts[] = []; + /** + * Instantiates a new WebSocketOrdersChannel instance + * @param client A WebSocket client + * @param handler An OrdersChannelHandler instance that responds to various + * channel updates + * @return An instance of WebSocketOrdersChannel + */ + constructor(client: WebSocket.w3cwebsocket, handler: OrdersChannelHandler) { + assert.isOrdersChannelHandler('handler', handler); + // set private members + this._client = client; + this._handler = handler; + // attach client callbacks + this._client.onerror = err => { + this._handler.onError(this, err); + }; + this._client.onclose = () => { + this._handler.onClose(this); + }; + this._client.onmessage = message => { + this._handleWebSocketMessage(message); + }; + } + /** + * Subscribe to orderbook snapshots and updates from the websocket + * @param subscriptionOpts An OrdersChannelSubscriptionOpts instance describing which + * assetData pair to subscribe to + */ + public subscribe(subscriptionOpts: OrdersChannelSubscriptionOpts): void { + assert.isOrdersChannelSubscriptionOpts('subscriptionOpts', subscriptionOpts); + assert.assert(this._client.readyState === WebSocket.w3cwebsocket.OPEN, 'WebSocket connection is closed'); + this._subscriptionOptsList.push(subscriptionOpts); + const subscribeMessage = { + type: 'subscribe', + channel: 'orders', + requestId: uuid(), + payload: subscriptionOpts, + }; + this._client.send(JSON.stringify(subscribeMessage)); + } + /** + * Close the websocket and stop receiving updates + */ + public close(): void { + this._client.close(); + } + private _handleWebSocketMessage(message: any): void { + if (_.isUndefined(message.data)) { + this._handler.onError(this, new Error(`Message does not contain data. Url: ${this._client.url}`)); + return; + } + try { + const data = message.data; + const parserResult = ordersChannelMessageParser.parse(data); + const subscriptionOpts = this._subscriptionOptsList[parserResult.requestId]; + if (_.isUndefined(subscriptionOpts)) { + this._handler.onError( + this, + new Error(`Message has unknown requestId. Url: ${this._client.url} Message: ${data}`), + ); + return; + } + switch (parserResult.type) { + case OrdersChannelMessageTypes.Update: { + this._handler.onUpdate(this, subscriptionOpts, parserResult.payload); + break; + } + default: { + this._handler.onError( + this, + new Error(`Message has unknown type parameter. Url: ${this._client.url} Message: ${data}`), + subscriptionOpts, + ); + } + } + } catch (error) { + this._handler.onError(this, error); + } + } +} -- cgit v1.2.3 From 48ec78d3aaa5dcef8544d17f26ef8ea8b31661e5 Mon Sep 17 00:00:00 2001 From: fragosti Date: Fri, 17 Aug 2018 10:43:44 -0700 Subject: Add networkId request param option --- packages/connect/src/http_client.ts | 50 ++++++++++++++++------ packages/connect/src/index.ts | 8 ++-- packages/connect/src/orders_channel_factory.ts | 4 +- packages/connect/src/schemas/schemas.ts | 2 + packages/connect/src/types.ts | 4 ++ .../connect/test/orderbook_channel_factory_test.ts | 17 +++----- packages/connect/test/ws_orderbook_channel_test.ts | 18 ++++---- 7 files changed, 64 insertions(+), 39 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 5aeba19dd..8f7825253 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -21,6 +21,7 @@ import { OrdersRequestOpts, OrdersResponse, PagedRequestOpts, + RequestOpts, } from './types'; import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers'; @@ -29,6 +30,9 @@ const DEFAULT_PAGED_REQUEST_OPTS: PagedRequestOpts = { page: 1, perPage: 100, }; +const DEFAULT_REQUEST_OPTS: RequestOpts = { + networkId: 1, +}; /** * This class includes all the functionality related to interacting with a set of HTTP endpoints @@ -62,13 +66,14 @@ export class HttpClient implements Client { * @param requestOpts Options specifying assetData information to retrieve and page information, defaults to { page: 1, perPage: 100 } * @return The resulting AssetPairsItems that match the request */ - public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise { + public async getAssetPairsAsync(requestOpts?: RequestOpts & AssetPairsRequestOpts & PagedRequestOpts): Promise { if (!_.isUndefined(requestOpts)) { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.assetPairsRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); } const httpRequestOpts = { - params: _.defaults({}, requestOpts, DEFAULT_PAGED_REQUEST_OPTS), + params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS), }; const responseJson = await this._requestAsync('/asset_pairs', HttpRequestType.Get, httpRequestOpts); const assetDataPairs = relayerResponseJsonParsers.parseAssetDataPairsJson(responseJson); @@ -79,13 +84,14 @@ export class HttpClient implements Client { * @param requestOpts Options specifying orders to retrieve and page information, defaults to { page: 1, perPage: 100 } * @return The resulting SignedOrders that match the request */ - public async getOrdersAsync(requestOpts?: OrdersRequestOpts & PagedRequestOpts): Promise { + public async getOrdersAsync(requestOpts?: RequestOpts & OrdersRequestOpts & PagedRequestOpts): Promise { if (!_.isUndefined(requestOpts)) { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.ordersRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); } const httpRequestOpts = { - params: _.defaults({}, requestOpts, DEFAULT_PAGED_REQUEST_OPTS), + params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS), }; const responseJson = await this._requestAsync(`/orders`, HttpRequestType.Get, httpRequestOpts); const orders = relayerResponseJsonParsers.parseOrdersJson(responseJson); @@ -96,9 +102,15 @@ export class HttpClient implements Client { * @param orderHash An orderHash generated from the desired order * @return The SignedOrder that matches the supplied orderHash */ - public async getOrderAsync(orderHash: string): Promise { + public async getOrderAsync(orderHash: string, requestOpts?: RequestOpts): Promise { + if (!_.isUndefined(requestOpts)) { + assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); + } assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); - const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get); + const httpRequestOpts = { + params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS), + }; + const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get, httpRequestOpts); const order = relayerResponseJsonParsers.parseAPIOrderJson(responseJson); return order; } @@ -110,14 +122,15 @@ export class HttpClient implements Client { */ public async getOrderbookAsync( request: OrderbookRequest, - requestOpts?: PagedRequestOpts, + requestOpts?: RequestOpts & PagedRequestOpts, ): Promise { assert.doesConformToSchema('request', request, clientSchemas.orderBookRequestSchema); if (!_.isUndefined(requestOpts)) { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); } const httpRequestOpts = { - params: _.defaults({}, request, requestOpts, DEFAULT_PAGED_REQUEST_OPTS), + params: _.defaults({}, request, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS), }; const responseJson = await this._requestAsync('/orderbook', HttpRequestType.Get, httpRequestOpts); const orderbook = relayerResponseJsonParsers.parseOrderbookResponseJson(responseJson); @@ -128,9 +141,13 @@ export class HttpClient implements Client { * @param request A OrderConfigRequest instance describing the specific fees to retrieve * @return The resulting OrderConfigResponse that matches the request */ - public async getOrderConfigAsync(request: OrderConfigRequest): Promise { + public async getOrderConfigAsync(request: OrderConfigRequest, requestOpts?: RequestOpts): Promise { + if (!_.isUndefined(requestOpts)) { + assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); + } assert.doesConformToSchema('request', request, clientSchemas.orderConfigRequestSchema); const httpRequestOpts = { + params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS), payload: request, }; const responseJson = await this._requestAsync('/order_config', HttpRequestType.Post, httpRequestOpts); @@ -140,11 +157,15 @@ export class HttpClient implements Client { /** * Retrieve the list of fee recipient addresses used by */ - public async getFeeRecipientsAsync(requestOpts?: PagedRequestOpts): Promise { + public async getFeeRecipientsAsync(requestOpts?: RequestOpts & PagedRequestOpts): Promise { if (!_.isUndefined(requestOpts)) { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); } - const feeRecipients = await this._requestAsync('/fee_recipients', HttpRequestType.Get); + const httpRequestOpts = { + params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS), + }; + const feeRecipients = await this._requestAsync('/fee_recipients', HttpRequestType.Get, httpRequestOpts); assert.doesConformToSchema('feeRecipients', feeRecipients, schemas.relayerApiFeeRecipientsResponseSchema); return feeRecipients; } @@ -152,12 +173,13 @@ export class HttpClient implements Client { * Submit a signed order to the API * @param signedOrder A SignedOrder instance to submit */ - public async submitOrderAsync(signedOrder: SignedOrder): Promise { + public async submitOrderAsync(signedOrder: SignedOrder, requestOpts?: RequestOpts): Promise { assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema); - const requestOpts = { + const httpRequestOpts = { + params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS), payload: signedOrder, }; - await this._requestAsync('/order', HttpRequestType.Post, requestOpts); + await this._requestAsync('/order', HttpRequestType.Post, httpRequestOpts); } private async _requestAsync( path: string, diff --git a/packages/connect/src/index.ts b/packages/connect/src/index.ts index e0c4293d9..33e1222b0 100644 --- a/packages/connect/src/index.ts +++ b/packages/connect/src/index.ts @@ -1,12 +1,12 @@ export { HttpClient } from './http_client'; -export { orderbookChannelFactory } from './orderbook_channel_factory'; +export { ordersChannelFactory } from './orders_channel_factory'; export { Client, OrderConfigRequest, OrderConfigResponse, - OrderbookChannel, - OrderbookChannelHandler, - OrderbookChannelSubscriptionOpts, + OrdersChannel, + OrdersChannelHandler, + OrdersChannelSubscriptionOpts, OrderbookRequest, OrderbookResponse, OrdersRequestOpts, diff --git a/packages/connect/src/orders_channel_factory.ts b/packages/connect/src/orders_channel_factory.ts index 4e9b74b2c..fae5cab8c 100644 --- a/packages/connect/src/orders_channel_factory.ts +++ b/packages/connect/src/orders_channel_factory.ts @@ -10,14 +10,14 @@ export const ordersChannelFactory = { * @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 + * @return An OrdersChannel Promise */ async createWebSocketOrdersChannelAsync( url: string, handler: OrdersChannelHandler, ): Promise { assert.isUri('url', url); - assert.isOrderbookChannelHandler('handler', handler); + assert.isOrdersChannelHandler('handler', handler); return new Promise((resolve, reject) => { const client = new WebSocket.w3cwebsocket(url); client.onopen = () => { diff --git a/packages/connect/src/schemas/schemas.ts b/packages/connect/src/schemas/schemas.ts index a7e968a01..8d101ed6f 100644 --- a/packages/connect/src/schemas/schemas.ts +++ b/packages/connect/src/schemas/schemas.ts @@ -3,11 +3,13 @@ import { orderConfigRequestSchema } from './order_config_request_schema'; import { orderBookRequestSchema } from './orderbook_request_schema'; import { ordersRequestOptsSchema } from './orders_request_opts_schema'; import { pagedRequestOptsSchema } from './paged_request_opts_schema'; +import { requestOptsSchema } from './request_opts_schema'; export const schemas = { orderConfigRequestSchema, orderBookRequestSchema, ordersRequestOptsSchema, pagedRequestOptsSchema, + requestOptsSchema, assetPairsRequestOptsSchema, }; diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index e85a0542c..f90f0808d 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -147,6 +147,10 @@ export interface OrderConfigResponse { export type FeeRecipientsResponse = PaginatedCollection; +export interface RequestOpts { + networkId?: number; +} + export interface PagedRequestOpts { page?: number; perPage?: number; diff --git a/packages/connect/test/orderbook_channel_factory_test.ts b/packages/connect/test/orderbook_channel_factory_test.ts index 2ce361bd2..66394cdc9 100644 --- a/packages/connect/test/orderbook_channel_factory_test.ts +++ b/packages/connect/test/orderbook_channel_factory_test.ts @@ -3,15 +3,12 @@ import * as dirtyChai from 'dirty-chai'; import * as _ from 'lodash'; import 'mocha'; -import { orderbookChannelFactory } from '../src/orderbook_channel_factory'; +import { ordersChannelFactory } from '../src/orders_channel_factory'; chai.config.includeStack = true; chai.use(dirtyChai); const expect = chai.expect; -const emptyOrderbookChannelHandler = { - onSnapshot: () => { - _.noop(); - }, +const emptyOrdersChannelHandler = { onUpdate: () => { _.noop(); }, @@ -23,22 +20,22 @@ const emptyOrderbookChannelHandler = { }, }; -describe('orderbookChannelFactory', () => { +describe('ordersChannelFactory', () => { const websocketUrl = 'ws://localhost:8080'; - describe('#createWebSocketOrderbookChannelAsync', () => { + describe('#createWebSocketOrdersChannelAsync', () => { it('throws when input is not a url', () => { const badUrlInput = 54; expect( - orderbookChannelFactory.createWebSocketOrderbookChannelAsync( + ordersChannelFactory.createWebSocketOrdersChannelAsync( badUrlInput as any, - emptyOrderbookChannelHandler, + emptyOrdersChannelHandler, ), ).to.be.rejected(); }); it('throws when handler has the incorrect members', () => { const badHandlerInput = {}; expect( - orderbookChannelFactory.createWebSocketOrderbookChannelAsync(websocketUrl, badHandlerInput as any), + ordersChannelFactory.createWebSocketOrdersChannelAsync(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 b5682af36..de097c295 100644 --- a/packages/connect/test/ws_orderbook_channel_test.ts +++ b/packages/connect/test/ws_orderbook_channel_test.ts @@ -5,12 +5,12 @@ import 'mocha'; import * as Sinon from 'sinon'; import * as WebSocket from 'websocket'; -import { WebSocketOrderbookChannel } from '../src/ws_orderbook_channel'; +import { WebSocketOrdersChannel } from '../src/ws_orders_channel'; chai.config.includeStack = true; chai.use(dirtyChai); const expect = chai.expect; -const emptyOrderbookChannelHandler = { +const emptyOrdersChannelHandler = { onSnapshot: () => { _.noop(); }, @@ -25,12 +25,12 @@ const emptyOrderbookChannelHandler = { }, }; -describe('WebSocketOrderbookChannel', () => { +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 openOrderbookChannel = new WebSocketOrderbookChannel(openClient, emptyOrderbookChannelHandler); + const openOrdersChannel = new WebSocketOrdersChannel(openClient, emptyOrdersChannelHandler); const subscriptionOpts = { baseAssetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d', quoteAssetData: '0xef7fff64389b814a946f3e92105513705ca6b990', @@ -39,20 +39,20 @@ describe('WebSocketOrderbookChannel', () => { }; describe('#subscribe', () => { it('throws when subscriptionOpts does not conform to schema', () => { - const badSubscribeCall = openOrderbookChannel.subscribe.bind(openOrderbookChannel, {}); + const badSubscribeCall = openOrdersChannel.subscribe.bind(openOrdersChannel, {}); expect(badSubscribeCall).throws( - 'Expected subscriptionOpts to conform to schema /RelayerApiOrderbookChannelSubscribePayload\nEncountered: {}\nValidation errors: instance requires property "baseAssetData", instance requires property "quoteAssetData"', + 'Expected subscriptionOpts to conform to schema /RelayerApiOrdersChannelSubscribePayload\nEncountered: {}\nValidation errors: instance requires property "baseAssetData", instance requires property "quoteAssetData"', ); }); it('does not throw when inputs are of correct types', () => { - const goodSubscribeCall = openOrderbookChannel.subscribe.bind(openOrderbookChannel, subscriptionOpts); + 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 closedOrderbookChannel = new WebSocketOrderbookChannel(closedClient, emptyOrderbookChannelHandler); - const badSubscribeCall = closedOrderbookChannel.subscribe.bind(closedOrderbookChannel, subscriptionOpts); + const closedOrdersChannel = new WebSocketOrdersChannel(closedClient, emptyOrdersChannelHandler); + const badSubscribeCall = closedOrdersChannel.subscribe.bind(closedOrdersChannel, subscriptionOpts); expect(badSubscribeCall).throws('WebSocket connection is closed'); }); }); -- cgit v1.2.3 From f2d1d953553adfa59f0a39bf2cf98817fae0a4ff Mon Sep 17 00:00:00 2001 From: fragosti Date: Fri, 17 Aug 2018 13:58:55 -0700 Subject: Remove default query parameters --- packages/connect/src/http_client.ts | 21 +++++---------- .../connect/src/schemas/request_opts_schema.ts | 7 +++++ .../standard_relayer_api/fee_recipients.json | 2 +- .../standard_relayer_api/fee_recipients.ts | 2 +- packages/connect/test/http_client_test.ts | 31 +++++++++++++--------- 5 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 packages/connect/src/schemas/request_opts_schema.ts (limited to 'packages/connect') diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 8f7825253..4fdcfc338 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -26,13 +26,6 @@ import { import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers'; const TRAILING_SLASHES_REGEX = /\/+$/; -const DEFAULT_PAGED_REQUEST_OPTS: PagedRequestOpts = { - page: 1, - perPage: 100, -}; -const DEFAULT_REQUEST_OPTS: RequestOpts = { - networkId: 1, -}; /** * This class includes all the functionality related to interacting with a set of HTTP endpoints @@ -73,7 +66,7 @@ export class HttpClient implements Client { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); } const httpRequestOpts = { - params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS), + params: requestOpts, }; const responseJson = await this._requestAsync('/asset_pairs', HttpRequestType.Get, httpRequestOpts); const assetDataPairs = relayerResponseJsonParsers.parseAssetDataPairsJson(responseJson); @@ -91,7 +84,7 @@ export class HttpClient implements Client { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); } const httpRequestOpts = { - params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS), + params: requestOpts, }; const responseJson = await this._requestAsync(`/orders`, HttpRequestType.Get, httpRequestOpts); const orders = relayerResponseJsonParsers.parseOrdersJson(responseJson); @@ -108,7 +101,7 @@ export class HttpClient implements Client { } assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); const httpRequestOpts = { - params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS), + params: requestOpts, }; const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get, httpRequestOpts); const order = relayerResponseJsonParsers.parseAPIOrderJson(responseJson); @@ -130,7 +123,7 @@ export class HttpClient implements Client { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); } const httpRequestOpts = { - params: _.defaults({}, request, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS), + params: _.defaults({}, request, requestOpts), }; const responseJson = await this._requestAsync('/orderbook', HttpRequestType.Get, httpRequestOpts); const orderbook = relayerResponseJsonParsers.parseOrderbookResponseJson(responseJson); @@ -147,7 +140,7 @@ export class HttpClient implements Client { } assert.doesConformToSchema('request', request, clientSchemas.orderConfigRequestSchema); const httpRequestOpts = { - params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS), + params: requestOpts, payload: request, }; const responseJson = await this._requestAsync('/order_config', HttpRequestType.Post, httpRequestOpts); @@ -163,7 +156,7 @@ export class HttpClient implements Client { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); } const httpRequestOpts = { - params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS), + params: requestOpts, }; const feeRecipients = await this._requestAsync('/fee_recipients', HttpRequestType.Get, httpRequestOpts); assert.doesConformToSchema('feeRecipients', feeRecipients, schemas.relayerApiFeeRecipientsResponseSchema); @@ -176,7 +169,7 @@ export class HttpClient implements Client { public async submitOrderAsync(signedOrder: SignedOrder, requestOpts?: RequestOpts): Promise { assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema); const httpRequestOpts = { - params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS), + params: requestOpts, payload: signedOrder, }; await this._requestAsync('/order', HttpRequestType.Post, httpRequestOpts); diff --git a/packages/connect/src/schemas/request_opts_schema.ts b/packages/connect/src/schemas/request_opts_schema.ts new file mode 100644 index 000000000..a51e98069 --- /dev/null +++ b/packages/connect/src/schemas/request_opts_schema.ts @@ -0,0 +1,7 @@ +export const requestOptsSchema = { + id: '/RequestOpts', + type: 'object', + properties: { + networkId: { type: 'number' }, + }, +}; diff --git a/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.json b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.json index 1ea3dcc0e..47ce42412 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.json +++ b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.json @@ -3,7 +3,7 @@ "page": 1, "perPage": 10, "records": [ - "0x6eC92694ea172ebC430C30fa31De87620967A082", + "0x6ec92694ea172ebc430c30fa31de87620967a082", "0x9e56625509c2f60af937f23b7b532600390e8c8b", "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32" ] diff --git a/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts index a95bd25dd..e17ffe7a8 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts +++ b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.ts @@ -5,7 +5,7 @@ export const feeRecipientsResponse: FeeRecipientsResponse = { page: 1, perPage: 10, records: [ - '0x6eC92694ea172ebC430C30fa31De87620967A082', + '0x6ec92694ea172ebc430c30fa31de87620967a082', '0x9e56625509c2f60af937f23b7b532600390e8c8b', '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32', ], diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index cdff00a61..1c40cb10f 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -43,8 +43,7 @@ describe('HttpClient', () => { describe('#getAssetPairsAsync', () => { const url = `${relayUrl}/asset_pairs`; it('gets assetData pairs with default options when none are provided', async () => { - const urlWithQuery = `${url}?page=1&perPage=100`; - fetchMock.get(urlWithQuery, assetDataPairsResponseJSON); + fetchMock.get(url, assetDataPairsResponseJSON); const assetDataPairs = await relayerClient.getAssetPairsAsync(); expect(assetDataPairs).to.be.deep.equal(assetDataPairsResponse); }); @@ -54,8 +53,9 @@ describe('HttpClient', () => { assetDataA: assetData, page: 3, perPage: 50, + networkdId: 42, }; - const urlWithQuery = `${url}?assetDataA=${assetData}&page=3&perPage=50`; + const urlWithQuery = `${url}?assetDataA=${assetData}&networkdId=42&page=3&perPage=50`; fetchMock.get(urlWithQuery, assetDataPairsResponseJSON); const assetDataPairs = await relayerClient.getAssetPairsAsync(assetPairsRequestOpts); expect(assetDataPairs).to.be.deep.equal(assetDataPairsResponse); @@ -68,8 +68,7 @@ describe('HttpClient', () => { describe('#getOrdersAsync', () => { const url = `${relayUrl}/orders`; it('gets orders with default options when none are provided', async () => { - const urlWithQuery = `${url}?page=1&perPage=100`; - fetchMock.get(urlWithQuery, ordersResponseJSON); + fetchMock.get(url, ordersResponseJSON); const orders = await relayerClient.getOrdersAsync(); expect(orders).to.be.deep.equal(ordersResponse); }); @@ -79,8 +78,9 @@ describe('HttpClient', () => { assetDataAddress, page: 3, perPage: 50, + networkdId: 42, }; - const urlWithQuery = `${url}?assetDataAddress=${assetDataAddress}&page=3&perPage=50`; + const urlWithQuery = `${url}?assetDataAddress=${assetDataAddress}&networkdId=42&page=3&perPage=50`; fetchMock.get(urlWithQuery, ordersResponseJSON); const orders = await relayerClient.getOrdersAsync(ordersRequest); expect(orders).to.be.deep.equal(ordersResponse); @@ -112,7 +112,7 @@ describe('HttpClient', () => { it('gets orderbook with default page options when none are provided', async () => { const urlWithQuery = `${url}?baseAssetData=${ request.baseAssetData - }&page=1&perPage=100"eAssetData=${request.quoteAssetData}`; + }"eAssetData=${request.quoteAssetData}`; fetchMock.get(urlWithQuery, orderbookJSON); const orderbook = await relayerClient.getOrderbookAsync(request); expect(orderbook).to.be.deep.equal(orderbookResponse); @@ -120,11 +120,12 @@ describe('HttpClient', () => { it('gets orderbook with specified page options', async () => { const urlWithQuery = `${url}?baseAssetData=${ request.baseAssetData - }&page=3&perPage=50"eAssetData=${request.quoteAssetData}`; + }&networkId=42&page=3&perPage=50"eAssetData=${request.quoteAssetData}`; fetchMock.get(urlWithQuery, orderbookJSON); const pagedRequestOptions = { page: 3, perPage: 50, + networkId: 42, }; const orderbook = await relayerClient.getOrderbookAsync(request, pagedRequestOptions); expect(orderbook).to.be.deep.equal(orderbookResponse); @@ -146,7 +147,7 @@ describe('HttpClient', () => { exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093', }; const url = `${relayUrl}/order_config`; - it('gets fees', async () => { + it('gets order config', async () => { fetchMock.post(url, orderConfigResponseJSON); const fees = await relayerClient.getOrderConfigAsync(request); expect(fees).to.be.deep.equal(orderConfigResponse); @@ -168,17 +169,18 @@ describe('HttpClient', () => { }); describe('#getFeeRecipientsAsync', () => { const url = `${relayUrl}/fee_recipients`; - it('gets orderbook with default page options when none are provided', async () => { + it('gets fee recipients with default page options when none are provided', async () => { fetchMock.get(url, feeRecipientsResponseJSON); const feeRecipients = await relayerClient.getFeeRecipientsAsync(); expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse); }); - it('gets orderbook with specified page options', async () => { - const urlWithQuery = `${url}?&page=3&perPage=50`; - fetchMock.get(url, feeRecipientsResponseJSON); + it('gets fee reciipient with specified page options', async () => { + const urlWithQuery = `${url}?networkId=42&page=3&perPage=50`; + fetchMock.get(urlWithQuery, feeRecipientsResponseJSON); const pagedRequestOptions = { page: 3, perPage: 50, + networkId: 42, }; const feeRecipients = await relayerClient.getFeeRecipientsAsync(pagedRequestOptions); expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse); @@ -189,3 +191,6 @@ describe('HttpClient', () => { }); }); }); + +// https://example.com/fee_recipients?networkId=42&page=3&perPage=50 +// https://example.com/fee_recipients?networkId=42&page=3&perPage=50 \ No newline at end of file -- cgit v1.2.3 From 075e3a41c876797907e3ad98f20940e32e8d0762 Mon Sep 17 00:00:00 2001 From: fragosti Date: Mon, 20 Aug 2018 11:42:29 -0700 Subject: Update websocket for SRA v2 --- packages/connect/CHANGELOG.json | 8 +++ packages/connect/src/types.ts | 8 +-- .../src/utils/orderbook_channel_message_parser.ts | 37 -------------- .../src/utils/orders_channel_message_parser.ts | 37 ++++++++++++++ .../src/utils/relayer_response_json_parsers.ts | 5 +- packages/connect/src/ws_orders_channel.ts | 15 ++++-- .../unknown_orderbook_channel_message.ts | 10 ---- .../unknown_orders_channel_message.ts | 10 ++++ .../update_orderbook_channel_message.ts | 17 ------- .../update_orders_channel_message.ts | 17 +++++++ packages/connect/test/http_client_test.ts | 3 -- .../connect/test/orderbook_channel_factory_test.ts | 42 --------------- .../test/orderbook_channel_message_parsers_test.ts | 59 ---------------------- .../connect/test/orders_channel_factory_test.ts | 36 +++++++++++++ .../test/orders_channel_message_parsers_test.ts | 59 ++++++++++++++++++++++ packages/connect/test/ws_orderbook_channel_test.ts | 59 ---------------------- packages/connect/test/ws_orders_channel_test.ts | 49 ++++++++++++++++++ 17 files changed, 234 insertions(+), 237 deletions(-) delete mode 100644 packages/connect/src/utils/orderbook_channel_message_parser.ts create mode 100644 packages/connect/src/utils/orders_channel_message_parser.ts delete mode 100644 packages/connect/test/fixtures/standard_relayer_api/unknown_orderbook_channel_message.ts create mode 100644 packages/connect/test/fixtures/standard_relayer_api/unknown_orders_channel_message.ts delete mode 100644 packages/connect/test/fixtures/standard_relayer_api/update_orderbook_channel_message.ts create mode 100644 packages/connect/test/fixtures/standard_relayer_api/update_orders_channel_message.ts delete mode 100644 packages/connect/test/orderbook_channel_factory_test.ts delete mode 100644 packages/connect/test/orderbook_channel_message_parsers_test.ts create mode 100644 packages/connect/test/orders_channel_factory_test.ts create mode 100644 packages/connect/test/orders_channel_message_parsers_test.ts delete mode 100644 packages/connect/test/ws_orderbook_channel_test.ts create mode 100644 packages/connect/test/ws_orders_channel_test.ts (limited to 'packages/connect') diff --git a/packages/connect/CHANGELOG.json b/packages/connect/CHANGELOG.json index 8d6feaa2e..1f17392a9 100644 --- a/packages/connect/CHANGELOG.json +++ b/packages/connect/CHANGELOG.json @@ -1,4 +1,12 @@ [ + { + "version": "2.0.0", + "changes": [ + { + "note": "Updated for SRA v2" + } + ] + }, { "timestamp": 1534210131, "version": "1.0.5", diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index f90f0808d..dbed8899f 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -31,7 +31,7 @@ export interface OrdersChannelHandler { onUpdate: ( channel: OrdersChannel, subscriptionOpts: OrdersChannelSubscriptionOpts, - order: APIOrder, + orders: APIOrder[], ) => void; onError: (channel: OrdersChannel, err: Error, subscriptionOpts?: OrdersChannelSubscriptionOpts) => void; onClose: (channel: OrdersChannel) => void; @@ -48,13 +48,13 @@ export enum OrdersChannelMessageTypes { export interface UpdateOrdersChannelMessage { type: OrdersChannelMessageTypes.Update; - requestId: number; - payload: APIOrder; + requestId: string; + payload: APIOrder[]; } export interface UnknownOrdersChannelMessage { type: OrdersChannelMessageTypes.Unknown; - requestId: number; + requestId: string; payload: undefined; } diff --git a/packages/connect/src/utils/orderbook_channel_message_parser.ts b/packages/connect/src/utils/orderbook_channel_message_parser.ts deleted file mode 100644 index 97d8f2d6a..000000000 --- a/packages/connect/src/utils/orderbook_channel_message_parser.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { assert } from '@0xproject/assert'; -import { schemas } from '@0xproject/json-schemas'; -import * as _ from 'lodash'; - -import { OrdersChannelMessage, OrdersChannelMessageTypes } from '../types'; - -import { relayerResponseJsonParsers } from './relayer_response_json_parsers'; - -export const ordersChannelMessageParser = { - parse(utf8Data: string): OrdersChannelMessage { - // parse the message - const messageObj = JSON.parse(utf8Data); - // ensure we have a type parameter to switch on - const type: string = _.get(messageObj, 'type'); - assert.assert(!_.isUndefined(type), `Message is missing a type parameter: ${utf8Data}`); - assert.isString('type', type); - // ensure we have a request id for the resulting message - const requestId: number = _.get(messageObj, 'requestId'); - assert.assert(!_.isUndefined(requestId), `Message is missing a requestId parameter: ${utf8Data}`); - assert.isNumber('requestId', requestId); - switch (type) { - case OrdersChannelMessageTypes.Update: { - assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrdersChannelUpdateSchema); - const orderJson = messageObj.payload; - const order = relayerResponseJsonParsers.parseAPIOrderJson(orderJson); - return _.assign(messageObj, { payload: order }); - } - default: { - return { - type: OrdersChannelMessageTypes.Unknown, - requestId, - payload: undefined, - }; - } - } - }, -}; diff --git a/packages/connect/src/utils/orders_channel_message_parser.ts b/packages/connect/src/utils/orders_channel_message_parser.ts new file mode 100644 index 000000000..1b6cda17b --- /dev/null +++ b/packages/connect/src/utils/orders_channel_message_parser.ts @@ -0,0 +1,37 @@ +import { assert } from '@0xproject/assert'; +import { schemas } from '@0xproject/json-schemas'; +import * as _ from 'lodash'; + +import { OrdersChannelMessage, OrdersChannelMessageTypes } from '../types'; + +import { relayerResponseJsonParsers } from './relayer_response_json_parsers'; + +export const ordersChannelMessageParser = { + parse(utf8Data: string): OrdersChannelMessage { + // parse the message + const messageObj = JSON.parse(utf8Data); + // ensure we have a type parameter to switch on + const type: string = _.get(messageObj, 'type'); + assert.assert(!_.isUndefined(type), `Message is missing a type parameter: ${utf8Data}`); + assert.isString('type', type); + // ensure we have a request id for the resulting message + const requestId: string = _.get(messageObj, 'requestId'); + assert.assert(!_.isUndefined(requestId), `Message is missing a requestId parameter: ${utf8Data}`); + assert.isString('requestId', requestId); + switch (type) { + case OrdersChannelMessageTypes.Update: { + assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrdersChannelUpdateSchema); + const ordersJson = messageObj.payload; + const orders = relayerResponseJsonParsers.parseAPIOrdersJson(ordersJson); + return _.assign(messageObj, { payload: orders }); + } + default: { + return { + type: OrdersChannelMessageTypes.Unknown, + requestId, + payload: undefined, + }; + } + } + }, +}; diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts index 2b2e1efe7..dff854dfb 100644 --- a/packages/connect/src/utils/relayer_response_json_parsers.ts +++ b/packages/connect/src/utils/relayer_response_json_parsers.ts @@ -22,7 +22,10 @@ export const relayerResponseJsonParsers = { }, parseOrdersJson(json: any): OrdersResponse { assert.doesConformToSchema('relayerApiOrdersResponse', json, schemas.relayerApiOrdersResponseSchema); - return { ...json, records: json.records.map(relayerResponseJsonParsers.parseAPIOrderJson.bind(relayerResponseJsonParsers)) }; + return { ...json, records: relayerResponseJsonParsers.parseAPIOrdersJson(json.records) }; + }, + parseAPIOrdersJson(json: any): APIOrder[] { + return json.map(relayerResponseJsonParsers.parseAPIOrderJson.bind(relayerResponseJsonParsers)); }, parseAPIOrderJson(json: any): APIOrder { assert.doesConformToSchema('relayerApiOrder', json, schemas.relayerApiOrderSchema); diff --git a/packages/connect/src/ws_orders_channel.ts b/packages/connect/src/ws_orders_channel.ts index 9d45b6570..62960d23a 100644 --- a/packages/connect/src/ws_orders_channel.ts +++ b/packages/connect/src/ws_orders_channel.ts @@ -9,7 +9,11 @@ import { OrdersChannelSubscriptionOpts, } from './types'; import { assert } from './utils/assert'; -import { ordersChannelMessageParser } from './utils/orderbook_channel_message_parser'; +import { ordersChannelMessageParser } from './utils/orders_channel_message_parser'; + +export interface OrdersChannelSubscriptionOptsMap { + [key: string]: OrdersChannelSubscriptionOpts; +} /** * This class includes all the functionality related to interacting with a websocket endpoint @@ -18,7 +22,7 @@ import { ordersChannelMessageParser } from './utils/orderbook_channel_message_pa export class WebSocketOrdersChannel implements OrdersChannel { private readonly _client: WebSocket.w3cwebsocket; private readonly _handler: OrdersChannelHandler; - private readonly _subscriptionOptsList: OrdersChannelSubscriptionOpts[] = []; + private readonly _subscriptionOptsMap: OrdersChannelSubscriptionOptsMap = {}; /** * Instantiates a new WebSocketOrdersChannel instance * @param client A WebSocket client @@ -50,11 +54,12 @@ export class WebSocketOrdersChannel implements OrdersChannel { public subscribe(subscriptionOpts: OrdersChannelSubscriptionOpts): void { assert.isOrdersChannelSubscriptionOpts('subscriptionOpts', subscriptionOpts); assert.assert(this._client.readyState === WebSocket.w3cwebsocket.OPEN, 'WebSocket connection is closed'); - this._subscriptionOptsList.push(subscriptionOpts); + const requestId = uuid(); + this._subscriptionOptsMap[requestId] = subscriptionOpts; const subscribeMessage = { type: 'subscribe', channel: 'orders', - requestId: uuid(), + requestId, payload: subscriptionOpts, }; this._client.send(JSON.stringify(subscribeMessage)); @@ -73,7 +78,7 @@ export class WebSocketOrdersChannel implements OrdersChannel { try { const data = message.data; const parserResult = ordersChannelMessageParser.parse(data); - const subscriptionOpts = this._subscriptionOptsList[parserResult.requestId]; + const subscriptionOpts = this._subscriptionOptsMap[parserResult.requestId]; if (_.isUndefined(subscriptionOpts)) { this._handler.onError( this, diff --git a/packages/connect/test/fixtures/standard_relayer_api/unknown_orderbook_channel_message.ts b/packages/connect/test/fixtures/standard_relayer_api/unknown_orderbook_channel_message.ts deleted file mode 100644 index c0e924a4b..000000000 --- a/packages/connect/test/fixtures/standard_relayer_api/unknown_orderbook_channel_message.ts +++ /dev/null @@ -1,10 +0,0 @@ -import * as orderResponseJSON from './order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json'; - -const orderJSONString = JSON.stringify(orderResponseJSON); - -export const unknownOrdersChannelMessage = `{ - "type": "superGoodUpdate", - "channel": "orderbook", - "requestId": 1, - "payload": ${orderJSONString} -}`; diff --git a/packages/connect/test/fixtures/standard_relayer_api/unknown_orders_channel_message.ts b/packages/connect/test/fixtures/standard_relayer_api/unknown_orders_channel_message.ts new file mode 100644 index 000000000..b6c0cd50c --- /dev/null +++ b/packages/connect/test/fixtures/standard_relayer_api/unknown_orders_channel_message.ts @@ -0,0 +1,10 @@ +import * as orderResponseJSON from './order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json'; + +const orderJSONString = JSON.stringify(orderResponseJSON); + +export const unknownOrdersChannelMessage = `{ + "type": "superGoodUpdate", + "channel": "orderbook", + "requestId": "6ce8c5a6-5c46-4027-a44a-51831c77b8a1", + "payload": [${orderJSONString}] +}`; diff --git a/packages/connect/test/fixtures/standard_relayer_api/update_orderbook_channel_message.ts b/packages/connect/test/fixtures/standard_relayer_api/update_orderbook_channel_message.ts deleted file mode 100644 index daab20368..000000000 --- a/packages/connect/test/fixtures/standard_relayer_api/update_orderbook_channel_message.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as orderResponseJSON from './order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json'; - -const orderJSONString = JSON.stringify(orderResponseJSON); - -export const updateOrdersChannelMessage = `{ - "type": "update", - "channel": "orderbook", - "requestId": 1, - "payload": ${orderJSONString} -}`; - -export const malformedUpdateOrdersChannelMessage = `{ - "type": "update", - "channel": "orderbook", - "requestId": 1, - "payload": {} -}`; diff --git a/packages/connect/test/fixtures/standard_relayer_api/update_orders_channel_message.ts b/packages/connect/test/fixtures/standard_relayer_api/update_orders_channel_message.ts new file mode 100644 index 000000000..c18a2c789 --- /dev/null +++ b/packages/connect/test/fixtures/standard_relayer_api/update_orders_channel_message.ts @@ -0,0 +1,17 @@ +import * as apiOrderJSON from './order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json'; + +const apiOrderJSONString = JSON.stringify(apiOrderJSON); + +export const updateOrdersChannelMessage = `{ + "type": "update", + "channel": "orders", + "requestId": "5a1ce3a2-22b9-41e6-a615-68077512e9e2", + "payload": [${apiOrderJSONString}] +}`; + +export const malformedUpdateOrdersChannelMessage = `{ + "type": "update", + "channel": "orders", + "requestId": "4d8efcee-adde-4475-9601-f0b30962ca2b", + "payload": {} +}`; diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 1c40cb10f..9ead010d3 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -191,6 +191,3 @@ describe('HttpClient', () => { }); }); }); - -// https://example.com/fee_recipients?networkId=42&page=3&perPage=50 -// https://example.com/fee_recipients?networkId=42&page=3&perPage=50 \ No newline at end of file diff --git a/packages/connect/test/orderbook_channel_factory_test.ts b/packages/connect/test/orderbook_channel_factory_test.ts deleted file mode 100644 index 66394cdc9..000000000 --- a/packages/connect/test/orderbook_channel_factory_test.ts +++ /dev/null @@ -1,42 +0,0 @@ -import * as chai from 'chai'; -import * as dirtyChai from 'dirty-chai'; -import * as _ from 'lodash'; -import 'mocha'; - -import { ordersChannelFactory } from '../src/orders_channel_factory'; - -chai.config.includeStack = true; -chai.use(dirtyChai); -const expect = chai.expect; -const emptyOrdersChannelHandler = { - onUpdate: () => { - _.noop(); - }, - onError: () => { - _.noop(); - }, - onClose: () => { - _.noop(); - }, -}; - -describe('ordersChannelFactory', () => { - const websocketUrl = 'ws://localhost:8080'; - describe('#createWebSocketOrdersChannelAsync', () => { - it('throws when input is not a url', () => { - const badUrlInput = 54; - expect( - ordersChannelFactory.createWebSocketOrdersChannelAsync( - badUrlInput as any, - emptyOrdersChannelHandler, - ), - ).to.be.rejected(); - }); - it('throws when handler has the incorrect members', () => { - const badHandlerInput = {}; - expect( - ordersChannelFactory.createWebSocketOrdersChannelAsync(websocketUrl, badHandlerInput as any), - ).to.be.rejected(); - }); - }); -}); diff --git a/packages/connect/test/orderbook_channel_message_parsers_test.ts b/packages/connect/test/orderbook_channel_message_parsers_test.ts deleted file mode 100644 index b5a91330d..000000000 --- a/packages/connect/test/orderbook_channel_message_parsers_test.ts +++ /dev/null @@ -1,59 +0,0 @@ -import * as chai from 'chai'; -import * as dirtyChai from 'dirty-chai'; -import 'mocha'; - -import { ordersChannelMessageParser } from '../src/utils/orderbook_channel_message_parser'; - -import { orderResponse } from './fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f'; -import { unknownOrdersChannelMessage } from './fixtures/standard_relayer_api/unknown_orderbook_channel_message'; -import { - malformedUpdateOrdersChannelMessage, - updateOrdersChannelMessage, -} from './fixtures/standard_relayer_api/update_orderbook_channel_message'; - -chai.config.includeStack = true; -chai.use(dirtyChai); -const expect = chai.expect; - -describe('ordersChannelMessageParser', () => { - describe('#parser', () => { - it('parses update messages', () => { - const updateMessage = ordersChannelMessageParser.parse(updateOrdersChannelMessage); - expect(updateMessage.type).to.be.equal('update'); - expect(updateMessage.payload).to.be.deep.equal(orderResponse); - }); - it('returns unknown message for messages with unsupported types', () => { - const unknownMessage = ordersChannelMessageParser.parse(unknownOrdersChannelMessage); - expect(unknownMessage.type).to.be.equal('unknown'); - expect(unknownMessage.payload).to.be.undefined(); - }); - it('throws when message does not include a type', () => { - const typelessMessage = `{ - "channel": "orderbook", - "requestId": 1, - "payload": {} - }`; - const badCall = () => ordersChannelMessageParser.parse(typelessMessage); - expect(badCall).throws(`Message is missing a type parameter: ${typelessMessage}`); - }); - it('throws when type is not a string', () => { - const messageWithBadType = `{ - "type": 1, - "channel": "orderbook", - "requestId": 1, - "payload": {} - }`; - const badCall = () => ordersChannelMessageParser.parse(messageWithBadType); - expect(badCall).throws('Expected type to be of type string, encountered: 1'); - }); - it('throws when update message has malformed payload', () => { - const badCall = () => ordersChannelMessageParser.parse(malformedUpdateOrdersChannelMessage); - expect(badCall).throws(/^Expected message to conform to schema/); - }); - it('throws when input message is not valid JSON', () => { - const nonJsonString = 'h93b{sdfs9fsd f'; - const badCall = () => ordersChannelMessageParser.parse(nonJsonString); - expect(badCall).throws('Unexpected assetData h in JSON at position 0'); - }); - }); -}); diff --git a/packages/connect/test/orders_channel_factory_test.ts b/packages/connect/test/orders_channel_factory_test.ts new file mode 100644 index 000000000..fcd07dd35 --- /dev/null +++ b/packages/connect/test/orders_channel_factory_test.ts @@ -0,0 +1,36 @@ +import * as chai from 'chai'; +import * as dirtyChai from 'dirty-chai'; +import * as _ from 'lodash'; +import 'mocha'; + +import { ordersChannelFactory } from '../src/orders_channel_factory'; + +chai.config.includeStack = true; +chai.use(dirtyChai); +const expect = chai.expect; +const emptyOrdersChannelHandler = { + onUpdate: _.noop, + onError: _.noop, + onClose: _.noop, +}; + +describe('ordersChannelFactory', () => { + const websocketUrl = 'ws://localhost:8080'; + describe('#createWebSocketOrdersChannelAsync', () => { + it('throws when input is not a url', () => { + const badUrlInput = 54; + expect( + ordersChannelFactory.createWebSocketOrdersChannelAsync( + badUrlInput as any, + emptyOrdersChannelHandler, + ), + ).to.be.rejected(); + }); + it('throws when handler has the incorrect members', () => { + const badHandlerInput = {}; + expect( + ordersChannelFactory.createWebSocketOrdersChannelAsync(websocketUrl, badHandlerInput as any), + ).to.be.rejected(); + }); + }); +}); diff --git a/packages/connect/test/orders_channel_message_parsers_test.ts b/packages/connect/test/orders_channel_message_parsers_test.ts new file mode 100644 index 000000000..4d4a2d23f --- /dev/null +++ b/packages/connect/test/orders_channel_message_parsers_test.ts @@ -0,0 +1,59 @@ +import * as chai from 'chai'; +import * as dirtyChai from 'dirty-chai'; +import 'mocha'; + +import { ordersChannelMessageParser } from '../src/utils/orders_channel_message_parser'; + +import { orderResponse } from './fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f'; +import { unknownOrdersChannelMessage } from './fixtures/standard_relayer_api/unknown_orders_channel_message'; +import { + malformedUpdateOrdersChannelMessage, + updateOrdersChannelMessage, +} from './fixtures/standard_relayer_api/update_orders_channel_message'; + +chai.config.includeStack = true; +chai.use(dirtyChai); +const expect = chai.expect; + +describe('ordersChannelMessageParser', () => { + describe('#parser', () => { + it('parses update messages', () => { + const updateMessage = ordersChannelMessageParser.parse(updateOrdersChannelMessage); + expect(updateMessage.type).to.be.equal('update'); + expect(updateMessage.payload).to.be.deep.equal([orderResponse]); + }); + it('returns unknown message for messages with unsupported types', () => { + const unknownMessage = ordersChannelMessageParser.parse(unknownOrdersChannelMessage); + expect(unknownMessage.type).to.be.equal('unknown'); + expect(unknownMessage.payload).to.be.undefined(); + }); + it('throws when message does not include a type', () => { + const typelessMessage = `{ + "channel": "orders", + "requestId": "4d8efcee-adde-4475-9601-f0b30962ca2b", + "payload": [] + }`; + const badCall = () => ordersChannelMessageParser.parse(typelessMessage); + expect(badCall).throws(`Message is missing a type parameter: ${typelessMessage}`); + }); + it('throws when type is not a string', () => { + const messageWithBadType = `{ + "type": 1, + "channel": "orders", + "requestId": "4d8efcee-adde-4475-9601-f0b30962ca2b", + "payload": [] + }`; + const badCall = () => ordersChannelMessageParser.parse(messageWithBadType); + expect(badCall).throws('Expected type to be of type string, encountered: 1'); + }); + it('throws when update message has malformed payload', () => { + const badCall = () => ordersChannelMessageParser.parse(malformedUpdateOrdersChannelMessage); + expect(badCall).throws(/^Expected message to conform to schema/); + }); + it('throws when input message is not valid JSON', () => { + const nonJsonString = 'h93b{sdfs9fsd f'; + const badCall = () => ordersChannelMessageParser.parse(nonJsonString); + expect(badCall).throws('Unexpected token h in JSON at position 0'); + }); + }); +}); diff --git a/packages/connect/test/ws_orderbook_channel_test.ts b/packages/connect/test/ws_orderbook_channel_test.ts deleted file mode 100644 index de097c295..000000000 --- a/packages/connect/test/ws_orderbook_channel_test.ts +++ /dev/null @@ -1,59 +0,0 @@ -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 = { - onSnapshot: () => { - _.noop(); - }, - 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', - snapshot: true, - limit: 100, - }; - describe('#subscribe', () => { - it('throws when subscriptionOpts does not conform to schema', () => { - const badSubscribeCall = openOrdersChannel.subscribe.bind(openOrdersChannel, {}); - expect(badSubscribeCall).throws( - 'Expected subscriptionOpts to conform to schema /RelayerApiOrdersChannelSubscribePayload\nEncountered: {}\nValidation errors: instance requires property "baseAssetData", instance requires property "quoteAssetData"', - ); - }); - 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'); - }); - }); -}); 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'); + }); + }); +}); -- cgit v1.2.3 From 1ae11ed8ae2cbe0f60a70925c9c8d348745c96c7 Mon Sep 17 00:00:00 2001 From: fragosti Date: Mon, 20 Aug 2018 11:51:26 -0700 Subject: lint everything --- packages/connect/test/http_client_test.ts | 5 ++--- packages/connect/test/orders_channel_factory_test.ts | 6 +++--- packages/connect/test/ws_orders_channel_test.ts | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 9ead010d3..8b76c4c88 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -1,4 +1,3 @@ -import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import * as dirtyChai from 'dirty-chai'; @@ -9,6 +8,8 @@ import { HttpClient } from '../src/index'; import { assetDataPairsResponse } from './fixtures/standard_relayer_api/asset_pairs'; import * as assetDataPairsResponseJSON from './fixtures/standard_relayer_api/asset_pairs.json'; +import { feeRecipientsResponse } from './fixtures/standard_relayer_api/fee_recipients'; +import * as feeRecipientsResponseJSON from './fixtures/standard_relayer_api/fee_recipients.json'; import { orderResponse } from './fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f'; import * as orderResponseJSON from './fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f.json'; import { orderConfigResponse } from './fixtures/standard_relayer_api/order_config'; @@ -17,8 +18,6 @@ import { orderbookResponse } from './fixtures/standard_relayer_api/orderbook'; import * as orderbookJSON from './fixtures/standard_relayer_api/orderbook.json'; import { ordersResponse } from './fixtures/standard_relayer_api/orders'; import * as ordersResponseJSON from './fixtures/standard_relayer_api/orders.json'; -import { feeRecipientsResponse } from './fixtures/standard_relayer_api/fee_recipients'; -import * as feeRecipientsResponseJSON from './fixtures/standard_relayer_api/fee_recipients.json'; chai.config.includeStack = true; chai.use(dirtyChai); diff --git a/packages/connect/test/orders_channel_factory_test.ts b/packages/connect/test/orders_channel_factory_test.ts index fcd07dd35..58f7e08d9 100644 --- a/packages/connect/test/orders_channel_factory_test.ts +++ b/packages/connect/test/orders_channel_factory_test.ts @@ -9,9 +9,9 @@ chai.config.includeStack = true; chai.use(dirtyChai); const expect = chai.expect; const emptyOrdersChannelHandler = { - onUpdate: _.noop, - onError: _.noop, - onClose: _.noop, + onUpdate: _.noop.bind(_), + onError: _.noop.bind(_), + onClose: _.noop.bind(_), }; describe('ordersChannelFactory', () => { diff --git a/packages/connect/test/ws_orders_channel_test.ts b/packages/connect/test/ws_orders_channel_test.ts index 98eb24e6e..df30bc41d 100644 --- a/packages/connect/test/ws_orders_channel_test.ts +++ b/packages/connect/test/ws_orders_channel_test.ts @@ -11,9 +11,9 @@ chai.config.includeStack = true; chai.use(dirtyChai); const expect = chai.expect; const emptyOrdersChannelHandler = { - onUpdate: _.noop, - onError: _.noop, - onClose: _.noop, + onUpdate: _.noop.bind(_), + onError: _.noop.bind(_), + onClose: _.noop.bind(_), }; describe('WebSocketOrdersChannel', () => { -- cgit v1.2.3 From 44cc5e45cc3a3ed7db2691a287500e5d61a2d0c1 Mon Sep 17 00:00:00 2001 From: fragosti Date: Mon, 20 Aug 2018 11:53:49 -0700 Subject: Run prettier --- packages/connect/src/http_client.ts | 13 ++++++++++--- packages/connect/src/orders_channel_factory.ts | 5 +---- .../connect/src/schemas/order_config_request_schema.ts | 2 +- packages/connect/src/types.ts | 14 +++++--------- .../connect/src/utils/relayer_response_json_parsers.ts | 9 ++++++++- packages/connect/src/ws_orders_channel.ts | 7 +------ .../test/fixtures/standard_relayer_api/fee_recipients.json | 2 +- .../test/fixtures/standard_relayer_api/orderbook.json | 2 +- .../connect/test/fixtures/standard_relayer_api/orders.json | 1 - packages/connect/test/http_client_test.ts | 6 +++--- packages/connect/test/orders_channel_factory_test.ts | 5 +---- 11 files changed, 32 insertions(+), 34 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 4fdcfc338..93f4eeb05 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -59,7 +59,9 @@ export class HttpClient implements Client { * @param requestOpts Options specifying assetData information to retrieve and page information, defaults to { page: 1, perPage: 100 } * @return The resulting AssetPairsItems that match the request */ - public async getAssetPairsAsync(requestOpts?: RequestOpts & AssetPairsRequestOpts & PagedRequestOpts): Promise { + public async getAssetPairsAsync( + requestOpts?: RequestOpts & AssetPairsRequestOpts & PagedRequestOpts, + ): Promise { if (!_.isUndefined(requestOpts)) { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.assetPairsRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); @@ -77,7 +79,9 @@ export class HttpClient implements Client { * @param requestOpts Options specifying orders to retrieve and page information, defaults to { page: 1, perPage: 100 } * @return The resulting SignedOrders that match the request */ - public async getOrdersAsync(requestOpts?: RequestOpts & OrdersRequestOpts & PagedRequestOpts): Promise { + public async getOrdersAsync( + requestOpts?: RequestOpts & OrdersRequestOpts & PagedRequestOpts, + ): Promise { if (!_.isUndefined(requestOpts)) { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.ordersRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); @@ -134,7 +138,10 @@ export class HttpClient implements Client { * @param request A OrderConfigRequest instance describing the specific fees to retrieve * @return The resulting OrderConfigResponse that matches the request */ - public async getOrderConfigAsync(request: OrderConfigRequest, requestOpts?: RequestOpts): Promise { + public async getOrderConfigAsync( + request: OrderConfigRequest, + requestOpts?: RequestOpts, + ): Promise { if (!_.isUndefined(requestOpts)) { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); } diff --git a/packages/connect/src/orders_channel_factory.ts b/packages/connect/src/orders_channel_factory.ts index fae5cab8c..5e8e625e0 100644 --- a/packages/connect/src/orders_channel_factory.ts +++ b/packages/connect/src/orders_channel_factory.ts @@ -12,10 +12,7 @@ export const ordersChannelFactory = { * channel updates * @return An OrdersChannel Promise */ - async createWebSocketOrdersChannelAsync( - url: string, - handler: OrdersChannelHandler, - ): Promise { + async createWebSocketOrdersChannelAsync(url: string, handler: OrdersChannelHandler): Promise { assert.isUri('url', url); assert.isOrdersChannelHandler('handler', handler); return new Promise((resolve, reject) => { diff --git a/packages/connect/src/schemas/order_config_request_schema.ts b/packages/connect/src/schemas/order_config_request_schema.ts index 8f6b19500..0eda430e8 100644 --- a/packages/connect/src/schemas/order_config_request_schema.ts +++ b/packages/connect/src/schemas/order_config_request_schema.ts @@ -6,7 +6,7 @@ export const orderConfigRequestSchema = { takerAddress: { $ref: '/addressSchema' }, makerAssetAmount: { $ref: '/numberSchema' }, takerAssetAmount: { $ref: '/numberSchema' }, - makerAssetData: { $ref: '/hexSchema'}, + makerAssetData: { $ref: '/hexSchema' }, takerAssetData: { $ref: '/hexSchema' }, exchangeAddress: { $ref: '/addressSchema' }, expirationTimeSeconds: { $ref: '/numberSchema' }, diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index dbed8899f..06ae732a5 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -2,7 +2,9 @@ import { SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; export interface Client { - getAssetPairsAsync: (requestOpts?: AssetPairsRequestOpts & PagedRequestOpts) => Promise>; + getAssetPairsAsync: ( + requestOpts?: AssetPairsRequestOpts & PagedRequestOpts, + ) => Promise>; getOrdersAsync: (requestOpts?: OrdersRequestOpts & PagedRequestOpts) => Promise>; getOrderAsync: (orderHash: string) => Promise; getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise; @@ -28,18 +30,12 @@ export interface OrdersChannelSubscriptionOpts { } export interface OrdersChannelHandler { - onUpdate: ( - channel: OrdersChannel, - subscriptionOpts: OrdersChannelSubscriptionOpts, - orders: APIOrder[], - ) => void; + onUpdate: (channel: OrdersChannel, subscriptionOpts: OrdersChannelSubscriptionOpts, orders: APIOrder[]) => void; onError: (channel: OrdersChannel, err: Error, subscriptionOpts?: OrdersChannelSubscriptionOpts) => void; onClose: (channel: OrdersChannel) => void; } -export type OrdersChannelMessage = - | UpdateOrdersChannelMessage - | UnknownOrdersChannelMessage; +export type OrdersChannelMessage = UpdateOrdersChannelMessage | UnknownOrdersChannelMessage; export enum OrdersChannelMessageTypes { Update = 'update', diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts index dff854dfb..ebd877b70 100644 --- a/packages/connect/src/utils/relayer_response_json_parsers.ts +++ b/packages/connect/src/utils/relayer_response_json_parsers.ts @@ -1,7 +1,14 @@ import { assert } from '@0xproject/assert'; import { schemas } from '@0xproject/json-schemas'; -import { APIOrder, AssetPairsItem, AssetPairsResponse, OrderbookResponse, OrderConfigResponse, OrdersResponse } from '../types'; +import { + APIOrder, + AssetPairsItem, + AssetPairsResponse, + OrderbookResponse, + OrderConfigResponse, + OrdersResponse, +} from '../types'; import { typeConverters } from './type_converters'; diff --git a/packages/connect/src/ws_orders_channel.ts b/packages/connect/src/ws_orders_channel.ts index 62960d23a..cde4acbc3 100644 --- a/packages/connect/src/ws_orders_channel.ts +++ b/packages/connect/src/ws_orders_channel.ts @@ -2,12 +2,7 @@ import * as _ from 'lodash'; import { v4 as uuid } from 'uuid'; import * as WebSocket from 'websocket'; -import { - OrdersChannel, - OrdersChannelHandler, - OrdersChannelMessageTypes, - OrdersChannelSubscriptionOpts, -} from './types'; +import { OrdersChannel, OrdersChannelHandler, OrdersChannelMessageTypes, OrdersChannelSubscriptionOpts } from './types'; import { assert } from './utils/assert'; import { ordersChannelMessageParser } from './utils/orders_channel_message_parser'; diff --git a/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.json b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.json index 47ce42412..b1d570b03 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.json +++ b/packages/connect/test/fixtures/standard_relayer_api/fee_recipients.json @@ -7,4 +7,4 @@ "0x9e56625509c2f60af937f23b7b532600390e8c8b", "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32" ] -} \ No newline at end of file +} diff --git a/packages/connect/test/fixtures/standard_relayer_api/orderbook.json b/packages/connect/test/fixtures/standard_relayer_api/orderbook.json index b14d12e57..5206c2217 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/orderbook.json +++ b/packages/connect/test/fixtures/standard_relayer_api/orderbook.json @@ -51,4 +51,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/connect/test/fixtures/standard_relayer_api/orders.json b/packages/connect/test/fixtures/standard_relayer_api/orders.json index e4fb3a3dd..683612071 100644 --- a/packages/connect/test/fixtures/standard_relayer_api/orders.json +++ b/packages/connect/test/fixtures/standard_relayer_api/orders.json @@ -24,4 +24,3 @@ } ] } - diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 8b76c4c88..ad1654765 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -109,9 +109,9 @@ describe('HttpClient', () => { }; const url = `${relayUrl}/orderbook`; it('gets orderbook with default page options when none are provided', async () => { - const urlWithQuery = `${url}?baseAssetData=${ - request.baseAssetData - }"eAssetData=${request.quoteAssetData}`; + const urlWithQuery = `${url}?baseAssetData=${request.baseAssetData}"eAssetData=${ + request.quoteAssetData + }`; fetchMock.get(urlWithQuery, orderbookJSON); const orderbook = await relayerClient.getOrderbookAsync(request); expect(orderbook).to.be.deep.equal(orderbookResponse); diff --git a/packages/connect/test/orders_channel_factory_test.ts b/packages/connect/test/orders_channel_factory_test.ts index 58f7e08d9..e4c4ce32f 100644 --- a/packages/connect/test/orders_channel_factory_test.ts +++ b/packages/connect/test/orders_channel_factory_test.ts @@ -20,10 +20,7 @@ describe('ordersChannelFactory', () => { it('throws when input is not a url', () => { const badUrlInput = 54; expect( - ordersChannelFactory.createWebSocketOrdersChannelAsync( - badUrlInput as any, - emptyOrdersChannelHandler, - ), + ordersChannelFactory.createWebSocketOrdersChannelAsync(badUrlInput as any, emptyOrdersChannelHandler), ).to.be.rejected(); }); it('throws when handler has the incorrect members', () => { -- cgit v1.2.3 From 83a36bc4b60726bd95736e62281540ccc22b1766 Mon Sep 17 00:00:00 2001 From: fragosti Date: Mon, 20 Aug 2018 17:18:08 -0700 Subject: Improve documentation --- packages/connect/CHANGELOG.json | 3 ++- packages/connect/src/http_client.ts | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/CHANGELOG.json b/packages/connect/CHANGELOG.json index 1f17392a9..618694b5f 100644 --- a/packages/connect/CHANGELOG.json +++ b/packages/connect/CHANGELOG.json @@ -3,7 +3,8 @@ "version": "2.0.0", "changes": [ { - "note": "Updated for SRA v2" + "note": "Updated for SRA v2", + "pr": 974 } ] }, diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 93f4eeb05..1b30bebf3 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -56,7 +56,7 @@ export class HttpClient implements Client { } /** * Retrieve assetData pair info from the API - * @param requestOpts Options specifying assetData information to retrieve and page information, defaults to { page: 1, perPage: 100 } + * @param requestOpts Options specifying assetData information to retrieve, page information, and network id. * @return The resulting AssetPairsItems that match the request */ public async getAssetPairsAsync( @@ -76,7 +76,7 @@ export class HttpClient implements Client { } /** * Retrieve orders from the API - * @param requestOpts Options specifying orders to retrieve and page information, defaults to { page: 1, perPage: 100 } + * @param requestOpts Options specifying orders to retrieve and page information, page information, and network id. * @return The resulting SignedOrders that match the request */ public async getOrdersAsync( @@ -114,7 +114,7 @@ export class HttpClient implements Client { /** * Retrieve an orderbook from the API * @param request An OrderbookRequest instance describing the specific orderbook to retrieve - * @param requestOpts Options specifying page information, defaults to { page: 1, perPage: 100 } + * @param requestOpts Options specifying page information, and network id. * @return The resulting OrderbookResponse that matches the request */ public async getOrderbookAsync( @@ -135,7 +135,8 @@ export class HttpClient implements Client { } /** * Retrieve fee information from the API - * @param request A OrderConfigRequest instance describing the specific fees to retrieve + * @param request A OrderConfigRequest instance describing the specific fees to retrieve + * @param requestOpts Options specifying network id. * @return The resulting OrderConfigResponse that matches the request */ public async getOrderConfigAsync( @@ -155,7 +156,8 @@ export class HttpClient implements Client { return fees; } /** - * Retrieve the list of fee recipient addresses used by + * Retrieve the list of fee recipient addresses used by the relayer. + * @param requestOpts Options specifying page information, and network id. */ public async getFeeRecipientsAsync(requestOpts?: RequestOpts & PagedRequestOpts): Promise { if (!_.isUndefined(requestOpts)) { @@ -172,6 +174,7 @@ export class HttpClient implements Client { /** * Submit a signed order to the API * @param signedOrder A SignedOrder instance to submit + * @param requestOpts Options specifying network id. */ public async submitOrderAsync(signedOrder: SignedOrder, requestOpts?: RequestOpts): Promise { assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema); -- cgit v1.2.3 From cd2bbd850d30e581273aae5d0524bce785639042 Mon Sep 17 00:00:00 2001 From: fragosti Date: Mon, 20 Aug 2018 17:23:38 -0700 Subject: Update more names in docs --- packages/connect/src/http_client.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 1b30bebf3..b90c2c35f 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -57,7 +57,7 @@ export class HttpClient implements Client { /** * Retrieve assetData pair info from the API * @param requestOpts Options specifying assetData information to retrieve, page information, and network id. - * @return The resulting AssetPairsItems that match the request + * @return The resulting AssetPairsResponse that match the request */ public async getAssetPairsAsync( requestOpts?: RequestOpts & AssetPairsRequestOpts & PagedRequestOpts, @@ -77,7 +77,7 @@ export class HttpClient implements Client { /** * Retrieve orders from the API * @param requestOpts Options specifying orders to retrieve and page information, page information, and network id. - * @return The resulting SignedOrders that match the request + * @return The resulting OrdersResponse that match the request */ public async getOrdersAsync( requestOpts?: RequestOpts & OrdersRequestOpts & PagedRequestOpts, @@ -97,7 +97,7 @@ export class HttpClient implements Client { /** * Retrieve a specific order from the API * @param orderHash An orderHash generated from the desired order - * @return The SignedOrder that matches the supplied orderHash + * @return The APIOrder that matches the supplied orderHash */ public async getOrderAsync(orderHash: string, requestOpts?: RequestOpts): Promise { if (!_.isUndefined(requestOpts)) { @@ -158,6 +158,7 @@ export class HttpClient implements Client { /** * Retrieve the list of fee recipient addresses used by the relayer. * @param requestOpts Options specifying page information, and network id. + * @return The resulting FeeRecipientsResponse */ public async getFeeRecipientsAsync(requestOpts?: RequestOpts & PagedRequestOpts): Promise { if (!_.isUndefined(requestOpts)) { -- cgit v1.2.3 From 8b79868c36b8cd5b155509bec668f7c629095c7a Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 21 Aug 2018 10:58:35 -0700 Subject: Update variable names, make release candidate --- packages/connect/CHANGELOG.json | 2 +- packages/connect/src/orders_channel_factory.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/CHANGELOG.json b/packages/connect/CHANGELOG.json index 618694b5f..d7e026b4f 100644 --- a/packages/connect/CHANGELOG.json +++ b/packages/connect/CHANGELOG.json @@ -1,6 +1,6 @@ [ { - "version": "2.0.0", + "version": "2.0.0-rc.1", "changes": [ { "note": "Updated for SRA v2", diff --git a/packages/connect/src/orders_channel_factory.ts b/packages/connect/src/orders_channel_factory.ts index 5e8e625e0..5986d2a77 100644 --- a/packages/connect/src/orders_channel_factory.ts +++ b/packages/connect/src/orders_channel_factory.ts @@ -8,7 +8,7 @@ export const ordersChannelFactory = { /** * Instantiates a new WebSocketOrdersChannel instance * @param url The relayer API base WS url you would like to interact with - * @param handler An OrderbookChannelHandler instance that responds to various + * @param handler An OrdersChannelHandler instance that responds to various * channel updates * @return An OrdersChannel Promise */ @@ -18,8 +18,8 @@ export const ordersChannelFactory = { return new Promise((resolve, reject) => { const client = new WebSocket.w3cwebsocket(url); client.onopen = () => { - const orderbookChannel = new WebSocketOrdersChannel(client, handler); - resolve(orderbookChannel); + const ordersChannel = new WebSocketOrdersChannel(client, handler); + resolve(ordersChannel); }; client.onerror = err => { reject(err); -- cgit v1.2.3 From c905b20ce69d64711126bc31318e24f76deb05af Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 21 Aug 2018 16:51:01 -0700 Subject: Fix typo --- packages/connect/test/http_client_test.ts | 2 +- packages/connect/test/orders_channel_factory_test.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/connect') diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index ad1654765..5b564e97b 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -173,7 +173,7 @@ describe('HttpClient', () => { const feeRecipients = await relayerClient.getFeeRecipientsAsync(); expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse); }); - it('gets fee reciipient with specified page options', async () => { + it('gets fee recipient with specified page options', async () => { const urlWithQuery = `${url}?networkId=42&page=3&perPage=50`; fetchMock.get(urlWithQuery, feeRecipientsResponseJSON); const pagedRequestOptions = { diff --git a/packages/connect/test/orders_channel_factory_test.ts b/packages/connect/test/orders_channel_factory_test.ts index e4c4ce32f..29aa87c65 100644 --- a/packages/connect/test/orders_channel_factory_test.ts +++ b/packages/connect/test/orders_channel_factory_test.ts @@ -1,6 +1,7 @@ import * as chai from 'chai'; import * as dirtyChai from 'dirty-chai'; import * as _ from 'lodash'; + import 'mocha'; import { ordersChannelFactory } from '../src/orders_channel_factory'; -- cgit v1.2.3