diff options
author | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
---|---|---|
committer | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
commit | 7ae38906926dc09bc10670c361af0d2bf0050426 (patch) | |
tree | 5fb10ae366b987db09e4ddb4bc3ba0f75404ad08 /packages/assert | |
parent | b5fd3c72a08aaa6957917d74c333387a16edf66b (diff) | |
download | dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.gz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.bz2 dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.lz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.xz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.zst dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.zip |
Update dependency packages
Diffstat (limited to 'packages/assert')
-rw-r--r-- | packages/assert/.npmignore | 7 | ||||
-rw-r--r-- | packages/assert/CHANGELOG.json | 373 | ||||
-rw-r--r-- | packages/assert/CHANGELOG.md | 164 | ||||
-rw-r--r-- | packages/assert/README.md | 77 | ||||
-rw-r--r-- | packages/assert/coverage/.gitkeep | 0 | ||||
-rw-r--r-- | packages/assert/package.json | 56 | ||||
-rw-r--r-- | packages/assert/src/globals.d.ts | 6 | ||||
-rw-r--r-- | packages/assert/src/index.ts | 97 | ||||
-rw-r--r-- | packages/assert/test/assert_test.ts | 255 | ||||
-rw-r--r-- | packages/assert/tsconfig.json | 8 | ||||
-rw-r--r-- | packages/assert/tslint.json | 3 |
11 files changed, 0 insertions, 1046 deletions
diff --git a/packages/assert/.npmignore b/packages/assert/.npmignore deleted file mode 100644 index 44df80fad..000000000 --- a/packages/assert/.npmignore +++ /dev/null @@ -1,7 +0,0 @@ -.* -yarn-error.log -/src/ -/scripts/ -test/ -tsconfig.json -/lib/src/monorepo_scripts/ diff --git a/packages/assert/CHANGELOG.json b/packages/assert/CHANGELOG.json deleted file mode 100644 index 278b7dfa1..000000000 --- a/packages/assert/CHANGELOG.json +++ /dev/null @@ -1,373 +0,0 @@ -[ - { - "version": "2.0.0", - "changes": [ - { - "note": "Upgrade the bignumber.js to v8.0.2", - "pr": 1517 - } - ] - }, - { - "timestamp": 1547561734, - "version": "1.0.23", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547225310, - "version": "1.0.22", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547040760, - "version": "1.0.21", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "1.0.20", - "changes": [ - { - "note": "Dependencies updated" - } - ], - "timestamp": 1544739608 - }, - { - "version": "1.0.19", - "changes": [ - { - "note": "Dependencies updated" - } - ], - "timestamp": 1544570656 - }, - { - "timestamp": 1542821676, - "version": "1.0.18", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1542208198, - "version": "1.0.17", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1542028948, - "version": "1.0.16", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "1.0.15", - "changes": [ - { - "note": "Dependencies updated" - } - ], - "timestamp": 1541740904 - }, - { - "timestamp": 1539871071, - "version": "1.0.14", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "1.0.13", - "changes": [ - { - "note": "Dependencies updated" - } - ], - "timestamp": 1538693146 - }, - { - "timestamp": 1538157789, - "version": "1.0.12", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1537907159, - "version": "1.0.11", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1537875740, - "version": "1.0.10", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1537541580, - "version": "1.0.9", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1536142250, - "version": "1.0.8", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1535377027, - "version": "1.0.7", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1535133899, - "version": "1.0.6", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1534210131, - "version": "1.0.5", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532619515, - "version": "1.0.4", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532614997, - "version": "1.0.3", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532605697, - "version": "1.0.2", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532357734, - "version": "1.0.1", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532043000, - "version": "1.0.0", - "changes": [ - { - "note": "Fix bug in string enum assertion. We erroneously were checking against the enum keys, not values", - "pr": 821 - } - ] - }, - { - "timestamp": 1531919263, - "version": "0.2.14", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1531149657, - "version": "0.2.13", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1529397769, - "version": "0.2.12", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "0.2.11", - "changes": [ - { - "note": "Incorrect publish that was unpublished" - } - ], - "timestamp": 1527810075 - }, - { - "timestamp": 1527008270, - "version": "0.2.10", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1525477860, - "version": "0.2.9", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1525428773, - "version": "0.2.8", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1524044013, - "version": "0.2.7", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1523462196, - "version": "0.2.6", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1522673609, - "version": "0.2.5", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1522658513, - "version": "0.2.4", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "0.2.0", - "changes": [ - { - "note": "Rename `isHttpUrl` to `isWebUri`", - "pr": 412 - } - ], - "timestamp": 1520434800 - }, - { - "version": "0.1.0", - "changes": [ - { - "note": "Remove isETHAddressHex checksum address check and assume address will be lowercased ", - "pr": 373 - }, - { - "note": "Add an optional parameter `subSchemas` to `doesConformToSchema` method", - "pr": 385 - } - ], - "timestamp": 1520089200 - }, - { - "version": "0.0.18", - "changes": [ - { - "note": "Fix publishing issue where .npmignore was not properly excluding undesired content", - "pr": 389 - } - ], - "timestamp": 1486566000 - }, - { - "version": "0.0.4", - "changes": [ - { - "note": "Re-publish Assert previously published under NPM package @0xproject/0x-assert" - }, - { - "note": "Added assertion isValidBaseUnitAmount which checks both that the value is a valid bigNumber and that it does not contain decimals." - } - ], - "timestamp": 1510585200 - } -] diff --git a/packages/assert/CHANGELOG.md b/packages/assert/CHANGELOG.md deleted file mode 100644 index 5a4af165a..000000000 --- a/packages/assert/CHANGELOG.md +++ /dev/null @@ -1,164 +0,0 @@ -<!-- -changelogUtils.file is auto-generated using the monorepo-scripts package. Don't edit directly. -Edit the package's CHANGELOG.json file only. ---> - -CHANGELOG - -## v1.0.23 - _January 15, 2019_ - - * Dependencies updated - -## v1.0.22 - _January 11, 2019_ - - * Dependencies updated - -## v1.0.21 - _January 9, 2019_ - - * Dependencies updated - -## v1.0.20 - _December 13, 2018_ - - * Dependencies updated - -## v1.0.19 - _December 11, 2018_ - - * Dependencies updated - -## v1.0.18 - _November 21, 2018_ - - * Dependencies updated - -## v1.0.17 - _November 14, 2018_ - - * Dependencies updated - -## v1.0.16 - _November 12, 2018_ - - * Dependencies updated - -## v1.0.15 - _November 9, 2018_ - - * Dependencies updated - -## v1.0.14 - _October 18, 2018_ - - * Dependencies updated - -## v1.0.13 - _October 4, 2018_ - - * Dependencies updated - -## v1.0.12 - _September 28, 2018_ - - * Dependencies updated - -## v1.0.11 - _September 25, 2018_ - - * Dependencies updated - -## v1.0.10 - _September 25, 2018_ - - * Dependencies updated - -## v1.0.9 - _September 21, 2018_ - - * Dependencies updated - -## v1.0.8 - _September 5, 2018_ - - * Dependencies updated - -## v1.0.7 - _August 27, 2018_ - - * Dependencies updated - -## v1.0.6 - _August 24, 2018_ - - * Dependencies updated - -## v1.0.5 - _August 14, 2018_ - - * Dependencies updated - -## v1.0.4 - _July 26, 2018_ - - * Dependencies updated - -## v1.0.3 - _July 26, 2018_ - - * Dependencies updated - -## v1.0.2 - _July 26, 2018_ - - * Dependencies updated - -## v1.0.1 - _July 23, 2018_ - - * Dependencies updated - -## v1.0.0 - _July 19, 2018_ - - * Fix bug in string enum assertion. We erroneously were checking against the enum keys, not values (#821) - -## v0.2.14 - _July 18, 2018_ - - * Dependencies updated - -## v0.2.13 - _July 9, 2018_ - - * Dependencies updated - -## v0.2.12 - _June 19, 2018_ - - * Dependencies updated - -## v0.2.11 - _May 31, 2018_ - - * Incorrect publish that was unpublished - -## v0.2.10 - _May 22, 2018_ - - * Dependencies updated - -## v0.2.9 - _May 4, 2018_ - - * Dependencies updated - -## v0.2.8 - _May 4, 2018_ - - * Dependencies updated - -## v0.2.7 - _April 18, 2018_ - - * Dependencies updated - -## v0.2.6 - _April 11, 2018_ - - * Dependencies updated - -## v0.2.5 - _April 2, 2018_ - - * Dependencies updated - -## v0.2.4 - _April 2, 2018_ - - * Dependencies updated - -## v0.2.0 - _March 7, 2018_ - - * Rename `isHttpUrl` to `isWebUri` (#412) - -## v0.1.0 - _March 3, 2018_ - - * Remove isETHAddressHex checksum address check and assume address will be lowercased (#373) - * Add an optional parameter `subSchemas` to `doesConformToSchema` method (#385) - -## v0.0.18 - _February 8, 2017_ - - * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) - -## v0.0.4 - _November 13, 2017_ - - * Re-publish Assert previously published under NPM package @0xproject/0x-assert - * Added assertion isValidBaseUnitAmount which checks both that the value is a valid bigNumber and that it does not contain decimals. diff --git a/packages/assert/README.md b/packages/assert/README.md deleted file mode 100644 index 647586f15..000000000 --- a/packages/assert/README.md +++ /dev/null @@ -1,77 +0,0 @@ -## @0x/assert - -Standard type and schema assertions to be used across all 0x projects and packages - -## Installation - -```bash -yarn add @0x/assert -``` - -## Usage - -```typescript -import { assert } from '@0x/assert'; - -assert.isValidBaseUnitAmount('baseUnitAmount', baseUnitAmount); -``` - -If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: - -```json -"compilerOptions": { - "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"], -} -``` - -## Contributing - -We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository. - -Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started. - -### Install dependencies - -If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them: - -```bash -yarn config set workspaces-experimental true -``` - -Then install dependencies - -```bash -yarn install -``` - -### Build - -To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: - -```bash -PKG=@0x/assert yarn build -``` - -Or continuously rebuild on change: - -```bash -PKG=@0x/assert yarn watch -``` - -### Clean - -```bash -yarn clean -``` - -### Lint - -```bash -yarn lint -``` - -### Run Tests - -```bash -yarn test -``` diff --git a/packages/assert/coverage/.gitkeep b/packages/assert/coverage/.gitkeep deleted file mode 100644 index e69de29bb..000000000 --- a/packages/assert/coverage/.gitkeep +++ /dev/null diff --git a/packages/assert/package.json b/packages/assert/package.json deleted file mode 100644 index 38481d6f0..000000000 --- a/packages/assert/package.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "name": "@0x/assert", - "version": "1.0.23", - "engines": { - "node": ">=6.12" - }, - "description": "Provides a standard way of performing type and schema validation across 0x projects", - "main": "lib/src/index.js", - "types": "lib/src/index.d.ts", - "scripts": { - "build": "tsc -b", - "build:ci": "yarn build", - "clean": "shx rm -rf lib test_temp", - "lint": "tslint --format stylish --project .", - "run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js --exit", - "test": "yarn run_mocha", - "rebuild_and_test": "run-s clean build test", - "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", - "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", - "test:circleci": "yarn test:coverage" - }, - "license": "Apache-2.0", - "repository": { - "type": "git", - "url": "https://github.com/0xProject/0x-monorepo.git" - }, - "bugs": { - "url": "https://github.com/0xProject/0x-monorepo/issues" - }, - "homepage": "https://github.com/0xProject/0x-monorepo/packages/assert/README.md", - "devDependencies": { - "@0x/tslint-config": "^2.0.2", - "@types/lodash": "4.14.104", - "@types/mocha": "^2.2.42", - "@types/valid-url": "^1.0.2", - "chai": "^4.0.1", - "dirty-chai": "^2.0.1", - "make-promises-safe": "^1.1.0", - "mocha": "^4.1.0", - "npm-run-all": "^4.1.2", - "nyc": "^11.0.1", - "shx": "^0.2.2", - "tslint": "5.11.0", - "typescript": "3.0.1" - }, - "dependencies": { - "@0x/json-schemas": "^2.1.7", - "@0x/typescript-typings": "^3.0.8", - "@0x/utils": "^3.0.1", - "lodash": "^4.17.5", - "valid-url": "^1.0.9" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/assert/src/globals.d.ts b/packages/assert/src/globals.d.ts deleted file mode 100644 index 94e63a32d..000000000 --- a/packages/assert/src/globals.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -declare module '*.json' { - const json: any; - /* tslint:disable */ - export default json; - /* tslint:enable */ -} diff --git a/packages/assert/src/index.ts b/packages/assert/src/index.ts deleted file mode 100644 index 741bd78e1..000000000 --- a/packages/assert/src/index.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { Schema, SchemaValidator } from '@0x/json-schemas'; -import { addressUtils, BigNumber } from '@0x/utils'; -import * as _ from 'lodash'; -import * as validUrl from 'valid-url'; - -const HEX_REGEX = /^0x[0-9A-F]*$/i; - -export const assert = { - isBigNumber(variableName: string, value: BigNumber): void { - const isBigNumber = BigNumber.isBigNumber(value); - assert.assert(isBigNumber, assert.typeAssertionMessage(variableName, 'BigNumber', value)); - }, - isValidBaseUnitAmount(variableName: string, value: BigNumber): void { - assert.isBigNumber(variableName, value); - const isNegative = value.isLessThan(0); - assert.assert(!isNegative, `${variableName} cannot be a negative number, found value: ${value.toNumber()}`); - const hasDecimals = value.decimalPlaces() !== 0; - assert.assert( - !hasDecimals, - `${variableName} should be in baseUnits (no decimals), found value: ${value.toNumber()}`, - ); - }, - isString(variableName: string, value: string): void { - assert.assert(_.isString(value), assert.typeAssertionMessage(variableName, 'string', value)); - }, - isFunction(variableName: string, value: any): void { - assert.assert(_.isFunction(value), assert.typeAssertionMessage(variableName, 'function', value)); - }, - isHexString(variableName: string, value: string): void { - assert.assert( - _.isString(value) && HEX_REGEX.test(value), - assert.typeAssertionMessage(variableName, 'HexString', value), - ); - }, - isETHAddressHex(variableName: string, value: string): void { - assert.assert(_.isString(value), assert.typeAssertionMessage(variableName, 'string', value)); - assert.assert(addressUtils.isAddress(value), assert.typeAssertionMessage(variableName, 'ETHAddressHex', value)); - }, - doesBelongToStringEnum( - variableName: string, - value: string, - stringEnum: any /* There is no base type for every string enum */, - ): void { - const enumValues = _.values(stringEnum); - const doesBelongToStringEnum = _.includes(enumValues, value); - const enumValuesAsStrings = _.map(enumValues, enumValue => `'${enumValue}'`); - const enumValuesAsString = enumValuesAsStrings.join(', '); - assert.assert( - doesBelongToStringEnum, - `Expected ${variableName} to be one of: ${enumValuesAsString}, encountered: ${value}`, - ); - }, - hasAtMostOneUniqueValue(value: any[], errMsg: string): void { - assert.assert(_.uniq(value).length <= 1, errMsg); - }, - isNumber(variableName: string, value: number): void { - assert.assert(_.isFinite(value), assert.typeAssertionMessage(variableName, 'number', value)); - }, - isBoolean(variableName: string, value: boolean): void { - assert.assert(_.isBoolean(value), assert.typeAssertionMessage(variableName, 'boolean', value)); - }, - isWeb3Provider(variableName: string, value: any): void { - const isWeb3Provider = _.isFunction(value.send) || _.isFunction(value.sendAsync); - assert.assert(isWeb3Provider, assert.typeAssertionMessage(variableName, 'Provider', value)); - }, - doesConformToSchema(variableName: string, value: any, schema: Schema, subSchemas?: Schema[]): void { - if (_.isUndefined(value)) { - throw new Error(`${variableName} can't be undefined`); - } - const schemaValidator = new SchemaValidator(); - if (!_.isUndefined(subSchemas)) { - _.map(subSchemas, schemaValidator.addSchema.bind(schemaValidator)); - } - const validationResult = schemaValidator.validate(value, schema); - const hasValidationErrors = validationResult.errors.length > 0; - const msg = `Expected ${variableName} to conform to schema ${schema.id} -Encountered: ${JSON.stringify(value, null, '\t')} -Validation errors: ${validationResult.errors.join(', ')}`; - assert.assert(!hasValidationErrors, msg); - }, - isWebUri(variableName: string, value: any): void { - const isValidUrl = !_.isUndefined(validUrl.isWebUri(value)); - assert.assert(isValidUrl, assert.typeAssertionMessage(variableName, 'web uri', value)); - }, - isUri(variableName: string, value: any): void { - const isValidUri = !_.isUndefined(validUrl.isUri(value)); - assert.assert(isValidUri, assert.typeAssertionMessage(variableName, 'uri', value)); - }, - assert(condition: boolean, message: string): void { - if (!condition) { - throw new Error(message); - } - }, - typeAssertionMessage(variableName: string, type: string, value: any): string { - return `Expected ${variableName} to be of type ${type}, encountered: ${value}`; - }, -}; diff --git a/packages/assert/test/assert_test.ts b/packages/assert/test/assert_test.ts deleted file mode 100644 index 9266496ac..000000000 --- a/packages/assert/test/assert_test.ts +++ /dev/null @@ -1,255 +0,0 @@ -import { schemas } from '@0x/json-schemas'; -import { BigNumber } from '@0x/utils'; -import * as chai from 'chai'; -import * as dirtyChai from 'dirty-chai'; -import 'mocha'; - -import { assert } from '../src/index'; - -chai.config.includeStack = true; -chai.use(dirtyChai); -const expect = chai.expect; - -// tslint:disable:custom-no-magic-numbers -describe('Assertions', () => { - const variableName = 'variable'; - describe('#isBigNumber', () => { - it('should not throw for valid input', () => { - const validInputs = [new BigNumber(23), new BigNumber('45')]; - validInputs.forEach(input => expect(assert.isBigNumber.bind(assert, variableName, input)).to.not.throw()); - }); - it('should throw for invalid input', () => { - const invalidInputs = ['test', 42, false, { random: 'test' }, undefined]; - invalidInputs.forEach(input => expect(assert.isBigNumber.bind(assert, variableName, input)).to.throw()); - }); - }); - describe('#isValidBaseUnitAmount', () => { - it('should not throw for valid input', () => { - const validInputs = [new BigNumber(23), new BigNumber('45000000')]; - validInputs.forEach(input => - expect(assert.isValidBaseUnitAmount.bind(assert, variableName, input)).to.not.throw(), - ); - }); - it('should throw for invalid input', () => { - const invalidInputs = [0, undefined, new BigNumber(3.145), 3.145, new BigNumber(-400)]; - invalidInputs.forEach(input => - expect(assert.isValidBaseUnitAmount.bind(assert, variableName, input)).to.throw(), - ); - }); - }); - describe('#isString', () => { - it('should not throw for valid input', () => { - const validInputs = ['hello', 'goodbye']; - validInputs.forEach(input => expect(assert.isString.bind(assert, variableName, input)).to.not.throw()); - }); - it('should throw for invalid input', () => { - const invalidInputs = [42, false, { random: 'test' }, undefined, new BigNumber(45)]; - invalidInputs.forEach(input => expect(assert.isString.bind(assert, variableName, input)).to.throw()); - }); - }); - describe('#isFunction', () => { - it('should not throw for valid input', () => { - const validInputs = [BigNumber, assert.isString.bind(assert)]; - validInputs.forEach(input => expect(assert.isFunction.bind(assert, variableName, input)).to.not.throw()); - }); - it('should throw for invalid input', () => { - const invalidInputs = [42, false, { random: 'test' }, undefined, new BigNumber(45)]; - invalidInputs.forEach(input => expect(assert.isFunction.bind(assert, variableName, input)).to.throw()); - }); - }); - describe('#isHexString', () => { - it('should not throw for valid input', () => { - const validInputs = [ - '0x61a3ed31B43c8780e905a260a35faefEc527be7516aa11c0256729b5b351bc33', - '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', - ]; - validInputs.forEach(input => expect(assert.isHexString.bind(assert, variableName, input)).to.not.throw()); - }); - it('should throw for invalid input', () => { - const invalidInputs = [ - 42, - false, - { random: 'test' }, - undefined, - new BigNumber(45), - '0x61a3ed31B43c8780e905a260a35faYfEc527be7516aa11c0256729b5b351bc33', - ]; - invalidInputs.forEach(input => expect(assert.isHexString.bind(assert, variableName, input)).to.throw()); - }); - }); - describe('#isETHAddressHex', () => { - it('should not throw for valid input', () => { - const validInputs = [ - '0x0000000000000000000000000000000000000000', - '0x6fffd0ae3f7d88c9b4925323f54c6e4b2918c5fd', - '0x12459c951127e0c374ff9105dda097662a027093', - ]; - validInputs.forEach(input => - expect(assert.isETHAddressHex.bind(assert, variableName, input)).to.not.throw(), - ); - }); - it('should throw for invalid input', () => { - const invalidInputs = [ - 42, - false, - { random: 'test' }, - undefined, - new BigNumber(45), - '0x6FFFd0ae3f7d88c9b4925323f54c6e4b2918c5fd', - '0x6FFFd0ae3f7d88c9b4925323f54c6e4', - ]; - invalidInputs.forEach(input => expect(assert.isETHAddressHex.bind(assert, variableName, input)).to.throw()); - }); - }); - describe('#doesBelongToStringEnum', () => { - enum TestEnums { - Test1 = 'Test1', - Test2 = 'Test2', - } - it('should not throw for valid input', () => { - const validInputs = [TestEnums.Test1, TestEnums.Test2]; - validInputs.forEach(input => - expect(assert.doesBelongToStringEnum.bind(assert, variableName, input, TestEnums)).to.not.throw(), - ); - }); - it('should throw for invalid input', () => { - const invalidInputs = [42, false, { random: 'test' }, undefined, new BigNumber(45)]; - invalidInputs.forEach(input => - expect(assert.doesBelongToStringEnum.bind(assert, variableName, input, TestEnums)).to.throw(), - ); - }); - }); - describe('#hasAtMostOneUniqueValue', () => { - const errorMsg = 'more than one unique value'; - it('should not throw for valid input', () => { - const validInputs = [['hello'], ['goodbye', 'goodbye', 'goodbye']]; - validInputs.forEach(input => - expect(assert.hasAtMostOneUniqueValue.bind(assert, input, errorMsg)).to.not.throw(), - ); - }); - it('should throw for invalid input', () => { - const invalidInputs = [['hello', 'goodbye'], ['goodbye', 42, false, false]]; - invalidInputs.forEach(input => - expect(assert.hasAtMostOneUniqueValue.bind(assert, input, errorMsg)).to.throw(), - ); - }); - }); - describe('#isNumber', () => { - it('should not throw for valid input', () => { - const validInputs = [42, 0, 21e42]; - validInputs.forEach(input => expect(assert.isNumber.bind(assert, variableName, input)).to.not.throw()); - }); - it('should throw for invalid input', () => { - const invalidInputs = [false, { random: 'test' }, undefined, new BigNumber(45)]; - invalidInputs.forEach(input => expect(assert.isNumber.bind(assert, variableName, input)).to.throw()); - }); - }); - describe('#isBoolean', () => { - it('should not throw for valid input', () => { - const validInputs = [true, false]; - validInputs.forEach(input => expect(assert.isBoolean.bind(assert, variableName, input)).to.not.throw()); - }); - it('should throw for invalid input', () => { - const invalidInputs = [42, { random: 'test' }, undefined, new BigNumber(45)]; - invalidInputs.forEach(input => expect(assert.isBoolean.bind(assert, variableName, input)).to.throw()); - }); - }); - describe('#isWeb3Provider', () => { - it('should not throw for valid input', () => { - const validInputs = [{ send: () => 45 }, { sendAsync: () => 45 }]; - validInputs.forEach(input => - expect(assert.isWeb3Provider.bind(assert, variableName, input)).to.not.throw(), - ); - }); - it('should throw for invalid input', () => { - const invalidInputs = [42, { random: 'test' }, undefined, new BigNumber(45)]; - invalidInputs.forEach(input => expect(assert.isWeb3Provider.bind(assert, variableName, input)).to.throw()); - }); - }); - describe('#doesConformToSchema', () => { - const schema = schemas.addressSchema; - it('should not throw for valid input', () => { - const validInputs = [ - '0x6fffd0ae3f7d88c9b4925323f54c6e4b2918c5fd', - '0x12459c951127e0c374ff9105dda097662a027093', - ]; - validInputs.forEach(input => - expect(assert.doesConformToSchema.bind(assert, variableName, input, schema)).to.not.throw(), - ); - }); - it('should throw for invalid input', () => { - const invalidInputs = [42, { random: 'test' }, undefined, new BigNumber(45)]; - invalidInputs.forEach(input => - expect(assert.doesConformToSchema.bind(assert, variableName, input, schema)).to.throw(), - ); - }); - }); - describe('#isWebUri', () => { - it('should not throw for valid input', () => { - const validInputs = [ - 'http://www.google.com', - 'https://api.example-relayer.net', - 'https://api.radarrelay.com/0x/v0/', - 'https://zeroex.beta.radarrelay.com:8000/0x/v0/', - ]; - validInputs.forEach(input => expect(assert.isWebUri.bind(assert, variableName, input)).to.not.throw()); - }); - it('should throw for invalid input', () => { - const invalidInputs = [ - 42, - { random: 'test' }, - undefined, - new BigNumber(45), - 'ws://www.api.example-relayer.net', - 'www.google.com', - 'api.example-relayer.net', - 'user:password@api.example-relayer.net', - '//api.example-relayer.net', - ]; - invalidInputs.forEach(input => expect(assert.isWebUri.bind(assert, variableName, input)).to.throw()); - }); - }); - describe('#isUri', () => { - it('should not throw for valid input', () => { - const validInputs = [ - 'http://www.google.com', - 'https://api.example-relayer.net', - 'https://api.radarrelay.com/0x/v0/', - 'https://zeroex.beta.radarrelay.com:8000/0x/v0/', - 'ws://www.api.example-relayer.net', - 'wss://www.api.example-relayer.net', - 'user:password@api.example-relayer.net', - ]; - validInputs.forEach(input => expect(assert.isUri.bind(assert, variableName, input)).to.not.throw()); - }); - it('should throw for invalid input', () => { - const invalidInputs = [ - 42, - { random: 'test' }, - undefined, - new BigNumber(45), - 'www.google.com', - 'api.example-relayer.net', - '//api.example-relayer.net', - ]; - invalidInputs.forEach(input => expect(assert.isUri.bind(assert, variableName, input)).to.throw()); - }); - }); - describe('#assert', () => { - const assertMessage = 'assert not satisfied'; - it('should not throw for valid input', () => { - expect(assert.assert.bind(assert, true, assertMessage)).to.not.throw(); - }); - it('should throw for invalid input', () => { - expect(assert.assert.bind(assert, false, assertMessage)).to.throw(); - }); - }); - describe('#typeAssertionMessage', () => { - it('should render correct message', () => { - expect(assert.typeAssertionMessage('variable', 'string', 'number')).to.equal( - `Expected variable to be of type string, encountered: number`, - ); - }); - }); -}); -// tslint:enable:custom-no-magic-numbers diff --git a/packages/assert/tsconfig.json b/packages/assert/tsconfig.json deleted file mode 100644 index 2ee711adc..000000000 --- a/packages/assert/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "rootDir": "." - }, - "include": ["./src/**/*", "./test/**/*"] -} diff --git a/packages/assert/tslint.json b/packages/assert/tslint.json deleted file mode 100644 index dd9053357..000000000 --- a/packages/assert/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": ["@0x/tslint-config"] -} |