From 43e07e7ce3dd61af8048c20aa2355010f0c72c22 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 4 Apr 2018 16:31:57 +0900 Subject: Update 0x.js to run tests against in-process ganache --- packages/0x.js/test/0x.js_test.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'packages/0x.js/test/0x.js_test.ts') diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index 70e85aa52..2ae944a99 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -1,17 +1,31 @@ +import { Deployer } from '@0xproject/deployer'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; import 'mocha'; +import * as path from 'path'; import * as Sinon from 'sinon'; import { ApprovalContractEventArgs, LogWithDecodedArgs, Order, TokenEvents, ZeroEx } from '../src'; +import { runMigrationsAsync } from './migrations/migrate'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { TokenUtils } from './utils/token_utils'; import { web3, web3Wrapper } from './utils/web3_wrapper'; +const artifactsDir = path.resolve('test', 'artifacts'); +const deployerOpts = { + artifactsDir, + web3Provider: web3.currentProvider, + networkId: constants.TESTRPC_NETWORK_ID, + defaults: { + gas: devConstants.GAS_ESTIMATE, + }, +}; +const deployer = new Deployer(deployerOpts); + const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); chaiSetup.configure(); const expect = chai.expect; @@ -19,10 +33,14 @@ const expect = chai.expect; const SHOULD_ADD_PERSONAL_MESSAGE_PREFIX = false; describe('ZeroEx library', () => { - const config = { - networkId: constants.TESTRPC_NETWORK_ID, - }; - const zeroEx = new ZeroEx(web3.currentProvider, config); + let zeroEx: ZeroEx; + before(async () => { + await runMigrationsAsync(deployer); + const config = { + networkId: constants.TESTRPC_NETWORK_ID, + }; + 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 @@ -31,7 +49,7 @@ describe('ZeroEx library', () => { expect((zeroEx.exchange as any)._exchangeContractIfExists).to.not.be.undefined(); expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).to.not.be.undefined(); - const newProvider = web3Factory.getRpcProvider(); + const newProvider = web3.currentProvider; // Add property to newProvider so that we can differentiate it from old provider (newProvider as any).zeroExTestId = 1; zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); -- cgit v1.2.3 From 24454938e51e40ae74809f15bd1f612c69c218ec Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 6 Apr 2018 15:03:14 +0900 Subject: Move away from using web3 directly in 0x.js tests --- packages/0x.js/test/0x.js_test.ts | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'packages/0x.js/test/0x.js_test.ts') diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index 2ae944a99..e6163d568 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -12,19 +12,9 @@ import { ApprovalContractEventArgs, LogWithDecodedArgs, Order, TokenEvents, Zero import { runMigrationsAsync } from './migrations/migrate'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; +import { deployer } from './utils/deployer'; import { TokenUtils } from './utils/token_utils'; -import { web3, web3Wrapper } from './utils/web3_wrapper'; - -const artifactsDir = path.resolve('test', 'artifacts'); -const deployerOpts = { - artifactsDir, - web3Provider: web3.currentProvider, - networkId: constants.TESTRPC_NETWORK_ID, - defaults: { - gas: devConstants.GAS_ESTIMATE, - }, -}; -const deployer = new Deployer(deployerOpts); +import { provider, web3Wrapper } from './utils/web3_wrapper'; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); chaiSetup.configure(); @@ -39,7 +29,7 @@ describe('ZeroEx library', () => { const config = { networkId: constants.TESTRPC_NETWORK_ID, }; - zeroEx = new ZeroEx(web3.currentProvider, config); + zeroEx = new ZeroEx(provider, config); }); describe('#setProvider', () => { it('overrides provider in nested web3s and invalidates contractInstances', async () => { @@ -49,7 +39,7 @@ describe('ZeroEx library', () => { expect((zeroEx.exchange as any)._exchangeContractIfExists).to.not.be.undefined(); expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).to.not.be.undefined(); - const newProvider = web3.currentProvider; + const newProvider = provider; // Add property to newProvider so that we can differentiate it from old provider (newProvider as any).zeroExTestId = 1; zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); @@ -296,7 +286,7 @@ describe('ZeroEx library', () => { exchangeContractAddress: ZeroEx.NULL_ADDRESS, networkId: constants.TESTRPC_NETWORK_ID, }; - const zeroExWithWrongExchangeAddress = new ZeroEx(web3.currentProvider, zeroExConfig); + const zeroExWithWrongExchangeAddress = new ZeroEx(provider, zeroExConfig); expect(zeroExWithWrongExchangeAddress.exchange.getContractAddress()).to.be.equal(ZeroEx.NULL_ADDRESS); }); it('allows to specify token registry token contract address', async () => { @@ -304,7 +294,7 @@ describe('ZeroEx library', () => { tokenRegistryContractAddress: ZeroEx.NULL_ADDRESS, networkId: constants.TESTRPC_NETWORK_ID, }; - const zeroExWithWrongTokenRegistryAddress = new ZeroEx(web3.currentProvider, zeroExConfig); + const zeroExWithWrongTokenRegistryAddress = new ZeroEx(provider, zeroExConfig); expect(zeroExWithWrongTokenRegistryAddress.tokenRegistry.getContractAddress()).to.be.equal( ZeroEx.NULL_ADDRESS, ); -- cgit v1.2.3 From 919b327fc534e3c2dc6330130cee690f0fa39fea Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 9 Apr 2018 17:14:25 +0900 Subject: Move migrations into separate monorepo subpackage and hook it up to 0x.js and contracts --- packages/0x.js/test/0x.js_test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'packages/0x.js/test/0x.js_test.ts') diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index e6163d568..5720f42ce 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -1,5 +1,9 @@ import { Deployer } from '@0xproject/deployer'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; +// HACK: This dependency is optional since it is only available when run from within +// the monorepo. tslint doesn't handle optional dependencies +// tslint:disable-next-line:no-implicit-dependencies +import { runMigrationsAsync } from '@0xproject/migrations'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; @@ -9,7 +13,6 @@ import * as Sinon from 'sinon'; import { ApprovalContractEventArgs, LogWithDecodedArgs, Order, TokenEvents, ZeroEx } from '../src'; -import { runMigrationsAsync } from './migrations/migrate'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { deployer } from './utils/deployer'; -- cgit v1.2.3 From b146acc69e46d2565474bcb4d47bfa760fd26fad Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 11 Apr 2018 21:59:30 +0900 Subject: Simplify the tests --- packages/0x.js/test/0x.js_test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'packages/0x.js/test/0x.js_test.ts') diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index 5720f42ce..de5a6be58 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -42,10 +42,9 @@ describe('ZeroEx library', () => { expect((zeroEx.exchange as any)._exchangeContractIfExists).to.not.be.undefined(); expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).to.not.be.undefined(); - const newProvider = provider; // Add property to newProvider so that we can differentiate it from old provider - (newProvider as any).zeroExTestId = 1; - zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); + (provider as any).zeroExTestId = 1; + zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID); // Check that contractInstances with old provider are removed after provider update expect((zeroEx.exchange as any)._exchangeContractIfExists).to.be.undefined(); -- cgit v1.2.3