From f3e6ef0fa96e2252e41b7ed6f2c3e88a1560153e Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 8 Feb 2018 18:01:53 +0100 Subject: Better validate ZeroExConfig on public networks --- packages/0x.js/src/0x.ts | 5 +++ .../0x.js/src/schemas/zero_ex_config_schema.ts | 24 +-------------- .../zero_ex_private_network_config_schema.ts | 35 +++++++++++++++++++++ .../zero_ex_public_network_config_schema.ts | 29 +++++++++++++++++ packages/0x.js/src/types.ts | 36 ++++++++++++++++------ packages/assert/src/index.ts | 5 +-- 6 files changed, 99 insertions(+), 35 deletions(-) create mode 100644 packages/0x.js/src/schemas/zero_ex_private_network_config_schema.ts create mode 100644 packages/0x.js/src/schemas/zero_ex_public_network_config_schema.ts (limited to 'packages') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 6cfa65cc2..d024e6097 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'; @@ -20,6 +22,9 @@ import { decorators } from './utils/decorators'; import { signatureUtils } from './utils/signature_utils'; import { utils } from './utils/utils'; +assert.schemaValidator.addSchema(zeroExPrivateNetworkConfigSchema); +assert.schemaValidator.addSchema(zeroExPublicNetworkConfigSchema); + /** * The ZeroEx class is the single entry-point into the 0x.js library. It contains all of the library's functionality * and all calls to the library should be made through a ZeroEx instance. 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..f0660391b 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -9,6 +9,10 @@ import { ExchangeContractEventArgs, ExchangeEvents } from './contract_wrappers/g import { TokenContractEventArgs, TokenEvents } from './contract_wrappers/generated/token'; export enum ZeroExError { + ZRXAddressRequired = 'ZRX_ADDREESS_REQUIRED', + ExchangeAddressRequired = 'EXCHANGE_ADDREESS_REQUIRED', + TokenRegistryAddressRequired = 'TOKEN_REGISTRY_ADDREESS_REQUIRED', + TokenTransferProxyAddressRequired = 'TOKEN_TRANSFER_PROXY_ADDREESS_REQUIRED', ExchangeContractDoesNotExist = 'EXCHANGE_CONTRACT_DOES_NOT_EXIST', ZRXContractDoesNotExist = 'ZRX_CONTRACT_DOES_NOT_EXIST', EtherTokenContractDoesNotExist = 'ETHER_TOKEN_CONTRACT_DOES_NOT_EXIST', @@ -195,8 +199,28 @@ export interface OrderStateWatcherConfig { cleanupJobIntervalMs?: number; } +export interface ZeroExPublicNetworkConfig { + networkId: 1 | 3 | 4 | 42 | 50; + gasPrice?: BigNumber; + exchangeContractAddress?: string; + zrxContractAddress?: string; + tokenRegistryContractAddress?: string; + tokenTransferProxyContractAddress?: string; + orderWatcherConfig?: OrderStateWatcherConfig; +} + +export interface ZeroExPrivateNetworkConfig { + networkId: number; + gasPrice?: BigNumber; + exchangeContractAddress: string; + zrxContractAddress: string; + tokenRegistryContractAddress: string; + tokenTransferProxyContractAddress: string; + orderWatcherConfig?: 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 @@ -204,15 +228,7 @@ export interface OrderStateWatcherConfig { * tokenTransferProxyContractAddress: The address of the token transfer proxy contract to use * orderWatcherConfig: All the configs related to the orderWatcher */ -export interface ZeroExConfig { - networkId: number; - gasPrice?: BigNumber; - exchangeContractAddress?: string; - zrxContractAddress?: string; - tokenRegistryContractAddress?: string; - tokenTransferProxyContractAddress?: string; - orderWatcherConfig?: OrderStateWatcherConfig; -} +export type ZeroExConfig = ZeroExPublicNetworkConfig | ZeroExPrivateNetworkConfig; export type ArtifactContractName = 'ZRX' | 'TokenTransferProxy' | 'TokenRegistry' | 'Token' | 'Exchange' | 'EtherToken'; diff --git a/packages/assert/src/index.ts b/packages/assert/src/index.ts index 7ad574ec7..38b330a46 100644 --- a/packages/assert/src/index.ts +++ b/packages/assert/src/index.ts @@ -4,8 +4,10 @@ import * as _ from 'lodash'; import * as validUrl from 'valid-url'; const HEX_REGEX = /^0x[0-9A-F]*$/i; +const schemaValidator = new SchemaValidator(); export const assert = { + schemaValidator, isBigNumber(variableName: string, value: BigNumber): void { const isBigNumber = _.isObject(value) && (value as any).isBigNumber; this.assert(isBigNumber, this.typeAssertionMessage(variableName, 'BigNumber', value)); @@ -67,8 +69,7 @@ export const assert = { this.assert(isWeb3Provider, this.typeAssertionMessage(variableName, 'Web3.Provider', value)); }, doesConformToSchema(variableName: string, value: any, schema: Schema): void { - const schemaValidator = new SchemaValidator(); - const validationResult = schemaValidator.validate(value, schema); + const validationResult = assert.schemaValidator.validate(value, schema); const hasValidationErrors = validationResult.errors.length > 0; const msg = `Expected ${variableName} to conform to schema ${schema.id} Encountered: ${JSON.stringify(value, null, '\t')} -- cgit v1.2.3 From 98b78c56c5fb5fbcbda11da993fb8d88f3b71df8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Feb 2018 10:11:12 +0100 Subject: Add entries to the CHANGELOG --- packages/0x.js/CHANGELOG.md | 4 ++++ packages/0x.js/src/index.ts | 2 ++ packages/0x.js/src/types.ts | 4 ---- packages/assert/CHANGELOG.md | 4 ++++ packages/website/ts/containers/zero_ex_js_documentation.tsx | 2 ++ 5 files changed, 12 insertions(+), 4 deletions(-) (limited to 'packages') 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/src/index.ts b/packages/0x.js/src/index.ts index 161945443..bb689f6dc 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -16,6 +16,8 @@ export { ContractEventArgs, Web3Provider, ZeroExConfig, + ZeroExPublicNetworkConfig, + ZeroExPrivateNetworkConfig, MethodOpts, OrderTransactionOpts, TransactionOpts, diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index f0660391b..886beeaaa 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -9,10 +9,6 @@ import { ExchangeContractEventArgs, ExchangeEvents } from './contract_wrappers/g import { TokenContractEventArgs, TokenEvents } from './contract_wrappers/generated/token'; export enum ZeroExError { - ZRXAddressRequired = 'ZRX_ADDREESS_REQUIRED', - ExchangeAddressRequired = 'EXCHANGE_ADDREESS_REQUIRED', - TokenRegistryAddressRequired = 'TOKEN_REGISTRY_ADDREESS_REQUIRED', - TokenTransferProxyAddressRequired = 'TOKEN_TRANSFER_PROXY_ADDREESS_REQUIRED', ExchangeContractDoesNotExist = 'EXCHANGE_CONTRACT_DOES_NOT_EXIST', ZRXContractDoesNotExist = 'ZRX_CONTRACT_DOES_NOT_EXIST', EtherTokenContractDoesNotExist = 'ETHER_TOKEN_CONTRACT_DOES_NOT_EXIST', diff --git a/packages/assert/CHANGELOG.md b/packages/assert/CHANGELOG.md index 23c2c5e56..ed3577c44 100644 --- a/packages/assert/CHANGELOG.md +++ b/packages/assert/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v0.1.0 - _TBD, 2018_ + + * Add schemaValidator as a field so that one can add custom schemas (#385) + ## v0.0.18 - _February 9, 2017_ * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) diff --git a/packages/website/ts/containers/zero_ex_js_documentation.tsx b/packages/website/ts/containers/zero_ex_js_documentation.tsx index 96c8c257d..018b99f8d 100644 --- a/packages/website/ts/containers/zero_ex_js_documentation.tsx +++ b/packages/website/ts/containers/zero_ex_js_documentation.tsx @@ -101,6 +101,8 @@ const docsInfoConfig: DocsInfoConfig = { 'ApprovalContractEventArgs', 'TokenContractEventArgs', 'ZeroExConfig', + 'ZeroExPublicNetworkConfig', + 'ZeroExPrivateNetworkConfig', 'TransactionReceiptWithDecodedLogs', 'LogWithDecodedArgs', 'EtherTokenEvents', -- cgit v1.2.3 From 49375c73d474fc844f3ee5b8f49244a33be52638 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Feb 2018 10:33:33 +0100 Subject: Fix tests --- packages/0x.js/src/utils/assert.ts | 2 +- packages/0x.js/test/ether_token_wrapper_test.ts | 11 +++++++---- packages/0x.js/test/expiration_watcher_test.ts | 2 +- packages/0x.js/test/token_wrapper_test.ts | 1 + packages/0x.js/test/utils/constants.ts | 6 +++--- 5 files changed, 13 insertions(+), 9 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/utils/assert.ts b/packages/0x.js/src/utils/assert.ts index c21f2dbca..f81e02f78 100644 --- a/packages/0x.js/src/utils/assert.ts +++ b/packages/0x.js/src/utils/assert.ts @@ -1,7 +1,7 @@ import { assert as sharedAssert } from '@0xproject/assert'; // We need those two unused imports because they're actually used by sharedAssert which gets injected here // tslint:disable-next-line:no-unused-variable -import { Schema } from '@0xproject/json-schemas'; +import { Schema, SchemaValidator } from '@0xproject/json-schemas'; // tslint:disable-next-line:no-unused-variable import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; 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'; diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index 34ebe30c2..6ecad4ccf 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -15,6 +15,7 @@ import { TransferContractEventArgs, ZeroEx, ZeroExError, + ZeroExPublicNetworkConfig, } from '../src'; import { DoneCallback } from '../src/types'; diff --git a/packages/0x.js/test/utils/constants.ts b/packages/0x.js/test/utils/constants.ts index cf030259c..bd7841feb 100644 --- a/packages/0x.js/test/utils/constants.ts +++ b/packages/0x.js/test/utils/constants.ts @@ -1,8 +1,8 @@ export const constants = { NULL_ADDRESS: '0x0000000000000000000000000000000000000000', - ROPSTEN_NETWORK_ID: 3, - KOVAN_NETWORK_ID: 42, - TESTRPC_NETWORK_ID: 50, + ROPSTEN_NETWORK_ID: 3 as 3, + KOVAN_NETWORK_ID: 42 as 42, + TESTRPC_NETWORK_ID: 50 as 50, KOVAN_RPC_URL: 'https://kovan.infura.io/', ROPSTEN_RPC_URL: 'https://ropsten.infura.io/', ZRX_DECIMALS: 18, -- cgit v1.2.3 From b53a1b51d6b7e6ec768b974f656329599585bee6 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Feb 2018 10:47:41 +0100 Subject: Add type cast --- packages/contracts/util/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/contracts/util/constants.ts b/packages/contracts/util/constants.ts index e61b2f802..0d46ad67f 100644 --- a/packages/contracts/util/constants.ts +++ b/packages/contracts/util/constants.ts @@ -2,7 +2,7 @@ export const constants = { NULL_BYTES: '0x', INVALID_OPCODE: 'invalid opcode', REVERT: 'revert', - TESTRPC_NETWORK_ID: 50, + TESTRPC_NETWORK_ID: 50 as 50, MAX_ETHERTOKEN_WITHDRAW_GAS: 43000, MAX_TOKEN_TRANSFERFROM_GAS: 80000, MAX_TOKEN_APPROVE_GAS: 60000, -- cgit v1.2.3 From 4d482438f554b50f3a5097d30ca37967b7aca994 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 14 Feb 2018 11:24:42 -0800 Subject: Access property over this --- packages/assert/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/assert/src/index.ts b/packages/assert/src/index.ts index 38b330a46..383cc2c42 100644 --- a/packages/assert/src/index.ts +++ b/packages/assert/src/index.ts @@ -69,7 +69,7 @@ export const assert = { this.assert(isWeb3Provider, this.typeAssertionMessage(variableName, 'Web3.Provider', value)); }, doesConformToSchema(variableName: string, value: any, schema: Schema): void { - const validationResult = assert.schemaValidator.validate(value, schema); + const validationResult = this.schemaValidator.validate(value, schema); const hasValidationErrors = validationResult.errors.length > 0; const msg = `Expected ${variableName} to conform to schema ${schema.id} Encountered: ${JSON.stringify(value, null, '\t')} -- cgit v1.2.3 From db52e877404b8f053bbdea823f1f6afd6eccecd1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 14 Feb 2018 15:23:06 -0800 Subject: Remove type-level validation --- packages/0x.js/src/index.ts | 2 -- packages/0x.js/src/types.ts | 30 +++++++--------------- packages/0x.js/test/token_wrapper_test.ts | 1 - packages/0x.js/test/utils/constants.ts | 6 ++--- .../ts/containers/zero_ex_js_documentation.tsx | 2 -- 5 files changed, 12 insertions(+), 29 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index bb689f6dc..161945443 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -16,8 +16,6 @@ export { ContractEventArgs, Web3Provider, ZeroExConfig, - ZeroExPublicNetworkConfig, - ZeroExPrivateNetworkConfig, MethodOpts, OrderTransactionOpts, TransactionOpts, diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 886beeaaa..0a3037258 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -195,26 +195,6 @@ export interface OrderStateWatcherConfig { cleanupJobIntervalMs?: number; } -export interface ZeroExPublicNetworkConfig { - networkId: 1 | 3 | 4 | 42 | 50; - gasPrice?: BigNumber; - exchangeContractAddress?: string; - zrxContractAddress?: string; - tokenRegistryContractAddress?: string; - tokenTransferProxyContractAddress?: string; - orderWatcherConfig?: OrderStateWatcherConfig; -} - -export interface ZeroExPrivateNetworkConfig { - networkId: number; - gasPrice?: BigNumber; - exchangeContractAddress: string; - zrxContractAddress: string; - tokenRegistryContractAddress: string; - tokenTransferProxyContractAddress: string; - orderWatcherConfig?: OrderStateWatcherConfig; -} - /* * 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 @@ -224,7 +204,15 @@ export interface ZeroExPrivateNetworkConfig { * tokenTransferProxyContractAddress: The address of the token transfer proxy contract to use * orderWatcherConfig: All the configs related to the orderWatcher */ -export type ZeroExConfig = ZeroExPublicNetworkConfig | ZeroExPrivateNetworkConfig; +export interface ZeroExConfig { + networkId: number; + gasPrice?: BigNumber; + exchangeContractAddress?: string; + zrxContractAddress?: string; + tokenRegistryContractAddress?: string; + tokenTransferProxyContractAddress?: string; + orderWatcherConfig?: OrderStateWatcherConfig; +} export type ArtifactContractName = 'ZRX' | 'TokenTransferProxy' | 'TokenRegistry' | 'Token' | 'Exchange' | 'EtherToken'; diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index 6ecad4ccf..34ebe30c2 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -15,7 +15,6 @@ import { TransferContractEventArgs, ZeroEx, ZeroExError, - ZeroExPublicNetworkConfig, } from '../src'; import { DoneCallback } from '../src/types'; diff --git a/packages/0x.js/test/utils/constants.ts b/packages/0x.js/test/utils/constants.ts index bd7841feb..cf030259c 100644 --- a/packages/0x.js/test/utils/constants.ts +++ b/packages/0x.js/test/utils/constants.ts @@ -1,8 +1,8 @@ export const constants = { NULL_ADDRESS: '0x0000000000000000000000000000000000000000', - ROPSTEN_NETWORK_ID: 3 as 3, - KOVAN_NETWORK_ID: 42 as 42, - TESTRPC_NETWORK_ID: 50 as 50, + ROPSTEN_NETWORK_ID: 3, + KOVAN_NETWORK_ID: 42, + TESTRPC_NETWORK_ID: 50, KOVAN_RPC_URL: 'https://kovan.infura.io/', ROPSTEN_RPC_URL: 'https://ropsten.infura.io/', ZRX_DECIMALS: 18, diff --git a/packages/website/ts/containers/zero_ex_js_documentation.tsx b/packages/website/ts/containers/zero_ex_js_documentation.tsx index 018b99f8d..96c8c257d 100644 --- a/packages/website/ts/containers/zero_ex_js_documentation.tsx +++ b/packages/website/ts/containers/zero_ex_js_documentation.tsx @@ -101,8 +101,6 @@ const docsInfoConfig: DocsInfoConfig = { 'ApprovalContractEventArgs', 'TokenContractEventArgs', 'ZeroExConfig', - 'ZeroExPublicNetworkConfig', - 'ZeroExPrivateNetworkConfig', 'TransactionReceiptWithDecodedLogs', 'LogWithDecodedArgs', 'EtherTokenEvents', -- cgit v1.2.3 From fe9e319a6136d4be4fa94287ad709a127c548750 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 20 Feb 2018 11:34:29 -0800 Subject: Remove a type assertion --- packages/contracts/util/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/contracts/util/constants.ts b/packages/contracts/util/constants.ts index 0d46ad67f..e61b2f802 100644 --- a/packages/contracts/util/constants.ts +++ b/packages/contracts/util/constants.ts @@ -2,7 +2,7 @@ export const constants = { NULL_BYTES: '0x', INVALID_OPCODE: 'invalid opcode', REVERT: 'revert', - TESTRPC_NETWORK_ID: 50 as 50, + TESTRPC_NETWORK_ID: 50, MAX_ETHERTOKEN_WITHDRAW_GAS: 43000, MAX_TOKEN_TRANSFERFROM_GAS: 80000, MAX_TOKEN_APPROVE_GAS: 60000, -- cgit v1.2.3 From 7b67afae06c93290e6d8c4a4f0de2435f31ae714 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 20 Feb 2018 11:39:36 -0800 Subject: Change assert.doesConformToShema interface --- packages/0x.js/src/0x.ts | 8 ++++---- packages/assert/src/index.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index d024e6097..c578478d8 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -22,9 +22,6 @@ import { decorators } from './utils/decorators'; import { signatureUtils } from './utils/signature_utils'; import { utils } from './utils/utils'; -assert.schemaValidator.addSchema(zeroExPrivateNetworkConfigSchema); -assert.schemaValidator.addSchema(zeroExPublicNetworkConfigSchema); - /** * The ZeroEx class is the single entry-point into the 0x.js library. It contains all of the library's functionality * and all calls to the library should be made through a ZeroEx instance. @@ -168,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/assert/src/index.ts b/packages/assert/src/index.ts index 383cc2c42..71f2cbeb2 100644 --- a/packages/assert/src/index.ts +++ b/packages/assert/src/index.ts @@ -4,10 +4,8 @@ import * as _ from 'lodash'; import * as validUrl from 'valid-url'; const HEX_REGEX = /^0x[0-9A-F]*$/i; -const schemaValidator = new SchemaValidator(); export const assert = { - schemaValidator, isBigNumber(variableName: string, value: BigNumber): void { const isBigNumber = _.isObject(value) && (value as any).isBigNumber; this.assert(isBigNumber, this.typeAssertionMessage(variableName, 'BigNumber', value)); @@ -68,8 +66,10 @@ export const assert = { const isWeb3Provider = _.isFunction(value.send) || _.isFunction(value.sendAsync); this.assert(isWeb3Provider, this.typeAssertionMessage(variableName, 'Web3.Provider', value)); }, - doesConformToSchema(variableName: string, value: any, schema: Schema): void { - const validationResult = this.schemaValidator.validate(value, schema); + doesConformToSchema(variableName: string, value: any, schema: Schema, subSchemas?: Schema[]): void { + const schemaValidator = new SchemaValidator(); + _.map(subSchemas, schemaValidator.addSchema.bind(schemaValidator)); + const validationResult = schemaValidator.validate(value, schema); const hasValidationErrors = validationResult.errors.length > 0; const msg = `Expected ${variableName} to conform to schema ${schema.id} Encountered: ${JSON.stringify(value, null, '\t')} -- cgit v1.2.3 From 0fb81a11a87eb24f82d459375803904e7795e6a4 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 20 Feb 2018 12:03:21 -0800 Subject: Remove unused import --- packages/0x.js/src/utils/assert.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/src/utils/assert.ts b/packages/0x.js/src/utils/assert.ts index f81e02f78..c21f2dbca 100644 --- a/packages/0x.js/src/utils/assert.ts +++ b/packages/0x.js/src/utils/assert.ts @@ -1,7 +1,7 @@ import { assert as sharedAssert } from '@0xproject/assert'; // We need those two unused imports because they're actually used by sharedAssert which gets injected here // tslint:disable-next-line:no-unused-variable -import { Schema, SchemaValidator } from '@0xproject/json-schemas'; +import { Schema } from '@0xproject/json-schemas'; // tslint:disable-next-line:no-unused-variable import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; -- cgit v1.2.3 From c85c14210fb3af93733430328d07b46007c84da1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 20 Feb 2018 12:03:33 -0800 Subject: Remove unused CHANGELOG entry --- packages/assert/CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) (limited to 'packages') diff --git a/packages/assert/CHANGELOG.md b/packages/assert/CHANGELOG.md index ed3577c44..23c2c5e56 100644 --- a/packages/assert/CHANGELOG.md +++ b/packages/assert/CHANGELOG.md @@ -1,9 +1,5 @@ # CHANGELOG -## v0.1.0 - _TBD, 2018_ - - * Add schemaValidator as a field so that one can add custom schemas (#385) - ## v0.0.18 - _February 9, 2017_ * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) -- cgit v1.2.3 From 3120d854f855a01ad7bce3427a64d931de1879d3 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 20 Feb 2018 12:09:39 -0800 Subject: Update CHANGELOG --- packages/assert/CHANGELOG.md | 4 ++++ packages/assert/src/index.ts | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/assert/CHANGELOG.md b/packages/assert/CHANGELOG.md index 23c2c5e56..f512f7b10 100644 --- a/packages/assert/CHANGELOG.md +++ b/packages/assert/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v0.1.0 - _TBD, 2018_ + + * Add an optional parameter `subSchemas` to `doesConformToSchema` method (#385) + ## v0.0.18 - _February 9, 2017_ * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) diff --git a/packages/assert/src/index.ts b/packages/assert/src/index.ts index 71f2cbeb2..4d090e493 100644 --- a/packages/assert/src/index.ts +++ b/packages/assert/src/index.ts @@ -68,7 +68,9 @@ export const assert = { }, doesConformToSchema(variableName: string, value: any, schema: Schema, subSchemas?: Schema[]): void { const schemaValidator = new SchemaValidator(); - _.map(subSchemas, schemaValidator.addSchema.bind(schemaValidator)); + if (!_.isUndefined(subSchemas)) { + _.map(subSchemas, schemaValidator.addSchema.bind(schemaValidator)); + } const validationResult = schemaValidator.validate(value, schema); const hasValidationErrors = validationResult.errors.length > 0; const msg = `Expected ${variableName} to conform to schema ${schema.id} -- cgit v1.2.3