aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/assert.ts
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-07-05 09:17:57 +0800
committerGitHub <noreply@github.com>2017-07-05 09:17:57 +0800
commit74b2308488832290340f3a6c6473ab7340510dfc (patch)
treebe598e0355a72486125cacfad837a2d06342f170 /src/utils/assert.ts
parent3302d18f6e0a4b7e51b318959c6b2d040ae3c5ed (diff)
parent371acc0ba12197de735dea20e09d50bbfd524118 (diff)
downloaddexon-sol-tools-74b2308488832290340f3a6c6473ab7340510dfc.tar
dexon-sol-tools-74b2308488832290340f3a6c6473ab7340510dfc.tar.gz
dexon-sol-tools-74b2308488832290340f3a6c6473ab7340510dfc.tar.bz2
dexon-sol-tools-74b2308488832290340f3a6c6473ab7340510dfc.tar.lz
dexon-sol-tools-74b2308488832290340f3a6c6473ab7340510dfc.tar.xz
dexon-sol-tools-74b2308488832290340f3a6c6473ab7340510dfc.tar.zst
dexon-sol-tools-74b2308488832290340f3a6c6473ab7340510dfc.zip
Merge pull request #90 from 0xProject/subscribe-token
Add implementation and tests for zeroEx.token.subscribeAsync
Diffstat (limited to 'src/utils/assert.ts')
-rw-r--r--src/utils/assert.ts16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/utils/assert.ts b/src/utils/assert.ts
index 38c1d4aae..b3c30c11d 100644
--- a/src/utils/assert.ts
+++ b/src/utils/assert.ts
@@ -5,6 +5,7 @@ import {Web3Wrapper} from '../web3_wrapper';
import {Schema} from 'jsonschema';
import {SchemaValidator} from './schema_validator';
import {utils} from './utils';
+import {StringEnum} from '../types';
const HEX_REGEX = /^0x[0-9A-F]*$/i;
@@ -27,6 +28,16 @@ export const assert = {
const web3 = new Web3();
this.assert(web3.isAddress(value), this.typeAssertionMessage(variableName, 'ETHAddressHex', value));
},
+ doesBelongToStringEnum(variableName: string, value: string, stringEnum: StringEnum): void {
+ const doesBelongToStringEnum = !_.isUndefined(stringEnum[value]);
+ const enumValues = _.keys(stringEnum);
+ const enumValuesAsStrings = _.map(enumValues, enumValue => `'${enumValue}'`);
+ const enumValuesAsString = enumValuesAsStrings.join(', ');
+ assert.assert(
+ doesBelongToStringEnum,
+ `Expected ${variableName} to be one of: ${enumValuesAsString}, encountered: ${value}`,
+ );
+ },
async isSenderAddressAsync(variableName: string, senderAddressHex: string,
web3Wrapper: Web3Wrapper): Promise<void> {
assert.isETHAddressHex(variableName, senderAddressHex);
@@ -45,13 +56,10 @@ export const assert = {
isNumber(variableName: string, value: number): void {
this.assert(_.isFinite(value), this.typeAssertionMessage(variableName, 'number', value));
},
- 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 {
+ doesConformToSchema(variableName: string, value: any, schema: Schema): void {
const schemaValidator = new SchemaValidator();
const validationResult = schemaValidator.validate(value, schema);
const hasValidationErrors = validationResult.errors.length > 0;