diff options
Diffstat (limited to 'packages/0x.js')
28 files changed, 140 insertions, 94 deletions
diff --git a/packages/0x.js/CHANGELOG.json b/packages/0x.js/CHANGELOG.json index 6d5dc0dd2..9b5c52d00 100644 --- a/packages/0x.js/CHANGELOG.json +++ b/packages/0x.js/CHANGELOG.json @@ -6,14 +6,15 @@ "note": "Moved Web3.Provider to `@0xproject/types:Provider`", "pr": 501 } - ] + ], + "timestamp": 1523462196 }, { "version": "0.35.0", "changes": [ { "note": - "Removed `ZeroExError.TransactionMiningTimeout` and moved it to '@0xproject/web3_wrapper' `Web3WrapperErrors.TransactionMiningTimeout`", + "Removed `ZeroExError.TransactionMiningTimeout` and moved it to '@0xproject/web3-wrapper' `Web3WrapperErrors.TransactionMiningTimeout`", "pr": 485 } ], diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index c18915417..693b4f4b2 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -5,6 +5,10 @@ Edit the package's CHANGELOG.json file only. CHANGELOG +## v0.36.0 - _April 11, 2018_ + + * Moved Web3.Provider to `@0xproject/types:Provider` (#501) + ## v0.35.0 - _April 2, 2018_ * Removed `ZeroExError.TransactionMiningTimeout` and moved it to '@0xproject/web3_wrapper' `Web3WrapperErrors.TransactionMiningTimeout` (#485) diff --git a/packages/0x.js/README.md b/packages/0x.js/README.md index 46848cbdd..72e5cc5fd 100644 --- a/packages/0x.js/README.md +++ b/packages/0x.js/README.md @@ -2,7 +2,7 @@ A TypeScript/Javascript library for interacting with the 0x protocol. -### Read the [Documentation](0xproject.com/docs/0xjs). +### Read the [Documentation](https://0xproject.com/docs/0x.js). ## Installation diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 882b40733..cd339e770 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -1,6 +1,6 @@ { "name": "0x.js", - "version": "0.35.0", + "version": "0.36.0", "description": "A javascript library for interacting with the 0x protocol", "keywords": [ "0x.js", @@ -15,16 +15,16 @@ "build:watch": "tsc -w", "prebuild": "run-s clean generate_contract_wrappers", "build": "run-p build:umd:prod build:commonjs; exit 0;", - "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'", + "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/compact_artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'", "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", "test:circleci": "run-s test:coverage", "test": "run-s clean test:commonjs", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", - "update_contracts": "for i in ${npm_package_config_artifacts}; do copyfiles -u 4 ../contracts/build/contracts/$i.json ../0x.js/src/artifacts; done;", + "update_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/src/artifacts/$i.json test/artifacts; done;", "clean": "shx rm -rf _bundles lib test_temp scripts", "build:umd:prod": "NODE_ENV=production webpack", - "build:commonjs": "tsc && copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", + "build:commonjs": "tsc && yarn update_artifacts && copyfiles -u 2 './src/compact_artifacts/**/*.json' ./lib/src/compact_artifacts && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "test:commonjs": "run-s build:commonjs run_mocha", "run_mocha": "mocha lib/test/**/*_test.js --timeout 10000 --bail --exit", "manual:postpublish": "yarn build; node ./scripts/postpublish.js", @@ -33,7 +33,8 @@ "upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json" }, "config": { - "artifacts": "TokenTransferProxy Exchange TokenRegistry Token EtherToken", + "compact_artifacts": "Exchange DummyToken ZRXToken Token EtherToken TokenTransferProxy TokenRegistry", + "contracts": "Exchange DummyToken ZRXToken Token WETH9 TokenTransferProxy MultiSigWallet MultiSigWalletWithTimeLock MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress MaliciousToken TokenRegistry Arbitrage EtherDelta AccountLevels", "postpublish": { "assets": [ "packages/0x.js/_bundles/index.js", @@ -60,9 +61,11 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/dev-utils": "^0.3.4", - "@0xproject/monorepo-scripts": "^0.1.16", - "@0xproject/tslint-config": "^0.4.14", + "@0xproject/deployer": "^0.4.0", + "@0xproject/dev-utils": "^0.3.5", + "@0xproject/monorepo-scripts": "^0.1.17", + "@0xproject/subproviders": "^0.8.4", + "@0xproject/tslint-config": "^0.4.15", "@types/bintrees": "^1.0.2", "@types/lodash": "4.14.104", "@types/mocha": "^2.2.42", @@ -90,16 +93,17 @@ "tslint": "5.8.0", "typedoc": "0xProject/typedoc", "typescript": "2.7.1", + "web3-provider-engine": "^13.0.1", "webpack": "^3.1.0" }, "dependencies": { - "@0xproject/assert": "^0.2.5", - "@0xproject/base-contract": "^0.1.0", - "@0xproject/json-schemas": "^0.7.19", - "@0xproject/types": "^0.5.0", - "@0xproject/typescript-typings": "^0.0.3", - "@0xproject/utils": "^0.5.0", - "@0xproject/web3-wrapper": "^0.5.0", + "@0xproject/assert": "^0.2.6", + "@0xproject/base-contract": "^0.2.0", + "@0xproject/json-schemas": "^0.7.20", + "@0xproject/types": "^0.6.0", + "@0xproject/typescript-typings": "^0.1.0", + "@0xproject/utils": "^0.5.1", + "@0xproject/web3-wrapper": "^0.6.0", "bintrees": "^1.0.2", "bn.js": "^4.11.8", "ethereumjs-abi": "^0.6.4", @@ -111,6 +115,9 @@ "uuid": "^3.1.0", "web3": "^0.20.0" }, + "optionalDependencies": { + "@0xproject/migrations": "^0.0.1" + }, "publishConfig": { "access": "public" } diff --git a/packages/0x.js/src/artifacts.ts b/packages/0x.js/src/artifacts.ts index cbacd7d56..a91d9ae1f 100644 --- a/packages/0x.js/src/artifacts.ts +++ b/packages/0x.js/src/artifacts.ts @@ -1,10 +1,10 @@ -import * as DummyTokenArtifact from './artifacts/DummyToken.json'; -import * as EtherTokenArtifact from './artifacts/EtherToken.json'; -import * as ExchangeArtifact from './artifacts/Exchange.json'; -import * as TokenArtifact from './artifacts/Token.json'; -import * as TokenRegistryArtifact from './artifacts/TokenRegistry.json'; -import * as TokenTransferProxyArtifact from './artifacts/TokenTransferProxy.json'; -import * as ZRXArtifact from './artifacts/ZRX.json'; +import * as DummyTokenArtifact from './compact_artifacts/DummyToken.json'; +import * as EtherTokenArtifact from './compact_artifacts/EtherToken.json'; +import * as ExchangeArtifact from './compact_artifacts/Exchange.json'; +import * as TokenArtifact from './compact_artifacts/Token.json'; +import * as TokenRegistryArtifact from './compact_artifacts/TokenRegistry.json'; +import * as TokenTransferProxyArtifact from './compact_artifacts/TokenTransferProxy.json'; +import * as ZRXArtifact from './compact_artifacts/ZRX.json'; import { Artifact } from './types'; export const artifacts = { diff --git a/packages/0x.js/src/artifacts/DummyToken.json b/packages/0x.js/src/compact_artifacts/DummyToken.json index f64a8cd3d..f64a8cd3d 100644 --- a/packages/0x.js/src/artifacts/DummyToken.json +++ b/packages/0x.js/src/compact_artifacts/DummyToken.json diff --git a/packages/0x.js/src/artifacts/EtherToken.json b/packages/0x.js/src/compact_artifacts/EtherToken.json index 26cca57cd..26cca57cd 100644 --- a/packages/0x.js/src/artifacts/EtherToken.json +++ b/packages/0x.js/src/compact_artifacts/EtherToken.json diff --git a/packages/0x.js/src/artifacts/Exchange.json b/packages/0x.js/src/compact_artifacts/Exchange.json index af8db7360..af8db7360 100644 --- a/packages/0x.js/src/artifacts/Exchange.json +++ b/packages/0x.js/src/compact_artifacts/Exchange.json diff --git a/packages/0x.js/src/artifacts/Token.json b/packages/0x.js/src/compact_artifacts/Token.json index 3b5a86ae0..3b5a86ae0 100644 --- a/packages/0x.js/src/artifacts/Token.json +++ b/packages/0x.js/src/compact_artifacts/Token.json diff --git a/packages/0x.js/src/artifacts/TokenRegistry.json b/packages/0x.js/src/compact_artifacts/TokenRegistry.json index 0f583628c..0f583628c 100644 --- a/packages/0x.js/src/artifacts/TokenRegistry.json +++ b/packages/0x.js/src/compact_artifacts/TokenRegistry.json diff --git a/packages/0x.js/src/artifacts/TokenTransferProxy.json b/packages/0x.js/src/compact_artifacts/TokenTransferProxy.json index 8cf551ddb..8cf551ddb 100644 --- a/packages/0x.js/src/artifacts/TokenTransferProxy.json +++ b/packages/0x.js/src/compact_artifacts/TokenTransferProxy.json diff --git a/packages/0x.js/src/artifacts/ZRX.json b/packages/0x.js/src/compact_artifacts/ZRX.json index e40b8f268..e40b8f268 100644 --- a/packages/0x.js/src/artifacts/ZRX.json +++ b/packages/0x.js/src/compact_artifacts/ZRX.json diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index 70e85aa52..de5a6be58 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -1,16 +1,23 @@ +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'; import 'mocha'; +import * as path from 'path'; import * as Sinon from 'sinon'; import { ApprovalContractEventArgs, LogWithDecodedArgs, Order, TokenEvents, ZeroEx } from '../src'; 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'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); chaiSetup.configure(); @@ -19,10 +26,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(provider, config); + }); describe('#setProvider', () => { it('overrides provider in nested web3s and invalidates contractInstances', async () => { // Instantiate the contract instances with the current provider @@ -31,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 = web3Factory.getRpcProvider(); // 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(); @@ -278,7 +288,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 () => { @@ -286,7 +296,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, ); diff --git a/packages/0x.js/test/artifacts_test.ts b/packages/0x.js/test/artifacts_test.ts index e8ab9aa97..17f068a2e 100644 --- a/packages/0x.js/test/artifacts_test.ts +++ b/packages/0x.js/test/artifacts_test.ts @@ -17,11 +17,11 @@ describe('Artifacts', () => { 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 provider = new HDWalletProvider(mnemonic, kovanRpcUrl); const config = { networkId: constants.KOVAN_NETWORK_ID, }; - const zeroEx = new ZeroEx(web3Provider, config); + const zeroEx = new ZeroEx(provider, config); it('token registry contract is deployed', async () => { await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync(); }).timeout(TIMEOUT); @@ -37,11 +37,11 @@ describe('Artifacts', () => { const packageJSONContent = fs.readFileSync('package.json', 'utf-8'); const packageJSON = JSON.parse(packageJSONContent); const mnemonic = packageJSON.config.mnemonic; - const web3Provider = new HDWalletProvider(mnemonic, ropstenRpcUrl); + const provider = new HDWalletProvider(mnemonic, ropstenRpcUrl); const config = { networkId: constants.ROPSTEN_NETWORK_ID, }; - const zeroEx = new ZeroEx(web3Provider, config); + const zeroEx = new ZeroEx(provider, 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 c4451742f..b08f3e23b 100644 --- a/packages/0x.js/test/assert_test.ts +++ b/packages/0x.js/test/assert_test.ts @@ -6,15 +6,15 @@ import { ZeroEx } from '../src'; import { assert } from '../src/utils/assert'; import { constants } from './utils/constants'; +import { provider } from './utils/web3_wrapper'; const expect = chai.expect; describe('Assertion library', () => { - const web3 = web3Factory.create(); const config = { networkId: constants.TESTRPC_NETWORK_ID, }; - const zeroEx = new ZeroEx(web3.currentProvider, config); + const zeroEx = new ZeroEx(provider, 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 644101dc7..99c42fe0b 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -3,7 +3,6 @@ import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; import 'mocha'; -import * as Web3 from 'web3'; import { ApprovalContractEventArgs, @@ -24,7 +23,7 @@ import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { TokenUtils } from './utils/token_utils'; -import { web3, web3Wrapper } from './utils/web3_wrapper'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -55,7 +54,7 @@ describe('EtherTokenWrapper', () => { const depositAmount = new BigNumber(42); const withdrawalAmount = new BigNumber(42); before(async () => { - zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig); + zeroEx = new ZeroEx(provider, zeroExConfig); tokens = await zeroEx.tokenRegistry.getTokensAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync(); addressWithETH = userAddresses[0]; @@ -79,7 +78,7 @@ describe('EtherTokenWrapper', () => { const UNKNOWN_NETWORK_NETWORK_ID = 10; expect( () => - new ZeroEx(web3.currentProvider, { + new ZeroEx(provider, { networkId: UNKNOWN_NETWORK_NETWORK_ID, } as any), ).to.throw(); @@ -261,8 +260,7 @@ describe('EtherTokenWrapper', () => { callbackNeverToBeCalled, ); const callbackToBeCalled = reportNodeCallbackErrors(done)(); - const newProvider = web3Factory.getRpcProvider(); - zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); + zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID); await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH); zeroEx.etherToken.subscribe( etherTokenAddress, diff --git a/packages/0x.js/test/event_watcher_test.ts b/packages/0x.js/test/event_watcher_test.ts index 2fa6c0580..40ffcc2f6 100644 --- a/packages/0x.js/test/event_watcher_test.ts +++ b/packages/0x.js/test/event_watcher_test.ts @@ -5,7 +5,6 @@ import * as chai from 'chai'; import * as _ from 'lodash'; import 'mocha'; import * as Sinon from 'sinon'; -import * as Web3 from 'web3'; import { LogEvent } from '../src'; import { EventWatcher } from '../src/order_watcher/event_watcher'; @@ -13,12 +12,12 @@ import { DoneCallback } from '../src/types'; import { chaiSetup } from './utils/chai_setup'; import { reportNodeCallbackErrors } from './utils/report_callback_errors'; +import { provider } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; describe('EventWatcher', () => { - let web3: Web3; let stubs: Sinon.SinonStub[] = []; let eventWatcher: EventWatcher; let web3Wrapper: Web3Wrapper; @@ -53,9 +52,8 @@ describe('EventWatcher', () => { transactionIndex: 0, }; before(async () => { - web3 = web3Factory.create(); const pollingIntervalMs = 10; - web3Wrapper = new Web3Wrapper(web3.currentProvider); + web3Wrapper = new Web3Wrapper(provider); eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalMs); }); afterEach(() => { diff --git a/packages/0x.js/test/exchange_transfer_simulator_test.ts b/packages/0x.js/test/exchange_transfer_simulator_test.ts index 4447a61cb..cb976a0ae 100644 --- a/packages/0x.js/test/exchange_transfer_simulator_test.ts +++ b/packages/0x.js/test/exchange_transfer_simulator_test.ts @@ -9,7 +9,7 @@ import { ExchangeTransferSimulator } from '../src/utils/exchange_transfer_simula import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; -import { web3, web3Wrapper } from './utils/web3_wrapper'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -19,7 +19,7 @@ describe('ExchangeTransferSimulator', () => { const config = { networkId: constants.TESTRPC_NETWORK_ID, }; - const zeroEx = new ZeroEx(web3.currentProvider, config); + const zeroEx = new ZeroEx(provider, 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 cfc390bae..cd74af5a1 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -4,7 +4,6 @@ import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; import 'mocha'; -import * as Web3 from 'web3'; import { BlockRange, @@ -26,7 +25,7 @@ import { constants } from './utils/constants'; import { FillScenarios } from './utils/fill_scenarios'; import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { TokenUtils } from './utils/token_utils'; -import { web3, web3Wrapper } from './utils/web3_wrapper'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -46,7 +45,7 @@ describe('ExchangeWrapper', () => { networkId: constants.TESTRPC_NETWORK_ID, }; before(async () => { - zeroEx = new ZeroEx(web3.currentProvider, config); + zeroEx = new ZeroEx(provider, config); exchangeContractAddress = zeroEx.exchange.getContractAddress(); userAddresses = await zeroEx.getAvailableAddressesAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync(); @@ -977,8 +976,7 @@ describe('ExchangeWrapper', () => { ); zeroEx.exchange.subscribe(ExchangeEvents.LogFill, indexFilterValues, callbackNeverToBeCalled); - const newProvider = web3Factory.getRpcProvider(); - zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); + zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID); const callback = reportNodeCallbackErrors(done)( (logEvent: DecodedLogEvent<LogFillContractEventArgs>) => { diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts index ed7a6e5e3..29b111fa3 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -4,7 +4,6 @@ import * as chai from 'chai'; import * as _ from 'lodash'; import 'mocha'; import * as Sinon from 'sinon'; -import * as Web3 from 'web3'; import { ZeroEx } from '../src/0x'; import { ExpirationWatcher } from '../src/order_watcher/expiration_watcher'; @@ -16,7 +15,7 @@ import { constants } from './utils/constants'; import { FillScenarios } from './utils/fill_scenarios'; import { reportNoErrorCallbackErrors } from './utils/report_callback_errors'; import { TokenUtils } from './utils/token_utils'; -import { web3, web3Wrapper } from './utils/web3_wrapper'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -44,7 +43,7 @@ describe('ExpirationWatcher', () => { const config = { networkId: constants.TESTRPC_NETWORK_ID, }; - zeroEx = new ZeroEx(web3.currentProvider, config); + zeroEx = new ZeroEx(provider, config); exchangeContractAddress = zeroEx.exchange.getContractAddress(); 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 4210e013f..45a292c8b 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -3,7 +3,6 @@ import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; import 'mocha'; -import * as Web3 from 'web3'; import { ExchangeContractErrs, @@ -23,7 +22,7 @@ import { constants } from './utils/constants'; import { FillScenarios } from './utils/fill_scenarios'; import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { TokenUtils } from './utils/token_utils'; -import { web3, web3Wrapper } from './utils/web3_wrapper'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; const TIMEOUT_MS = 150; @@ -51,7 +50,7 @@ describe('OrderStateWatcher', () => { const decimals = constants.ZRX_DECIMALS; const fillableAmount = ZeroEx.toBaseUnitAmount(new BigNumber(5), decimals); before(async () => { - zeroEx = new ZeroEx(web3.currentProvider, config); + zeroEx = new ZeroEx(provider, config); orderStateWatcher = zeroEx.createOrderStateWatcher(); exchangeContractAddress = zeroEx.exchange.getContractAddress(); userAddresses = await zeroEx.getAvailableAddressesAsync(); diff --git a/packages/0x.js/test/order_validation_test.ts b/packages/0x.js/test/order_validation_test.ts index 5472ca8f6..c894774b8 100644 --- a/packages/0x.js/test/order_validation_test.ts +++ b/packages/0x.js/test/order_validation_test.ts @@ -3,7 +3,6 @@ import { BlockParamLiteral } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as Sinon from 'sinon'; -import * as Web3 from 'web3'; import { ExchangeContractErrs, SignedOrder, Token, ZeroEx, ZeroExError } from '../src'; import { TradeSide, TransferType } from '../src/types'; @@ -14,7 +13,7 @@ import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { FillScenarios } from './utils/fill_scenarios'; import { TokenUtils } from './utils/token_utils'; -import { web3, web3Wrapper } from './utils/web3_wrapper'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -40,7 +39,7 @@ describe('OrderValidation', () => { networkId: constants.TESTRPC_NETWORK_ID, }; before(async () => { - zeroEx = new ZeroEx(web3.currentProvider, config); + zeroEx = new ZeroEx(provider, config); exchangeContractAddress = zeroEx.exchange.getContractAddress(); 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 9b4751287..ed4f838c0 100644 --- a/packages/0x.js/test/subscription_test.ts +++ b/packages/0x.js/test/subscription_test.ts @@ -3,7 +3,6 @@ import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import 'mocha'; import * as Sinon from 'sinon'; -import * as Web3 from 'web3'; import { ApprovalContractEventArgs, DecodedLogEvent, Token, TokenEvents, ZeroEx } from '../src'; import { DoneCallback } from '../src/types'; @@ -11,7 +10,7 @@ import { DoneCallback } from '../src/types'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { assertNodeCallbackError } from './utils/report_callback_errors'; -import { web3, web3Wrapper } from './utils/web3_wrapper'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); @@ -26,7 +25,7 @@ describe('SubscriptionTest', () => { networkId: constants.TESTRPC_NETWORK_ID, }; before(async () => { - zeroEx = new ZeroEx(web3.currentProvider, config); + zeroEx = new ZeroEx(provider, config); userAddresses = await zeroEx.getAvailableAddressesAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync(); coinbase = userAddresses[0]; diff --git a/packages/0x.js/test/token_registry_wrapper_test.ts b/packages/0x.js/test/token_registry_wrapper_test.ts index 3b7ce46fb..19caa2ed4 100644 --- a/packages/0x.js/test/token_registry_wrapper_test.ts +++ b/packages/0x.js/test/token_registry_wrapper_test.ts @@ -8,7 +8,7 @@ import { Token, ZeroEx } from '../src'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; -import { web3, web3Wrapper } from './utils/web3_wrapper'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -31,7 +31,7 @@ describe('TokenRegistryWrapper', () => { networkId: constants.TESTRPC_NETWORK_ID, }; before(async () => { - zeroEx = new ZeroEx(web3.currentProvider, config); + zeroEx = new ZeroEx(provider, 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 fb003634a..9415d7c08 100644 --- a/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts +++ b/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts @@ -1,14 +1,13 @@ -import { web3Factory } from '@0xproject/dev-utils'; import * as chai from 'chai'; import { ZeroEx } from '../src'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; +import { provider } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; -const web3 = web3Factory.create(); describe('TokenTransferProxyWrapper', () => { let zeroEx: ZeroEx; @@ -16,7 +15,7 @@ describe('TokenTransferProxyWrapper', () => { networkId: constants.TESTRPC_NETWORK_ID, }; before(async () => { - zeroEx = new ZeroEx(web3.currentProvider, config); + zeroEx = new ZeroEx(provider, 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 0c6335d5e..04fd943aa 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -1,9 +1,10 @@ -import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants } from '@0xproject/dev-utils'; +import { EmptyWalletSubprovider } from '@0xproject/subproviders'; +import { Provider } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; import 'mocha'; -import * as Web3 from 'web3'; +import Web3ProviderEngine = require('web3-provider-engine'); import { ApprovalContractEventArgs, @@ -22,7 +23,7 @@ import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { TokenUtils } from './utils/token_utils'; -import { web3, web3Wrapper } from './utils/web3_wrapper'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -39,7 +40,7 @@ describe('TokenWrapper', () => { networkId: constants.TESTRPC_NETWORK_ID, }; before(async () => { - zeroEx = new ZeroEx(web3.currentProvider, config); + zeroEx = new ZeroEx(provider, config); userAddresses = await zeroEx.getAvailableAddressesAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokenUtils = new TokenUtils(tokens); @@ -164,7 +165,7 @@ describe('TokenWrapper', () => { }); }); describe('#getBalanceAsync', () => { - describe('With web3 provider with accounts', () => { + describe('With provider with accounts', () => { it('should return the balance for an existing ERC20 token', async () => { const token = tokens[0]; const ownerAddress = coinbase; @@ -187,14 +188,14 @@ describe('TokenWrapper', () => { return expect(balance).to.be.bignumber.equal(expectedBalance); }); }); - describe('With web3 provider without accounts', () => { + describe('With provider without accounts', () => { let zeroExWithoutAccounts: ZeroEx; before(async () => { const hasAddresses = false; - const web3WithoutAccounts = web3Factory.create({ hasAddresses }); - zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider, config); + const emptyWalletProvider = addEmptyWalletSubprovider(provider); + zeroExWithoutAccounts = new ZeroEx(emptyWalletProvider, config); }); - it('should return balance even when called with Web3 provider instance without addresses', async () => { + it('should return balance even when called with provider instance without addresses', async () => { const token = tokens[0]; const ownerAddress = coinbase; const balance = await zeroExWithoutAccounts.token.getBalanceAsync(token.address, ownerAddress); @@ -277,7 +278,7 @@ describe('TokenWrapper', () => { }); }); describe('#getAllowanceAsync', () => { - describe('With web3 provider with accounts', () => { + describe('With provider with accounts', () => { it('should get the proxy allowance', async () => { const token = tokens[0]; const ownerAddress = coinbase; @@ -299,12 +300,12 @@ describe('TokenWrapper', () => { return expect(allowance).to.be.bignumber.equal(expectedAllowance); }); }); - describe('With web3 provider without accounts', () => { + describe('With provider without accounts', () => { let zeroExWithoutAccounts: ZeroEx; before(async () => { const hasAddresses = false; - const web3WithoutAccounts = web3Factory.create({ hasAddresses }); - zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider, config); + const emptyWalletProvider = addEmptyWalletSubprovider(provider); + zeroExWithoutAccounts = new ZeroEx(emptyWalletProvider, config); }); it('should get the proxy allowance', async () => { const token = tokens[0]; @@ -424,8 +425,7 @@ describe('TokenWrapper', () => { ); zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackNeverToBeCalled); const callbackToBeCalled = reportNodeCallbackErrors(done)(); - const newProvider = web3Factory.getRpcProvider(); - zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); + zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID); zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackToBeCalled); await zeroEx.token.transferAsync(tokenAddress, coinbase, addressWithoutFunds, transferAmount); })().catch(done); @@ -515,3 +515,14 @@ describe('TokenWrapper', () => { }); }); // tslint:disable:max-file-line-count + +function addEmptyWalletSubprovider(p: Provider): Provider { + const providerEngine = new Web3ProviderEngine(); + providerEngine.addProvider(new EmptyWalletSubprovider()); + const currentSubproviders = (p as any)._providers; + for (const subprovider of currentSubproviders) { + providerEngine.addProvider(subprovider); + } + providerEngine.start(); + return providerEngine; +} diff --git a/packages/0x.js/test/utils/deployer.ts b/packages/0x.js/test/utils/deployer.ts new file mode 100644 index 000000000..b092322e2 --- /dev/null +++ b/packages/0x.js/test/utils/deployer.ts @@ -0,0 +1,18 @@ +import { Deployer } from '@0xproject/deployer'; +import { devConstants } from '@0xproject/dev-utils'; +import * as path from 'path'; + +import { constants } from './constants'; + +import { provider } from './web3_wrapper'; + +const artifactsDir = path.resolve('test', 'artifacts'); +const deployerOpts = { + artifactsDir, + provider, + networkId: constants.TESTRPC_NETWORK_ID, + defaults: { + gas: devConstants.GAS_ESTIMATE, + }, +}; +export const deployer = new Deployer(deployerOpts); diff --git a/packages/0x.js/test/utils/web3_wrapper.ts b/packages/0x.js/test/utils/web3_wrapper.ts index 4b374fc7e..b7b3f0b7f 100644 --- a/packages/0x.js/test/utils/web3_wrapper.ts +++ b/packages/0x.js/test/utils/web3_wrapper.ts @@ -1,6 +1,12 @@ -import { web3Factory } from '@0xproject/dev-utils'; +import { devConstants, web3Factory } from '@0xproject/dev-utils'; +import { Provider } from '@0xproject/types'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as Web3 from 'web3'; -export const web3 = web3Factory.create(); -export const web3Wrapper = new Web3Wrapper(web3.currentProvider); +import { constants } from './constants'; + +const web3 = web3Factory.create({ shouldUseInProcessGanache: true }); +const provider: Provider = web3.currentProvider; +const web3Wrapper = new Web3Wrapper(web3.currentProvider); + +export { provider, web3Wrapper }; |