aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/utils/assert.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/utils/assert.ts b/src/utils/assert.ts
index ec3790870..029b69321 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);