Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Fix failing TS client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albrow committed Jan 8, 2020
1 parent 8d77bbe commit 630e6c5
Showing 1 changed file with 48 additions and 41 deletions.
89 changes: 48 additions & 41 deletions rpc/clients/typescript/test/ws_client_test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import {getContractAddressesForChainOrThrow} from '@0x/contract-addresses';
import {DummyERC20TokenContract} from '@0x/contracts-erc20';
import {ExchangeContract} from '@0x/contracts-exchange';
import {blockchainTests, constants, expect, OrderFactory, orderHashUtils} from '@0x/contracts-test-utils';
import {callbackErrorReporter, Web3Config, web3Factory} from '@0x/dev-utils';
import {assetDataUtils} from '@0x/order-utils';
import {Web3ProviderEngine} from '@0x/subproviders';
import {DoneCallback, SignedOrder} from '@0x/types';
import {BigNumber, hexUtils} from '@0x/utils';
import { getContractAddressesForChainOrThrow } from '@0x/contract-addresses';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { ExchangeContract } from '@0x/contracts-exchange';
import { blockchainTests, constants, expect, OrderFactory, orderHashUtils } from '@0x/contracts-test-utils';
import { callbackErrorReporter, Web3Config, web3Factory } from '@0x/dev-utils';
import { assetDataUtils } from '@0x/order-utils';
import { Web3ProviderEngine } from '@0x/subproviders';
import { DoneCallback, SignedOrder } from '@0x/types';
import { BigNumber, hexUtils } from '@0x/utils';
import 'mocha';
import * as uuidValidate from 'uuid-validate';
import * as WebSocket from 'websocket';

import {OrderEvent, OrderEventEndState, WSClient} from '../src/index';
import {ContractEventKind, ExchangeCancelEvent, RejectedKind, WSMessage} from '../src/types';
import { OrderEvent, OrderEventEndState, WSClient } from '../src/index';
import { ContractEventKind, ExchangeCancelEvent, RejectedKind, WSMessage } from '../src/types';

import {SERVER_PORT, setupServerAsync, stopServer} from './utils/mock_ws_server';
import {MeshDeployment, startServerAndClientAsync} from './utils/ws_server';
import { SERVER_PORT, setupServerAsync, stopServer } from './utils/mock_ws_server';
import { MeshDeployment, startServerAndClientAsync } from './utils/ws_server';

