aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-02-26 10:32:12 +0800
committerFabio Berger <me@fabioberger.com>2018-02-26 10:32:12 +0800
commitfffaafe4c996ac0c458dd6cb9e3598b1d93b7aa4 (patch)
tree21f9398ba2975bda4706fb8f54c0c717b88ecfd4 /packages/0x.js
parent66b36f6d8f7c0f0487e53badb035ac50e1ec5669 (diff)
parent709fa9e02ec21cee9fc145b4a578742c8dd190aa (diff)
downloaddexon-sol-tools-fffaafe4c996ac0c458dd6cb9e3598b1d93b7aa4.tar
dexon-sol-tools-fffaafe4c996ac0c458dd6cb9e3598b1d93b7aa4.tar.gz
dexon-sol-tools-fffaafe4c996ac0c458dd6cb9e3598b1d93b7aa4.tar.bz2
dexon-sol-tools-fffaafe4c996ac0c458dd6cb9e3598b1d93b7aa4.tar.lz
dexon-sol-tools-fffaafe4c996ac0c458dd6cb9e3598b1d93b7aa4.tar.xz
dexon-sol-tools-fffaafe4c996ac0c458dd6cb9e3598b1d93b7aa4.tar.zst
dexon-sol-tools-fffaafe4c996ac0c458dd6cb9e3598b1d93b7aa4.zip
Merge branch 'development' into moveOutDocGenerator
* development: (36 commits) Fix english translations Fix footer on mobile re-add google analytics code Fix Russian translation Move all dependencies on @0xproject/types out of devDependencies Slight improvement to footer Fix a few Korean translations Address feedback Use source tree hash instead of compile flag Fix race condition Update CHANGELOG Delete artifacts directory Add generated contract artifacts to gitignore Check dependencies when determining if should be recompiled Update CHANGELOG Remove unused CHANGELOG entry Remove unused import Change assert.doesConformToShema interface Remove a type assertion Publish ...
Diffstat (limited to 'packages/0x.js')
-rw-r--r--packages/0x.js/CHANGELOG.md4
-rw-r--r--packages/0x.js/package.json18
-rw-r--r--packages/0x.js/src/0x.ts7
-rw-r--r--packages/0x.js/src/schemas/zero_ex_config_schema.ts24
-rw-r--r--packages/0x.js/src/schemas/zero_ex_private_network_config_schema.ts35
-rw-r--r--packages/0x.js/src/schemas/zero_ex_public_network_config_schema.ts29
-rw-r--r--packages/0x.js/src/types.ts2
-rw-r--r--packages/0x.js/test/ether_token_wrapper_test.ts11
-rw-r--r--packages/0x.js/test/expiration_watcher_test.ts2
9 files changed, 93 insertions, 39 deletions
diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md
index 0af474c74..57cd381ee 100644
--- a/packages/0x.js/CHANGELOG.md
+++ b/packages/0x.js/CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG
+## v0.33.0 - _TBD, 2018_
+
+ * Improve validation to force passing contract addresses on private networks (#385)
+
## v0.32.2 - _February 9, 2018_
* Fix publishing issue where .npmignore was not properly excluding undesired content (#389)
diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json
index 41ebbf4d9..4fb0eb6ac 100644
--- a/packages/0x.js/package.json
+++ b/packages/0x.js/package.json
@@ -1,6 +1,6 @@
{
"name": "0x.js",
- "version": "0.32.3",
+ "version": "0.32.4",
"description": "A javascript library for interacting with the 0x protocol",
"keywords": [
"0x.js",
@@ -42,8 +42,8 @@
"node": ">=6.0.0"
},
"devDependencies": {
- "@0xproject/abi-gen": "^0.2.2",
- "@0xproject/dev-utils": "^0.0.13",
+ "@0xproject/abi-gen": "^0.2.3",
+ "@0xproject/dev-utils": "^0.1.0",
"@0xproject/tslint-config": "^0.4.9",
"@types/bintrees": "^1.0.2",
"@types/jsonschema": "^1.1.1",
@@ -77,15 +77,15 @@
"types-bn": "^0.0.1",
"typescript": "2.7.1",
"web3-provider-engine": "^13.0.1",
- "web3-typescript-typings": "^0.9.10",
+ "web3-typescript-typings": "^0.9.11",
"webpack": "^3.1.0"
},
"dependencies": {
- "@0xproject/assert": "^0.0.19",
- "@0xproject/json-schemas": "^0.7.11",
- "@0xproject/types": "^0.2.2",
- "@0xproject/utils": "^0.3.3",
- "@0xproject/web3-wrapper": "^0.1.13",
+ "@0xproject/assert": "^0.0.20",
+ "@0xproject/json-schemas": "^0.7.12",
+ "@0xproject/types": "^0.2.3",
+ "@0xproject/utils": "^0.3.4",
+ "@0xproject/web3-wrapper": "^0.1.14",
"bintrees": "^1.0.2",
"bn.js": "^4.11.8",
"ethereumjs-abi": "^0.6.4",
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts
index 6cfa65cc2..c578478d8 100644
--- a/packages/0x.js/src/0x.ts
+++ b/packages/0x.js/src/0x.ts
@@ -13,6 +13,8 @@ import { TokenTransferProxyWrapper } from './contract_wrappers/token_transfer_pr
import { TokenWrapper } from './contract_wrappers/token_wrapper';
import { OrderStateWatcher } from './order_watcher/order_state_watcher';
import { zeroExConfigSchema } from './schemas/zero_ex_config_schema';
+import { zeroExPrivateNetworkConfigSchema } from './schemas/zero_ex_private_network_config_schema';
+import { zeroExPublicNetworkConfigSchema } from './schemas/zero_ex_public_network_config_schema';
import { ECSignature, Order, SignedOrder, Web3Provider, ZeroExConfig, ZeroExError } from './types';
import { assert } from './utils/assert';
import { constants } from './utils/constants';
@@ -163,7 +165,10 @@ export class ZeroEx {
*/
constructor(provider: Web3Provider, config: ZeroExConfig) {
assert.isWeb3Provider('provider', provider);
- assert.doesConformToSchema('config', config, zeroExConfigSchema);
+ assert.doesConformToSchema('config', config, zeroExConfigSchema, [
+ zeroExPrivateNetworkConfigSchema,
+ zeroExPublicNetworkConfigSchema,
+ ]);
const artifactJSONs = _.values(artifacts);
const abiArrays = _.map(artifactJSONs, artifact => artifact.abi);
this._abiDecoder = new AbiDecoder(abiArrays);
diff --git a/packages/0x.js/src/schemas/zero_ex_config_schema.ts b/packages/0x.js/src/schemas/zero_ex_config_schema.ts
index 546b1c2d0..a9c3c64fc 100644
--- a/packages/0x.js/src/schemas/zero_ex_config_schema.ts
+++ b/packages/0x.js/src/schemas/zero_ex_config_schema.ts
@@ -1,27 +1,5 @@
export const zeroExConfigSchema = {
id: '/ZeroExConfig',
- properties: {
- networkId: {
- type: 'number',
- minimum: 0,
- },
- gasPrice: { $ref: '/Number' },
- exchangeContractAddress: { $ref: '/Address' },
- tokenRegistryContractAddress: { $ref: '/Address' },
- orderWatcherConfig: {
- type: 'object',
- properties: {
- pollingIntervalMs: {
- type: 'number',
- minimum: 0,
- },
- numConfirmations: {
- type: 'number',
- minimum: 0,
- },
- },
- },
- },
+ oneOf: [{ $ref: '/ZeroExPrivateNetworkConfig' }, { $ref: '/ZeroExPublicNetworkConfig' }],
type: 'object',
- required: ['networkId'],
};
diff --git a/packages/0x.js/src/schemas/zero_ex_private_network_config_schema.ts b/packages/0x.js/src/schemas/zero_ex_private_network_config_schema.ts
new file mode 100644
index 000000000..f7f649a6d
--- /dev/null
+++ b/packages/0x.js/src/schemas/zero_ex_private_network_config_schema.ts
@@ -0,0 +1,35 @@
+export const zeroExPrivateNetworkConfigSchema = {
+ id: '/ZeroExPrivateNetworkConfig',
+ properties: {
+ networkId: {
+ type: 'number',
+ minimum: 1,
+ },
+ gasPrice: { $ref: '/Number' },
+ zrxContractAddress: { $ref: '/Address' },
+ exchangeContractAddress: { $ref: '/Address' },
+ tokenRegistryContractAddress: { $ref: '/Address' },
+ tokenTransferProxyContractAddress: { $ref: '/Address' },
+ orderWatcherConfig: {
+ type: 'object',
+ properties: {
+ pollingIntervalMs: {
+ type: 'number',
+ minimum: 0,
+ },
+ numConfirmations: {
+ type: 'number',
+ minimum: 0,
+ },
+ },
+ },
+ },
+ type: 'object',
+ required: [
+ 'networkId',
+ 'zrxContractAddress',
+ 'exchangeContractAddress',
+ 'tokenRegistryContractAddress',
+ 'tokenTransferProxyContractAddress',
+ ],
+};
diff --git a/packages/0x.js/src/schemas/zero_ex_public_network_config_schema.ts b/packages/0x.js/src/schemas/zero_ex_public_network_config_schema.ts
new file mode 100644
index 000000000..9da31481a
--- /dev/null
+++ b/packages/0x.js/src/schemas/zero_ex_public_network_config_schema.ts
@@ -0,0 +1,29 @@
+export const zeroExPublicNetworkConfigSchema = {
+ id: '/ZeroExPublicNetworkConfig',
+ properties: {
+ networkId: {
+ type: 'number',
+ enum: [1, 3, 4, 42, 50],
+ },
+ gasPrice: { $ref: '/Number' },
+ zrxContractAddress: { $ref: '/Address' },
+ exchangeContractAddress: { $ref: '/Address' },
+ tokenRegistryContractAddress: { $ref: '/Address' },
+ tokenTransferProxyContractAddress: { $ref: '/Address' },
+ orderWatcherConfig: {
+ type: 'object',
+ properties: {
+ pollingIntervalMs: {
+ type: 'number',
+ minimum: 0,
+ },
+ numConfirmations: {
+ type: 'number',
+ minimum: 0,
+ },
+ },
+ },
+ },
+ type: 'object',
+ required: ['networkId'],
+};
diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts
index ab97f7775..0a3037258 100644
--- a/packages/0x.js/src/types.ts
+++ b/packages/0x.js/src/types.ts
@@ -196,7 +196,7 @@ export interface OrderStateWatcherConfig {
}
/*
- * networkId: The id of the underlying ethereum network your provider is connected to. (1-mainnet, 42-kovan, 50-testrpc)
+ * networkId: The id of the underlying ethereum network your provider is connected to. (1-mainnet, 3-ropsten, 4-rinkeby, 42-kovan, 50-testrpc)
* gasPrice: Gas price to use with every transaction
* exchangeContractAddress: The address of an exchange contract to use
* zrxContractAddress: The address of the ZRX contract to use
diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts
index da49ec467..72086dff0 100644
--- a/packages/0x.js/test/ether_token_wrapper_test.ts
+++ b/packages/0x.js/test/ether_token_wrapper_test.ts
@@ -75,11 +75,14 @@ describe('EtherTokenWrapper', () => {
const contractAddressIfExists = zeroEx.etherToken.getContractAddressIfExists();
expect(contractAddressIfExists).to.not.be.undefined();
});
- it('should return undefined if connected to an unknown network', () => {
+ it('should throw if connected to a private network and contract addresses are not specified', () => {
const UNKNOWN_NETWORK_NETWORK_ID = 10;
- const unknownNetworkZeroEx = new ZeroEx(web3.currentProvider, { networkId: UNKNOWN_NETWORK_NETWORK_ID });
- const contractAddressIfExists = unknownNetworkZeroEx.etherToken.getContractAddressIfExists();
- expect(contractAddressIfExists).to.be.undefined();
+ expect(
+ () =>
+ new ZeroEx(web3.currentProvider, {
+ networkId: UNKNOWN_NETWORK_NETWORK_ID,
+ } as any),
+ ).to.throw();
});
});
describe('#depositAsync', () => {
diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts
index b49dee8e5..7f79e3802 100644
--- a/packages/0x.js/test/expiration_watcher_test.ts
+++ b/packages/0x.js/test/expiration_watcher_test.ts
@@ -9,10 +9,10 @@ import * as Web3 from 'web3';
import { ZeroEx } from '../src/0x';
import { ExpirationWatcher } from '../src/order_watcher/expiration_watcher';
import { DoneCallback, Token } from '../src/types';
-import { constants } from '../src/utils/constants';
import { utils } from '../src/utils/utils';
import { chaiSetup } from './utils/chai_setup';
+import { constants } from './utils/constants';
import { FillScenarios } from './utils/fill_scenarios';
import { reportNoErrorCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils';