diff options
author | Fabio Berger <me@fabioberger.com> | 2017-06-02 00:14:17 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-06-02 00:14:17 +0800 |
commit | acb8a6c55ee2c97db5d738621929feea759465b3 (patch) | |
tree | 57cfa925d645cb11bb1731381be56d0f66f8f0f1 /src/utils | |
parent | ecf92a4ad786a324d4c8ce9dba926f377766a144 (diff) | |
parent | 389c18e98e2b5663b1732d7c34f9b21afef66e44 (diff) | |
download | dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.tar dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.tar.gz dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.tar.bz2 dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.tar.lz dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.tar.xz dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.tar.zst dexon-sol-tools-acb8a6c55ee2c97db5d738621929feea759465b3.zip |
Merge branch 'fillOrderAsync' into unavailableFilledCancelled
# Conflicts:
# src/contract_wrappers/exchange_wrapper.ts
# src/types.ts
# src/utils/assert.ts
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/assert.ts | 3 | ||||
-rw-r--r-- | src/utils/schema_validator.ts | 16 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/utils/assert.ts b/src/utils/assert.ts index 0088b3b13..406f2b149 100644 --- a/src/utils/assert.ts +++ b/src/utils/assert.ts @@ -31,6 +31,9 @@ export const assert = { isValidOrderHash(variableName: string, value: string): void { this.assert(utils.isValidOrderHash(value), this.typeAssertionMessage(variableName, 'orderHash', value)); }, + isBoolean(variableName: string, value: boolean): void { + this.assert(_.isBoolean(value), this.typeAssertionMessage(variableName, 'boolean', value)); + }, doesConformToSchema(variableName: string, value: object, schema: Schema): void { const schemaValidator = new SchemaValidator(); const validationResult = schemaValidator.validate(value, schema); diff --git a/src/utils/schema_validator.ts b/src/utils/schema_validator.ts index 8132f7414..db8a960ba 100644 --- a/src/utils/schema_validator.ts +++ b/src/utils/schema_validator.ts @@ -1,14 +1,26 @@ import {Validator, ValidatorResult} from 'jsonschema'; import {ecSignatureSchema, ecSignatureParameter} from '../schemas/ec_signature_schema'; +import {addressSchema, numberSchema, orderSchema, signedOrderSchema} from '../schemas/order_schemas'; import {tokenSchema} from '../schemas/token_schema'; export class SchemaValidator { private validator: Validator; + // In order to validate a complex JS object using jsonschema, we must replace any complex + // sub-types (e.g BigNumber) with a simpler string represenation. Since BigNumber and other + // complex types implement the `toString` method, we can stringify the object and + // then parse it. The resultant object can then be checked using jsonschema. + public static convertToJSONSchemaCompatibleObject(obj: object): object { + return JSON.parse(JSON.stringify(obj)); + } constructor() { this.validator = new Validator(); - this.validator.addSchema(ecSignatureParameter, ecSignatureParameter.id); - this.validator.addSchema(ecSignatureSchema, ecSignatureSchema.id); this.validator.addSchema(tokenSchema, tokenSchema.id); + this.validator.addSchema(orderSchema, orderSchema.id); + this.validator.addSchema(numberSchema, numberSchema.id); + this.validator.addSchema(addressSchema, addressSchema.id); + this.validator.addSchema(ecSignatureSchema, ecSignatureSchema.id); + this.validator.addSchema(signedOrderSchema, signedOrderSchema.id); + this.validator.addSchema(ecSignatureParameter, ecSignatureParameter.id); } public validate(instance: object, schema: Schema): ValidatorResult { return this.validator.validate(instance, schema); |