aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/test/subscription_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js/test/subscription_test.ts')
-rw-r--r--packages/0x.js/test/subscription_test.ts58
1 files changed, 41 insertions, 17 deletions
diff --git a/packages/0x.js/test/subscription_test.ts b/packages/0x.js/test/subscription_test.ts
index f69ae0b13..7a818af37 100644
--- a/packages/0x.js/test/subscription_test.ts
+++ b/packages/0x.js/test/subscription_test.ts
@@ -1,23 +1,26 @@
-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 {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 +34,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 +68,40 @@ 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 errMsg = 'Error fetching block';
const callback = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
- expect(err).to.not.be.null();
+ expect(err).to.be.equal(errMsg);
expect(logEvent).to.be.undefined();
done();
};
stubs = [
Sinon.stub((zeroEx as any)._web3Wrapper, 'getBlockAsync')
- .throws('JSON RPC error'),
+ .throws(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 = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ expect(err).to.be.equal(errMsg);
+ expect(logEvent).to.be.undefined();
+ done();
+ };
+ stubs = [
+ Sinon.stub((zeroEx as any)._web3Wrapper, 'getLogsAsync')
+ .throws(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;
@@ -90,6 +114,6 @@ describe('SubscriptionTest', () => {
zeroEx.token.unsubscribeAll();
done();
})().catch(done);
- });
+ });
});
});