blockchainTests.resets('WSClient', env => {
describe('integration tests', () => {
Expand Down Expand Up @@ -63,10 +63,10 @@ blockchainTests.resets('WSClient', env => {
await feeToken.mint(mintAmount).awaitTransactionSuccessAsync({ from: makerAddress });
await makerToken
.approve(erc20ProxyAddress, new BigNumber('100e18'))
.awaitTransactionSuccessAsync({from: makerAddress});
.awaitTransactionSuccessAsync({ from: makerAddress });
await feeToken
.approve(erc20ProxyAddress, new BigNumber('100e18'))
.awaitTransactionSuccessAsync({from: makerAddress});
.awaitTransactionSuccessAsync({ from: makerAddress });
orderFactory = new OrderFactory(constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)], {
...constants.STATIC_ORDER_PARAMS,
feeRecipientAddress: constants.NULL_ADDRESS,
Expand All @@ -85,12 +85,14 @@ blockchainTests.resets('WSClient', env => {
const order = await orderFactory.newSignedOrderAsync({});
const validationResults = await deployment.client.addOrdersAsync([order]);
expect(validationResults).to.be.deep.eq({
accepted: [{
fillableTakerAssetAmount: order.takerAssetAmount,
isNew: true,
orderHash: orderHashUtils.getOrderHashHex(order),
signedOrder: order,
}],
accepted: [
{
fillableTakerAssetAmount: order.takerAssetAmount,
isNew: true,
orderHash: orderHashUtils.getOrderHashHex(order),
signedOrder: order,
},
],
rejected: [],
});
});
Expand All @@ -103,15 +105,17 @@ blockchainTests.resets('WSClient', env => {
const validationResults = await deployment.client.addOrdersAsync([invalidOrder]);
expect(validationResults).to.be.deep.eq({
accepted: [],
rejected: [{
kind: RejectedKind.ZeroexValidation,
orderHash: orderHashUtils.getOrderHashHex(invalidOrder),
signedOrder: invalidOrder,
status: {
code: 'OrderHasInvalidSignature',
message: 'order signature must be valid',
rejected: [
{
kind: RejectedKind.ZeroexValidation,
orderHash: orderHashUtils.getOrderHashHex(invalidOrder),
signedOrder: invalidOrder,
status: {
code: 'OrderHasInvalidSignature',
message: 'order signature must be valid',
},
},
}],
],
});
});
});
Expand All @@ -132,11 +136,12 @@ blockchainTests.resets('WSClient', env => {
};

const now = new Date(Date.now());
const expectedStartOfCurrentUTCDay = `${now.getUTCFullYear()}-${leftPad(now.getUTCMonth() +
1)}-${leftPad(now.getUTCDate())}T00:00:00Z`;
const expectedStartOfCurrentUTCDay = `${now.getUTCFullYear()}-${leftPad(
now.getUTCMonth() + 1,
)}-${leftPad(now.getUTCDate())}T00:00:00Z`;
const expectedStats = {
version: '',
pubSubTopic: '/0x-orders/network/1337/version/2',
pubSubTopic: '/0x-orders/version/3/chain/1337/schema/e30=',
rendezvous: '/0x-mesh/network/1337/version/2',
peerID: deployment.peerID,
ethereumChainID: 1337,
Expand Down Expand Up @@ -199,11 +204,12 @@ blockchainTests.resets('WSClient', env => {
it('should receive subscription updates', (done: DoneCallback) => {
(async () => {
const expectToBeCalledOnce = true;
const callback = callbackErrorReporter.reportNoErrorCallbackErrors(done, expectToBeCalledOnce)(
async (ack: string) => {
expect(ack).to.be.equal('tick');
},
);
const callback = callbackErrorReporter.reportNoErrorCallbackErrors(
done,
expectToBeCalledOnce,
)(async (ack: string) => {
expect(ack).to.be.equal('tick');
});
await (deployment.client as any)._subscribeToHeartbeatAsync(callback);
})().catch(done);
});
Expand Down Expand Up @@ -237,7 +243,9 @@ blockchainTests.resets('WSClient', env => {
if (orderHash === orderEvent.orderHash) {
hasSeenMatch = true;
expect(orderEvent.signedOrder).to.be.deep.eq(order);
expect(orderEvent.fillableTakerAssetAmount).to.be.bignumber.eq(order.takerAssetAmount);
expect(orderEvent.fillableTakerAssetAmount).to.be.bignumber.eq(
order.takerAssetAmount,
);
break;
}
}
Expand All @@ -257,7 +265,7 @@ blockchainTests.resets('WSClient', env => {
(async () => {
// Add an order and then cancel it.
const order = await orderFactory.newSignedOrderAsync({});
const validationResults = await deployment.client.addOrdersAsync([ order ]);
const validationResults = await deployment.client.addOrdersAsync([order]);
expect(validationResults.accepted.length).to.be.eq(1);

// Subscribe to order events and assert that only a single cancel event was received.
Expand Down Expand Up @@ -301,7 +309,6 @@ blockchainTests.resets('WSClient', env => {
await subscription;
})().catch(done);
});

});

describe('#unsubscribeAsync', async () => {
Expand Down Expand Up @@ -380,7 +387,7 @@ blockchainTests.resets('WSClient', env => {
}) as any);
});

const client = new WSClient(`ws://localhost:${SERVER_PORT}`, {reconnectDelay: 100});
const client = new WSClient(`ws://localhost:${SERVER_PORT}`, { reconnectDelay: 100 });
client.onReconnected(async () => {
// We need to add a sleep here so that we leave time for the client
// to get connected before destroying it.
Expand Down

0 comments on commit 630e6c5

Please sign in to comment.