diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-28 07:15:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-28 07:15:18 +0800 |
commit | 54ef916b93ba0939dcb8824149c9a9fb74df4f2e (patch) | |
tree | 6559179e99d077ae8d78350580a082e75d50a7c8 /packages/0x.js/test/subscription_test.ts | |
parent | 4a770dee84ee49e8038da7dd32ce26338176bf36 (diff) | |
parent | f862a2af6d9802c2c75f813025517e0c52cd513c (diff) | |
download | dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.tar dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.tar.gz dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.tar.bz2 dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.tar.lz dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.tar.xz dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.tar.zst dexon-sol-tools-54ef916b93ba0939dcb8824149c9a9fb74df4f2e.zip |
Merge pull request #233 from 0xProject/feature/passNetworkId
Forces the users of 0x.js to pass the network id
Diffstat (limited to 'packages/0x.js/test/subscription_test.ts')
-rw-r--r-- | packages/0x.js/test/subscription_test.ts | 73 |
1 files changed, 51 insertions, 22 deletions
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); - }); + }); }); }); |