aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/assert.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-11-13 10:12:37 +0800
committerFabio Berger <me@fabioberger.com>2017-11-13 10:12:37 +0800
commite33027c6244b99a1fb181404668bd2a259d923e2 (patch)
tree24438eda01318a80b5cbc7f1939d1640764a9859 /src/utils/assert.ts
parent5d2b6585c66fc17a36bb9841a3b3fb009e23024c (diff)
parentb0be323e899ea7be42b6c695b4fd6d526070b213 (diff)
downloaddexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar
dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.gz
dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.bz2
dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.lz
dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.xz
dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.tar.zst
dexon-sol-tools-e33027c6244b99a1fb181404668bd2a259d923e2.zip
Merge branch 'development' into feature/receipt-status
* development: (164 commits) Remove old tests Remove unused code Fix tests Remove redundant spaces Don't store empty objects Fix a typo Remove duplicate operations Remove redundant instance variables Fix tests Remove blockStore and default to numConfirmations === 0 Add a comment Store number of confirmations in a blockStore Remove tautology check Pass blockStore to eventWatcher Fix last merge conflicts Clear cache on unsubscribe Clear store cache on events Add more configs for order watcher Make subscribe function async and make blockStore operational Adjust tests to new interface ... # Conflicts: # package.json # src/types.ts # yarn.lock
Diffstat (limited to 'src/utils/assert.ts')
-rw-r--r--src/utils/assert.ts17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/utils/assert.ts b/src/utils/assert.ts
index 286105345..e5c9439f3 100644
--- a/src/utils/assert.ts
+++ b/src/utils/assert.ts
@@ -1,8 +1,10 @@
import * as _ from 'lodash';
-import BigNumber from 'bignumber.js';
import * as Web3 from 'web3';
-import {Web3Wrapper} from '../web3_wrapper';
+import BigNumber from 'bignumber.js';
import {SchemaValidator, Schema} from '0x-json-schemas';
+import {Web3Wrapper} from '../web3_wrapper';
+import {signatureUtils} from '../utils/signature_utils';
+import {ECSignature} from '../types';
const HEX_REGEX = /^0x[0-9A-F]*$/i;
@@ -11,6 +13,17 @@ export const assert = {
const isBigNumber = _.isObject(value) && (value as any).isBigNumber;
this.assert(isBigNumber, this.typeAssertionMessage(variableName, 'BigNumber', value));
},
+ isValidBaseUnitAmount(variableName: string, value: BigNumber) {
+ assert.isBigNumber(variableName, value);
+ const hasDecimals = value.decimalPlaces() !== 0;
+ this.assert(
+ !hasDecimals, `${variableName} should be in baseUnits (no decimals), found value: ${value.toNumber()}`,
+ );
+ },
+ isValidSignature(orderHash: string, ecSignature: ECSignature, signerAddress: string) {
+ const isValidSignature = signatureUtils.isValidSignature(orderHash, ecSignature, signerAddress);
+ this.assert(isValidSignature, `Expected order with hash '${orderHash}' to have a valid signature`);
+ },
isUndefined(value: any, variableName?: string): void {
this.assert(_.isUndefined(value), this.typeAssertionMessage(variableName, 'undefined', value));
},