aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/test/http_client_test.ts
diff options
context:
space:
mode:
authorRemco Bloemen <remco@wicked.ventures>2018-11-09 01:32:40 +0800
committerRemco Bloemen <remco@wicked.ventures>2018-11-09 01:32:40 +0800
commitd71362af993d3797dbdbfcac245ad57f0086bce3 (patch)
tree888826fe23c2d06d6c9191fb3a238e14f9fe4aac /packages/connect/test/http_client_test.ts
parenta5665a68756c905637c551fc48c9b7011a55c237 (diff)
parentf6abc007ffb249e4bbf85b8a7a77309d43e0a147 (diff)
downloaddexon-sol-tools-d71362af993d3797dbdbfcac245ad57f0086bce3.tar
dexon-sol-tools-d71362af993d3797dbdbfcac245ad57f0086bce3.tar.gz
dexon-sol-tools-d71362af993d3797dbdbfcac245ad57f0086bce3.tar.bz2
dexon-sol-tools-d71362af993d3797dbdbfcac245ad57f0086bce3.tar.lz
dexon-sol-tools-d71362af993d3797dbdbfcac245ad57f0086bce3.tar.xz
dexon-sol-tools-d71362af993d3797dbdbfcac245ad57f0086bce3.tar.zst
dexon-sol-tools-d71362af993d3797dbdbfcac245ad57f0086bce3.zip
Merge remote-tracking branch 'origin/development' into feature/utils/prettybignum
Diffstat (limited to 'packages/connect/test/http_client_test.ts')
-rw-r--r--packages/connect/test/http_client_test.ts147
1 files changed, 85 insertions, 62 deletions
diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts
index 311dc96e6..f799ca849 100644
--- a/packages/connect/test/http_client_test.ts
+++ b/packages/connect/test/http_client_test.ts
@@ -1,4 +1,4 @@
-import { BigNumber } from '@0xproject/utils';
+import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as dirtyChai from 'dirty-chai';
@@ -7,16 +7,18 @@ import 'mocha';
import { HttpClient } from '../src/index';
-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 { 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';
+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';
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';
chai.config.includeStack = true;
chai.use(dirtyChai);
@@ -26,7 +28,7 @@ const expect = chai.expect;
describe('HttpClient', () => {
const relayUrl = 'https://example.com';
const relayerClient = new HttpClient(relayUrl);
- afterEach(() => {
+ beforeEach(() => {
fetchMock.restore();
});
describe('#constructor', () => {
@@ -38,47 +40,47 @@ describe('HttpClient', () => {
expect(sanitizedUrl).to.be.deep.equal(urlWithoutTrailingSlash);
});
});
- describe('#getTokenPairsAsync', () => {
- 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();
- expect(tokenPairs).to.be.deep.equal(tokenPairsResponse);
- });
- it('gets token pairs with specified request options', async () => {
- const tokenAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d';
- const tokenPairsRequestOpts = {
- tokenA: tokenAddress,
+ describe('#getAssetPairsAsync', () => {
+ const url = `${relayUrl}/asset_pairs`;
+ it('gets assetData pairs with default options when none are provided', async () => {
+ fetchMock.get(url, assetDataPairsResponseJSON);
+ const assetDataPairs = await relayerClient.getAssetPairsAsync();
+ expect(assetDataPairs).to.be.deep.equal(assetDataPairsResponse);
+ });
+ it('gets assetData pairs with specified request options', async () => {
+ const assetData = '0xf47261b04c32345ced77393b3530b1eed0f346429d';
+ const assetPairsRequestOpts = {
+ assetDataA: assetData,
page: 3,
perPage: 50,
+ networkdId: 42,
};
- const urlWithQuery = `${url}?page=3&per_page=50&tokenA=${tokenAddress}`;
- fetchMock.get(urlWithQuery, tokenPairsResponseJSON);
- const tokenPairs = await relayerClient.getTokenPairsAsync(tokenPairsRequestOpts);
- expect(tokenPairs).to.be.deep.equal(tokenPairsResponse);
+ 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);
});
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', () => {
const url = `${relayUrl}/orders`;
it('gets orders with default options when none are provided', async () => {
- const urlWithQuery = `${url}?page=1&per_page=100`;
- fetchMock.get(urlWithQuery, ordersResponseJSON);
+ fetchMock.get(url, ordersResponseJSON);
const orders = await relayerClient.getOrdersAsync();
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,
+ networkdId: 42,
};
- const urlWithQuery = `${url}?page=3&per_page=50&tokenAddress=${tokenAddress}`;
+ 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);
@@ -103,26 +105,27 @@ 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&quoteTokenAddress=${request.quoteTokenAddress}`;
+ const urlWithQuery = `${url}?baseAssetData=${request.baseAssetData}&quoteAssetData=${
+ 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&quoteTokenAddress=${request.quoteTokenAddress}`;
+ const urlWithQuery = `${url}?baseAssetData=${
+ request.baseAssetData
+ }&networkId=42&page=3&perPage=50&quoteAssetData=${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);
@@ -132,39 +135,59 @@ describe('HttpClient', () => {
expect(relayerClient.getOrderbookAsync(request)).to.be.rejected();
});
});
- describe('#getFeesAsync', () => {
+ describe('#getOrderConfigAsync', () => {
const request = {
- exchangeContractAddress: '0x12459c951127e0c374ff9105dda097662a027093',
- maker: '0x9e56625509c2f60af937f23b7b532600390e8c8b',
- taker: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
- makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990',
- makerTokenAmount: new BigNumber('10000000000000000000'),
- takerTokenAmount: new BigNumber('30000000000000000000'),
- salt: new BigNumber('256'),
- expirationUnixTimestampSec: new BigNumber('42'),
+ makerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b',
+ takerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
+ makerAssetAmount: new BigNumber('10000000000000000'),
+ takerAssetAmount: new BigNumber('20000000000000000'),
+ expirationTimeSeconds: new BigNumber('1532560590'),
+ makerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
+ takerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990',
+ exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093',
};
- const url = `${relayUrl}/fees`;
- it('gets fees', async () => {
- fetchMock.post(url, feesResponseJSON);
- const fees = await relayerClient.getFeesAsync(request);
- expect(fees).to.be.deep.equal(feesResponse);
+ const url = `${relayUrl}/order_config`;
+ it('gets order config', async () => {
+ fetchMock.post(url, orderConfigResponseJSON);
+ const fees = await relayerClient.getOrderConfigAsync(request);
+ expect(fees).to.be.deep.equal(orderConfigResponse);
});
it('does not mutate input', async () => {
- fetchMock.post(url, feesResponseJSON);
- const makerTokenAmountBefore = new BigNumber(request.makerTokenAmount);
- const takerTokenAmountBefore = new BigNumber(request.takerTokenAmount);
- const saltBefore = new BigNumber(request.salt);
- const expirationUnixTimestampSecBefore = new BigNumber(request.expirationUnixTimestampSec);
- await relayerClient.getFeesAsync(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);
- expect(expirationUnixTimestampSecBefore).to.be.deep.equal(request.expirationUnixTimestampSec);
+ fetchMock.post(url, orderConfigResponseJSON);
+ 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);
+ expect(expirationTimeSecondsBefore).to.be.deep.equal(request.expirationTimeSeconds);
});
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();
+ });
+ });
+ describe('#getFeeRecipientsAsync', () => {
+ const url = `${relayUrl}/fee_recipients`;
+ 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 fee recipient 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);
+ });
+ it('throws an error for invalid JSON response', async () => {
+ fetchMock.get(url, { test: 'dummy' });
+ expect(relayerClient.getFeeRecipientsAsync()).to.be.rejected();
});
});
});