Merge pull request #500 from 0xProject/removeMigrateStep

Run all tests against in-process Ganache
This commit is contained in:
Fabio Berger 2018-04-12 08:53:32 +09:00 committed by GitHub
commit c47fb8f9a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
82 changed files with 476 additions and 350 deletions

3
.gitignore vendored
View File

@ -74,7 +74,8 @@ packages/react-docs/example/public/bundle*
bin/ bin/
# generated contract artifacts # generated contract artifacts
packages/contracts/src/artifacts packages/0x.js/test/artifacts
packages/migrations/src/artifacts
# generated contract wrappers # generated contract wrappers
packages/0x.js/src/contract_wrappers/generated/ packages/0x.js/src/contract_wrappers/generated/

View File

@ -1,5 +1,6 @@
lib lib
.nyc_output .nyc_output
/packages/contracts/src/artifacts /packages/contracts/src/artifacts
/packages/metacoin/artifacts
package.json package.json
scripts/postpublish_utils.js scripts/postpublish_utils.js

View File

@ -74,7 +74,7 @@ You can include those by prepending @0xproject/typescript-typings package to you
We strongly recommend that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository. We strongly recommend that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository.
Please read our [contribution guidelines](./CONTRIBUTING.md) before getting started. #### Read our [contribution guidelines](./CONTRIBUTING.md).
### Install dependencies ### Install dependencies
@ -118,24 +118,6 @@ yarn lerna:run lint
### Run Tests ### Run Tests
Before running the tests, you will need to spin up a [TestRPC](https://www.npmjs.com/package/ethereumjs-testrpc) instance and deploy all the 0x smart contracts.
In a separate terminal, start TestRPC (a convenience command is provided as part of this repo)
```bash ```bash
yarn testrpc yarn lerna:test
```
Then in your main terminal run
```
cd packages/contracts
yarn migrate
cd ..
```
And finally from the root project directory run
```bash
yarn lerna:run test
``` ```

View File

@ -13,6 +13,7 @@
"test:installation": "node ./packages/monorepo-scripts/lib/test_installation.js", "test:installation": "node ./packages/monorepo-scripts/lib/test_installation.js",
"lerna:install": "yarn install", "lerna:install": "yarn install",
"lerna:run": "lerna run", "lerna:run": "lerna run",
"lerna:test": "lerna run test",
"lerna:clean": "lerna run clean", "lerna:clean": "lerna run clean",
"lerna:build": "lerna run build", "lerna:build": "lerna run build",
"lerna:rebuild": "run-s lerna:clean lerna:build", "lerna:rebuild": "run-s lerna:clean lerna:build",

View File

@ -15,16 +15,16 @@
"build:watch": "tsc -w", "build:watch": "tsc -w",
"prebuild": "run-s clean generate_contract_wrappers", "prebuild": "run-s clean generate_contract_wrappers",
"build": "run-p build:umd:prod build:commonjs; exit 0;", "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'", "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'",
"test:circleci": "run-s test:coverage", "test:circleci": "run-s test:coverage",
"test": "run-s clean test:commonjs", "test": "run-s clean test:commonjs",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "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", "clean": "shx rm -rf _bundles lib test_temp scripts",
"build:umd:prod": "NODE_ENV=production webpack", "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", "test:commonjs": "run-s build:commonjs run_mocha",
"run_mocha": "mocha lib/test/**/*_test.js --timeout 10000 --bail --exit", "run_mocha": "mocha lib/test/**/*_test.js --timeout 10000 --bail --exit",
"manual:postpublish": "yarn build; node ./scripts/postpublish.js", "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" "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": { "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": { "postpublish": {
"assets": [ "assets": [
"packages/0x.js/_bundles/index.js", "packages/0x.js/_bundles/index.js",
@ -60,8 +61,10 @@
"node": ">=6.0.0" "node": ">=6.0.0"
}, },
"devDependencies": { "devDependencies": {
"@0xproject/deployer": "^0.4.0",
"@0xproject/dev-utils": "^0.3.5", "@0xproject/dev-utils": "^0.3.5",
"@0xproject/monorepo-scripts": "^0.1.17", "@0xproject/monorepo-scripts": "^0.1.17",
"@0xproject/subproviders": "^0.8.4",
"@0xproject/tslint-config": "^0.4.15", "@0xproject/tslint-config": "^0.4.15",
"@types/bintrees": "^1.0.2", "@types/bintrees": "^1.0.2",
"@types/lodash": "4.14.104", "@types/lodash": "4.14.104",
@ -90,6 +93,7 @@
"tslint": "5.8.0", "tslint": "5.8.0",
"typedoc": "0xProject/typedoc", "typedoc": "0xProject/typedoc",
"typescript": "2.7.1", "typescript": "2.7.1",
"web3-provider-engine": "^13.0.1",
"webpack": "^3.1.0" "webpack": "^3.1.0"
}, },
"dependencies": { "dependencies": {
@ -111,6 +115,9 @@
"uuid": "^3.1.0", "uuid": "^3.1.0",
"web3": "^0.20.0" "web3": "^0.20.0"
}, },
"optionalDependencies": {
"@0xproject/migrations": "^0.0.1"
},
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
} }

View File

@ -1,10 +1,10 @@
import * as DummyTokenArtifact from './artifacts/DummyToken.json'; import * as DummyTokenArtifact from './compact_artifacts/DummyToken.json';
import * as EtherTokenArtifact from './artifacts/EtherToken.json'; import * as EtherTokenArtifact from './compact_artifacts/EtherToken.json';
import * as ExchangeArtifact from './artifacts/Exchange.json'; import * as ExchangeArtifact from './compact_artifacts/Exchange.json';
import * as TokenArtifact from './artifacts/Token.json'; import * as TokenArtifact from './compact_artifacts/Token.json';
import * as TokenRegistryArtifact from './artifacts/TokenRegistry.json'; import * as TokenRegistryArtifact from './compact_artifacts/TokenRegistry.json';
import * as TokenTransferProxyArtifact from './artifacts/TokenTransferProxy.json'; import * as TokenTransferProxyArtifact from './compact_artifacts/TokenTransferProxy.json';
import * as ZRXArtifact from './artifacts/ZRX.json'; import * as ZRXArtifact from './compact_artifacts/ZRX.json';
import { Artifact } from './types'; import { Artifact } from './types';
export const artifacts = { export const artifacts = {

View File

@ -1,16 +1,23 @@
import { Deployer } from '@0xproject/deployer';
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; 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 { BigNumber } from '@0xproject/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import * as _ from 'lodash'; import * as _ from 'lodash';
import 'mocha'; import 'mocha';
import * as path from 'path';
import * as Sinon from 'sinon'; import * as Sinon from 'sinon';
import { ApprovalContractEventArgs, LogWithDecodedArgs, Order, TokenEvents, ZeroEx } from '../src'; import { ApprovalContractEventArgs, LogWithDecodedArgs, Order, TokenEvents, ZeroEx } from '../src';
import { chaiSetup } from './utils/chai_setup'; import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants'; import { constants } from './utils/constants';
import { deployer } from './utils/deployer';
import { TokenUtils } from './utils/token_utils'; 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); const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
chaiSetup.configure(); chaiSetup.configure();
@ -19,10 +26,14 @@ const expect = chai.expect;
const SHOULD_ADD_PERSONAL_MESSAGE_PREFIX = false; const SHOULD_ADD_PERSONAL_MESSAGE_PREFIX = false;
describe('ZeroEx library', () => { describe('ZeroEx library', () => {
const config = { let zeroEx: ZeroEx;
networkId: constants.TESTRPC_NETWORK_ID, before(async () => {
}; await runMigrationsAsync(deployer);
const zeroEx = new ZeroEx(web3.currentProvider, config); const config = {
networkId: constants.TESTRPC_NETWORK_ID,
};
zeroEx = new ZeroEx(provider, config);
});
describe('#setProvider', () => { describe('#setProvider', () => {
it('overrides provider in nested web3s and invalidates contractInstances', async () => { it('overrides provider in nested web3s and invalidates contractInstances', async () => {
// Instantiate the contract instances with the current provider // 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.exchange as any)._exchangeContractIfExists).to.not.be.undefined();
expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).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 // Add property to newProvider so that we can differentiate it from old provider
(newProvider as any).zeroExTestId = 1; (provider as any).zeroExTestId = 1;
zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID); zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID);
// Check that contractInstances with old provider are removed after provider update // Check that contractInstances with old provider are removed after provider update
expect((zeroEx.exchange as any)._exchangeContractIfExists).to.be.undefined(); expect((zeroEx.exchange as any)._exchangeContractIfExists).to.be.undefined();
@ -278,7 +288,7 @@ describe('ZeroEx library', () => {
exchangeContractAddress: ZeroEx.NULL_ADDRESS, exchangeContractAddress: ZeroEx.NULL_ADDRESS,
networkId: constants.TESTRPC_NETWORK_ID, 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); expect(zeroExWithWrongExchangeAddress.exchange.getContractAddress()).to.be.equal(ZeroEx.NULL_ADDRESS);
}); });
it('allows to specify token registry token contract address', async () => { it('allows to specify token registry token contract address', async () => {
@ -286,7 +296,7 @@ describe('ZeroEx library', () => {
tokenRegistryContractAddress: ZeroEx.NULL_ADDRESS, tokenRegistryContractAddress: ZeroEx.NULL_ADDRESS,
networkId: constants.TESTRPC_NETWORK_ID, 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( expect(zeroExWithWrongTokenRegistryAddress.tokenRegistry.getContractAddress()).to.be.equal(
ZeroEx.NULL_ADDRESS, ZeroEx.NULL_ADDRESS,
); );

View File

@ -17,11 +17,11 @@ describe('Artifacts', () => {
const packageJSONContent = fs.readFileSync('package.json', 'utf-8'); const packageJSONContent = fs.readFileSync('package.json', 'utf-8');
const packageJSON = JSON.parse(packageJSONContent); const packageJSON = JSON.parse(packageJSONContent);
const mnemonic = packageJSON.config.mnemonic; const mnemonic = packageJSON.config.mnemonic;
const web3Provider = new HDWalletProvider(mnemonic, kovanRpcUrl); const provider = new HDWalletProvider(mnemonic, kovanRpcUrl);
const config = { const config = {
networkId: constants.KOVAN_NETWORK_ID, networkId: constants.KOVAN_NETWORK_ID,
}; };
const zeroEx = new ZeroEx(web3Provider, config); const zeroEx = new ZeroEx(provider, config);
it('token registry contract is deployed', async () => { it('token registry contract is deployed', async () => {
await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync(); await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync();
}).timeout(TIMEOUT); }).timeout(TIMEOUT);
@ -37,11 +37,11 @@ describe('Artifacts', () => {
const packageJSONContent = fs.readFileSync('package.json', 'utf-8'); const packageJSONContent = fs.readFileSync('package.json', 'utf-8');
const packageJSON = JSON.parse(packageJSONContent); const packageJSON = JSON.parse(packageJSONContent);
const mnemonic = packageJSON.config.mnemonic; const mnemonic = packageJSON.config.mnemonic;
const web3Provider = new HDWalletProvider(mnemonic, ropstenRpcUrl); const provider = new HDWalletProvider(mnemonic, ropstenRpcUrl);
const config = { const config = {
networkId: constants.ROPSTEN_NETWORK_ID, networkId: constants.ROPSTEN_NETWORK_ID,
}; };
const zeroEx = new ZeroEx(web3Provider, config); const zeroEx = new ZeroEx(provider, config);
it('token registry contract is deployed', async () => { it('token registry contract is deployed', async () => {
await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync(); await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync();
}).timeout(TIMEOUT); }).timeout(TIMEOUT);

View File

@ -6,15 +6,15 @@ import { ZeroEx } from '../src';
import { assert } from '../src/utils/assert'; import { assert } from '../src/utils/assert';
import { constants } from './utils/constants'; import { constants } from './utils/constants';
import { provider } from './utils/web3_wrapper';
const expect = chai.expect; const expect = chai.expect;
describe('Assertion library', () => { describe('Assertion library', () => {
const web3 = web3Factory.create();
const config = { const config = {
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
}; };
const zeroEx = new ZeroEx(web3.currentProvider, config); const zeroEx = new ZeroEx(provider, config);
describe('#isSenderAddressHexAsync', () => { describe('#isSenderAddressHexAsync', () => {
it('throws when address is invalid', async () => { it('throws when address is invalid', async () => {
const address = '0xdeadbeef'; const address = '0xdeadbeef';

View File

@ -3,7 +3,6 @@ import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai'; import * as chai from 'chai';
import 'mocha'; import 'mocha';
import * as Web3 from 'web3';
import { import {
ApprovalContractEventArgs, ApprovalContractEventArgs,
@ -24,7 +23,7 @@ import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants'; import { constants } from './utils/constants';
import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { reportNodeCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils'; import { TokenUtils } from './utils/token_utils';
import { web3, web3Wrapper } from './utils/web3_wrapper'; import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
@ -55,7 +54,7 @@ describe('EtherTokenWrapper', () => {
const depositAmount = new BigNumber(42); const depositAmount = new BigNumber(42);
const withdrawalAmount = new BigNumber(42); const withdrawalAmount = new BigNumber(42);
before(async () => { before(async () => {
zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig); zeroEx = new ZeroEx(provider, zeroExConfig);
tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync();
userAddresses = await zeroEx.getAvailableAddressesAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync();
addressWithETH = userAddresses[0]; addressWithETH = userAddresses[0];
@ -79,7 +78,7 @@ describe('EtherTokenWrapper', () => {
const UNKNOWN_NETWORK_NETWORK_ID = 10; const UNKNOWN_NETWORK_NETWORK_ID = 10;
expect( expect(
() => () =>
new ZeroEx(web3.currentProvider, { new ZeroEx(provider, {
networkId: UNKNOWN_NETWORK_NETWORK_ID, networkId: UNKNOWN_NETWORK_NETWORK_ID,
} as any), } as any),
).to.throw(); ).to.throw();
@ -261,8 +260,7 @@ describe('EtherTokenWrapper', () => {
callbackNeverToBeCalled, callbackNeverToBeCalled,
); );
const callbackToBeCalled = reportNodeCallbackErrors(done)(); const callbackToBeCalled = reportNodeCallbackErrors(done)();
const newProvider = web3Factory.getRpcProvider(); zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID);
zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH); await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH);
zeroEx.etherToken.subscribe( zeroEx.etherToken.subscribe(
etherTokenAddress, etherTokenAddress,

View File

@ -5,7 +5,6 @@ import * as chai from 'chai';
import * as _ from 'lodash'; import * as _ from 'lodash';
import 'mocha'; import 'mocha';
import * as Sinon from 'sinon'; import * as Sinon from 'sinon';
import * as Web3 from 'web3';
import { LogEvent } from '../src'; import { LogEvent } from '../src';
import { EventWatcher } from '../src/order_watcher/event_watcher'; import { EventWatcher } from '../src/order_watcher/event_watcher';
@ -13,12 +12,12 @@ import { DoneCallback } from '../src/types';
import { chaiSetup } from './utils/chai_setup'; import { chaiSetup } from './utils/chai_setup';
import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { reportNodeCallbackErrors } from './utils/report_callback_errors';
import { provider } from './utils/web3_wrapper';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
describe('EventWatcher', () => { describe('EventWatcher', () => {
let web3: Web3;
let stubs: Sinon.SinonStub[] = []; let stubs: Sinon.SinonStub[] = [];
let eventWatcher: EventWatcher; let eventWatcher: EventWatcher;
let web3Wrapper: Web3Wrapper; let web3Wrapper: Web3Wrapper;
@ -53,9 +52,8 @@ describe('EventWatcher', () => {
transactionIndex: 0, transactionIndex: 0,
}; };
before(async () => { before(async () => {
web3 = web3Factory.create();
const pollingIntervalMs = 10; const pollingIntervalMs = 10;
web3Wrapper = new Web3Wrapper(web3.currentProvider); web3Wrapper = new Web3Wrapper(provider);
eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalMs); eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalMs);
}); });
afterEach(() => { afterEach(() => {

View File

@ -9,7 +9,7 @@ import { ExchangeTransferSimulator } from '../src/utils/exchange_transfer_simula
import { chaiSetup } from './utils/chai_setup'; import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants'; import { constants } from './utils/constants';
import { web3, web3Wrapper } from './utils/web3_wrapper'; import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
@ -19,7 +19,7 @@ describe('ExchangeTransferSimulator', () => {
const config = { const config = {
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
}; };
const zeroEx = new ZeroEx(web3.currentProvider, config); const zeroEx = new ZeroEx(provider, config);
const transferAmount = new BigNumber(5); const transferAmount = new BigNumber(5);
let userAddresses: string[]; let userAddresses: string[];
let tokens: Token[]; let tokens: Token[];

View File

@ -4,7 +4,6 @@ import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import * as _ from 'lodash'; import * as _ from 'lodash';
import 'mocha'; import 'mocha';
import * as Web3 from 'web3';
import { import {
BlockRange, BlockRange,
@ -26,7 +25,7 @@ import { constants } from './utils/constants';
import { FillScenarios } from './utils/fill_scenarios'; import { FillScenarios } from './utils/fill_scenarios';
import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { reportNodeCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils'; import { TokenUtils } from './utils/token_utils';
import { web3, web3Wrapper } from './utils/web3_wrapper'; import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
@ -46,7 +45,7 @@ describe('ExchangeWrapper', () => {
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
}; };
before(async () => { before(async () => {
zeroEx = new ZeroEx(web3.currentProvider, config); zeroEx = new ZeroEx(provider, config);
exchangeContractAddress = zeroEx.exchange.getContractAddress(); exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync();
@ -977,8 +976,7 @@ describe('ExchangeWrapper', () => {
); );
zeroEx.exchange.subscribe(ExchangeEvents.LogFill, indexFilterValues, callbackNeverToBeCalled); zeroEx.exchange.subscribe(ExchangeEvents.LogFill, indexFilterValues, callbackNeverToBeCalled);
const newProvider = web3Factory.getRpcProvider(); zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID);
zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
const callback = reportNodeCallbackErrors(done)( const callback = reportNodeCallbackErrors(done)(
(logEvent: DecodedLogEvent<LogFillContractEventArgs>) => { (logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {

View File

@ -4,7 +4,6 @@ import * as chai from 'chai';
import * as _ from 'lodash'; import * as _ from 'lodash';
import 'mocha'; import 'mocha';
import * as Sinon from 'sinon'; import * as Sinon from 'sinon';
import * as Web3 from 'web3';
import { ZeroEx } from '../src/0x'; import { ZeroEx } from '../src/0x';
import { ExpirationWatcher } from '../src/order_watcher/expiration_watcher'; import { ExpirationWatcher } from '../src/order_watcher/expiration_watcher';
@ -16,7 +15,7 @@ import { constants } from './utils/constants';
import { FillScenarios } from './utils/fill_scenarios'; import { FillScenarios } from './utils/fill_scenarios';
import { reportNoErrorCallbackErrors } from './utils/report_callback_errors'; import { reportNoErrorCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils'; import { TokenUtils } from './utils/token_utils';
import { web3, web3Wrapper } from './utils/web3_wrapper'; import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
@ -44,7 +43,7 @@ describe('ExpirationWatcher', () => {
const config = { const config = {
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
}; };
zeroEx = new ZeroEx(web3.currentProvider, config); zeroEx = new ZeroEx(provider, config);
exchangeContractAddress = zeroEx.exchange.getContractAddress(); exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync();

View File

@ -3,7 +3,6 @@ import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import * as _ from 'lodash'; import * as _ from 'lodash';
import 'mocha'; import 'mocha';
import * as Web3 from 'web3';
import { import {
ExchangeContractErrs, ExchangeContractErrs,
@ -23,7 +22,7 @@ import { constants } from './utils/constants';
import { FillScenarios } from './utils/fill_scenarios'; import { FillScenarios } from './utils/fill_scenarios';
import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { reportNodeCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils'; import { TokenUtils } from './utils/token_utils';
import { web3, web3Wrapper } from './utils/web3_wrapper'; import { provider, web3Wrapper } from './utils/web3_wrapper';
const TIMEOUT_MS = 150; const TIMEOUT_MS = 150;
@ -51,7 +50,7 @@ describe('OrderStateWatcher', () => {
const decimals = constants.ZRX_DECIMALS; const decimals = constants.ZRX_DECIMALS;
const fillableAmount = ZeroEx.toBaseUnitAmount(new BigNumber(5), decimals); const fillableAmount = ZeroEx.toBaseUnitAmount(new BigNumber(5), decimals);
before(async () => { before(async () => {
zeroEx = new ZeroEx(web3.currentProvider, config); zeroEx = new ZeroEx(provider, config);
orderStateWatcher = zeroEx.createOrderStateWatcher(); orderStateWatcher = zeroEx.createOrderStateWatcher();
exchangeContractAddress = zeroEx.exchange.getContractAddress(); exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync();

View File

@ -3,7 +3,6 @@ import { BlockParamLiteral } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import * as Sinon from 'sinon'; import * as Sinon from 'sinon';
import * as Web3 from 'web3';
import { ExchangeContractErrs, SignedOrder, Token, ZeroEx, ZeroExError } from '../src'; import { ExchangeContractErrs, SignedOrder, Token, ZeroEx, ZeroExError } from '../src';
import { TradeSide, TransferType } from '../src/types'; import { TradeSide, TransferType } from '../src/types';
@ -14,7 +13,7 @@ import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants'; import { constants } from './utils/constants';
import { FillScenarios } from './utils/fill_scenarios'; import { FillScenarios } from './utils/fill_scenarios';
import { TokenUtils } from './utils/token_utils'; import { TokenUtils } from './utils/token_utils';
import { web3, web3Wrapper } from './utils/web3_wrapper'; import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
@ -40,7 +39,7 @@ describe('OrderValidation', () => {
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
}; };
before(async () => { before(async () => {
zeroEx = new ZeroEx(web3.currentProvider, config); zeroEx = new ZeroEx(provider, config);
exchangeContractAddress = zeroEx.exchange.getContractAddress(); exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync();
[coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses;

View File

@ -3,7 +3,6 @@ import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash'; import * as _ from 'lodash';
import 'mocha'; import 'mocha';
import * as Sinon from 'sinon'; import * as Sinon from 'sinon';
import * as Web3 from 'web3';
import { ApprovalContractEventArgs, DecodedLogEvent, Token, TokenEvents, ZeroEx } from '../src'; import { ApprovalContractEventArgs, DecodedLogEvent, Token, TokenEvents, ZeroEx } from '../src';
import { DoneCallback } from '../src/types'; import { DoneCallback } from '../src/types';
@ -11,7 +10,7 @@ import { DoneCallback } from '../src/types';
import { chaiSetup } from './utils/chai_setup'; import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants'; import { constants } from './utils/constants';
import { assertNodeCallbackError } from './utils/report_callback_errors'; import { assertNodeCallbackError } from './utils/report_callback_errors';
import { web3, web3Wrapper } from './utils/web3_wrapper'; import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure(); chaiSetup.configure();
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
@ -26,7 +25,7 @@ describe('SubscriptionTest', () => {
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
}; };
before(async () => { before(async () => {
zeroEx = new ZeroEx(web3.currentProvider, config); zeroEx = new ZeroEx(provider, config);
userAddresses = await zeroEx.getAvailableAddressesAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync();
coinbase = userAddresses[0]; coinbase = userAddresses[0];

View File

@ -8,7 +8,7 @@ import { Token, ZeroEx } from '../src';
import { chaiSetup } from './utils/chai_setup'; import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants'; import { constants } from './utils/constants';
import { web3, web3Wrapper } from './utils/web3_wrapper'; import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
@ -31,7 +31,7 @@ describe('TokenRegistryWrapper', () => {
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
}; };
before(async () => { before(async () => {
zeroEx = new ZeroEx(web3.currentProvider, config); zeroEx = new ZeroEx(provider, config);
tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync();
_.map(tokens, token => { _.map(tokens, token => {
tokenAddressBySymbol[token.symbol] = token.address; tokenAddressBySymbol[token.symbol] = token.address;

View File

@ -1,14 +1,13 @@
import { web3Factory } from '@0xproject/dev-utils';
import * as chai from 'chai'; import * as chai from 'chai';
import { ZeroEx } from '../src'; import { ZeroEx } from '../src';
import { chaiSetup } from './utils/chai_setup'; import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants'; import { constants } from './utils/constants';
import { provider } from './utils/web3_wrapper';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
const web3 = web3Factory.create();
describe('TokenTransferProxyWrapper', () => { describe('TokenTransferProxyWrapper', () => {
let zeroEx: ZeroEx; let zeroEx: ZeroEx;
@ -16,7 +15,7 @@ describe('TokenTransferProxyWrapper', () => {
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
}; };
before(async () => { before(async () => {
zeroEx = new ZeroEx(web3.currentProvider, config); zeroEx = new ZeroEx(provider, config);
}); });
describe('#isAuthorizedAsync', () => { describe('#isAuthorizedAsync', () => {
it('should return false if the address is not authorized', async () => { it('should return false if the address is not authorized', async () => {

View File

@ -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 { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai'; import * as chai from 'chai';
import 'mocha'; import 'mocha';
import * as Web3 from 'web3'; import Web3ProviderEngine = require('web3-provider-engine');
import { import {
ApprovalContractEventArgs, ApprovalContractEventArgs,
@ -22,7 +23,7 @@ import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants'; import { constants } from './utils/constants';
import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { reportNodeCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils'; import { TokenUtils } from './utils/token_utils';
import { web3, web3Wrapper } from './utils/web3_wrapper'; import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
@ -39,7 +40,7 @@ describe('TokenWrapper', () => {
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
}; };
before(async () => { before(async () => {
zeroEx = new ZeroEx(web3.currentProvider, config); zeroEx = new ZeroEx(provider, config);
userAddresses = await zeroEx.getAvailableAddressesAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync();
tokenUtils = new TokenUtils(tokens); tokenUtils = new TokenUtils(tokens);
@ -164,7 +165,7 @@ describe('TokenWrapper', () => {
}); });
}); });
describe('#getBalanceAsync', () => { describe('#getBalanceAsync', () => {
describe('With web3 provider with accounts', () => { describe('With provider with accounts', () => {
it('should return the balance for an existing ERC20 token', async () => { it('should return the balance for an existing ERC20 token', async () => {
const token = tokens[0]; const token = tokens[0];
const ownerAddress = coinbase; const ownerAddress = coinbase;
@ -187,14 +188,14 @@ describe('TokenWrapper', () => {
return expect(balance).to.be.bignumber.equal(expectedBalance); return expect(balance).to.be.bignumber.equal(expectedBalance);
}); });
}); });
describe('With web3 provider without accounts', () => { describe('With provider without accounts', () => {
let zeroExWithoutAccounts: ZeroEx; let zeroExWithoutAccounts: ZeroEx;
before(async () => { before(async () => {
const hasAddresses = false; const hasAddresses = false;
const web3WithoutAccounts = web3Factory.create({ hasAddresses }); const emptyWalletProvider = addEmptyWalletSubprovider(provider);
zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider, config); 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 token = tokens[0];
const ownerAddress = coinbase; const ownerAddress = coinbase;
const balance = await zeroExWithoutAccounts.token.getBalanceAsync(token.address, ownerAddress); const balance = await zeroExWithoutAccounts.token.getBalanceAsync(token.address, ownerAddress);
@ -277,7 +278,7 @@ describe('TokenWrapper', () => {
}); });
}); });
describe('#getAllowanceAsync', () => { describe('#getAllowanceAsync', () => {
describe('With web3 provider with accounts', () => { describe('With provider with accounts', () => {
it('should get the proxy allowance', async () => { it('should get the proxy allowance', async () => {
const token = tokens[0]; const token = tokens[0];
const ownerAddress = coinbase; const ownerAddress = coinbase;
@ -299,12 +300,12 @@ describe('TokenWrapper', () => {
return expect(allowance).to.be.bignumber.equal(expectedAllowance); return expect(allowance).to.be.bignumber.equal(expectedAllowance);
}); });
}); });
describe('With web3 provider without accounts', () => { describe('With provider without accounts', () => {
let zeroExWithoutAccounts: ZeroEx; let zeroExWithoutAccounts: ZeroEx;
before(async () => { before(async () => {
const hasAddresses = false; const hasAddresses = false;
const web3WithoutAccounts = web3Factory.create({ hasAddresses }); const emptyWalletProvider = addEmptyWalletSubprovider(provider);
zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider, config); zeroExWithoutAccounts = new ZeroEx(emptyWalletProvider, config);
}); });
it('should get the proxy allowance', async () => { it('should get the proxy allowance', async () => {
const token = tokens[0]; const token = tokens[0];
@ -424,8 +425,7 @@ describe('TokenWrapper', () => {
); );
zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackNeverToBeCalled); zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackNeverToBeCalled);
const callbackToBeCalled = reportNodeCallbackErrors(done)(); const callbackToBeCalled = reportNodeCallbackErrors(done)();
const newProvider = web3Factory.getRpcProvider(); zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID);
zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackToBeCalled); zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackToBeCalled);
await zeroEx.token.transferAsync(tokenAddress, coinbase, addressWithoutFunds, transferAmount); await zeroEx.token.transferAsync(tokenAddress, coinbase, addressWithoutFunds, transferAmount);
})().catch(done); })().catch(done);
@ -515,3 +515,14 @@ describe('TokenWrapper', () => {
}); });
}); });
// tslint:disable:max-file-line-count // 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;
}

View File

@ -2,19 +2,17 @@ import { Deployer } from '@0xproject/deployer';
import { devConstants } from '@0xproject/dev-utils'; import { devConstants } from '@0xproject/dev-utils';
import * as path from 'path'; import * as path from 'path';
import { constants } from '../util/constants'; import { constants } from './constants';
import { runMigrationsAsync } from './migrate'; import { provider } from './web3_wrapper';
const artifactsDir = path.resolve('test', 'artifacts');
const deployerOpts = { const deployerOpts = {
artifactsDir: path.resolve('src', 'artifacts'), artifactsDir,
jsonrpcUrl: devConstants.RPC_URL, provider,
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
defaults: { defaults: {
gas: devConstants.GAS_ESTIMATE, gas: devConstants.GAS_ESTIMATE,
}, },
}; };
export const deployer = new Deployer(deployerOpts); export const deployer = new Deployer(deployerOpts);
runMigrationsAsync(deployer).catch(console.log);

View File

@ -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 { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as Web3 from 'web3'; import * as Web3 from 'web3';
export const web3 = web3Factory.create(); import { constants } from './constants';
export const web3Wrapper = new Web3Wrapper(web3.currentProvider);
const web3 = web3Factory.create({ shouldUseInProcessGanache: true });
const provider: Provider = web3.currentProvider;
const web3Wrapper = new Web3Wrapper(web3.currentProvider);
export { provider, web3Wrapper };

View File

@ -9,7 +9,7 @@
"build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
"clean": "shx rm -rf lib test_temp scripts", "clean": "shx rm -rf lib test_temp scripts",
"lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'",
"run_mocha": "mocha lib/test/**/*_test.js", "run_mocha": "mocha lib/test/**/*_test.js --exit",
"prepublishOnly": "run-p build", "prepublishOnly": "run-p build",
"test": "run-s clean build run_mocha", "test": "run-s clean build run_mocha",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",

View File

@ -17,7 +17,7 @@
"clean": "shx rm -rf lib test_temp scripts", "clean": "shx rm -rf lib test_temp scripts",
"copy_test_fixtures": "copyfiles -u 2 './test/fixtures/**/*.json' ./lib/test/fixtures", "copy_test_fixtures": "copyfiles -u 2 './test/fixtures/**/*.json' ./lib/test/fixtures",
"lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'",
"run_mocha": "mocha lib/test/**/*_test.js", "run_mocha": "mocha lib/test/**/*_test.js --exit",
"test": "run-s clean build copy_test_fixtures run_mocha", "test": "run-s clean build copy_test_fixtures run_mocha",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",

View File

@ -72,17 +72,6 @@ yarn lint
### Run Tests ### Run Tests
Before running the tests, you will need to spin up a [TestRPC](https://www.npmjs.com/package/ethereumjs-testrpc) instance.
In a separate terminal, start TestRPC (a convenience command is provided as part of the [0x.js monorepo](https://github.com/0xProject/0x-monorepo))
```bash
cd ../..
yarn testrpc
```
Then in your main terminal run
```bash ```bash
yarn test yarn test
``` ```

View File

@ -1,10 +0,0 @@
import { MultiSigConfigByNetwork } from '../types';
// Make a copy of this file named `multisig.js` and input custom params as needed
export const multiSig: MultiSigConfigByNetwork = {
kovan: {
owners: [],
confirmationsRequired: 0,
secondsRequired: 0,
},
};

View File

@ -1,23 +0,0 @@
export interface MultiSigConfig {
owners: string[];
confirmationsRequired: number;
secondsRequired: number;
}
export interface MultiSigConfigByNetwork {
[networkName: string]: MultiSigConfig;
}
export interface Token {
address?: string;
name: string;
symbol: string;
decimals: number;
ipfsHash: string;
swarmHash: string;
}
export interface TokenInfoByNetwork {
development: Token[];
live: Token[];
}

View File

@ -10,16 +10,15 @@
"scripts": { "scripts": {
"build:watch": "tsc -w", "build:watch": "tsc -w",
"prebuild": "run-s clean compile copy_artifacts generate_contract_wrappers", "prebuild": "run-s clean compile copy_artifacts generate_contract_wrappers",
"copy_artifacts": "copyfiles './src/artifacts/**/*' ./lib", "copy_artifacts": "copyfiles -u 4 '../migrations/src/artifacts/**/*' ./lib/src/artifacts;",
"build": "tsc", "build": "tsc",
"test": "run-s build run_mocha", "test": "run-s build run_mocha",
"test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov", "test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov",
"run_mocha": "mocha 'lib/test/**/*.js' --timeout 100000 --bail --exit", "run_mocha": "mocha 'lib/test/**/*.js' --timeout 100000 --bail --exit",
"compile:comment": "Yarn workspaces do not link binaries correctly so we need to reference them directly https://github.com/yarnpkg/yarn/issues/3846", "compile:comment": "Yarn workspaces do not link binaries correctly so we need to reference them directly https://github.com/yarnpkg/yarn/issues/3846",
"compile": "node ../deployer/lib/src/cli.js compile --contracts ${npm_package_config_contracts} --contract-dirs src/contracts --artifacts-dir src/artifacts", "compile": "node ../deployer/lib/src/cli.js compile --contracts ${npm_package_config_contracts} --contract-dirs src/contracts --artifacts-dir ../migrations/src/artifacts",
"clean": "shx rm -rf ./lib", "clean": "shx rm -rf ./lib",
"generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis ${npm_package_config_abis} --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 ${npm_package_config_abis} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'",
"migrate": "yarn build && yarn compile && node ./lib/migrations/index.js",
"lint": "tslint --project . 'migrations/**/*.ts' 'test/**/*.ts' 'util/**/*.ts' 'deploy/**/*.ts'", "lint": "tslint --project . 'migrations/**/*.ts' 'test/**/*.ts' 'util/**/*.ts' 'deploy/**/*.ts'",
"coverage:report:text": "istanbul report text", "coverage:report:text": "istanbul report text",
"coverage:report:html": "istanbul report html && open coverage/index.html", "coverage:report:html": "istanbul report html && open coverage/index.html",
@ -27,7 +26,7 @@
"test:circleci": "yarn test:coverage" "test:circleci": "yarn test:coverage"
}, },
"config": { "config": {
"abis": "src/artifacts/@(DummyToken|TokenTransferProxy|Exchange|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|Arbitrage|EtherDelta|AccountLevels).json", "abis": "../migrations/src/artifacts/@(DummyToken|TokenTransferProxy|Exchange|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|Arbitrage|EtherDelta|AccountLevels).json",
"contracts": "Exchange,DummyToken,ZRXToken,Token,WETH9,TokenTransferProxy,MultiSigWallet,MultiSigWalletWithTimeLock,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,MaliciousToken,TokenRegistry,Arbitrage,EtherDelta,AccountLevels" "contracts": "Exchange,DummyToken,ZRXToken,Token,WETH9,TokenTransferProxy,MultiSigWallet,MultiSigWalletWithTimeLock,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,MaliciousToken,TokenRegistry,Arbitrage,EtherDelta,AccountLevels"
}, },
"repository": { "repository": {

View File

@ -46,7 +46,7 @@ describe('MultiSigWalletWithTimeLock', () => {
describe('changeTimeLock', () => { describe('changeTimeLock', () => {
describe('initially non-time-locked', async () => { describe('initially non-time-locked', async () => {
before('deploy a walet', async () => { before('deploy a wallet', async () => {
const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [ const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [
owners, owners,
SIGNATURES_REQUIRED, SIGNATURES_REQUIRED,
@ -143,7 +143,7 @@ describe('MultiSigWalletWithTimeLock', () => {
}); });
}); });
describe('initially time-locked', async () => { describe('initially time-locked', async () => {
before('deploy a walet', async () => { before('deploy a wallet', async () => {
const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [ const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [
owners, owners,
SIGNATURES_REQUIRED, SIGNATURES_REQUIRED,

View File

@ -1,6 +1,6 @@
import { ZeroEx } from '0x.js'; import { ZeroEx } from '0x.js';
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils'; import { BigNumber, NULL_BYTES } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai'; import * as chai from 'chai';
import ethUtil = require('ethereumjs-util'); import ethUtil = require('ethereumjs-util');
@ -66,8 +66,8 @@ describe('TokenRegistry', () => {
name: '', name: '',
symbol: '', symbol: '',
decimals: 0, decimals: 0,
ipfsHash: constants.NULL_BYTES, ipfsHash: NULL_BYTES,
swarmHash: constants.NULL_BYTES, swarmHash: NULL_BYTES,
}; };
describe('addToken', () => { describe('addToken', () => {

View File

@ -8,7 +8,7 @@ import { web3 } from './web3_wrapper';
const deployerOpts = { const deployerOpts = {
provider: web3.currentProvider, provider: web3.currentProvider,
artifactsDir: path.resolve('src', 'artifacts'), artifactsDir: path.resolve('lib', 'src', 'artifacts'),
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
defaults: { defaults: {
gas: devConstants.GAS_ESTIMATE, gas: devConstants.GAS_ESTIMATE,

View File

@ -1,7 +1,8 @@
import { web3Factory } from '@0xproject/dev-utils'; import { web3Factory } from '@0xproject/dev-utils';
import { Provider } from '@0xproject/types';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
const web3ProviderConfig = { shouldUseInProcessGanache: true }; const providerConfigs = { shouldUseInProcessGanache: true };
export const web3 = web3Factory.create(web3ProviderConfig); export const web3 = web3Factory.create(providerConfigs);
export const provider = web3.currentProvider; export const provider = web3.currentProvider;
export const web3Wrapper = new Web3Wrapper(provider); export const web3Wrapper = new Web3Wrapper(provider);

View File

@ -4,7 +4,6 @@ const DUMMY_TOKEN_DECIMALS = 18;
const DUMMY_TOKEN_TOTAL_SUPPLY = 0; const DUMMY_TOKEN_TOTAL_SUPPLY = 0;
export const constants = { export const constants = {
NULL_BYTES: '0x',
INVALID_OPCODE: 'invalid opcode', INVALID_OPCODE: 'invalid opcode',
REVERT: 'revert', REVERT: 'revert',
TESTRPC_NETWORK_ID: 50, TESTRPC_NETWORK_ID: 50,

View File

@ -8,7 +8,7 @@
"build:watch": "tsc -w", "build:watch": "tsc -w",
"build": "yarn clean && copyfiles 'test/fixtures/contracts/**/*' ./lib && tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "build": "yarn clean && copyfiles 'test/fixtures/contracts/**/*' ./lib && tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
"test": "run-s build run_mocha", "test": "run-s build run_mocha",
"run_mocha": "mocha lib/test/*_test.js", "run_mocha": "mocha lib/test/*_test.js --bail --exit",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"compile": "npm run build; node lib/src/cli.js compile", "compile": "npm run build; node lib/src/cli.js compile",
@ -47,7 +47,7 @@
}, },
"homepage": "https://github.com/0xProject/0x-monorepo/packages/deployer/README.md", "homepage": "https://github.com/0xProject/0x-monorepo/packages/deployer/README.md",
"devDependencies": { "devDependencies": {
"@0xproject/dev-utils": "^0.2.1", "@0xproject/dev-utils": "^0.3.4",
"@0xproject/monorepo-scripts": "^0.1.17", "@0xproject/monorepo-scripts": "^0.1.17",
"@0xproject/tslint-config": "^0.4.15", "@0xproject/tslint-config": "^0.4.15",
"@types/require-from-string": "^1.2.0", "@types/require-from-string": "^1.2.0",

View File

@ -41,8 +41,8 @@ async function onCompileCommandAsync(argv: CliOptions): Promise<void> {
*/ */
async function onDeployCommandAsync(argv: CliOptions): Promise<void> { async function onDeployCommandAsync(argv: CliOptions): Promise<void> {
const url = argv.jsonrpcUrl; const url = argv.jsonrpcUrl;
const web3Provider = new Web3.providers.HttpProvider(url); const provider = new Web3.providers.HttpProvider(url);
const web3Wrapper = new Web3Wrapper(web3Provider); const web3Wrapper = new Web3Wrapper(provider);
const networkId = await web3Wrapper.getNetworkIdAsync(); const networkId = await web3Wrapper.getNetworkIdAsync();
const compilerOpts: CompilerOptions = { const compilerOpts: CompilerOptions = {
contractDirs: getContractDirectoriesFromList(argv.contractDirs), contractDirs: getContractDirectoriesFromList(argv.contractDirs),

View File

@ -38,17 +38,17 @@ export class Deployer {
this._artifactsDir = opts.artifactsDir; this._artifactsDir = opts.artifactsDir;
this._networkId = opts.networkId; this._networkId = opts.networkId;
this._defaults = opts.defaults; this._defaults = opts.defaults;
let web3Provider: Provider; let provider: Provider;
if (_.isUndefined((opts as ProviderDeployerOptions).provider)) { if (_.isUndefined((opts as ProviderDeployerOptions).provider)) {
const jsonrpcUrl = (opts as UrlDeployerOptions).jsonrpcUrl; const jsonrpcUrl = (opts as UrlDeployerOptions).jsonrpcUrl;
if (_.isUndefined(jsonrpcUrl)) { if (_.isUndefined(jsonrpcUrl)) {
throw new Error(`Deployer options don't contain web3Provider nor jsonrpcUrl. Please pass one of them`); throw new Error(`Deployer options don't contain provider nor jsonrpcUrl. Please pass one of them`);
} }
web3Provider = new Web3.providers.HttpProvider(jsonrpcUrl); provider = new Web3.providers.HttpProvider(jsonrpcUrl);
} else { } else {
web3Provider = (opts as ProviderDeployerOptions).provider; provider = (opts as ProviderDeployerOptions).provider;
} }
this.web3Wrapper = new Web3Wrapper(web3Provider, this._defaults); this.web3Wrapper = new Web3Wrapper(provider, this._defaults);
} }
/** /**
* Loads a contract's corresponding artifacts and deploys it with the supplied constructor arguments. * Loads a contract's corresponding artifacts and deploys it with the supplied constructor arguments.
@ -170,7 +170,7 @@ export class Deployer {
const contractArtifact: ContractArtifact = require(artifactPath); const contractArtifact: ContractArtifact = require(artifactPath);
return contractArtifact; return contractArtifact;
} catch (err) { } catch (err) {
throw new Error(`Artifact not found for contract: ${contractName}`); throw new Error(`Artifact not found for contract: ${contractName} at ${artifactPath}`);
} }
} }
/** /**

View File

@ -14,6 +14,7 @@ import {
import { constructor_args, exchange_binary } from './fixtures/exchange_bin'; import { constructor_args, exchange_binary } from './fixtures/exchange_bin';
import { constants } from './util/constants'; import { constants } from './util/constants';
import { provider } from './util/provider';
const expect = chai.expect; const expect = chai.expect;
@ -36,7 +37,7 @@ describe('#Deployer', () => {
const deployerOpts = { const deployerOpts = {
artifactsDir, artifactsDir,
networkId: constants.networkId, networkId: constants.networkId,
jsonrpcUrl: constants.jsonrpcUrl, provider,
defaults: { defaults: {
gasPrice: constants.gasPrice, gasPrice: constants.gasPrice,
}, },

View File

@ -2,7 +2,6 @@ import { BigNumber } from '@0xproject/utils';
export const constants = { export const constants = {
networkId: 0, networkId: 0,
jsonrpcUrl: 'http://localhost:8545',
optimizerEnabled: false, optimizerEnabled: false,
gasPrice: new BigNumber(20000000000), gasPrice: new BigNumber(20000000000),
timeoutMs: 30000, timeoutMs: 30000,

View File

@ -0,0 +1,9 @@
import { web3Factory } from '@0xproject/dev-utils';
import { Provider } from '@0xproject/types';
import * as Web3 from 'web3';
const providerConfigs = { shouldUseInProcessGanache: true };
const web3Instance = web3Factory.create(providerConfigs);
const provider: Provider = web3Instance.currentProvider;
export { provider };

View File

@ -8,8 +8,8 @@ import { BlockchainLifecycle, web3Factory } from '../src';
const expect = chai.expect; const expect = chai.expect;
describe('BlockchainLifecycle tests', () => { describe('BlockchainLifecycle tests', () => {
const web3Provider = web3Factory.getRpcProvider(); const provider = web3Factory.getRpcProvider({ shouldUseInProcessGanache: true });
const web3Wrapper = new Web3Wrapper(web3Provider); const web3Wrapper = new Web3Wrapper(provider);
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('#startAsync/revertAsync', () => { describe('#startAsync/revertAsync', () => {
it('reverts changes in between', async () => { it('reverts changes in between', async () => {

View File

@ -8,8 +8,8 @@ import { web3Factory } from '../src';
const expect = chai.expect; const expect = chai.expect;
describe('RPC tests', () => { describe('RPC tests', () => {
const web3Provider = web3Factory.getRpcProvider(); const provider = web3Factory.getRpcProvider({ shouldUseInProcessGanache: true });
const web3Wrapper = new Web3Wrapper(web3Provider); const web3Wrapper = new Web3Wrapper(provider);
describe('#mineBlockAsync', () => { describe('#mineBlockAsync', () => {
it('increases block number when called', async () => { it('increases block number when called', async () => {
const blockNumberBefore = await web3Wrapper.getBlockNumberAsync(); const blockNumberBefore = await web3Wrapper.getBlockNumberAsync();

View File

@ -11,7 +11,7 @@
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"test:circleci": "yarn test:coverage", "test:circleci": "yarn test:coverage",
"run_mocha": "mocha lib/test/**/*_test.js", "run_mocha": "mocha lib/test/**/*_test.js --exit",
"clean": "shx rm -rf lib test_temp scripts", "clean": "shx rm -rf lib test_temp scripts",
"build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
"manual:postpublish": "yarn build; node ./scripts/postpublish.js", "manual:postpublish": "yarn build; node ./scripts/postpublish.js",

View File

@ -12,7 +12,7 @@
"build": "tsc", "build": "tsc",
"test": "run-s build run_mocha", "test": "run-s build run_mocha",
"test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov", "test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov",
"run_mocha": "mocha 'lib/test/**/*.js'", "run_mocha": "mocha lib/test/**/*.js --bail --exit",
"generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'artifacts/Metacoin.json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers --backend ethers && prettier --write 'src/contract_wrappers/**.ts'", "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'artifacts/Metacoin.json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers --backend ethers && prettier --write 'src/contract_wrappers/**.ts'",
"coverage:report:text": "istanbul report text", "coverage:report:text": "istanbul report text",
"coverage:report:html": "istanbul report html && open coverage/index.html", "coverage:report:html": "istanbul report html && open coverage/index.html",

View File

@ -0,0 +1,69 @@
## Migrations
Migrate the 0x system of smart contracts on the network of your choice using these migrations.
## Contributing
We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.
Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
### Install dependencies
If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
```bash
yarn config set workspaces-experimental true
```
Then install dependencies
```bash
yarn install
```
### Build
If this is your **first** time building this package, you must first build **all** packages within the monorepo. This is because packages that depend on other packages located inside this monorepo are symlinked when run from **within** the monorepo. This allows you to make changes across multiple packages without first publishing dependent packages to NPM. To build all packages, run the following from the monorepo root directory:
```bash
yarn lerna:rebuild
```
Or continuously rebuild on change:
```bash
yarn dev
```
You can also build this specific package by running the following from within its directory:
```bash
yarn build
```
or continuously rebuild on change:
```bash
yarn build:watch
```
### Clean
```bash
yarn clean
```
### Lint
```bash
yarn lint
```
### Migrate
In order to migrate the 0x smart contracts to TestRPC/Ganache running at `http://localhost:8545`, run:
```bash
yarn migrate
```

View File

@ -0,0 +1,36 @@
{
"private": true,
"name": "@0xproject/migrations",
"version": "0.0.1",
"description": "0x smart contract migrations",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build:watch": "tsc -w",
"build": "tsc",
"clean": "shx rm -rf lib",
"lint": "tslint --project . 'src/**/*.ts'",
"migrate": "run-s build compile script:migrate",
"script:migrate": "node ./lib/migrate.js",
"copy_artifacts": "copyfiles 'src/artifacts/**/*' ./lib",
"compile": "node ../deployer/lib/src/cli.js compile --contracts ${npm_package_config_contracts} --contracts-dir ../contracts/src/contracts --artifacts-dir src/artifacts"
},
"config": {
"contracts": "Exchange,DummyToken,ZRXToken,Token,WETH9,TokenTransferProxy,MultiSigWallet,MultiSigWalletWithTimeLock,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,MaliciousToken,TokenRegistry,Arbitrage,EtherDelta,AccountLevels"
},
"license": "Apache-2.0",
"devDependencies": {
"@0xproject/tslint-config": "^0.4.14",
"@0xproject/dev-utils": "^0.3.4",
"npm-run-all": "^4.1.2",
"shx": "^0.2.2",
"tslint": "5.8.0",
"typescript": "2.7.1"
},
"dependencies": {
"@0xproject/deployer": "^0.4.0",
"@0xproject/utils": "^0.5.0",
"@0xproject/web3-wrapper": "^0.5.0",
"lodash": "^4.17.4"
}
}

6
packages/migrations/src/globals.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
declare module '*.json' {
const json: any;
/* tslint:disable */
export default json;
/* tslint:enable */
}

View File

@ -0,0 +1 @@
export { runMigrationsAsync } from './migration';

View File

@ -0,0 +1,25 @@
#!/usr/bin/env node
import { Deployer } from '@0xproject/deployer';
import { devConstants } from '@0xproject/dev-utils';
import { logUtils } from '@0xproject/utils';
import * as path from 'path';
import { runMigrationsAsync } from './migration';
(async () => {
const deployerOpts = {
jsonrpcUrl: 'http://localhost:8545',
artifactsDir: path.resolve('src', 'artifacts'),
networkId: 50,
defaults: {
gas: devConstants.GAS_ESTIMATE,
},
};
const deployer = new Deployer(deployerOpts);
await runMigrationsAsync(deployer);
})().catch(err => {
logUtils.log(err);
process.exit(1);
});

View File

@ -1,12 +1,10 @@
import { Deployer } from '@0xproject/deployer'; import { Deployer } from '@0xproject/deployer';
import { BigNumber } from '@0xproject/utils'; import { BigNumber, NULL_BYTES } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { constants } from '../util/constants'; import { ContractName } from './types';
import { ContractName } from '../util/types'; import { tokenInfo } from './utils/token_info';
import { tokenInfo } from './config/token_info';
/** /**
* Custom migrations should be defined in this function. This will be called with the CLI 'migrate' command. * Custom migrations should be defined in this function. This will be called with the CLI 'migrate' command.
@ -20,7 +18,7 @@ export const runMigrationsAsync = async (deployer: Deployer) => {
const tokenTransferProxy = await deployer.deployAndSaveAsync(ContractName.TokenTransferProxy); const tokenTransferProxy = await deployer.deployAndSaveAsync(ContractName.TokenTransferProxy);
const zrxToken = await deployer.deployAndSaveAsync(ContractName.ZRXToken); const zrxToken = await deployer.deployAndSaveAsync(ContractName.ZRXToken);
const etherToken = await deployer.deployAndSaveAsync(ContractName.EtherToken); const etherToken = await deployer.deployAndSaveAsync(ContractName.WETH9);
const tokenReg = await deployer.deployAndSaveAsync(ContractName.TokenRegistry); const tokenReg = await deployer.deployAndSaveAsync(ContractName.TokenRegistry);
const exchangeArgs = [zrxToken.address, tokenTransferProxy.address]; const exchangeArgs = [zrxToken.address, tokenTransferProxy.address];
@ -51,8 +49,8 @@ export const runMigrationsAsync = async (deployer: Deployer) => {
'0x Protocol Token', '0x Protocol Token',
'ZRX', 'ZRX',
18, 18,
constants.NULL_BYTES, NULL_BYTES,
constants.NULL_BYTES, NULL_BYTES,
{ {
from: owner, from: owner,
gas: addTokenGasEstimate, gas: addTokenGasEstimate,
@ -63,8 +61,8 @@ export const runMigrationsAsync = async (deployer: Deployer) => {
'Ether Token', 'Ether Token',
'WETH', 'WETH',
18, 18,
constants.NULL_BYTES, NULL_BYTES,
constants.NULL_BYTES, NULL_BYTES,
{ {
from: owner, from: owner,
gas: addTokenGasEstimate, gas: addTokenGasEstimate,

View File

@ -0,0 +1,38 @@
export interface MultiSigConfig {
owners: string[];
confirmationsRequired: number;
secondsRequired: number;
}
export interface MultiSigConfigByNetwork {
[networkName: string]: MultiSigConfig;
}
export interface Token {
address?: string;
name: string;
symbol: string;
decimals: number;
ipfsHash: string;
swarmHash: string;
}
export interface TokenInfoByNetwork {
development: Token[];
live: Token[];
}
export enum ContractName {
TokenTransferProxy = 'TokenTransferProxy',
TokenRegistry = 'TokenRegistry',
MultiSigWalletWithTimeLock = 'MultiSigWalletWithTimeLock',
Exchange = 'Exchange',
ZRXToken = 'ZRXToken',
DummyToken = 'DummyToken',
WETH9 = 'WETH9',
MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress = 'MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress',
MaliciousToken = 'MaliciousToken',
AccountLevels = 'AccountLevels',
EtherDelta = 'EtherDelta',
Arbitrage = 'Arbitrage',
}

View File

@ -1,4 +1,5 @@
import { constants } from '../../util/constants'; import { NULL_BYTES } from '@0xproject/utils';
import { Token } from '../types'; import { Token } from '../types';
export const tokenInfo: Token[] = [ export const tokenInfo: Token[] = [
@ -6,35 +7,35 @@ export const tokenInfo: Token[] = [
name: 'Augur Reputation Token', name: 'Augur Reputation Token',
symbol: 'REP', symbol: 'REP',
decimals: 18, decimals: 18,
ipfsHash: constants.NULL_BYTES, ipfsHash: NULL_BYTES,
swarmHash: constants.NULL_BYTES, swarmHash: NULL_BYTES,
}, },
{ {
name: 'Digix DAO Token', name: 'Digix DAO Token',
symbol: 'DGD', symbol: 'DGD',
decimals: 18, decimals: 18,
ipfsHash: constants.NULL_BYTES, ipfsHash: NULL_BYTES,
swarmHash: constants.NULL_BYTES, swarmHash: NULL_BYTES,
}, },
{ {
name: 'Golem Network Token', name: 'Golem Network Token',
symbol: 'GNT', symbol: 'GNT',
decimals: 18, decimals: 18,
ipfsHash: constants.NULL_BYTES, ipfsHash: NULL_BYTES,
swarmHash: constants.NULL_BYTES, swarmHash: NULL_BYTES,
}, },
{ {
name: 'MakerDAO', name: 'MakerDAO',
symbol: 'MKR', symbol: 'MKR',
decimals: 18, decimals: 18,
ipfsHash: constants.NULL_BYTES, ipfsHash: NULL_BYTES,
swarmHash: constants.NULL_BYTES, swarmHash: NULL_BYTES,
}, },
{ {
name: 'Melon Token', name: 'Melon Token',
symbol: 'MLN', symbol: 'MLN',
decimals: 18, decimals: 18,
ipfsHash: constants.NULL_BYTES, ipfsHash: NULL_BYTES,
swarmHash: constants.NULL_BYTES, swarmHash: NULL_BYTES,
}, },
]; ];

View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib"
},
"include": ["src/**/*"]
}

View File

@ -0,0 +1,3 @@
{
"extends": ["@0xproject/tslint-config"]
}

View File

@ -11,7 +11,7 @@
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"test:circleci": "yarn test:coverage", "test:circleci": "yarn test:coverage",
"run_mocha": "mocha lib/test/**/*_test.js", "run_mocha": "mocha lib/test/**/*_test.js --exit",
"clean": "shx rm -rf lib scripts", "clean": "shx rm -rf lib scripts",
"build": "copyfiles 'test/fixtures/**/*' ./lib && tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "build": "copyfiles 'test/fixtures/**/*' ./lib && tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
"manual:postpublish": "yarn build; node ./scripts/postpublish.js", "manual:postpublish": "yarn build; node ./scripts/postpublish.js",

View File

@ -56,8 +56,8 @@ export class CoverageSubprovider extends Subprovider {
* @param next Callback to call if this subprovider decides not to handle the request * @param next Callback to call if this subprovider decides not to handle the request
* @param end Callback to call if subprovider handled the request and wants to pass back the request. * @param end Callback to call if subprovider handled the request and wants to pass back the request.
*/ */
// tslint:disable-next-line:prefer-function-over-method // tslint:disable-next-line:prefer-function-over-method async-suffix
public handleRequest(payload: JSONRPCRequestPayload, next: NextCallback, end: ErrorCallback) { public async handleRequest(payload: JSONRPCRequestPayload, next: NextCallback, end: ErrorCallback) {
switch (payload.method) { switch (payload.method) {
case 'eth_sendTransaction': case 'eth_sendTransaction':
const txData = payload.params[0]; const txData = payload.params[0];

View File

@ -12,7 +12,7 @@
"test": "run-s clean build copy_test_environments copy_test_fixtures run_mocha", "test": "run-s clean build copy_test_environments copy_test_fixtures run_mocha",
"copy_test_fixtures": "copyfiles -u 2 './test/fixtures/**/*.json' ./lib/test/fixtures", "copy_test_fixtures": "copyfiles -u 2 './test/fixtures/**/*.json' ./lib/test/fixtures",
"copy_test_environments": "copyfiles -u 2 './test/environments/**/*.json' ./lib/test/environments", "copy_test_environments": "copyfiles -u 2 './test/environments/**/*.json' ./lib/test/environments",
"run_mocha": "mocha lib/test/**/*_test.js", "run_mocha": "mocha lib/test/**/*_test.js --exit",
"manual:postpublish": "yarn build; node ./scripts/postpublish.js" "manual:postpublish": "yarn build; node ./scripts/postpublish.js"
}, },
"bin": { "bin": {

View File

@ -1,7 +1,12 @@
[ [
{ {
"version": "0.8.5", "version": "0.9.0",
"changes": [ "changes": [
{
"note":
"Refactor RedundantRPCSubprovider into RedundantSubprovider where it now accepts an array of subproviders rather then an array of RPC endpoints",
"pr": 500
},
{ {
"note": "Add private key subprovider and refactor shared functionality into a base wallet subprovider", "note": "Add private key subprovider and refactor shared functionality into a base wallet subprovider",
"pr": 506 "pr": 506

View File

@ -7,7 +7,7 @@ import { LedgerEthereumClient } from './types';
export { EmptyWalletSubprovider } from './subproviders/empty_wallet_subprovider'; export { EmptyWalletSubprovider } from './subproviders/empty_wallet_subprovider';
export { FakeGasEstimateSubprovider } from './subproviders/fake_gas_estimate_subprovider'; export { FakeGasEstimateSubprovider } from './subproviders/fake_gas_estimate_subprovider';
export { InjectedWeb3Subprovider } from './subproviders/injected_web3'; export { InjectedWeb3Subprovider } from './subproviders/injected_web3';
export { RedundantRPCSubprovider } from './subproviders/redundant_rpc'; export { RedundantSubprovider } from './subproviders/redundant_subprovider';
export { LedgerSubprovider } from './subproviders/ledger'; export { LedgerSubprovider } from './subproviders/ledger';
export { GanacheSubprovider } from './subproviders/ganache'; export { GanacheSubprovider } from './subproviders/ganache';
export { Subprovider } from './subproviders/subprovider'; export { Subprovider } from './subproviders/subprovider';

View File

@ -17,8 +17,8 @@ export class EmptyWalletSubprovider extends Subprovider {
* @param next Callback to call if this subprovider decides not to handle the request * @param next Callback to call if this subprovider decides not to handle the request
* @param end Callback to call if subprovider handled the request and wants to pass back the request. * @param end Callback to call if subprovider handled the request and wants to pass back the request.
*/ */
// tslint:disable-next-line:prefer-function-over-method // tslint:disable-next-line:prefer-function-over-method async-suffix
public handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { public async handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) {
switch (payload.method) { switch (payload.method) {
case 'eth_accounts': case 'eth_accounts':
end(null, []); end(null, []);

View File

@ -31,8 +31,8 @@ export class FakeGasEstimateSubprovider extends Subprovider {
* @param next Callback to call if this subprovider decides not to handle the request * @param next Callback to call if this subprovider decides not to handle the request
* @param end Callback to call if subprovider handled the request and wants to pass back the request. * @param end Callback to call if subprovider handled the request and wants to pass back the request.
*/ */
// tslint:disable-next-line:prefer-function-over-method // tslint:disable-next-line:prefer-function-over-method async-suffix
public handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { public async handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) {
switch (payload.method) { switch (payload.method) {
case 'eth_estimateGas': case 'eth_estimateGas':
end(null, this._constantGasAmount); end(null, this._constantGasAmount);

View File

@ -27,8 +27,8 @@ export class GanacheSubprovider extends Subprovider {
* @param next Callback to call if this subprovider decides not to handle the request * @param next Callback to call if this subprovider decides not to handle the request
* @param end Callback to call if subprovider handled the request and wants to pass back the request. * @param end Callback to call if subprovider handled the request and wants to pass back the request.
*/ */
// tslint:disable-next-line:prefer-function-over-method // tslint:disable-next-line:prefer-function-over-method async-suffix
public handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { public async handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) {
this._ganacheProvider.sendAsync(payload, (err: Error | null, result: any) => { this._ganacheProvider.sendAsync(payload, (err: Error | null, result: any) => {
end(err, result && result.result); end(err, result && result.result);
}); });

View File

@ -30,8 +30,8 @@ export class InjectedWeb3Subprovider extends Subprovider {
* @param next Callback to call if this subprovider decides not to handle the request * @param next Callback to call if this subprovider decides not to handle the request
* @param end Callback to call if subprovider handled the request and wants to pass back the request. * @param end Callback to call if subprovider handled the request and wants to pass back the request.
*/ */
// tslint:disable-next-line:prefer-function-over-method // tslint:disable-next-line:prefer-function-over-method async-suffix
public handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) { public async handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback) {
switch (payload.method) { switch (payload.method) {
case 'web3_clientVersion': case 'web3_clientVersion':
this._injectedWeb3.version.getNode(end); this._injectedWeb3.version.getNode(end);

View File

@ -1,7 +1,6 @@
import { JSONRPCRequestPayload } from '@0xproject/types'; import { JSONRPCRequestPayload } from '@0xproject/types';
import { promisify } from '@0xproject/utils'; import { promisify } from '@0xproject/utils';
import * as _ from 'lodash'; import * as _ from 'lodash';
import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
import { Callback } from '../types'; import { Callback } from '../types';
@ -12,17 +11,17 @@ import { Subprovider } from './subprovider';
* It attempts to handle each JSON RPC request by sequentially attempting to receive a valid response from one of a * It attempts to handle each JSON RPC request by sequentially attempting to receive a valid response from one of a
* set of JSON RPC endpoints. * set of JSON RPC endpoints.
*/ */
export class RedundantRPCSubprovider extends Subprovider { export class RedundantSubprovider extends Subprovider {
private _rpcs: RpcSubprovider[]; private _subproviders: Subprovider[];
private static async _firstSuccessAsync( private static async _firstSuccessAsync(
rpcs: RpcSubprovider[], subproviders: Subprovider[],
payload: JSONRPCRequestPayload, payload: JSONRPCRequestPayload,
next: Callback, next: Callback,
): Promise<any> { ): Promise<any> {
let lastErr: Error | undefined; let lastErr: Error | undefined;
for (const rpc of rpcs) { for (const subprovider of subproviders) {
try { try {
const data = await promisify(rpc.handleRequest.bind(rpc))(payload, next); const data = await promisify(subprovider.handleRequest.bind(subprovider))(payload, next);
return data; return data;
} catch (err) { } catch (err) {
lastErr = err; lastErr = err;
@ -34,16 +33,12 @@ export class RedundantRPCSubprovider extends Subprovider {
} }
} }
/** /**
* Instantiates a new RedundantRPCSubprovider * Instantiates a new RedundantSubprovider
* @param endpoints JSON RPC endpoints to attempt. Attempts are made in the order of the endpoints. * @param endpoints JSON RPC endpoints to attempt. Attempts are made in the order of the endpoints.
*/ */
constructor(endpoints: string[]) { constructor(subproviders: Subprovider[]) {
super(); super();
this._rpcs = _.map(endpoints, endpoint => { this._subproviders = subproviders;
return new RpcSubprovider({
rpcUrl: endpoint,
});
});
} }
/** /**
* This method conforms to the web3-provider-engine interface. * This method conforms to the web3-provider-engine interface.
@ -59,9 +54,9 @@ export class RedundantRPCSubprovider extends Subprovider {
next: Callback, next: Callback,
end: (err: Error | null, data?: any) => void, end: (err: Error | null, data?: any) => void,
): Promise<void> { ): Promise<void> {
const rpcsCopy = this._rpcs.slice(); const subprovidersCopy = this._subproviders.slice();
try { try {
const data = await RedundantRPCSubprovider._firstSuccessAsync(rpcsCopy, payload, next); const data = await RedundantSubprovider._firstSuccessAsync(subprovidersCopy, payload, next);
end(null, data); end(null, data);
} catch (err) { } catch (err) {
end(err); end(err);

View File

@ -2,13 +2,14 @@ import { JSONRPCRequestPayload, JSONRPCResponsePayload } from '@0xproject/types'
import { promisify } from '@0xproject/utils'; import { promisify } from '@0xproject/utils';
import * as Web3 from 'web3'; import * as Web3 from 'web3';
import { JSONRPCRequestPayloadWithMethod } from '../types'; import { Callback, ErrorCallback, JSONRPCRequestPayloadWithMethod } from '../types';
/** /**
* A altered version of the base class Subprovider found in [web3-provider-engine](https://github.com/MetaMask/provider-engine). * A altered version of the base class Subprovider found in [web3-provider-engine](https://github.com/MetaMask/provider-engine).
* This one has an async/await `emitPayloadAsync` and also defined types. * This one has an async/await `emitPayloadAsync` and also defined types.
*/ */
export class Subprovider { export abstract class Subprovider {
private _engine: any; // tslint:disable-next-line:underscore-private-and-protected
private engine: any;
// Ported from: https://github.com/MetaMask/provider-engine/blob/master/util/random-id.js // Ported from: https://github.com/MetaMask/provider-engine/blob/master/util/random-id.js
private static _getRandomId() { private static _getRandomId() {
const extraDigits = 3; const extraDigits = 3;
@ -31,6 +32,13 @@ export class Subprovider {
}; };
return finalPayload; return finalPayload;
} }
// tslint:disable-next-line:async-suffix
public abstract async handleRequest(
payload: JSONRPCRequestPayload,
next: Callback,
end: ErrorCallback,
): Promise<void>;
/** /**
* Emits a JSON RPC payload that will then be handled by the ProviderEngine instance * Emits a JSON RPC payload that will then be handled by the ProviderEngine instance
* this subprovider is a part of. The payload will cascade down the subprovider middleware * this subprovider is a part of. The payload will cascade down the subprovider middleware
@ -40,7 +48,7 @@ export class Subprovider {
*/ */
public async emitPayloadAsync(payload: Partial<JSONRPCRequestPayloadWithMethod>): Promise<JSONRPCResponsePayload> { public async emitPayloadAsync(payload: Partial<JSONRPCRequestPayloadWithMethod>): Promise<JSONRPCResponsePayload> {
const finalPayload = Subprovider._createFinalPayload(payload); const finalPayload = Subprovider._createFinalPayload(payload);
const response = await promisify<JSONRPCResponsePayload>(this._engine.sendAsync, this._engine)(finalPayload); const response = await promisify<JSONRPCResponsePayload>(this.engine.sendAsync, this.engine)(finalPayload);
return response; return response;
} }
/** /**
@ -49,6 +57,6 @@ export class Subprovider {
* directly. * directly.
*/ */
public setEngine(engine: any): void { public setEngine(engine: any): void {
this._engine = engine; this.engine = engine;
} }
} }

View File

@ -1,7 +1,7 @@
import { JSONRPCResponsePayload } from '@0xproject/types'; import { JSONRPCResponsePayload } from '@0xproject/types';
import { promisify } from '@0xproject/utils'; import { promisify } from '@0xproject/utils';
import Eth from '@ledgerhq/hw-app-eth'; import Eth from '@ledgerhq/hw-app-eth';
// HACK: This depdency is optional and tslint skips optional depdencies // HACK: This dependency is optional and tslint skips optional dependencies
// tslint:disable-next-line:no-implicit-dependencies // tslint:disable-next-line:no-implicit-dependencies
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'; import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
import * as chai from 'chai'; import * as chai from 'chai';

View File

@ -4,7 +4,6 @@ import * as ethUtils from 'ethereumjs-util';
import * as _ from 'lodash'; import * as _ from 'lodash';
import Web3 = require('web3'); import Web3 = require('web3');
import Web3ProviderEngine = require('web3-provider-engine'); import Web3ProviderEngine = require('web3-provider-engine');
import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
import { LedgerSubprovider } from '../../src'; import { LedgerSubprovider } from '../../src';
import { import {
@ -15,6 +14,7 @@ import {
} from '../../src/types'; } from '../../src/types';
import { chaiSetup } from '../chai_setup'; import { chaiSetup } from '../chai_setup';
import { fixtureData } from '../utils/fixture_data'; import { fixtureData } from '../utils/fixture_data';
import { ganacheSubprovider } from '../utils/ganache_subprovider';
import { reportCallbackErrors } from '../utils/report_callback_errors'; import { reportCallbackErrors } from '../utils/report_callback_errors';
chaiSetup.configure(); chaiSetup.configure();
@ -105,10 +105,7 @@ describe('LedgerSubprovider', () => {
before(() => { before(() => {
provider = new Web3ProviderEngine(); provider = new Web3ProviderEngine();
provider.addProvider(ledgerSubprovider); provider.addProvider(ledgerSubprovider);
const httpProvider = new RpcSubprovider({ provider.addProvider(ganacheSubprovider);
rpcUrl: 'http://localhost:8545',
});
provider.addProvider(httpProvider);
provider.start(); provider.start();
}); });
describe('success cases', () => { describe('success cases', () => {

View File

@ -3,21 +3,24 @@ import * as chai from 'chai';
import * as _ from 'lodash'; import * as _ from 'lodash';
import Web3 = require('web3'); import Web3 = require('web3');
import Web3ProviderEngine = require('web3-provider-engine'); import Web3ProviderEngine = require('web3-provider-engine');
import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
import { RedundantRPCSubprovider } from '../../src'; import { RedundantSubprovider } from '../../src';
import { Subprovider } from '../../src/subproviders/subprovider';
import { DoneCallback } from '../../src/types'; import { DoneCallback } from '../../src/types';
import { chaiSetup } from '../chai_setup'; import { chaiSetup } from '../chai_setup';
import { ganacheSubprovider } from '../utils/ganache_subprovider';
import { reportCallbackErrors } from '../utils/report_callback_errors'; import { reportCallbackErrors } from '../utils/report_callback_errors';
const expect = chai.expect; const expect = chai.expect;
chaiSetup.configure(); chaiSetup.configure();
describe('RedundantRpcSubprovider', () => { describe('RedundantSubprovider', () => {
let provider: Web3ProviderEngine; let provider: Web3ProviderEngine;
it('succeeds when supplied a healthy endpoint', (done: DoneCallback) => { it('succeeds when supplied a healthy endpoint', (done: DoneCallback) => {
provider = new Web3ProviderEngine(); provider = new Web3ProviderEngine();
const endpoints = ['http://localhost:8545']; const subproviders = [ganacheSubprovider];
const redundantSubprovider = new RedundantRPCSubprovider(endpoints); const redundantSubprovider = new RedundantSubprovider(subproviders);
provider.addProvider(redundantSubprovider); provider.addProvider(redundantSubprovider);
provider.start(); provider.start();
@ -36,8 +39,11 @@ describe('RedundantRpcSubprovider', () => {
}); });
it('succeeds when supplied at least one healthy endpoint', (done: DoneCallback) => { it('succeeds when supplied at least one healthy endpoint', (done: DoneCallback) => {
provider = new Web3ProviderEngine(); provider = new Web3ProviderEngine();
const endpoints = ['http://does-not-exist:3000', 'http://localhost:8545']; const nonExistentSubprovider = new RpcSubprovider({
const redundantSubprovider = new RedundantRPCSubprovider(endpoints); rpcUrl: 'http://does-not-exist:3000',
});
const subproviders = [nonExistentSubprovider as Subprovider, ganacheSubprovider];
const redundantSubprovider = new RedundantSubprovider(subproviders);
provider.addProvider(redundantSubprovider); provider.addProvider(redundantSubprovider);
provider.start(); provider.start();

View File

@ -0,0 +1,5 @@
export const configs = {
port: 8545,
networkId: 50,
mnemonic: 'concert load couple harbor equip island argue ramp clarify fence smart topic',
};

View File

@ -0,0 +1,18 @@
import * as fs from 'fs';
import { GanacheSubprovider } from '../../src/subproviders/ganache';
import { configs } from '../utils/configs';
const logger = {
log: (arg: any) => {
fs.appendFileSync('ganache.log', `${arg}\n`);
},
};
export const ganacheSubprovider = new GanacheSubprovider({
logger,
verbose: false,
port: configs.port,
networkId: configs.networkId,
mnemonic: configs.mnemonic,
});

View File

@ -1,4 +1,13 @@
[ [
{
"version": "0.5.2",
"changes": [
{
"note": "Export NULL_BYTES constant",
"pr": 500
}
]
},
{ {
"timestamp": 1523462196, "timestamp": 1523462196,
"version": "0.5.1", "version": "0.5.1",

View File

@ -0,0 +1 @@
export const NULL_BYTES = '0x';

View File

@ -6,3 +6,5 @@ export { BigNumber } from './configured_bignumber';
export { AbiDecoder } from './abi_decoder'; export { AbiDecoder } from './abi_decoder';
export { logUtils } from './log_utils'; export { logUtils } from './log_utils';
export { abiUtils } from './abi_utils'; export { abiUtils } from './abi_utils';
export { NULL_BYTES } from './constants';

View File

@ -8,13 +8,9 @@
"clean": "shx rm -f public/bundle*", "clean": "shx rm -f public/bundle*",
"lint": "tslint --project . 'ts/**/*.ts' 'ts/**/*.tsx'", "lint": "tslint --project . 'ts/**/*.ts' 'ts/**/*.tsx'",
"dev": "webpack-dev-server --content-base public --https", "dev": "webpack-dev-server --content-base public --https",
"update_contracts": "for i in ${npm_package_config_artifacts}; do copyfiles -u 4 ../contracts/build/contracts/$i.json ../website/contracts; done;",
"deploy_staging": "npm run build; aws s3 sync ./public/. s3://staging-0xproject --profile 0xproject --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers", "deploy_staging": "npm run build; aws s3 sync ./public/. s3://staging-0xproject --profile 0xproject --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers",
"deploy_live": "npm run build; aws s3 sync ./public/. s3://0xproject.com --profile 0xproject --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers" "deploy_live": "npm run build; aws s3 sync ./public/. s3://0xproject.com --profile 0xproject --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers"
}, },
"config": {
"artifacts": "Mintable"
},
"author": "Fabio Berger", "author": "Fabio Berger",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {

View File

@ -21,7 +21,8 @@ import {
ledgerEthereumBrowserClientFactoryAsync, ledgerEthereumBrowserClientFactoryAsync,
LedgerSubprovider, LedgerSubprovider,
LedgerWalletSubprovider, LedgerWalletSubprovider,
RedundantRPCSubprovider, RedundantSubprovider,
Subprovider,
} from '@0xproject/subproviders'; } from '@0xproject/subproviders';
import { Provider } from '@0xproject/types'; import { Provider } from '@0xproject/types';
import { BigNumber, intervalUtils, logUtils, promisify } from '@0xproject/utils'; import { BigNumber, intervalUtils, logUtils, promisify } from '@0xproject/utils';
@ -54,6 +55,7 @@ import { utils } from 'ts/utils/utils';
import Web3 = require('web3'); import Web3 = require('web3');
import ProviderEngine = require('web3-provider-engine'); import ProviderEngine = require('web3-provider-engine');
import FilterSubprovider = require('web3-provider-engine/subproviders/filters'); import FilterSubprovider = require('web3-provider-engine/subproviders/filters');
import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
import * as MintableArtifacts from '../contracts/Mintable.json'; import * as MintableArtifacts from '../contracts/Mintable.json';
@ -98,7 +100,12 @@ export class Blockchain {
provider = new ProviderEngine(); provider = new ProviderEngine();
provider.addProvider(new InjectedWeb3Subprovider(injectedWeb3.currentProvider)); provider.addProvider(new InjectedWeb3Subprovider(injectedWeb3.currentProvider));
provider.addProvider(new FilterSubprovider()); provider.addProvider(new FilterSubprovider());
provider.addProvider(new RedundantRPCSubprovider(publicNodeUrlsIfExistsForNetworkId)); const rpcSubproviders = _.map(publicNodeUrlsIfExistsForNetworkId, publicNodeUrl => {
return new RpcSubprovider({
rpcUrl: publicNodeUrl,
});
});
provider.addProvider(new RedundantSubprovider(rpcSubproviders as Subprovider[]));
provider.start(); provider.start();
} else if (doesInjectedWeb3Exist) { } else if (doesInjectedWeb3Exist) {
// Since no public node for this network, all requests go to injectedWeb3 instance // Since no public node for this network, all requests go to injectedWeb3 instance
@ -110,7 +117,12 @@ export class Blockchain {
provider = new ProviderEngine(); provider = new ProviderEngine();
provider.addProvider(new FilterSubprovider()); provider.addProvider(new FilterSubprovider());
const networkId = configs.IS_MAINNET_ENABLED ? constants.NETWORK_ID_MAINNET : constants.NETWORK_ID_KOVAN; const networkId = configs.IS_MAINNET_ENABLED ? constants.NETWORK_ID_MAINNET : constants.NETWORK_ID_KOVAN;
provider.addProvider(new RedundantRPCSubprovider(configs.PUBLIC_NODE_URLS_BY_NETWORK_ID[networkId])); const rpcSubproviders = _.map(configs.PUBLIC_NODE_URLS_BY_NETWORK_ID[networkId], publicNodeUrl => {
return new RpcSubprovider({
rpcUrl: publicNodeUrl,
});
});
provider.addProvider(new RedundantSubprovider(rpcSubproviders as Subprovider[]));
provider.start(); provider.start();
} }
@ -201,7 +213,12 @@ export class Blockchain {
this._ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs); this._ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs);
provider.addProvider(this._ledgerSubprovider); provider.addProvider(this._ledgerSubprovider);
provider.addProvider(new FilterSubprovider()); provider.addProvider(new FilterSubprovider());
provider.addProvider(new RedundantRPCSubprovider(configs.PUBLIC_NODE_URLS_BY_NETWORK_ID[networkId])); const rpcSubproviders = _.map(configs.PUBLIC_NODE_URLS_BY_NETWORK_ID[networkId], publicNodeUrl => {
return new RpcSubprovider({
rpcUrl: publicNodeUrl,
});
});
provider.addProvider(new RedundantSubprovider(rpcSubproviders as Subprovider[]));
provider.start(); provider.start();
this.networkId = networkId; this.networkId = networkId;
this._dispatcher.updateNetworkId(this.networkId); this._dispatcher.updateNetworkId(this.networkId);

View File

@ -6,41 +6,6 @@
version "0.3.9" version "0.3.9"
resolved "https://registry.yarnpkg.com/8fold-marked/-/8fold-marked-0.3.9.tgz#bb89c645612f8ccfaffac1ca6e3c11f168c9cf59" resolved "https://registry.yarnpkg.com/8fold-marked/-/8fold-marked-0.3.9.tgz#bb89c645612f8ccfaffac1ca6e3c11f168c9cf59"
"@0xproject/dev-utils@^0.2.1":
version "0.2.1"
resolved "https://registry.yarnpkg.com/@0xproject/dev-utils/-/dev-utils-0.2.1.tgz#a54465376fd7c8cf58781b02b1790d74fb51e91b"
dependencies:
"@0xproject/subproviders" "^0.7.0"
"@0xproject/types" "^0.3.1"
"@0xproject/utils" "^0.4.1"
ethereumjs-util "^5.1.2"
lodash "^4.17.4"
request-promise-native "^1.0.5"
web3 "^0.20.0"
web3-provider-engine "^13.0.1"
"@0xproject/subproviders@^0.7.0":
version "0.7.0"
resolved "https://registry.yarnpkg.com/@0xproject/subproviders/-/subproviders-0.7.0.tgz#ce3379a85649773e5c08f5fc3239e8ed07f13361"
dependencies:
"@0xproject/assert" "^0.2.0"
"@0xproject/types" "^0.3.1"
"@0xproject/utils" "^0.4.1"
"@ledgerhq/hw-app-eth" "^4.3.0"
"@ledgerhq/hw-transport-u2f" "^4.3.0"
bn.js "^4.11.8"
es6-promisify "^5.0.0"
ethereumjs-tx "^1.3.3"
ethereumjs-util "^5.1.1"
hdkey "^0.7.1"
lodash "^4.17.4"
semaphore-async-await "^1.5.1"
web3 "^0.20.0"
web3-provider-engine "^13.0.1"
web3-typescript-typings "^0.10.0"
optionalDependencies:
"@ledgerhq/hw-transport-node-hid" "^4.3.0"
"@0xproject/tslint-config@0.4.13": "@0xproject/tslint-config@0.4.13":
version "0.4.13" version "0.4.13"
resolved "https://registry.yarnpkg.com/@0xproject/tslint-config/-/tslint-config-0.4.13.tgz#98c71c5ae5e80315a23eda0134cc9f6f4438cac2" resolved "https://registry.yarnpkg.com/@0xproject/tslint-config/-/tslint-config-0.4.13.tgz#98c71c5ae5e80315a23eda0134cc9f6f4438cac2"
@ -50,40 +15,6 @@
tslint-eslint-rules "^4.1.1" tslint-eslint-rules "^4.1.1"
tslint-react "^3.2.0" tslint-react "^3.2.0"
"@0xproject/types@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@0xproject/types/-/types-0.3.1.tgz#9a75be6d3a2d41b7ecbd9105c3fdc09f3e3ec297"
dependencies:
bignumber.js "~4.1.0"
web3 "^0.20.0"
web3-typescript-typings "^0.10.0"
"@0xproject/types@^0.4.2":
version "0.4.2"
resolved "https://registry.yarnpkg.com/@0xproject/types/-/types-0.4.2.tgz#83d6ebef60f41e6209acb2656b1d68ff79367ca5"
dependencies:
bignumber.js "~4.1.0"
"@0xproject/typescript-typings@^0.0.2":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@0xproject/typescript-typings/-/typescript-typings-0.0.2.tgz#b549ea3c81ce2d81b99f05583bdf7c411a3ca90c"
dependencies:
"@0xproject/types" "^0.4.2"
bignumber.js "~4.1.0"
"@0xproject/utils@^0.4.1":
version "0.4.4"
resolved "https://registry.yarnpkg.com/@0xproject/utils/-/utils-0.4.4.tgz#bce4f7a5a46570a69911f4a4ade5d49016330087"
dependencies:
"@0xproject/types" "^0.4.2"
"@0xproject/typescript-typings" "^0.0.2"
"@types/node" "^8.0.53"
bignumber.js "~4.1.0"
ethers-contracts "^2.2.1"
js-sha3 "^0.7.0"
lodash "^4.17.4"
web3 "^0.20.0"
"@ledgerhq/hw-app-eth@^4.3.0": "@ledgerhq/hw-app-eth@^4.3.0":
version "4.7.3" version "4.7.3"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-eth/-/hw-app-eth-4.7.3.tgz#d352e19658ae296532e522c53c8ec2a1a77b64e5" resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-eth/-/hw-app-eth-4.7.3.tgz#d352e19658ae296532e522c53c8ec2a1a77b64e5"
@ -3653,7 +3584,7 @@ ethereumjs-util@^4.0.1, ethereumjs-util@^4.3.0, ethereumjs-util@^4.4.0:
rlp "^2.0.0" rlp "^2.0.0"
secp256k1 "^3.0.1" secp256k1 "^3.0.1"
ethereumjs-util@^5.0.0, ethereumjs-util@^5.0.1, ethereumjs-util@^5.1.1, ethereumjs-util@^5.1.2, ethereumjs-util@^5.1.3, ethereumjs-util@^5.1.5: ethereumjs-util@^5.0.0, ethereumjs-util@^5.0.1, ethereumjs-util@^5.1.1, ethereumjs-util@^5.1.3, ethereumjs-util@^5.1.5:
version "5.1.5" version "5.1.5"
resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-5.1.5.tgz#2f02575852627d45622426f25ee4a0b5f377f27a" resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-5.1.5.tgz#2f02575852627d45622426f25ee4a0b5f377f27a"
dependencies: dependencies:
@ -8988,20 +8919,6 @@ request-ip@~1.2.3:
version "1.2.3" version "1.2.3"
resolved "https://registry.yarnpkg.com/request-ip/-/request-ip-1.2.3.tgz#66988f0e22406ec4af630d19b573fe4b447c3b49" resolved "https://registry.yarnpkg.com/request-ip/-/request-ip-1.2.3.tgz#66988f0e22406ec4af630d19b573fe4b447c3b49"
request-promise-core@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/request-promise-core/-/request-promise-core-1.1.1.tgz#3eee00b2c5aa83239cfb04c5700da36f81cd08b6"
dependencies:
lodash "^4.13.1"
request-promise-native@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/request-promise-native/-/request-promise-native-1.0.5.tgz#5281770f68e0c9719e5163fd3fab482215f4fda5"
dependencies:
request-promise-core "1.1.1"
stealthy-require "^1.1.0"
tough-cookie ">=2.3.3"
request@2.81.0: request@2.81.0:
version "2.81.0" version "2.81.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0" resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0"
@ -9887,10 +9804,6 @@ static-extend@^0.1.1:
version "1.4.0" version "1.4.0"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.4.0.tgz#bb73d446da2796106efcc1b601a253d6c46bd087" resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.4.0.tgz#bb73d446da2796106efcc1b601a253d6c46bd087"
stealthy-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
stream-browserify@^2.0.1: stream-browserify@^2.0.1:
version "2.0.1" version "2.0.1"
resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.1.tgz#66266ee5f9bdb9940a4e4514cafb43bb71e5c9db" resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.1.tgz#66266ee5f9bdb9940a4e4514cafb43bb71e5c9db"
@ -10463,7 +10376,7 @@ touch@^3.1.0:
dependencies: dependencies:
nopt "~1.0.10" nopt "~1.0.10"
tough-cookie@>=2.3.3, tough-cookie@~2.3.0, tough-cookie@~2.3.3: tough-cookie@~2.3.0, tough-cookie@~2.3.3:
version "2.3.4" version "2.3.4"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655"
dependencies: dependencies:
@ -11418,7 +11331,7 @@ web3-shh@1.0.0-beta.33:
web3-core-subscriptions "1.0.0-beta.33" web3-core-subscriptions "1.0.0-beta.33"
web3-net "1.0.0-beta.33" web3-net "1.0.0-beta.33"
web3-typescript-typings@^0.10.0, web3-typescript-typings@^0.10.2: web3-typescript-typings@^0.10.2:
version "0.10.2" version "0.10.2"
resolved "https://registry.yarnpkg.com/web3-typescript-typings/-/web3-typescript-typings-0.10.2.tgz#a9903815d2a8a0dbd73fd5db374070de0bd30497" resolved "https://registry.yarnpkg.com/web3-typescript-typings/-/web3-typescript-typings-0.10.2.tgz#a9903815d2a8a0dbd73fd5db374070de0bd30497"
dependencies: dependencies: