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/assert/src/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'packages/assert') 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/assert/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'packages/assert') 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) -- 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/assert') 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 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/assert/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packages/assert') 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 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/assert') 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/assert') 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