aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/test
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js/test')
-rw-r--r--packages/0x.js/test/0x.js_test.ts52
-rw-r--r--packages/0x.js/test/artifacts_test.ts24
-rw-r--r--packages/0x.js/test/assert_test.ts8
-rw-r--r--packages/0x.js/test/ether_token_wrapper_test.ts14
-rw-r--r--packages/0x.js/test/event_watcher_test.ts21
-rw-r--r--packages/0x.js/test/exchange_transfer_simulator_test.ts18
-rw-r--r--packages/0x.js/test/exchange_wrapper_test.ts60
-rw-r--r--packages/0x.js/test/expiration_watcher_test.ts26
-rw-r--r--packages/0x.js/test/order_state_watcher_test.ts81
-rw-r--r--packages/0x.js/test/order_validation_test.ts38
-rw-r--r--packages/0x.js/test/remaining_fillable_calculator_test.ts12
-rw-r--r--packages/0x.js/test/subscription_test.ts73
-rw-r--r--packages/0x.js/test/token_registry_wrapper_test.ts16
-rw-r--r--packages/0x.js/test/token_transfer_proxy_wrapper_test.ts12
-rw-r--r--packages/0x.js/test/token_wrapper_test.ts54
-rw-r--r--packages/0x.js/test/utils/chai_setup.ts4
-rw-r--r--packages/0x.js/test/utils/constants.ts2
-rw-r--r--packages/0x.js/test/utils/fill_scenarios.ts4
-rw-r--r--packages/0x.js/test/utils/order_factory.ts11
-rw-r--r--packages/0x.js/test/utils/report_callback_errors.ts4
-rw-r--r--packages/0x.js/test/utils/rpc.ts1
-rw-r--r--packages/0x.js/test/utils/token_utils.ts3
-rw-r--r--packages/0x.js/test/utils/web3_factory.ts6
-rw-r--r--packages/0x.js/test/web3_wrapper_test.ts29
24 files changed, 329 insertions, 244 deletions
diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts
index d56acc38b..6b7a70699 100644
--- a/packages/0x.js/test/0x.js_test.ts
+++ b/packages/0x.js/test/0x.js_test.ts
@@ -1,14 +1,16 @@
-import * as _ from 'lodash';
+import BigNumber from 'bignumber.js';
import * as chai from 'chai';
-import {chaiSetup} from './utils/chai_setup';
+import * as _ from 'lodash';
import 'mocha';
-import BigNumber from 'bignumber.js';
import * as Sinon from 'sinon';
-import {ZeroEx, Order, ZeroExError, LogWithDecodedArgs, ApprovalContractEventArgs, TokenEvents} from '../src';
+
+import {ApprovalContractEventArgs, LogWithDecodedArgs, Order, TokenEvents, ZeroEx, ZeroExError} from '../src';
+
+import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
+import {chaiSetup} from './utils/chai_setup';
import {constants} from './utils/constants';
import {TokenUtils} from './utils/token_utils';
import {web3Factory} from './utils/web3_factory';
-import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
const blockchainLifecycle = new BlockchainLifecycle();
chaiSetup.configure();
@@ -16,7 +18,10 @@ const expect = chai.expect;
describe('ZeroEx library', () => {
const web3 = web3Factory.create();
- const zeroEx = new ZeroEx(web3.currentProvider);
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
+ const zeroEx = new ZeroEx(web3.currentProvider, config);
describe('#setProvider', () => {
it('overrides provider in nested web3s and invalidates contractInstances', async () => {
// Instantiate the contract instances with the current provider
@@ -28,7 +33,7 @@ describe('ZeroEx library', () => {
const newProvider = web3Factory.getRpcProvider();
// Add property to newProvider so that we can differentiate it from old provider
(newProvider as any).zeroExTestId = 1;
- await zeroEx.setProviderAsync(newProvider);
+ zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
// Check that contractInstances with old provider are removed after provider update
expect((zeroEx.exchange as any)._exchangeContractIfExists).to.be.undefined();
@@ -36,11 +41,11 @@ describe('ZeroEx library', () => {
// Check that all nested web3 wrapper instances return the updated provider
const nestedWeb3WrapperProvider = (zeroEx as any)._web3Wrapper.getCurrentProvider();
- expect((nestedWeb3WrapperProvider as any).zeroExTestId).to.be.a('number');
+ expect((nestedWeb3WrapperProvider).zeroExTestId).to.be.a('number');
const exchangeWeb3WrapperProvider = (zeroEx.exchange as any)._web3Wrapper.getCurrentProvider();
- expect((exchangeWeb3WrapperProvider as any).zeroExTestId).to.be.a('number');
+ expect((exchangeWeb3WrapperProvider).zeroExTestId).to.be.a('number');
const tokenRegistryWeb3WrapperProvider = (zeroEx.tokenRegistry as any)._web3Wrapper.getCurrentProvider();
- expect((tokenRegistryWeb3WrapperProvider as any).zeroExTestId).to.be.a('number');
+ expect((tokenRegistryWeb3WrapperProvider).zeroExTestId).to.be.a('number');
});
});
describe('#isValidSignature', () => {
@@ -220,7 +225,7 @@ describe('ZeroEx library', () => {
const tokens = await zeroEx.tokenRegistry.getTokensAsync();
const tokenUtils = new TokenUtils(tokens);
const zrxTokenAddress = tokenUtils.getProtocolTokenOrThrow().address;
- const proxyAddress = await zeroEx.proxy.getContractAddressAsync();
+ const proxyAddress = zeroEx.proxy.getContractAddress();
const txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(zrxTokenAddress, coinbase);
const txReceiptWithDecodedLogs = await zeroEx.awaitTransactionMinedAsync(txHash);
const log = txReceiptWithDecodedLogs.logs[0] as LogWithDecodedArgs<ApprovalContractEventArgs>;
@@ -232,28 +237,29 @@ describe('ZeroEx library', () => {
});
describe('#config', () => {
it('allows to specify exchange contract address', async () => {
- const config = {
+ const zeroExConfig = {
exchangeContractAddress: ZeroEx.NULL_ADDRESS,
+ networkId: constants.TESTRPC_NETWORK_ID,
};
- const zeroExWithWrongExchangeAddress = new ZeroEx(web3.currentProvider, config);
- return expect(zeroExWithWrongExchangeAddress.exchange.getContractAddressAsync())
- .to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
+ const zeroExWithWrongExchangeAddress = new ZeroEx(web3.currentProvider, zeroExConfig);
+ expect(zeroExWithWrongExchangeAddress.exchange.getContractAddress()).to.be.equal(ZeroEx.NULL_ADDRESS);
});
it('allows to specify ether token contract address', async () => {
- const config = {
+ const zeroExConfig = {
etherTokenContractAddress: ZeroEx.NULL_ADDRESS,
+ networkId: constants.TESTRPC_NETWORK_ID,
};
- const zeroExWithWrongEtherTokenAddress = new ZeroEx(web3.currentProvider, config);
- return expect(zeroExWithWrongEtherTokenAddress.etherToken.getContractAddressAsync())
- .to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
+ const zeroExWithWrongEtherTokenAddress = new ZeroEx(web3.currentProvider, zeroExConfig);
+ expect(zeroExWithWrongEtherTokenAddress.etherToken.getContractAddress()).to.be.equal(ZeroEx.NULL_ADDRESS);
});
it('allows to specify token registry token contract address', async () => {
- const config = {
+ const zeroExConfig = {
tokenRegistryContractAddress: ZeroEx.NULL_ADDRESS,
+ networkId: constants.TESTRPC_NETWORK_ID,
};
- const zeroExWithWrongTokenRegistryAddress = new ZeroEx(web3.currentProvider, config);
- return expect(zeroExWithWrongTokenRegistryAddress.tokenRegistry.getContractAddressAsync())
- .to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
+ const zeroExWithWrongTokenRegistryAddress = new ZeroEx(web3.currentProvider, zeroExConfig);
+ expect(zeroExWithWrongTokenRegistryAddress.tokenRegistry.getContractAddress())
+ .to.be.equal(ZeroEx.NULL_ADDRESS);
});
});
});
diff --git a/packages/0x.js/test/artifacts_test.ts b/packages/0x.js/test/artifacts_test.ts
index b2866a1d6..f4599a24d 100644
--- a/packages/0x.js/test/artifacts_test.ts
+++ b/packages/0x.js/test/artifacts_test.ts
@@ -1,8 +1,10 @@
-import * as fs from 'fs';
import * as chai from 'chai';
-import {chaiSetup} from './utils/chai_setup';
+import * as fs from 'fs';
import HDWalletProvider = require('truffle-hdwallet-provider');
+
import {ZeroEx} from '../src';
+
+import {chaiSetup} from './utils/chai_setup';
import {constants} from './utils/constants';
chaiSetup.configure();
@@ -18,15 +20,18 @@ describe('Artifacts', () => {
const packageJSON = JSON.parse(packageJSONContent);
const mnemonic = packageJSON.config.mnemonic;
const web3Provider = new HDWalletProvider(mnemonic, kovanRpcUrl);
- const zeroEx = new ZeroEx(web3Provider);
+ const config = {
+ networkId: constants.KOVAN_NETWORK_ID,
+ };
+ const zeroEx = new ZeroEx(web3Provider, config);
it('token registry contract is deployed', async () => {
await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync();
}).timeout(TIMEOUT);
it('proxy contract is deployed', async () => {
- await (zeroEx.token as any)._getTokenTransferProxyAddressAsync();
+ await (zeroEx.proxy as any)._getTokenTransferProxyContractAsync();
}).timeout(TIMEOUT);
it('exchange contract is deployed', async () => {
- await zeroEx.exchange.getContractAddressAsync();
+ await (zeroEx.exchange as any)._getExchangeContractAsync();
}).timeout(TIMEOUT);
});
describe('contracts are deployed on ropsten', () => {
@@ -35,15 +40,18 @@ describe('Artifacts', () => {
const packageJSON = JSON.parse(packageJSONContent);
const mnemonic = packageJSON.config.mnemonic;
const web3Provider = new HDWalletProvider(mnemonic, ropstenRpcUrl);
- const zeroEx = new ZeroEx(web3Provider);
+ const config = {
+ networkId: constants.ROPSTEN_NETWORK_ID,
+ };
+ const zeroEx = new ZeroEx(web3Provider, config);
it('token registry contract is deployed', async () => {
await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync();
}).timeout(TIMEOUT);
it('proxy contract is deployed', async () => {
- await (zeroEx.token as any)._getTokenTransferProxyAddressAsync();
+ await (zeroEx.proxy as any)._getTokenTransferProxyContractAsync();
}).timeout(TIMEOUT);
it('exchange contract is deployed', async () => {
- await zeroEx.exchange.getContractAddressAsync();
+ await (zeroEx.exchange as any)._getExchangeContractAsync();
}).timeout(TIMEOUT);
});
});
diff --git a/packages/0x.js/test/assert_test.ts b/packages/0x.js/test/assert_test.ts
index bfca95d9c..9fa7f780f 100644
--- a/packages/0x.js/test/assert_test.ts
+++ b/packages/0x.js/test/assert_test.ts
@@ -1,14 +1,20 @@
import * as chai from 'chai';
import 'mocha';
+
import {ZeroEx} from '../src';
import {assert} from '../src/utils/assert';
+
+import {constants} from './utils/constants';
import {web3Factory} from './utils/web3_factory';
const expect = chai.expect;
describe('Assertion library', () => {
const web3 = web3Factory.create();
- const zeroEx = new ZeroEx(web3.currentProvider);
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
+ const zeroEx = new ZeroEx(web3.currentProvider, config);
describe('#isSenderAddressHexAsync', () => {
it('throws when address is invalid', async () => {
const address = '0xdeadbeef';
diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts
index ba679d1a1..5b5e4c656 100644
--- a/packages/0x.js/test/ether_token_wrapper_test.ts
+++ b/packages/0x.js/test/ether_token_wrapper_test.ts
@@ -1,11 +1,14 @@
-import 'mocha';
+import BigNumber from 'bignumber.js';
import * as chai from 'chai';
-import {chaiSetup} from './utils/chai_setup';
+import 'mocha';
import * as Web3 from 'web3';
-import BigNumber from 'bignumber.js';
-import {web3Factory} from './utils/web3_factory';
+
import {ZeroEx, ZeroExError} from '../src';
+
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
+import {chaiSetup} from './utils/chai_setup';
+import {constants} from './utils/constants';
+import {web3Factory} from './utils/web3_factory';
chaiSetup.configure();
const expect = chai.expect;
@@ -28,13 +31,14 @@ describe('EtherTokenWrapper', () => {
const gasPrice = new BigNumber(1);
const zeroExConfig = {
gasPrice,
+ networkId: constants.TESTRPC_NETWORK_ID,
};
before(async () => {
web3 = web3Factory.create();
zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig);
userAddresses = await zeroEx.getAvailableAddressesAsync();
addressWithETH = userAddresses[0];
- wethContractAddress = await zeroEx.etherToken.getContractAddressAsync();
+ wethContractAddress = zeroEx.etherToken.getContractAddress();
depositWeiAmount = (zeroEx as any)._web3Wrapper.toWei(new BigNumber(5));
decimalPlaces = 7;
});
diff --git a/packages/0x.js/test/event_watcher_test.ts b/packages/0x.js/test/event_watcher_test.ts
index b4164fe63..f27a7da2c 100644
--- a/packages/0x.js/test/event_watcher_test.ts
+++ b/packages/0x.js/test/event_watcher_test.ts
@@ -1,19 +1,22 @@
-import 'mocha';
+import BigNumber from 'bignumber.js';
import * as chai from 'chai';
import * as _ from 'lodash';
+import 'mocha';
import * as Sinon from 'sinon';
import * as Web3 from 'web3';
-import BigNumber from 'bignumber.js';
-import {chaiSetup} from './utils/chai_setup';
-import {web3Factory} from './utils/web3_factory';
-import {Web3Wrapper} from '../src/web3_wrapper';
-import {EventWatcher} from '../src/order_watcher/event_watcher';
+
import {
- ZeroEx,
- LogEvent,
DecodedLogEvent,
+ LogEvent,
+ ZeroEx,
} from '../src';
+import {EventWatcher} from '../src/order_watcher/event_watcher';
import {DoneCallback} from '../src/types';
+import {Web3Wrapper} from '../src/web3_wrapper';
+
+import {chaiSetup} from './utils/chai_setup';
+import {constants} from './utils/constants';
+import {web3Factory} from './utils/web3_factory';
chaiSetup.configure();
const expect = chai.expect;
@@ -57,7 +60,7 @@ describe('EventWatcher', () => {
before(async () => {
web3 = web3Factory.create();
const pollingIntervalMs = 10;
- web3Wrapper = new Web3Wrapper(web3.currentProvider);
+ web3Wrapper = new Web3Wrapper(web3.currentProvider, constants.TESTRPC_NETWORK_ID);
eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalMs);
});
afterEach(() => {
diff --git a/packages/0x.js/test/exchange_transfer_simulator_test.ts b/packages/0x.js/test/exchange_transfer_simulator_test.ts
index 43a6404a1..a1d9bdade 100644
--- a/packages/0x.js/test/exchange_transfer_simulator_test.ts
+++ b/packages/0x.js/test/exchange_transfer_simulator_test.ts
@@ -1,11 +1,14 @@
-import * as chai from 'chai';
import BigNumber from 'bignumber.js';
+import * as chai from 'chai';
+
+import {ExchangeContractErrs, Token, ZeroEx} from '../src';
+import {BlockParamLiteral, TradeSide, TransferType} from '../src/types';
+import {ExchangeTransferSimulator} from '../src/utils/exchange_transfer_simulator';
+
+import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
import {chaiSetup} from './utils/chai_setup';
+import {constants} from './utils/constants';
import {web3Factory} from './utils/web3_factory';
-import {ZeroEx, ExchangeContractErrs, Token} from '../src';
-import {TradeSide, TransferType, BlockParamLiteral} from '../src/types';
-import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
-import {ExchangeTransferSimulator} from '../src/utils/exchange_transfer_simulator';
chaiSetup.configure();
const expect = chai.expect;
@@ -13,7 +16,10 @@ const blockchainLifecycle = new BlockchainLifecycle();
describe('ExchangeTransferSimulator', () => {
const web3 = web3Factory.create();
- const zeroEx = new ZeroEx(web3.currentProvider);
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
+ const zeroEx = new ZeroEx(web3.currentProvider, config);
const transferAmount = new BigNumber(5);
let userAddresses: string[];
let tokens: Token[];
diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts
index 13ac4c1d3..f6c823cc4 100644
--- a/packages/0x.js/test/exchange_wrapper_test.ts
+++ b/packages/0x.js/test/exchange_wrapper_test.ts
@@ -1,27 +1,30 @@
-import 'mocha';
+import BigNumber from 'bignumber.js';
import * as chai from 'chai';
+import 'mocha';
import * as Web3 from 'web3';
-import BigNumber from 'bignumber.js';
-import {chaiSetup} from './utils/chai_setup';
-import {web3Factory} from './utils/web3_factory';
-import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
+
import {
- ZeroEx,
- Token,
- SignedOrder,
- SubscriptionOpts,
- ExchangeEvents,
+ DecodedLogEvent,
ExchangeContractErrs,
- OrderCancellationRequest,
- OrderFillRequest,
- LogFillContractEventArgs,
+ ExchangeEvents,
LogCancelContractEventArgs,
LogEvent,
- DecodedLogEvent,
+ LogFillContractEventArgs,
+ OrderCancellationRequest,
+ OrderFillRequest,
+ SignedOrder,
+ SubscriptionOpts,
+ Token,
+ ZeroEx,
} from '../src';
-import {DoneCallback, BlockParamLiteral} from '../src/types';
+import {BlockParamLiteral, DoneCallback} from '../src/types';
+
+import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
+import {chaiSetup} from './utils/chai_setup';
+import {constants} from './utils/constants';
import {FillScenarios} from './utils/fill_scenarios';
import {TokenUtils} from './utils/token_utils';
+import {web3Factory} from './utils/web3_factory';
chaiSetup.configure();
const expect = chai.expect;
@@ -38,10 +41,13 @@ describe('ExchangeWrapper', () => {
let zrxTokenAddress: string;
let fillScenarios: FillScenarios;
let exchangeContractAddress: string;
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
before(async () => {
web3 = web3Factory.create();
- zeroEx = new ZeroEx(web3.currentProvider);
- exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync();
+ zeroEx = new ZeroEx(web3.currentProvider, config);
+ exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync();
tokenUtils = new TokenUtils(tokens);
@@ -613,7 +619,7 @@ describe('ExchangeWrapper', () => {
});
});
});
- describe('#subscribeAsync', () => {
+ describe('#subscribe', () => {
const indexFilterValues = {};
const shouldThrowOnInsufficientBalanceOrAllowance = true;
let makerTokenAddress: string;
@@ -652,7 +658,7 @@ describe('ExchangeWrapper', () => {
expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogFill);
done();
};
- await zeroEx.exchange.subscribeAsync(
+ zeroEx.exchange.subscribe(
ExchangeEvents.LogFill, indexFilterValues, callback,
);
await zeroEx.exchange.fillOrderAsync(
@@ -668,7 +674,7 @@ describe('ExchangeWrapper', () => {
expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogCancel);
done();
};
- await zeroEx.exchange.subscribeAsync(
+ zeroEx.exchange.subscribe(
ExchangeEvents.LogCancel, indexFilterValues, callback,
);
await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelTakerAmountInBaseUnits);
@@ -680,18 +686,18 @@ describe('ExchangeWrapper', () => {
const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
};
- await zeroEx.exchange.subscribeAsync(
+ zeroEx.exchange.subscribe(
ExchangeEvents.LogFill, indexFilterValues, callbackNeverToBeCalled,
);
const newProvider = web3Factory.getRpcProvider();
- await zeroEx.setProviderAsync(newProvider);
+ zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
const callback = (err: Error, logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogFill);
done();
};
- await zeroEx.exchange.subscribeAsync(
+ zeroEx.exchange.subscribe(
ExchangeEvents.LogFill, indexFilterValues, callback,
);
await zeroEx.exchange.fillOrderAsync(
@@ -705,7 +711,7 @@ describe('ExchangeWrapper', () => {
const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
};
- const subscriptionToken = await zeroEx.exchange.subscribeAsync(
+ const subscriptionToken = zeroEx.exchange.subscribe(
ExchangeEvents.LogFill, indexFilterValues, callbackNeverToBeCalled,
);
zeroEx.exchange.unsubscribe(subscriptionToken);
@@ -740,8 +746,8 @@ describe('ExchangeWrapper', () => {
});
});
describe('#getZRXTokenAddressAsync', () => {
- it('gets the same token as is in token registry', async () => {
- const zrxAddress = await zeroEx.exchange.getZRXTokenAddressAsync();
+ it('gets the same token as is in token registry', () => {
+ const zrxAddress = zeroEx.exchange.getZRXTokenAddress();
const zrxToken = tokenUtils.getProtocolTokenOrThrow();
expect(zrxAddress).to.equal(zrxToken.address);
});
@@ -821,4 +827,4 @@ describe('ExchangeWrapper', () => {
expect(args.maker).to.be.equal(differentMakerAddress);
});
});
-});
+}); // tslint:disable:max-file-line-count
diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts
index 0f2470070..c60b5dc6c 100644
--- a/packages/0x.js/test/expiration_watcher_test.ts
+++ b/packages/0x.js/test/expiration_watcher_test.ts
@@ -1,20 +1,23 @@
-import 'mocha';
+import BigNumber from 'bignumber.js';
import * as chai from 'chai';
import * as _ from 'lodash';
+import 'mocha';
import * as Sinon from 'sinon';
import * as Web3 from 'web3';
-import BigNumber from 'bignumber.js';
-import {chaiSetup} from './utils/chai_setup';
-import {web3Factory} from './utils/web3_factory';
+
+import {ZeroEx} from '../src/0x';
+import {ExpirationWatcher} from '../src/order_watcher/expiration_watcher';
+import {DoneCallback, Token} from '../src/types';
+import {constants} from '../src/utils/constants';
import {utils} from '../src/utils/utils';
import {Web3Wrapper} from '../src/web3_wrapper';
-import {TokenUtils} from './utils/token_utils';
-import {ExpirationWatcher} from '../src/order_watcher/expiration_watcher';
-import {Token, DoneCallback} from '../src/types';
-import {ZeroEx} from '../src/0x';
+
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
+import {chaiSetup} from './utils/chai_setup';
import {FillScenarios} from './utils/fill_scenarios';
import {reportCallbackErrors} from './utils/report_callback_errors';
+import {TokenUtils} from './utils/token_utils';
+import {web3Factory} from './utils/web3_factory';
chaiSetup.configure();
const expect = chai.expect;
@@ -41,8 +44,11 @@ describe('ExpirationWatcher', () => {
let expirationWatcher: ExpirationWatcher;
before(async () => {
web3 = web3Factory.create();
- zeroEx = new ZeroEx(web3.currentProvider);
- exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync();
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
+ zeroEx = new ZeroEx(web3.currentProvider, config);
+ exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync();
tokenUtils = new TokenUtils(tokens);
diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts
index e635071b8..1e5bc1a35 100644
--- a/packages/0x.js/test/order_state_watcher_test.ts
+++ b/packages/0x.js/test/order_state_watcher_test.ts
@@ -1,31 +1,33 @@
-import 'mocha';
+import BigNumber from 'bignumber.js';
import * as chai from 'chai';
import * as _ from 'lodash';
+import 'mocha';
import * as Web3 from 'web3';
-import BigNumber from 'bignumber.js';
-import {chaiSetup} from './utils/chai_setup';
-import {web3Factory} from './utils/web3_factory';
-import {Web3Wrapper} from '../src/web3_wrapper';
-import {OrderStateWatcher} from '../src/order_watcher/order_state_watcher';
+
import {
- Token,
- ZeroEx,
- LogEvent,
DecodedLogEvent,
- ZeroExConfig,
+ ExchangeContractErrs,
+ LogEvent,
OrderState,
+ OrderStateInvalid,
+ OrderStateValid,
SignedOrder,
+ Token,
+ ZeroEx,
+ ZeroExConfig,
ZeroExError,
- OrderStateValid,
- OrderStateInvalid,
- ExchangeContractErrs,
} from '../src';
-import {TokenUtils} from './utils/token_utils';
-import {FillScenarios} from './utils/fill_scenarios';
+import {OrderStateWatcher} from '../src/order_watcher/order_state_watcher';
import {DoneCallback} from '../src/types';
+import {Web3Wrapper} from '../src/web3_wrapper';
+
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
+import {chaiSetup} from './utils/chai_setup';
+import {constants} from './utils/constants';
+import {FillScenarios} from './utils/fill_scenarios';
import {reportCallbackErrors} from './utils/report_callback_errors';
-import {constants as constants} from './utils/constants';
+import {TokenUtils} from './utils/token_utils';
+import {web3Factory} from './utils/web3_factory';
const TIMEOUT_MS = 150;
@@ -48,12 +50,15 @@ describe('OrderStateWatcher', () => {
let taker: string;
let web3Wrapper: Web3Wrapper;
let signedOrder: SignedOrder;
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
const decimals = constants.ZRX_DECIMALS;
const fillableAmount = ZeroEx.toBaseUnitAmount(new BigNumber(5), decimals);
before(async () => {
web3 = web3Factory.create();
- zeroEx = new ZeroEx(web3.currentProvider);
- exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync();
+ zeroEx = new ZeroEx(web3.currentProvider, config);
+ exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync();
[, maker, taker] = userAddresses;
tokens = await zeroEx.tokenRegistry.getTokensAsync();
@@ -75,13 +80,13 @@ describe('OrderStateWatcher', () => {
makerToken.address, takerToken.address, maker, taker, fillableAmount,
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
expect((zeroEx.orderStateWatcher as any)._orderByOrderHash).to.include({
[orderHash]: signedOrder,
});
let dependentOrderHashes = (zeroEx.orderStateWatcher as any)._dependentOrderHashes;
expect(dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress]).to.have.keys(orderHash);
- await zeroEx.orderStateWatcher.removeOrderAsync(orderHash);
+ zeroEx.orderStateWatcher.removeOrder(orderHash);
expect((zeroEx.orderStateWatcher as any)._orderByOrderHash).to.not.include({
[orderHash]: signedOrder,
});
@@ -94,7 +99,7 @@ describe('OrderStateWatcher', () => {
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
const nonExistentOrderHash = `0x${orderHash.substr(2).split('').reverse().join('')}`;
- await zeroEx.orderStateWatcher.removeOrderAsync(nonExistentOrderHash);
+ zeroEx.orderStateWatcher.removeOrder(nonExistentOrderHash);
});
});
describe('#subscribe', async () => {
@@ -111,7 +116,7 @@ describe('OrderStateWatcher', () => {
afterEach(async () => {
zeroEx.orderStateWatcher.unsubscribe();
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- await zeroEx.orderStateWatcher.removeOrderAsync(orderHash);
+ zeroEx.orderStateWatcher.removeOrder(orderHash);
});
it('should emit orderStateInvalid when maker allowance set to 0 for watched order', (done: DoneCallback) => {
(async () => {
@@ -119,7 +124,7 @@ describe('OrderStateWatcher', () => {
makerToken.address, takerToken.address, maker, taker, fillableAmount,
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.false();
const invalidOrderState = orderState as OrderStateInvalid;
@@ -137,7 +142,7 @@ describe('OrderStateWatcher', () => {
makerToken.address, takerToken.address, maker, taker, fillableAmount,
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
throw new Error('OrderState callback fired for irrelevant order');
});
@@ -158,7 +163,7 @@ describe('OrderStateWatcher', () => {
makerToken.address, takerToken.address, maker, taker, fillableAmount,
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.false();
const invalidOrderState = orderState as OrderStateInvalid;
@@ -178,7 +183,7 @@ describe('OrderStateWatcher', () => {
makerToken.address, takerToken.address, maker, taker, fillableAmount,
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.false();
@@ -206,7 +211,7 @@ describe('OrderStateWatcher', () => {
const fillAmountInBaseUnits = new BigNumber(2);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.true();
@@ -237,7 +242,7 @@ describe('OrderStateWatcher', () => {
makerToken.address, takerToken.address, makerFee, takerFee, maker, taker, fillableAmount,
taker);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
done();
});
@@ -258,7 +263,7 @@ describe('OrderStateWatcher', () => {
const takerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, taker);
const fillAmountInBaseUnits = ZeroEx.toBaseUnitAmount(new BigNumber(2), decimals);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.true();
const validOrderState = orderState as OrderStateValid;
@@ -286,7 +291,7 @@ describe('OrderStateWatcher', () => {
const makerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, maker);
const changedMakerApprovalAmount = ZeroEx.toBaseUnitAmount(new BigNumber(3), decimals);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
const validOrderState = orderState as OrderStateValid;
@@ -311,7 +316,7 @@ describe('OrderStateWatcher', () => {
const remainingAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), decimals);
const transferAmount = makerBalance.sub(remainingAmount);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.true();
@@ -341,7 +346,7 @@ describe('OrderStateWatcher', () => {
const remainingTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(4), decimals);
const transferTokenAmount = makerFee.sub(remainingTokenAmount);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.true();
@@ -371,7 +376,7 @@ describe('OrderStateWatcher', () => {
const remainingTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(4), decimals);
const transferTokenAmount = makerFee.sub(remainingTokenAmount);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
const validOrderState = orderState as OrderStateValid;
@@ -396,7 +401,7 @@ describe('OrderStateWatcher', () => {
taker, fillableAmount, feeRecipient);
const makerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, maker);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
const validOrderState = orderState as OrderStateValid;
@@ -417,7 +422,7 @@ describe('OrderStateWatcher', () => {
makerToken.address, takerToken.address, maker, taker, fillableAmount,
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.false();
@@ -439,7 +444,7 @@ describe('OrderStateWatcher', () => {
makerToken.address, takerToken.address, maker, taker, fillableAmount,
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.false();
@@ -465,7 +470,7 @@ describe('OrderStateWatcher', () => {
const cancelAmountInBaseUnits = new BigNumber(2);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- await zeroEx.orderStateWatcher.addOrderAsync(signedOrder);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.true();
@@ -480,4 +485,4 @@ describe('OrderStateWatcher', () => {
})().catch(done);
});
});
-});
+}); // tslint:disable:max-file-line-count
diff --git a/packages/0x.js/test/order_validation_test.ts b/packages/0x.js/test/order_validation_test.ts
index d689ef073..d585c1f3c 100644
--- a/packages/0x.js/test/order_validation_test.ts
+++ b/packages/0x.js/test/order_validation_test.ts
@@ -1,16 +1,19 @@
-import * as chai from 'chai';
-import * as Web3 from 'web3';
import BigNumber from 'bignumber.js';
+import * as chai from 'chai';
import * as Sinon from 'sinon';
-import {chaiSetup} from './utils/chai_setup';
-import {web3Factory} from './utils/web3_factory';
-import {ZeroEx, SignedOrder, Token, ExchangeContractErrs, ZeroExError} from '../src';
-import {TradeSide, TransferType, BlockParamLiteral} from '../src/types';
-import {TokenUtils} from './utils/token_utils';
+import * as Web3 from 'web3';
+
+import {ExchangeContractErrs, SignedOrder, Token, ZeroEx, ZeroExError} from '../src';
+import {BlockParamLiteral, TradeSide, TransferType} from '../src/types';
+import {ExchangeTransferSimulator} from '../src/utils/exchange_transfer_simulator';
+import {OrderValidationUtils} from '../src/utils/order_validation_utils';
+
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
+import {chaiSetup} from './utils/chai_setup';
+import {constants} from './utils/constants';
import {FillScenarios} from './utils/fill_scenarios';
-import {OrderValidationUtils} from '../src/utils/order_validation_utils';
-import {ExchangeTransferSimulator} from '../src/utils/exchange_transfer_simulator';
+import {TokenUtils} from './utils/token_utils';
+import {web3Factory} from './utils/web3_factory';
chaiSetup.configure();
const expect = chai.expect;
@@ -34,10 +37,13 @@ describe('OrderValidation', () => {
let orderValidationUtils: OrderValidationUtils;
const fillableAmount = new BigNumber(5);
const fillTakerAmount = new BigNumber(5);
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
before(async () => {
web3 = web3Factory.create();
- zeroEx = new ZeroEx(web3.currentProvider);
- exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync();
+ zeroEx = new ZeroEx(web3.currentProvider, config);
+ exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync();
[coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses;
tokens = await zeroEx.tokenRegistry.getTokensAsync();
@@ -110,7 +116,7 @@ describe('OrderValidation', () => {
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
// 27 <--> 28
- signedOrder.ecSignature.v = 27 + (28 - signedOrder.ecSignature.v);
+ signedOrder.ecSignature.v = (28 - signedOrder.ecSignature.v) + 27;
return expect(zeroEx.exchange.validateFillOrderThrowIfInvalidAsync(
signedOrder, fillableAmount, takerAddress,
)).to.be.rejectedWith(ZeroExError.InvalidSignature);
@@ -226,7 +232,7 @@ describe('OrderValidation', () => {
makerTokenAddress, takerTokenAddress, makerFee, takerFee,
makerAddress, takerAddress, fillableAmount, feeRecipient,
);
- await orderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
+ await OrderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
exchangeTransferSimulator, signedOrder, fillableAmount, takerAddress, zrxTokenAddress,
);
expect(transferFromAsync.callCount).to.be.equal(4);
@@ -262,7 +268,7 @@ describe('OrderValidation', () => {
makerTokenAddress, takerTokenAddress, makerFee, takerFee,
makerAddress, ZeroEx.NULL_ADDRESS, fillableAmount, feeRecipient,
);
- await orderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
+ await OrderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
exchangeTransferSimulator, signedOrder, fillableAmount, takerAddress, zrxTokenAddress,
);
expect(transferFromAsync.callCount).to.be.equal(4);
@@ -297,7 +303,7 @@ describe('OrderValidation', () => {
const signedOrder = await fillScenarios.createAsymmetricFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, makerTokenAmount, takerTokenAmount,
);
- await orderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
+ await OrderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
exchangeTransferSimulator, signedOrder, takerTokenAmount, takerAddress, zrxTokenAddress,
);
expect(transferFromAsync.callCount).to.be.equal(4);
@@ -312,7 +318,7 @@ describe('OrderValidation', () => {
fillableAmount, ZeroEx.NULL_ADDRESS,
);
const fillTakerTokenAmount = fillableAmount.div(2).round(0);
- await orderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
+ await OrderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
exchangeTransferSimulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress,
);
const makerPartialFee = makerFee.div(2);
diff --git a/packages/0x.js/test/remaining_fillable_calculator_test.ts b/packages/0x.js/test/remaining_fillable_calculator_test.ts
index 65b65efd8..610bf9b1a 100644
--- a/packages/0x.js/test/remaining_fillable_calculator_test.ts
+++ b/packages/0x.js/test/remaining_fillable_calculator_test.ts
@@ -1,11 +1,13 @@
-import 'mocha';
-import * as chai from 'chai';
import BigNumber from 'bignumber.js';
-import { chaiSetup } from './utils/chai_setup';
+import * as chai from 'chai';
+import 'mocha';
+
+import { ZeroEx } from '../src/0x';
import { RemainingFillableCalculator } from '../src/order_watcher/remaining_fillable_calculator';
-import { SignedOrder, ECSignature } from '../src/types';
+import { ECSignature, SignedOrder } from '../src/types';
+
+import { chaiSetup } from './utils/chai_setup';
import { TokenUtils } from './utils/token_utils';
-import { ZeroEx } from '../src/0x';
chaiSetup.configure();
const expect = chai.expect;
diff --git a/packages/0x.js/test/subscription_test.ts b/packages/0x.js/test/subscription_test.ts
index f69ae0b13..e3b15808b 100644
--- a/packages/0x.js/test/subscription_test.ts
+++ b/packages/0x.js/test/subscription_test.ts
@@ -1,23 +1,27 @@
-import 'mocha';
-import * as _ from 'lodash';
+import BigNumber from 'bignumber.js';
import * as chai from 'chai';
+import promisify = require('es6-promisify');
+import * as _ from 'lodash';
+import 'mocha';
import * as Sinon from 'sinon';
-import {chaiSetup} from './utils/chai_setup';
import * as Web3 from 'web3';
-import BigNumber from 'bignumber.js';
-import promisify = require('es6-promisify');
-import {web3Factory} from './utils/web3_factory';
+
import {
- ZeroEx,
- ZeroExError,
- Token,
ApprovalContractEventArgs,
- TokenEvents,
DecodedLogEvent,
+ Token,
+ TokenEvents,
+ ZeroEx,
+ ZeroExError,
} from '../src';
+import {BlockParamLiteral, DoneCallback} from '../src/types';
+
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
+import {chaiSetup} from './utils/chai_setup';
+import {constants} from './utils/constants';
+import {reportCallbackErrors} from './utils/report_callback_errors';
import {TokenUtils} from './utils/token_utils';
-import {DoneCallback, BlockParamLiteral} from '../src/types';
+import {web3Factory} from './utils/web3_factory';
chaiSetup.configure();
const expect = chai.expect;
@@ -31,9 +35,12 @@ describe('SubscriptionTest', () => {
let tokenUtils: TokenUtils;
let coinbase: string;
let addressWithoutFunds: string;
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
before(async () => {
web3 = web3Factory.create();
- zeroEx = new ZeroEx(web3.currentProvider);
+ zeroEx = new ZeroEx(web3.currentProvider, config);
userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync();
tokenUtils = new TokenUtils(tokens);
@@ -62,22 +69,44 @@ describe('SubscriptionTest', () => {
_.each(stubs, s => s.restore());
stubs = [];
});
- it('Should receive the Error when an error occurs', (done: DoneCallback) => {
+ it('Should receive the Error when an error occurs while fetching the block', (done: DoneCallback) => {
(async () => {
- const callback = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
- expect(err).to.not.be.null();
- expect(logEvent).to.be.undefined();
- done();
- };
+ const errMsg = 'Error fetching block';
+ const callback = reportCallbackErrors(done)(
+ (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ expect(err.message).to.be.equal(errMsg);
+ expect(logEvent).to.be.undefined();
+ done();
+ },
+ );
stubs = [
Sinon.stub((zeroEx as any)._web3Wrapper, 'getBlockAsync')
- .throws('JSON RPC error'),
+ .throws(new Error(errMsg)),
+ ];
+ zeroEx.token.subscribe(
+ tokenAddress, TokenEvents.Approval, indexFilterValues, callback);
+ await zeroEx.token.setAllowanceAsync(tokenAddress, coinbase, addressWithoutFunds, allowanceAmount);
+ })().catch(done);
+ });
+ it('Should receive the Error when an error occurs while reconciling the new block', (done: DoneCallback) => {
+ (async () => {
+ const errMsg = 'Error fetching logs';
+ const callback = reportCallbackErrors(done)(
+ (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ expect(err.message).to.be.equal(errMsg);
+ expect(logEvent).to.be.undefined();
+ done();
+ },
+ );
+ stubs = [
+ Sinon.stub((zeroEx as any)._web3Wrapper, 'getLogsAsync')
+ .throws(new Error(errMsg)),
];
zeroEx.token.subscribe(
tokenAddress, TokenEvents.Approval, indexFilterValues, callback);
await zeroEx.token.setAllowanceAsync(tokenAddress, coinbase, addressWithoutFunds, allowanceAmount);
})().catch(done);
- });
+ });
it('Should allow unsubscribeAll to be called successfully after an error', (done: DoneCallback) => {
(async () => {
const callback = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => _.noop;
@@ -85,11 +114,11 @@ describe('SubscriptionTest', () => {
tokenAddress, TokenEvents.Approval, indexFilterValues, callback);
stubs = [
Sinon.stub((zeroEx as any)._web3Wrapper, 'getBlockAsync')
- .throws('JSON RPC error'),
+ .throws(new Error('JSON RPC error')),
];
zeroEx.token.unsubscribeAll();
done();
})().catch(done);
- });
+ });
});
});
diff --git a/packages/0x.js/test/token_registry_wrapper_test.ts b/packages/0x.js/test/token_registry_wrapper_test.ts
index d3497451b..f1f307f3a 100644
--- a/packages/0x.js/test/token_registry_wrapper_test.ts
+++ b/packages/0x.js/test/token_registry_wrapper_test.ts
@@ -1,11 +1,14 @@
+import {schemas, SchemaValidator} from '@0xproject/json-schemas';
+import * as chai from 'chai';
import * as _ from 'lodash';
import 'mocha';
-import * as chai from 'chai';
-import {SchemaValidator, schemas} from '@0xproject/json-schemas';
+
+import {Token, ZeroEx} from '../src';
+
+import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
import {chaiSetup} from './utils/chai_setup';
+import {constants} from './utils/constants';
import {web3Factory} from './utils/web3_factory';
-import {ZeroEx, Token} from '../src';
-import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
chaiSetup.configure();
const expect = chai.expect;
@@ -24,9 +27,12 @@ describe('TokenRegistryWrapper', () => {
const registeredName = '0x Protocol Token';
const unregisteredSymbol = 'MAL';
const unregisteredName = 'Malicious Token';
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
before(async () => {
const web3 = web3Factory.create();
- zeroEx = new ZeroEx(web3.currentProvider);
+ zeroEx = new ZeroEx(web3.currentProvider, config);
tokens = await zeroEx.tokenRegistry.getTokensAsync();
_.map(tokens, token => {
tokenAddressBySymbol[token.symbol] = token.address;
diff --git a/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts b/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts
index 8faef0b30..05861d112 100644
--- a/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts
+++ b/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts
@@ -1,17 +1,23 @@
import * as chai from 'chai';
-import {chaiSetup} from './utils/chai_setup';
-import {web3Factory} from './utils/web3_factory';
+
import {ZeroEx} from '../src';
import {TokenTransferProxyWrapper} from '../src/contract_wrappers/token_transfer_proxy_wrapper';
+import {chaiSetup} from './utils/chai_setup';
+import {constants} from './utils/constants';
+import {web3Factory} from './utils/web3_factory';
+
chaiSetup.configure();
const expect = chai.expect;
describe('TokenTransferProxyWrapper', () => {
let zeroEx: ZeroEx;
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
before(async () => {
const web3 = web3Factory.create();
- zeroEx = new ZeroEx(web3.currentProvider);
+ zeroEx = new ZeroEx(web3.currentProvider, config);
});
describe('#isAuthorizedAsync', () => {
it('should return false if the address is not authorized', async () => {
diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts
index b3c8edcc4..cc61c2324 100644
--- a/packages/0x.js/test/token_wrapper_test.ts
+++ b/packages/0x.js/test/token_wrapper_test.ts
@@ -1,27 +1,30 @@
-import 'mocha';
-import * as chai from 'chai';
-import {chaiSetup} from './utils/chai_setup';
-import * as Web3 from 'web3';
import BigNumber from 'bignumber.js';
+import * as chai from 'chai';
import promisify = require('es6-promisify');
-import {web3Factory} from './utils/web3_factory';
+import 'mocha';
+import * as Web3 from 'web3';
+
import {
- ZeroEx,
- ZeroExError,
- Token,
+ ApprovalContractEventArgs,
+ ContractEvent,
+ DecodedLogEvent,
+ LogEvent,
+ LogWithDecodedArgs,
SubscriptionOpts,
+ Token,
+ TokenContractEventArgs,
TokenEvents,
- ContractEvent,
TransferContractEventArgs,
- ApprovalContractEventArgs,
- TokenContractEventArgs,
- LogWithDecodedArgs,
- LogEvent,
- DecodedLogEvent,
+ ZeroEx,
+ ZeroExError,
} from '../src';
+import {BlockParamLiteral, DoneCallback} from '../src/types';
+
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
+import {chaiSetup} from './utils/chai_setup';
+import {constants} from './utils/constants';
import {TokenUtils} from './utils/token_utils';
-import {DoneCallback, BlockParamLiteral} from '../src/types';
+import {web3Factory} from './utils/web3_factory';
chaiSetup.configure();
const expect = chai.expect;
@@ -35,9 +38,12 @@ describe('TokenWrapper', () => {
let tokenUtils: TokenUtils;
let coinbase: string;
let addressWithoutFunds: string;
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
before(async () => {
web3 = web3Factory.create();
- zeroEx = new ZeroEx(web3.currentProvider);
+ zeroEx = new ZeroEx(web3.currentProvider, config);
userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync();
tokenUtils = new TokenUtils(tokens);
@@ -80,7 +86,7 @@ describe('TokenWrapper', () => {
const toAddress = coinbase;
return expect(zeroEx.token.transferAsync(
nonExistentTokenAddress, fromAddress, toAddress, transferAmount,
- )).to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
+ )).to.be.rejectedWith(ZeroExError.TokenContractDoesNotExist);
});
});
describe('#transferFromAsync', () => {
@@ -153,7 +159,7 @@ describe('TokenWrapper', () => {
const nonExistentTokenAddress = '0x9dd402f14d67e001d8efbe6583e51bf9706aa065';
return expect(zeroEx.token.transferFromAsync(
nonExistentTokenAddress, fromAddress, toAddress, senderAddress, new BigNumber(42),
- )).to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
+ )).to.be.rejectedWith(ZeroExError.TokenContractDoesNotExist);
});
});
describe('#getBalanceAsync', () => {
@@ -169,7 +175,7 @@ describe('TokenWrapper', () => {
const nonExistentTokenAddress = '0x9dd402f14d67e001d8efbe6583e51bf9706aa065';
const ownerAddress = coinbase;
return expect(zeroEx.token.getBalanceAsync(nonExistentTokenAddress, ownerAddress))
- .to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
+ .to.be.rejectedWith(ZeroExError.TokenContractDoesNotExist);
});
it('should return a balance of 0 for a non-existent owner address', async () => {
const token = tokens[0];
@@ -184,7 +190,7 @@ describe('TokenWrapper', () => {
before(async () => {
const hasAddresses = false;
const web3WithoutAccounts = web3Factory.create(hasAddresses);
- zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider);
+ zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider, config);
});
it('should return balance even when called with Web3 provider instance without addresses', async () => {
const token = tokens[0];
@@ -281,7 +287,7 @@ describe('TokenWrapper', () => {
before(async () => {
const hasAddresses = false;
const web3WithoutAccounts = web3Factory.create(hasAddresses);
- zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider);
+ zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider, config);
});
it('should get the proxy allowance', async () => {
const token = tokens[0];
@@ -404,7 +410,7 @@ describe('TokenWrapper', () => {
done();
};
const newProvider = web3Factory.getRpcProvider();
- await zeroEx.setProviderAsync(newProvider);
+ zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
zeroEx.token.subscribe(
tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackToBeCalled,
);
@@ -432,10 +438,10 @@ describe('TokenWrapper', () => {
toBlock: BlockParamLiteral.Latest,
};
let txHash: string;
- before(async () => {
+ before(() => {
const token = tokens[0];
tokenAddress = token.address;
- tokenTransferProxyAddress = await zeroEx.proxy.getContractAddressAsync();
+ tokenTransferProxyAddress = zeroEx.proxy.getContractAddress();
});
it('should get logs with decoded args emitted by Approval', async () => {
txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(tokenAddress, coinbase);
diff --git a/packages/0x.js/test/utils/chai_setup.ts b/packages/0x.js/test/utils/chai_setup.ts
index c18988106..078edd309 100644
--- a/packages/0x.js/test/utils/chai_setup.ts
+++ b/packages/0x.js/test/utils/chai_setup.ts
@@ -1,7 +1,7 @@
import * as chai from 'chai';
-import * as dirtyChai from 'dirty-chai';
-import ChaiBigNumber = require('chai-bignumber');
import chaiAsPromised = require('chai-as-promised');
+import ChaiBigNumber = require('chai-bignumber');
+import * as dirtyChai from 'dirty-chai';
export const chaiSetup = {
configure() {
diff --git a/packages/0x.js/test/utils/constants.ts b/packages/0x.js/test/utils/constants.ts
index 5992c226e..212abf4d6 100644
--- a/packages/0x.js/test/utils/constants.ts
+++ b/packages/0x.js/test/utils/constants.ts
@@ -2,6 +2,8 @@ export const constants = {
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
RPC_HOST: 'localhost',
RPC_PORT: 8545,
+ ROPSTEN_NETWORK_ID: 3,
+ KOVAN_NETWORK_ID: 42,
TESTRPC_NETWORK_ID: 50,
KOVAN_RPC_URL: 'https://kovan.infura.io',
ROPSTEN_RPC_URL: 'https://ropsten.infura.io',
diff --git a/packages/0x.js/test/utils/fill_scenarios.ts b/packages/0x.js/test/utils/fill_scenarios.ts
index a0632b12c..090493935 100644
--- a/packages/0x.js/test/utils/fill_scenarios.ts
+++ b/packages/0x.js/test/utils/fill_scenarios.ts
@@ -1,6 +1,8 @@
import BigNumber from 'bignumber.js';
-import {ZeroEx, Token, SignedOrder} from '../../src';
+
+import {SignedOrder, Token, ZeroEx} from '../../src';
import {orderFactory} from '../utils/order_factory';
+
import {constants} from './constants';
export class FillScenarios {
diff --git a/packages/0x.js/test/utils/order_factory.ts b/packages/0x.js/test/utils/order_factory.ts
index 6086e09f7..41d93e340 100644
--- a/packages/0x.js/test/utils/order_factory.ts
+++ b/packages/0x.js/test/utils/order_factory.ts
@@ -1,6 +1,7 @@
-import * as _ from 'lodash';
import BigNumber from 'bignumber.js';
-import {ZeroEx, SignedOrder} from '../../src';
+import * as _ from 'lodash';
+
+import {SignedOrder, ZeroEx} from '../../src';
export const orderFactory = {
async createSignedOrderAsync(
@@ -15,11 +16,11 @@ export const orderFactory = {
takerTokenAddress: string,
exchangeContractAddress: string,
feeRecipient: string,
- expirationUnixTimestampSec?: BigNumber): Promise<SignedOrder> {
+ expirationUnixTimestampSecIfExists?: BigNumber): Promise<SignedOrder> {
const defaultExpirationUnixTimestampSec = new BigNumber(2524604400); // Close to infinite
- expirationUnixTimestampSec = _.isUndefined(expirationUnixTimestampSec) ?
+ const expirationUnixTimestampSec = _.isUndefined(expirationUnixTimestampSecIfExists) ?
defaultExpirationUnixTimestampSec :
- expirationUnixTimestampSec;
+ expirationUnixTimestampSecIfExists;
const order = {
maker,
taker,
diff --git a/packages/0x.js/test/utils/report_callback_errors.ts b/packages/0x.js/test/utils/report_callback_errors.ts
index 4f9517704..8a8f4d966 100644
--- a/packages/0x.js/test/utils/report_callback_errors.ts
+++ b/packages/0x.js/test/utils/report_callback_errors.ts
@@ -1,10 +1,10 @@
import { DoneCallback } from '../../src/types';
export const reportCallbackErrors = (done: DoneCallback) => {
- return (fAsync: (...args: any[]) => void|Promise<void>) => {
+ return (f: (...args: any[]) => void) => {
const wrapped = async (...args: any[]) => {
try {
- await fAsync(...args);
+ f(...args);
} catch (err) {
done(err);
}
diff --git a/packages/0x.js/test/utils/rpc.ts b/packages/0x.js/test/utils/rpc.ts
index 299e72e79..309a96d5e 100644
--- a/packages/0x.js/test/utils/rpc.ts
+++ b/packages/0x.js/test/utils/rpc.ts
@@ -1,5 +1,6 @@
import * as ethUtil from 'ethereumjs-util';
import * as request from 'request-promise-native';
+
import {constants} from './constants';
export class RPC {
diff --git a/packages/0x.js/test/utils/token_utils.ts b/packages/0x.js/test/utils/token_utils.ts
index 51cb9411c..9c20f52a1 100644
--- a/packages/0x.js/test/utils/token_utils.ts
+++ b/packages/0x.js/test/utils/token_utils.ts
@@ -1,5 +1,6 @@
import * as _ from 'lodash';
-import {Token, InternalZeroExError} from '../../src/types';
+
+import {InternalZeroExError, Token} from '../../src/types';
const PROTOCOL_TOKEN_SYMBOL = 'ZRX';
diff --git a/packages/0x.js/test/utils/web3_factory.ts b/packages/0x.js/test/utils/web3_factory.ts
index b20070c74..b4bf1acd3 100644
--- a/packages/0x.js/test/utils/web3_factory.ts
+++ b/packages/0x.js/test/utils/web3_factory.ts
@@ -3,12 +3,14 @@
// we are not running in a browser env.
// Filed issue: https://github.com/ethereum/web3.js/issues/844
(global as any).XMLHttpRequest = undefined;
+import * as Web3 from 'web3';
import ProviderEngine = require('web3-provider-engine');
import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
-import * as Web3 from 'web3';
-import {constants} from './constants';
+
import {EmptyWalletSubProvider} from '../../src/subproviders/empty_wallet_subprovider';
+import {constants} from './constants';
+
export const web3Factory = {
create(hasAddresses: boolean = true): Web3 {
const provider = this.getRpcProvider(hasAddresses);
diff --git a/packages/0x.js/test/web3_wrapper_test.ts b/packages/0x.js/test/web3_wrapper_test.ts
deleted file mode 100644
index d1c2e8e89..000000000
--- a/packages/0x.js/test/web3_wrapper_test.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import * as chai from 'chai';
-import {web3Factory} from './utils/web3_factory';
-import {ZeroEx} from '../src/';
-import {Web3Wrapper} from '../src/web3_wrapper';
-import {constants} from './utils/constants';
-
-chai.config.includeStack = true;
-const expect = chai.expect;
-
-describe('Web3Wrapper', () => {
- const web3Provider = web3Factory.create().currentProvider;
- describe('#getNetworkIdIfExistsAsync', () => {
- it('caches network id requests', async () => {
- const web3Wrapper = (new ZeroEx(web3Provider) as any)._web3Wrapper as Web3Wrapper;
- expect((web3Wrapper as any).networkIdIfExists).to.be.undefined();
- const networkIdIfExists = await web3Wrapper.getNetworkIdIfExistsAsync();
- expect((web3Wrapper as any).networkIdIfExists).to.be.equal(constants.TESTRPC_NETWORK_ID);
- });
- it('invalidates network id cache on setProvider call', async () => {
- const web3Wrapper = (new ZeroEx(web3Provider) as any)._web3Wrapper as Web3Wrapper;
- expect((web3Wrapper as any).networkIdIfExists).to.be.undefined();
- const networkIdIfExists = await web3Wrapper.getNetworkIdIfExistsAsync();
- expect((web3Wrapper as any).networkIdIfExists).to.be.equal(constants.TESTRPC_NETWORK_ID);
- const newProvider = web3Factory.create().currentProvider;
- web3Wrapper.setProvider(newProvider);
- expect((web3Wrapper as any).networkIdIfExists).to.be.undefined();
- });
- });
-});