aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-06-03 01:45:57 +0800
committerFabio Berger <me@fabioberger.com>2017-06-03 01:45:57 +0800
commit1443c0838cbd795ae8e6273b1d7659c8e449f2eb (patch)
tree531df9d489dd4c5ce15623bee0beeae3ad58ccd4 /src/utils
parent3de655954743db4e2b9d02f5ac1243855b909236 (diff)
parentd4320fec724c5bf34e7dcd006cba8ffe7a3c76d1 (diff)
downloaddexon-sol-tools-1443c0838cbd795ae8e6273b1d7659c8e449f2eb.tar
dexon-sol-tools-1443c0838cbd795ae8e6273b1d7659c8e449f2eb.tar.gz
dexon-sol-tools-1443c0838cbd795ae8e6273b1d7659c8e449f2eb.tar.bz2
dexon-sol-tools-1443c0838cbd795ae8e6273b1d7659c8e449f2eb.tar.lz
dexon-sol-tools-1443c0838cbd795ae8e6273b1d7659c8e449f2eb.tar.xz
dexon-sol-tools-1443c0838cbd795ae8e6273b1d7659c8e449f2eb.tar.zst
dexon-sol-tools-1443c0838cbd795ae8e6273b1d7659c8e449f2eb.zip
Merge branch 'master' into remainingTokenMethods
# Conflicts: # src/types.ts # src/web3_wrapper.ts
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/assert.ts3
-rw-r--r--src/utils/schema_validator.ts16
2 files changed, 17 insertions, 2 deletions
diff --git a/src/utils/assert.ts b/src/utils/assert.ts
index 9a6a132e0..7dffcd98e 100644
--- a/src/utils/assert.ts
+++ b/src/utils/assert.ts
@@ -33,6 +33,9 @@ export const assert = {
isNumber(variableName: string, value: number): void {
this.assert(_.isFinite(value), this.typeAssertionMessage(variableName, 'number', 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..932ddf62a 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 representation. 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);