diff options
author | Fabio Berger <me@fabioberger.com> | 2018-01-25 23:42:58 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-01-25 23:42:58 +0800 |
commit | 71d68f975cd7bc089f0cbef4e5888a73eab4ee42 (patch) | |
tree | 9482602fc23d2baec3fff1fb97750ad45adc6eca /packages/assert/test | |
parent | ec3d8a034fe763d8255935985b1fb97aff6c177b (diff) | |
parent | f58f0ddb67555c3f0c7252ea3e003824984c48ad (diff) | |
download | dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.gz dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.bz2 dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.lz dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.xz dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.zst dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.zip |
Merge branch 'development' into feature/portal-ledger-support
* development: (437 commits)
Publish
Update yarn.lock
Update the CHANGELOG
Fix the bug making it impossible to specify the custom ZRX address
Fix fill/cancel order by looking for NoError instead of empty blockchainErr given the BlockchainErrs type refactor
Add a comment about a yarn bug
Add our mainnet and kovan nodes as backups for Portal requests
Fix bug hiding the user info from topBar
Add dev-utils package to top level README
Prettier newline
Prettier
Allow Token symbols to be alphanumeric
Update CHANGELOG, rebase on development
Should not -> cannot
Reject negative amounts in isValidBaseUnitAmount
Re-add changelog for 0x.js
Fix prettier
Update yarn.lock
Move tests to a separate folder
Change file layout
...
# Conflicts:
# packages/website/README.md
Diffstat (limited to 'packages/assert/test')
-rw-r--r-- | packages/assert/test/assert_test.ts | 162 |
1 files changed, 38 insertions, 124 deletions
diff --git a/packages/assert/test/assert_test.ts b/packages/assert/test/assert_test.ts index 5fa96e49a..b0fa398d6 100644 --- a/packages/assert/test/assert_test.ts +++ b/packages/assert/test/assert_test.ts @@ -1,10 +1,10 @@ -import {schemas} from '@0xproject/json-schemas'; -import {BigNumber} from 'bignumber.js'; +import { schemas } from '@0xproject/json-schemas'; +import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as dirtyChai from 'dirty-chai'; import 'mocha'; -import {assert} from '../src/index'; +import { assert } from '../src/index'; chai.config.includeStack = true; chai.use(dirtyChai); @@ -14,75 +14,45 @@ describe('Assertions', () => { const variableName = 'variable'; describe('#isBigNumber', () => { it('should not throw for valid input', () => { - const validInputs = [ - new BigNumber(23), - new BigNumber('45'), - ]; + 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, - ]; + const invalidInputs = ['test', 42, false, { random: 'test' }, undefined]; invalidInputs.forEach(input => expect(assert.isBigNumber.bind(assert, variableName, input)).to.throw()); }); }); - describe('#isUndefined', () => { + describe('#isValidBaseUnitAmount', () => { it('should not throw for valid input', () => { - const validInputs = [ - undefined, - ]; - validInputs.forEach(input => expect(assert.isUndefined.bind(assert, input, variableName)).to.not.throw()); + 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 = [ - 'test', - 42, - false, - { random: 'test' }, - ]; - invalidInputs.forEach(input => expect(assert.isUndefined.bind(assert, input, variableName)).to.throw()); + 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', - ]; + 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), - ]; + 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(this), - ]; + const validInputs = [BigNumber, assert.isString]; 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), - ]; + const invalidInputs = [42, false, { random: 'test' }, undefined, new BigNumber(45)]; invalidInputs.forEach(input => expect(assert.isFunction.bind(assert, variableName, input)).to.throw()); }); }); @@ -127,9 +97,7 @@ describe('Assertions', () => { '0x6FFFd0ae3f7d88c9b4925323f54c6e4b2918c5fd', '0x6FFFd0ae3f7d88c9b4925323f54c6e4', ]; - invalidInputs.forEach(input => - expect(assert.isETHAddressHex.bind(assert, variableName, input)).to.throw(), - ); + invalidInputs.forEach(input => expect(assert.isETHAddressHex.bind(assert, variableName, input)).to.throw()); }); }); describe('#doesBelongToStringEnum', () => { @@ -138,22 +106,13 @@ describe('Assertions', () => { Test2 = 'Test2', } it('should not throw for valid input', () => { - const validInputs = [ - TestEnums.Test1, - TestEnums.Test2, - ]; + 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), - ]; + const invalidInputs = [42, false, { random: 'test' }, undefined, new BigNumber(45)]; invalidInputs.forEach(input => expect(assert.doesBelongToStringEnum.bind(assert, variableName, input, TestEnums)).to.throw(), ); @@ -162,19 +121,13 @@ describe('Assertions', () => { describe('#hasAtMostOneUniqueValue', () => { const errorMsg = 'more than one unique value'; it('should not throw for valid input', () => { - const validInputs = [ - ['hello'], - ['goodbye', 'goodbye', 'goodbye'], - ]; + 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], - ]; + const invalidInputs = [['hello', 'goodbye'], ['goodbye', 42, false, false]]; invalidInputs.forEach(input => expect(assert.hasAtMostOneUniqueValue.bind(assert, input, errorMsg)).to.throw(), ); @@ -182,61 +135,34 @@ describe('Assertions', () => { }); describe('#isNumber', () => { it('should not throw for valid input', () => { - const validInputs = [ - 42, - 0, - 21e+42, - ]; + 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), - ]; + 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, - ]; + 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), - ]; + 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 }, - ]; + 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(), - ); + const invalidInputs = [42, { random: 'test' }, undefined, new BigNumber(45)]; + invalidInputs.forEach(input => expect(assert.isWeb3Provider.bind(assert, variableName, input)).to.throw()); }); }); describe('#doesConformToSchema', () => { @@ -251,12 +177,7 @@ describe('Assertions', () => { ); }); it('should throw for invalid input', () => { - const invalidInputs = [ - 42, - { random: 'test' }, - undefined, - new BigNumber(45), - ]; + const invalidInputs = [42, { random: 'test' }, undefined, new BigNumber(45)]; invalidInputs.forEach(input => expect(assert.doesConformToSchema.bind(assert, variableName, input, schema)).to.throw(), ); @@ -270,9 +191,7 @@ describe('Assertions', () => { 'https://api.radarrelay.com/0x/v0/', 'https://zeroex.beta.radarrelay.com:8000/0x/v0/', ]; - validInputs.forEach(input => - expect(assert.isHttpUrl.bind(assert, variableName, input)).to.not.throw(), - ); + validInputs.forEach(input => expect(assert.isHttpUrl.bind(assert, variableName, input)).to.not.throw()); }); it('should throw for invalid input', () => { const invalidInputs = [ @@ -286,9 +205,7 @@ describe('Assertions', () => { 'user:password@api.example-relayer.net', '//api.example-relayer.net', ]; - invalidInputs.forEach(input => - expect(assert.isHttpUrl.bind(assert, variableName, input)).to.throw(), - ); + invalidInputs.forEach(input => expect(assert.isHttpUrl.bind(assert, variableName, input)).to.throw()); }); }); describe('#isUri', () => { @@ -302,9 +219,7 @@ describe('Assertions', () => { '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(), - ); + validInputs.forEach(input => expect(assert.isUri.bind(assert, variableName, input)).to.not.throw()); }); it('should throw for invalid input', () => { const invalidInputs = [ @@ -316,9 +231,7 @@ describe('Assertions', () => { 'api.example-relayer.net', '//api.example-relayer.net', ]; - invalidInputs.forEach(input => - expect(assert.isUri.bind(assert, variableName, input)).to.throw(), - ); + invalidInputs.forEach(input => expect(assert.isUri.bind(assert, variableName, input)).to.throw()); }); }); describe('#assert', () => { @@ -332,8 +245,9 @@ describe('Assertions', () => { }); describe('#typeAssertionMessage', () => { it('should render correct message', () => { - expect(assert.typeAssertionMessage('variable', 'string', 'number')) - .to.equal(`Expected variable to be of type string, encountered: number`); + expect(assert.typeAssertionMessage('variable', 'string', 'number')).to.equal( + `Expected variable to be of type string, encountered: number`, + ); }); }); }); |