aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-07-05 01:59:11 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-07-05 01:59:11 +0800
commit40d1d30b5816c9631fd4a0aa9824c6fea0d11bec (patch)
tree0500f5b0f8f6b4f5e0c3e6e33c0e7649390e5a19 /src
parent196194c04aa5dca0b11e86158e510ec49cf72030 (diff)
downloaddexon-sol-tools-40d1d30b5816c9631fd4a0aa9824c6fea0d11bec.tar
dexon-sol-tools-40d1d30b5816c9631fd4a0aa9824c6fea0d11bec.tar.gz
dexon-sol-tools-40d1d30b5816c9631fd4a0aa9824c6fea0d11bec.tar.bz2
dexon-sol-tools-40d1d30b5816c9631fd4a0aa9824c6fea0d11bec.tar.lz
dexon-sol-tools-40d1d30b5816c9631fd4a0aa9824c6fea0d11bec.tar.xz
dexon-sol-tools-40d1d30b5816c9631fd4a0aa9824c6fea0d11bec.tar.zst
dexon-sol-tools-40d1d30b5816c9631fd4a0aa9824c6fea0d11bec.zip
Add assert.doesBelongToStringEnum
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);