From cbf35de4c11d5f2b538d4e8f1b98ae3d76f137c9 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 15:43:49 -0600 Subject: Fix CI tests --- packages/0x.js/test/0x.js_test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index d56acc38b..6e7b53b6f 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -16,7 +16,10 @@ const expect = chai.expect; describe('ZeroEx library', () => { const web3 = web3Factory.create(); - const zeroEx = new ZeroEx(web3.currentProvider); + const networkId = 50; + const zeroEx = new ZeroEx(web3.currentProvider, { + networkId, + }); describe('#setProvider', () => { it('overrides provider in nested web3s and invalidates contractInstances', async () => { // Instantiate the contract instances with the current provider @@ -234,6 +237,7 @@ describe('ZeroEx library', () => { it('allows to specify exchange contract address', async () => { const config = { exchangeContractAddress: ZeroEx.NULL_ADDRESS, + networkId, }; const zeroExWithWrongExchangeAddress = new ZeroEx(web3.currentProvider, config); return expect(zeroExWithWrongExchangeAddress.exchange.getContractAddressAsync()) @@ -242,6 +246,7 @@ describe('ZeroEx library', () => { it('allows to specify ether token contract address', async () => { const config = { etherTokenContractAddress: ZeroEx.NULL_ADDRESS, + networkId, }; const zeroExWithWrongEtherTokenAddress = new ZeroEx(web3.currentProvider, config); return expect(zeroExWithWrongEtherTokenAddress.etherToken.getContractAddressAsync()) @@ -250,6 +255,7 @@ describe('ZeroEx library', () => { it('allows to specify token registry token contract address', async () => { const config = { tokenRegistryContractAddress: ZeroEx.NULL_ADDRESS, + networkId, }; const zeroExWithWrongTokenRegistryAddress = new ZeroEx(web3.currentProvider, config); return expect(zeroExWithWrongTokenRegistryAddress.tokenRegistry.getContractAddressAsync()) -- cgit v1.2.3 From 311d42626a8eb6c07e4746172b8d868920e37e6c Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 15:58:41 -0600 Subject: Adjust the tests --- packages/0x.js/test/0x.js_test.ts | 26 +++++++++++----------- packages/0x.js/test/artifacts_test.ts | 7 ++++-- packages/0x.js/test/assert_test.ts | 6 ++++- packages/0x.js/test/ether_token_wrapper_test.ts | 2 ++ packages/0x.js/test/event_watcher_test.ts | 1 + .../0x.js/test/exchange_transfer_simulator_test.ts | 6 ++++- packages/0x.js/test/exchange_wrapper_test.ts | 6 ++++- packages/0x.js/test/order_state_watcher_test.ts | 7 ++++-- packages/0x.js/test/order_validation_test.ts | 6 ++++- packages/0x.js/test/subscription_test.ts | 6 ++++- packages/0x.js/test/token_registry_wrapper_test.ts | 6 ++++- .../test/token_transfer_proxy_wrapper_test.ts | 6 ++++- packages/0x.js/test/token_wrapper_test.ts | 10 ++++++--- packages/0x.js/test/web3_wrapper_test.ts | 7 ++++-- 14 files changed, 73 insertions(+), 29 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index 6e7b53b6f..94387e740 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -16,10 +16,10 @@ const expect = chai.expect; describe('ZeroEx library', () => { const web3 = web3Factory.create(); - const networkId = 50; - const zeroEx = new ZeroEx(web3.currentProvider, { - networkId, - }); + 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 @@ -235,29 +235,29 @@ describe('ZeroEx library', () => { }); describe('#config', () => { it('allows to specify exchange contract address', async () => { - const config = { + const zeroExConfig = { exchangeContractAddress: ZeroEx.NULL_ADDRESS, - networkId, + networkId: constants.TESTRPC_NETWORK_ID, }; - const zeroExWithWrongExchangeAddress = new ZeroEx(web3.currentProvider, config); + const zeroExWithWrongExchangeAddress = new ZeroEx(web3.currentProvider, zeroExConfig); return expect(zeroExWithWrongExchangeAddress.exchange.getContractAddressAsync()) .to.be.rejectedWith(ZeroExError.ContractDoesNotExist); }); it('allows to specify ether token contract address', async () => { - const config = { + const zeroExConfig = { etherTokenContractAddress: ZeroEx.NULL_ADDRESS, - networkId, + networkId: constants.TESTRPC_NETWORK_ID, }; - const zeroExWithWrongEtherTokenAddress = new ZeroEx(web3.currentProvider, config); + const zeroExWithWrongEtherTokenAddress = new ZeroEx(web3.currentProvider, zeroExConfig); return expect(zeroExWithWrongEtherTokenAddress.etherToken.getContractAddressAsync()) .to.be.rejectedWith(ZeroExError.ContractDoesNotExist); }); it('allows to specify token registry token contract address', async () => { - const config = { + const zeroExConfig = { tokenRegistryContractAddress: ZeroEx.NULL_ADDRESS, - networkId, + networkId: constants.TESTRPC_NETWORK_ID, }; - const zeroExWithWrongTokenRegistryAddress = new ZeroEx(web3.currentProvider, config); + const zeroExWithWrongTokenRegistryAddress = new ZeroEx(web3.currentProvider, zeroExConfig); return expect(zeroExWithWrongTokenRegistryAddress.tokenRegistry.getContractAddressAsync()) .to.be.rejectedWith(ZeroExError.ContractDoesNotExist); }); diff --git a/packages/0x.js/test/artifacts_test.ts b/packages/0x.js/test/artifacts_test.ts index b2866a1d6..65feb306e 100644 --- a/packages/0x.js/test/artifacts_test.ts +++ b/packages/0x.js/test/artifacts_test.ts @@ -12,13 +12,16 @@ const expect = chai.expect; const TIMEOUT = 10000; describe('Artifacts', () => { + const config = { + networkId: constants.TESTRPC_NETWORK_ID, + }; describe('contracts are deployed on kovan', () => { const kovanRpcUrl = constants.KOVAN_RPC_URL; const packageJSONContent = fs.readFileSync('package.json', 'utf-8'); const packageJSON = JSON.parse(packageJSONContent); const mnemonic = packageJSON.config.mnemonic; const web3Provider = new HDWalletProvider(mnemonic, kovanRpcUrl); - const zeroEx = new ZeroEx(web3Provider); + const zeroEx = new ZeroEx(web3Provider, config); it('token registry contract is deployed', async () => { await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync(); }).timeout(TIMEOUT); @@ -35,7 +38,7 @@ describe('Artifacts', () => { const packageJSON = JSON.parse(packageJSONContent); const mnemonic = packageJSON.config.mnemonic; const web3Provider = new HDWalletProvider(mnemonic, ropstenRpcUrl); - const zeroEx = new ZeroEx(web3Provider); + const zeroEx = new ZeroEx(web3Provider, config); it('token registry contract is deployed', async () => { await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync(); }).timeout(TIMEOUT); diff --git a/packages/0x.js/test/assert_test.ts b/packages/0x.js/test/assert_test.ts index bfca95d9c..628adceeb 100644 --- a/packages/0x.js/test/assert_test.ts +++ b/packages/0x.js/test/assert_test.ts @@ -2,13 +2,17 @@ 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..d2408938c 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -4,6 +4,7 @@ import {chaiSetup} from './utils/chai_setup'; import * as Web3 from 'web3'; import BigNumber from 'bignumber.js'; import {web3Factory} from './utils/web3_factory'; +import {constants} from './utils/constants'; import {ZeroEx, ZeroExError} from '../src'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; @@ -28,6 +29,7 @@ describe('EtherTokenWrapper', () => { const gasPrice = new BigNumber(1); const zeroExConfig = { gasPrice, + networkId: constants.TESTRPC_NETWORK_ID, }; before(async () => { web3 = web3Factory.create(); diff --git a/packages/0x.js/test/event_watcher_test.ts b/packages/0x.js/test/event_watcher_test.ts index b4164fe63..0b0d6d885 100644 --- a/packages/0x.js/test/event_watcher_test.ts +++ b/packages/0x.js/test/event_watcher_test.ts @@ -5,6 +5,7 @@ import * as Sinon from 'sinon'; import * as Web3 from 'web3'; import BigNumber from 'bignumber.js'; import {chaiSetup} from './utils/chai_setup'; +import {constants} from './utils/constants'; import {web3Factory} from './utils/web3_factory'; import {Web3Wrapper} from '../src/web3_wrapper'; import {EventWatcher} from '../src/order_watcher/event_watcher'; diff --git a/packages/0x.js/test/exchange_transfer_simulator_test.ts b/packages/0x.js/test/exchange_transfer_simulator_test.ts index 99cb7fb4f..ad15f55fd 100644 --- a/packages/0x.js/test/exchange_transfer_simulator_test.ts +++ b/packages/0x.js/test/exchange_transfer_simulator_test.ts @@ -2,6 +2,7 @@ import * as chai from 'chai'; import BigNumber from 'bignumber.js'; import {chaiSetup} from './utils/chai_setup'; import {web3Factory} from './utils/web3_factory'; +import {constants} from './utils/constants'; import {ZeroEx, ExchangeContractErrs, Token} from '../src'; import {TradeSide, TransferType} from '../src/types'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; @@ -13,7 +14,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 4ea17ec26..773829b4e 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -22,6 +22,7 @@ import { import {DoneCallback, BlockParamLiteral} from '../src/types'; import {FillScenarios} from './utils/fill_scenarios'; import {TokenUtils} from './utils/token_utils'; +import {constants} from './utils/constants'; chaiSetup.configure(); const expect = chai.expect; @@ -38,9 +39,12 @@ 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); + zeroEx = new ZeroEx(web3.currentProvider, config); exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync(); diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts index 834099ef6..887fc8605 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -20,12 +20,12 @@ import { OrderStateInvalid, ExchangeContractErrs, } from '../src'; +import {constants} from './utils/constants'; import {TokenUtils} from './utils/token_utils'; import {FillScenarios} from './utils/fill_scenarios'; import {DoneCallback} from '../src/types'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; import {reportCallbackErrors} from './utils/report_callback_errors'; -import {constants as constants} from './utils/constants'; const TIMEOUT_MS = 150; @@ -48,11 +48,14 @@ 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); + zeroEx = new ZeroEx(web3.currentProvider, config); exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync(); [, maker, taker] = userAddresses; diff --git a/packages/0x.js/test/order_validation_test.ts b/packages/0x.js/test/order_validation_test.ts index 4f18742d3..7345b1094 100644 --- a/packages/0x.js/test/order_validation_test.ts +++ b/packages/0x.js/test/order_validation_test.ts @@ -7,6 +7,7 @@ import {web3Factory} from './utils/web3_factory'; import {ZeroEx, SignedOrder, Token, ExchangeContractErrs, ZeroExError} from '../src'; import {TradeSide, TransferType} from '../src/types'; import {TokenUtils} from './utils/token_utils'; +import {constants} from './utils/constants'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; import {FillScenarios} from './utils/fill_scenarios'; import {OrderValidationUtils} from '../src/utils/order_validation_utils'; @@ -34,9 +35,12 @@ 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); + zeroEx = new ZeroEx(web3.currentProvider, config); exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync(); [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; diff --git a/packages/0x.js/test/subscription_test.ts b/packages/0x.js/test/subscription_test.ts index f69ae0b13..9a436c1f2 100644 --- a/packages/0x.js/test/subscription_test.ts +++ b/packages/0x.js/test/subscription_test.ts @@ -7,6 +7,7 @@ import * as Web3 from 'web3'; import BigNumber from 'bignumber.js'; import promisify = require('es6-promisify'); import {web3Factory} from './utils/web3_factory'; +import {constants} from './utils/constants'; import { ZeroEx, ZeroExError, @@ -31,9 +32,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); diff --git a/packages/0x.js/test/token_registry_wrapper_test.ts b/packages/0x.js/test/token_registry_wrapper_test.ts index d3497451b..fec5a5909 100644 --- a/packages/0x.js/test/token_registry_wrapper_test.ts +++ b/packages/0x.js/test/token_registry_wrapper_test.ts @@ -2,6 +2,7 @@ import * as _ from 'lodash'; import 'mocha'; import * as chai from 'chai'; import {SchemaValidator, schemas} from '@0xproject/json-schemas'; +import {constants} from './utils/constants'; import {chaiSetup} from './utils/chai_setup'; import {web3Factory} from './utils/web3_factory'; import {ZeroEx, Token} from '../src'; @@ -24,9 +25,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..3a6fc5403 100644 --- a/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts +++ b/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts @@ -2,6 +2,7 @@ import * as chai from 'chai'; import {chaiSetup} from './utils/chai_setup'; import {web3Factory} from './utils/web3_factory'; import {ZeroEx} from '../src'; +import {constants} from './utils/constants'; import {TokenTransferProxyWrapper} from '../src/contract_wrappers/token_transfer_proxy_wrapper'; chaiSetup.configure(); @@ -9,9 +10,12 @@ 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 882913793..170dae6a6 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -19,6 +19,7 @@ import { LogEvent, DecodedLogEvent, } from '../src'; +import {constants} from './utils/constants'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; import {TokenUtils} from './utils/token_utils'; import {DoneCallback, BlockParamLiteral} from '../src/types'; @@ -35,9 +36,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); @@ -184,7 +188,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 +285,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]; diff --git a/packages/0x.js/test/web3_wrapper_test.ts b/packages/0x.js/test/web3_wrapper_test.ts index d1c2e8e89..ccbf336ab 100644 --- a/packages/0x.js/test/web3_wrapper_test.ts +++ b/packages/0x.js/test/web3_wrapper_test.ts @@ -9,15 +9,18 @@ const expect = chai.expect; describe('Web3Wrapper', () => { const web3Provider = web3Factory.create().currentProvider; + const config = { + networkId: constants.TESTRPC_NETWORK_ID, + }; describe('#getNetworkIdIfExistsAsync', () => { it('caches network id requests', async () => { - const web3Wrapper = (new ZeroEx(web3Provider) as any)._web3Wrapper as Web3Wrapper; + const web3Wrapper = (new ZeroEx(web3Provider, config) 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; + const web3Wrapper = (new ZeroEx(web3Provider, config) 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); -- cgit v1.2.3 From 63dc606a9c08dad5e0aae09b86178fcd3e78e867 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 21 Nov 2017 16:50:14 -0600 Subject: Make getZRXTokenAddress non async --- packages/0x.js/test/artifacts_test.ts | 9 +++++--- packages/0x.js/test/event_watcher_test.ts | 2 +- packages/0x.js/test/exchange_wrapper_test.ts | 4 ++-- packages/0x.js/test/utils/constants.ts | 2 ++ packages/0x.js/test/web3_wrapper_test.ts | 32 ---------------------------- 5 files changed, 11 insertions(+), 38 deletions(-) delete mode 100644 packages/0x.js/test/web3_wrapper_test.ts (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/artifacts_test.ts b/packages/0x.js/test/artifacts_test.ts index 65feb306e..1c36fb358 100644 --- a/packages/0x.js/test/artifacts_test.ts +++ b/packages/0x.js/test/artifacts_test.ts @@ -12,15 +12,15 @@ const expect = chai.expect; const TIMEOUT = 10000; describe('Artifacts', () => { - const config = { - networkId: constants.TESTRPC_NETWORK_ID, - }; describe('contracts are deployed on kovan', () => { const kovanRpcUrl = constants.KOVAN_RPC_URL; const packageJSONContent = fs.readFileSync('package.json', 'utf-8'); const packageJSON = JSON.parse(packageJSONContent); const mnemonic = packageJSON.config.mnemonic; const web3Provider = new HDWalletProvider(mnemonic, kovanRpcUrl); + 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(); @@ -38,6 +38,9 @@ describe('Artifacts', () => { const packageJSON = JSON.parse(packageJSONContent); const mnemonic = packageJSON.config.mnemonic; const web3Provider = new HDWalletProvider(mnemonic, ropstenRpcUrl); + 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(); diff --git a/packages/0x.js/test/event_watcher_test.ts b/packages/0x.js/test/event_watcher_test.ts index 0b0d6d885..fc52d522a 100644 --- a/packages/0x.js/test/event_watcher_test.ts +++ b/packages/0x.js/test/event_watcher_test.ts @@ -58,7 +58,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_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts index 773829b4e..5d1ff8f50 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -744,8 +744,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); }); 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/web3_wrapper_test.ts b/packages/0x.js/test/web3_wrapper_test.ts deleted file mode 100644 index ccbf336ab..000000000 --- a/packages/0x.js/test/web3_wrapper_test.ts +++ /dev/null @@ -1,32 +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; - const config = { - networkId: constants.TESTRPC_NETWORK_ID, - }; - describe('#getNetworkIdIfExistsAsync', () => { - it('caches network id requests', async () => { - const web3Wrapper = (new ZeroEx(web3Provider, config) 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, config) 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(); - }); - }); -}); -- cgit v1.2.3 From 4fe28ec53c4e84544c3c21853dff57c4c6a4e45d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 11:53:04 -0600 Subject: Make zeroEx.exchange.getContractAddress non-async --- packages/0x.js/test/0x.js_test.ts | 3 +-- packages/0x.js/test/artifacts_test.ts | 4 ++-- packages/0x.js/test/exchange_wrapper_test.ts | 2 +- packages/0x.js/test/order_state_watcher_test.ts | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index 94387e740..95a8b027d 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -240,8 +240,7 @@ describe('ZeroEx library', () => { networkId: constants.TESTRPC_NETWORK_ID, }; const zeroExWithWrongExchangeAddress = new ZeroEx(web3.currentProvider, zeroExConfig); - return expect(zeroExWithWrongExchangeAddress.exchange.getContractAddressAsync()) - .to.be.rejectedWith(ZeroExError.ContractDoesNotExist); + expect(zeroExWithWrongExchangeAddress.exchange.getContractAddress()).to.be.equal(ZeroEx.NULL_ADDRESS); }); it('allows to specify ether token contract address', async () => { const zeroExConfig = { diff --git a/packages/0x.js/test/artifacts_test.ts b/packages/0x.js/test/artifacts_test.ts index 1c36fb358..265a71715 100644 --- a/packages/0x.js/test/artifacts_test.ts +++ b/packages/0x.js/test/artifacts_test.ts @@ -29,7 +29,7 @@ describe('Artifacts', () => { await (zeroEx.token as any)._getTokenTransferProxyAddressAsync(); }).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', () => { @@ -49,7 +49,7 @@ describe('Artifacts', () => { await (zeroEx.token as any)._getTokenTransferProxyAddressAsync(); }).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/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts index 5d1ff8f50..c1f9316c4 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -45,7 +45,7 @@ describe('ExchangeWrapper', () => { before(async () => { web3 = web3Factory.create(); zeroEx = new ZeroEx(web3.currentProvider, config); - exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync(); + 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 887fc8605..fd94a3df6 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -56,7 +56,7 @@ describe('OrderStateWatcher', () => { before(async () => { web3 = web3Factory.create(); zeroEx = new ZeroEx(web3.currentProvider, config); - exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync(); + exchangeContractAddress = zeroEx.exchange.getContractAddress(); userAddresses = await zeroEx.getAvailableAddressesAsync(); [, maker, taker] = userAddresses; tokens = await zeroEx.tokenRegistry.getTokensAsync(); -- cgit v1.2.3 From 66aaceea915b6412c8ff8bcb5001363da8aaca39 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 12:15:31 -0600 Subject: Cleanup order watcher from redundant asyncs --- packages/0x.js/test/expiration_watcher_test.ts | 8 +++++-- packages/0x.js/test/order_state_watcher_test.ts | 32 ++++++++++++------------- packages/0x.js/test/order_validation_test.ts | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts index 0f2470070..5b8848eba 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -7,6 +7,7 @@ import BigNumber from 'bignumber.js'; import {chaiSetup} from './utils/chai_setup'; import {web3Factory} from './utils/web3_factory'; import {utils} from '../src/utils/utils'; +import {constants} from '../src/utils/constants'; import {Web3Wrapper} from '../src/web3_wrapper'; import {TokenUtils} from './utils/token_utils'; import {ExpirationWatcher} from '../src/order_watcher/expiration_watcher'; @@ -41,8 +42,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 = await 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 fd94a3df6..2c7c2a971 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -78,13 +78,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, }); @@ -97,7 +97,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 () => { @@ -114,7 +114,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 () => { @@ -122,7 +122,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; @@ -140,7 +140,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'); }); @@ -161,7 +161,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; @@ -181,7 +181,7 @@ describe('OrderStateWatcher', () => { makerToken.address, takerToken.address, maker, taker, fillableAmount, ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); + zeroEx.orderStateWatcher.addOrder(signedOrder); let eventCount = 0; const callback = reportCallbackErrors(done)((orderState: OrderState) => { @@ -213,7 +213,7 @@ describe('OrderStateWatcher', () => { const fillAmountInBaseUnits = new BigNumber(2); const orderHash = ZeroEx.getOrderHashHex(signedOrder); - await zeroEx.orderStateWatcher.addOrderAsync(signedOrder); + zeroEx.orderStateWatcher.addOrder(signedOrder); let eventCount = 0; const callback = reportCallbackErrors(done)((orderState: OrderState) => { @@ -248,7 +248,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(); }); @@ -269,7 +269,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); let eventCount = 0; const callback = reportCallbackErrors(done)((orderState: OrderState) => { eventCount++; @@ -301,7 +301,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; @@ -326,7 +326,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(); @@ -432,7 +432,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(); @@ -454,7 +454,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(); @@ -480,7 +480,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(); diff --git a/packages/0x.js/test/order_validation_test.ts b/packages/0x.js/test/order_validation_test.ts index 7345b1094..811cd48c4 100644 --- a/packages/0x.js/test/order_validation_test.ts +++ b/packages/0x.js/test/order_validation_test.ts @@ -41,7 +41,7 @@ describe('OrderValidation', () => { before(async () => { web3 = web3Factory.create(); zeroEx = new ZeroEx(web3.currentProvider, config); - exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync(); + exchangeContractAddress = zeroEx.exchange.getContractAddress(); userAddresses = await zeroEx.getAvailableAddressesAsync(); [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; tokens = await zeroEx.tokenRegistry.getTokensAsync(); -- cgit v1.2.3 From 8935146240838fc84c9b73308908119f9567e6b3 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 13:13:34 -0600 Subject: Make exchange subscriptions non-async --- packages/0x.js/test/exchange_wrapper_test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts index c1f9316c4..8b89baa67 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -617,7 +617,7 @@ describe('ExchangeWrapper', () => { }); }); }); - describe('#subscribeAsync', () => { + describe('#subscribe', () => { const indexFilterValues = {}; const shouldThrowOnInsufficientBalanceOrAllowance = true; let makerTokenAddress: string; @@ -656,7 +656,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( @@ -672,7 +672,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); @@ -684,7 +684,7 @@ describe('ExchangeWrapper', () => { const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent) => { done(new Error('Expected this subscription to have been cancelled')); }; - await zeroEx.exchange.subscribeAsync( + zeroEx.exchange.subscribe( ExchangeEvents.LogFill, indexFilterValues, callbackNeverToBeCalled, ); @@ -695,7 +695,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( @@ -709,7 +709,7 @@ describe('ExchangeWrapper', () => { const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent) => { 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); -- cgit v1.2.3 From a38ef3655b47228c2cc949d917636a19d7e0dddc Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 13:37:07 -0600 Subject: Remove even more asyncs --- packages/0x.js/test/0x.js_test.ts | 9 ++++----- packages/0x.js/test/ether_token_wrapper_test.ts | 2 +- packages/0x.js/test/token_wrapper_test.ts | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index 95a8b027d..ba7a92fe4 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -223,7 +223,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; @@ -248,8 +248,7 @@ describe('ZeroEx library', () => { networkId: constants.TESTRPC_NETWORK_ID, }; const zeroExWithWrongEtherTokenAddress = new ZeroEx(web3.currentProvider, zeroExConfig); - return expect(zeroExWithWrongEtherTokenAddress.etherToken.getContractAddressAsync()) - .to.be.rejectedWith(ZeroExError.ContractDoesNotExist); + expect(zeroExWithWrongEtherTokenAddress.etherToken.getContractAddress()).to.be.equal(ZeroEx.NULL_ADDRESS); }); it('allows to specify token registry token contract address', async () => { const zeroExConfig = { @@ -257,8 +256,8 @@ describe('ZeroEx library', () => { networkId: constants.TESTRPC_NETWORK_ID, }; const zeroExWithWrongTokenRegistryAddress = new ZeroEx(web3.currentProvider, zeroExConfig); - return expect(zeroExWithWrongTokenRegistryAddress.tokenRegistry.getContractAddressAsync()) - .to.be.rejectedWith(ZeroExError.ContractDoesNotExist); + expect(zeroExWithWrongTokenRegistryAddress.tokenRegistry.getContractAddress()) + .to.be.equal(ZeroEx.NULL_ADDRESS); }); }); }); diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index d2408938c..b86e79054 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -36,7 +36,7 @@ describe('EtherTokenWrapper', () => { 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/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index 170dae6a6..b07fed045 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -436,10 +436,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); -- cgit v1.2.3 From d20926e150beed4785b31451a415bbf545f850be Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 14:00:16 -0600 Subject: Don't reassign the parameter --- packages/0x.js/test/utils/order_factory.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/utils/order_factory.ts b/packages/0x.js/test/utils/order_factory.ts index 6086e09f7..e3161e262 100644 --- a/packages/0x.js/test/utils/order_factory.ts +++ b/packages/0x.js/test/utils/order_factory.ts @@ -15,11 +15,11 @@ export const orderFactory = { takerTokenAddress: string, exchangeContractAddress: string, feeRecipient: string, - expirationUnixTimestampSec?: BigNumber): Promise { + expirationUnixTimestampSecIfExists?: BigNumber): Promise { const defaultExpirationUnixTimestampSec = new BigNumber(2524604400); // Close to infinite - expirationUnixTimestampSec = _.isUndefined(expirationUnixTimestampSec) ? + const expirationUnixTimestampSec = _.isUndefined(expirationUnixTimestampSecIfExists) ? defaultExpirationUnixTimestampSec : - expirationUnixTimestampSec; + expirationUnixTimestampSecIfExists; const order = { maker, taker, -- cgit v1.2.3 From 87d34f9c7f3ccf22e01798c27c4a4d5d4f943816 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 14:07:53 -0600 Subject: Auto-fix linter errors --- packages/0x.js/test/order_state_watcher_test.ts | 34 +++++++++++++------------ packages/0x.js/test/utils/chai_setup.ts | 4 +-- packages/0x.js/test/utils/fill_scenarios.ts | 4 ++- packages/0x.js/test/utils/order_factory.ts | 5 ++-- packages/0x.js/test/utils/rpc.ts | 1 + packages/0x.js/test/utils/token_utils.ts | 3 ++- packages/0x.js/test/utils/web3_factory.ts | 6 +++-- 7 files changed, 33 insertions(+), 24 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts index 2c7c2a971..616d8fda0 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 {constants} from './utils/constants'; -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 {TokenUtils} from './utils/token_utils'; +import {web3Factory} from './utils/web3_factory'; const TIMEOUT_MS = 150; 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/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 e3161e262..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( 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); -- cgit v1.2.3 From db2917b01caa49d74c9ebcae2d36e9c3946b94d8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 15:43:17 -0600 Subject: Enable some new linter rules and fix the issues --- packages/0x.js/test/order_validation_test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/order_validation_test.ts b/packages/0x.js/test/order_validation_test.ts index 811cd48c4..3282ebb3e 100644 --- a/packages/0x.js/test/order_validation_test.ts +++ b/packages/0x.js/test/order_validation_test.ts @@ -114,7 +114,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); @@ -230,7 +230,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); @@ -266,7 +266,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); @@ -301,7 +301,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); @@ -316,7 +316,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); -- cgit v1.2.3 From 010e6f8d7f7403cb91c020fc501fdb4f59861c58 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 16:19:06 -0600 Subject: Fix the imports order --- packages/0x.js/test/0x.js_test.ts | 18 ++++++----- packages/0x.js/test/artifacts_test.ts | 10 +++--- packages/0x.js/test/assert_test.ts | 2 ++ packages/0x.js/test/ether_token_wrapper_test.ts | 12 +++++--- packages/0x.js/test/event_watcher_test.ts | 20 ++++++------ .../0x.js/test/exchange_transfer_simulator_test.ts | 14 +++++---- packages/0x.js/test/exchange_wrapper_test.ts | 36 ++++++++++++---------- packages/0x.js/test/expiration_watcher_test.ts | 22 +++++++------ packages/0x.js/test/order_validation_test.ts | 20 ++++++------ packages/0x.js/test/subscription_test.ts | 26 ++++++++-------- packages/0x.js/test/token_registry_wrapper_test.ts | 12 +++++--- .../test/token_transfer_proxy_wrapper_test.ts | 8 +++-- packages/0x.js/test/token_wrapper_test.ts | 34 ++++++++++---------- 13 files changed, 130 insertions(+), 104 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index ba7a92fe4..cb4753248 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(); @@ -39,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', () => { diff --git a/packages/0x.js/test/artifacts_test.ts b/packages/0x.js/test/artifacts_test.ts index 265a71715..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(); @@ -26,7 +28,7 @@ describe('Artifacts', () => { 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 as any)._getExchangeContractAsync(); @@ -46,7 +48,7 @@ describe('Artifacts', () => { 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 as any)._getExchangeContractAsync(); diff --git a/packages/0x.js/test/assert_test.ts b/packages/0x.js/test/assert_test.ts index 628adceeb..9fa7f780f 100644 --- a/packages/0x.js/test/assert_test.ts +++ b/packages/0x.js/test/assert_test.ts @@ -1,7 +1,9 @@ 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'; diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index b86e79054..5b5e4c656 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -1,12 +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 {constants} from './utils/constants'; + 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; diff --git a/packages/0x.js/test/event_watcher_test.ts b/packages/0x.js/test/event_watcher_test.ts index fc52d522a..f27a7da2c 100644 --- a/packages/0x.js/test/event_watcher_test.ts +++ b/packages/0x.js/test/event_watcher_test.ts @@ -1,20 +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 {constants} from './utils/constants'; -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; diff --git a/packages/0x.js/test/exchange_transfer_simulator_test.ts b/packages/0x.js/test/exchange_transfer_simulator_test.ts index ad15f55fd..8e45b67a5 100644 --- a/packages/0x.js/test/exchange_transfer_simulator_test.ts +++ b/packages/0x.js/test/exchange_transfer_simulator_test.ts @@ -1,13 +1,15 @@ -import * as chai from 'chai'; import BigNumber from 'bignumber.js'; -import {chaiSetup} from './utils/chai_setup'; -import {web3Factory} from './utils/web3_factory'; -import {constants} from './utils/constants'; -import {ZeroEx, ExchangeContractErrs, Token} from '../src'; +import * as chai from 'chai'; + +import {ExchangeContractErrs, Token, ZeroEx} from '../src'; import {TradeSide, TransferType} from '../src/types'; -import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; 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'; + chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(); diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts index 8b89baa67..43dfeb425 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -1,28 +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 {constants} from './utils/constants'; +import {web3Factory} from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; @@ -825,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 5b8848eba..c60b5dc6c 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -1,21 +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 {utils} from '../src/utils/utils'; + +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; @@ -46,7 +48,7 @@ describe('ExpirationWatcher', () => { networkId: constants.TESTRPC_NETWORK_ID, }; zeroEx = new ZeroEx(web3.currentProvider, config); - exchangeContractAddress = await zeroEx.exchange.getContractAddress(); + 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_validation_test.ts b/packages/0x.js/test/order_validation_test.ts index 3282ebb3e..e210c04a8 100644 --- a/packages/0x.js/test/order_validation_test.ts +++ b/packages/0x.js/test/order_validation_test.ts @@ -1,17 +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 * as Web3 from 'web3'; + +import {ExchangeContractErrs, SignedOrder, Token, ZeroEx, ZeroExError} from '../src'; import {TradeSide, TransferType} from '../src/types'; -import {TokenUtils} from './utils/token_utils'; -import {constants} from './utils/constants'; +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; diff --git a/packages/0x.js/test/subscription_test.ts b/packages/0x.js/test/subscription_test.ts index 9a436c1f2..df40ae75a 100644 --- a/packages/0x.js/test/subscription_test.ts +++ b/packages/0x.js/test/subscription_test.ts @@ -1,24 +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 {constants} from './utils/constants'; + 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; diff --git a/packages/0x.js/test/token_registry_wrapper_test.ts b/packages/0x.js/test/token_registry_wrapper_test.ts index fec5a5909..f1f307f3a 100644 --- a/packages/0x.js/test/token_registry_wrapper_test.ts +++ b/packages/0x.js/test/token_registry_wrapper_test.ts @@ -1,12 +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 {constants} from './utils/constants'; + +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; 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 3a6fc5403..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,10 +1,12 @@ import * as chai from 'chai'; -import {chaiSetup} from './utils/chai_setup'; -import {web3Factory} from './utils/web3_factory'; + import {ZeroEx} from '../src'; -import {constants} from './utils/constants'; 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; diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index b07fed045..49af19a25 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -1,28 +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 {constants} from './utils/constants'; +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; -- cgit v1.2.3 From e32c453bc3a1f40fa83686b0c35b0e5bd1aa0a2c Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 16:50:33 -0600 Subject: Remove unused asyncs --- packages/0x.js/test/utils/report_callback_errors.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/0x.js/test') 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) => { + return (f: (...args: any[]) => void) => { const wrapped = async (...args: any[]) => { try { - await fAsync(...args); + f(...args); } catch (err) { done(err); } -- cgit v1.2.3 From 55ddf62df2ec8dfc3d2146f31356df67603fb259 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 23 Nov 2017 13:47:42 -0600 Subject: Fix rebasing issues --- packages/0x.js/test/order_state_watcher_test.ts | 8 ++++---- packages/0x.js/test/remaining_fillable_calculator_test.ts | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts index 616d8fda0..ba37d1ce5 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -358,7 +358,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(); @@ -388,7 +388,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; @@ -413,7 +413,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; @@ -497,4 +497,4 @@ describe('OrderStateWatcher', () => { })().catch(done); }); }); -}); +}); // tslint:disable:max-file-line-count 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; -- cgit v1.2.3 From 062f85e5069d0c2d56cd10bdb8a31a6d0a6c88dc Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 23 Nov 2017 13:56:28 -0600 Subject: Pass networkId on provider update --- packages/0x.js/test/0x.js_test.ts | 2 +- packages/0x.js/test/exchange_wrapper_test.ts | 2 +- packages/0x.js/test/token_wrapper_test.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index cb4753248..6b7a70699 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -33,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(); diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts index 43dfeb425..6fe52a75a 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -691,7 +691,7 @@ describe('ExchangeWrapper', () => { ); const newProvider = web3Factory.getRpcProvider(); - await zeroEx.setProviderAsync(newProvider); + zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); const callback = (err: Error, logEvent: DecodedLogEvent) => { expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogFill); diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index 49af19a25..abd4243c3 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -410,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, ); -- cgit v1.2.3 From 8c54e9a8731ccd831daf5533070302746af575e5 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 23 Nov 2017 14:15:01 -0600 Subject: Add a regression test --- packages/0x.js/test/subscription_test.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/subscription_test.ts b/packages/0x.js/test/subscription_test.ts index df40ae75a..7a818af37 100644 --- a/packages/0x.js/test/subscription_test.ts +++ b/packages/0x.js/test/subscription_test.ts @@ -68,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) => { - 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) => { + 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) => _.noop; @@ -96,6 +114,6 @@ describe('SubscriptionTest', () => { zeroEx.token.unsubscribeAll(); done(); })().catch(done); - }); + }); }); }); -- cgit v1.2.3 From c780d04ceea70bbe706bdd740b4dec01a34de00b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 23 Nov 2017 14:29:49 -0600 Subject: Remove ContractDoesNotExist error and replace it with more specific errors --- packages/0x.js/test/token_wrapper_test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index abd4243c3..d0ca0144a 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -86,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', () => { @@ -159,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', () => { @@ -175,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]; -- cgit v1.2.3 From 32867c9a07fc7c833ff8491ec4feea8c783e7f4d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 27 Nov 2017 16:03:57 -0600 Subject: Fix merge conflicts --- packages/0x.js/test/exchange_transfer_simulator_test.ts | 7 +------ packages/0x.js/test/order_validation_test.ts | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/exchange_transfer_simulator_test.ts b/packages/0x.js/test/exchange_transfer_simulator_test.ts index 82cd54a34..a1d9bdade 100644 --- a/packages/0x.js/test/exchange_transfer_simulator_test.ts +++ b/packages/0x.js/test/exchange_transfer_simulator_test.ts @@ -2,12 +2,7 @@ import BigNumber from 'bignumber.js'; import * as chai from 'chai'; import {ExchangeContractErrs, Token, ZeroEx} from '../src'; -import {TradeSide, TransferType} from '../src/types'; -import {chaiSetup} from './utils/chai_setup'; -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 {BlockParamLiteral, TradeSide, TransferType} from '../src/types'; import {ExchangeTransferSimulator} from '../src/utils/exchange_transfer_simulator'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; diff --git a/packages/0x.js/test/order_validation_test.ts b/packages/0x.js/test/order_validation_test.ts index 3725c85da..d585c1f3c 100644 --- a/packages/0x.js/test/order_validation_test.ts +++ b/packages/0x.js/test/order_validation_test.ts @@ -4,15 +4,10 @@ import * as Sinon from 'sinon'; import * as Web3 from 'web3'; import {ExchangeContractErrs, SignedOrder, Token, ZeroEx, ZeroExError} from '../src'; -import {TradeSide, TransferType} from '../src/types'; +import {BlockParamLiteral, TradeSide, TransferType} from '../src/types'; import {ExchangeTransferSimulator} from '../src/utils/exchange_transfer_simulator'; import {OrderValidationUtils} from '../src/utils/order_validation_utils'; -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 {BlockchainLifecycle} from './utils/blockchain_lifecycle'; import {chaiSetup} from './utils/chai_setup'; import {constants} from './utils/constants'; -- cgit v1.2.3 From f862a2af6d9802c2c75f813025517e0c52cd513c Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 27 Nov 2017 16:32:33 -0600 Subject: Fix tests --- packages/0x.js/test/subscription_test.ts | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'packages/0x.js/test') diff --git a/packages/0x.js/test/subscription_test.ts b/packages/0x.js/test/subscription_test.ts index 7a818af37..e3b15808b 100644 --- a/packages/0x.js/test/subscription_test.ts +++ b/packages/0x.js/test/subscription_test.ts @@ -19,6 +19,7 @@ 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 {web3Factory} from './utils/web3_factory'; @@ -71,14 +72,16 @@ describe('SubscriptionTest', () => { 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) => { - expect(err).to.be.equal(errMsg); - expect(logEvent).to.be.undefined(); - done(); - }; + const callback = reportCallbackErrors(done)( + (err: Error, logEvent: DecodedLogEvent) => { + expect(err.message).to.be.equal(errMsg); + expect(logEvent).to.be.undefined(); + done(); + }, + ); stubs = [ Sinon.stub((zeroEx as any)._web3Wrapper, 'getBlockAsync') - .throws(errMsg), + .throws(new Error(errMsg)), ]; zeroEx.token.subscribe( tokenAddress, TokenEvents.Approval, indexFilterValues, callback); @@ -88,14 +91,16 @@ describe('SubscriptionTest', () => { 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) => { - expect(err).to.be.equal(errMsg); - expect(logEvent).to.be.undefined(); - done(); - }; + const callback = reportCallbackErrors(done)( + (err: Error, logEvent: DecodedLogEvent) => { + expect(err.message).to.be.equal(errMsg); + expect(logEvent).to.be.undefined(); + done(); + }, + ); stubs = [ Sinon.stub((zeroEx as any)._web3Wrapper, 'getLogsAsync') - .throws(errMsg), + .throws(new Error(errMsg)), ]; zeroEx.token.subscribe( tokenAddress, TokenEvents.Approval, indexFilterValues, callback); @@ -109,7 +114,7 @@ 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(); -- cgit v1.2.3