diff options
-rw-r--r-- | src/globals.d.ts | 4 | ||||
-rw-r--r-- | test/0x.js_test.ts | 30 | ||||
-rw-r--r-- | test/exchange_wrapper_test.ts | 16 |
3 files changed, 28 insertions, 22 deletions
diff --git a/src/globals.d.ts b/src/globals.d.ts index d86f54dfc..901377bd2 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -18,6 +18,10 @@ declare namespace Chai { bignumber: Assertion; // HACK: In order to comply with chai-as-promised we make eventually a `PromisedAssertion` not an `Assertion` eventually: PromisedAssertion; + true: () => void; + false: () => void; + rejected: () => void; + undefined: () => void; } } /* tslint:enable */ diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index a84785f4b..32040bd33 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -3,6 +3,7 @@ import * as chai from 'chai'; import 'mocha'; import * as BigNumber from 'bignumber.js'; import ChaiBigNumber = require('chai-bignumber'); +import * as dirtyChai from 'dirty-chai'; import * as Sinon from 'sinon'; import {ZeroEx} from '../src/0x.js'; import {constants} from './utils/constants'; @@ -11,6 +12,7 @@ import {Order} from '../src/types'; // Use BigNumber chai add-on chai.use(ChaiBigNumber()); +chai.use(dirtyChai); const expect = chai.expect; describe('ZeroEx library', () => { @@ -21,8 +23,8 @@ describe('ZeroEx library', () => { // Instantiate the contract instances with the current provider await (zeroEx.exchange as any).getExchangeContractAsync(); await (zeroEx.tokenRegistry as any).getTokenRegistryContractAsync(); - expect((zeroEx.exchange as any).exchangeContractIfExists).to.not.be.undefined; - expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.not.be.undefined; + expect((zeroEx.exchange as any).exchangeContractIfExists).to.not.be.undefined(); + expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.not.be.undefined(); const newProvider = web3Factory.getRpcProvider(); // Add property to newProvider so that we can differentiate it from old provider @@ -30,8 +32,8 @@ describe('ZeroEx library', () => { zeroEx.setProvider(newProvider); // Check that contractInstances with old provider are removed after provider update - expect((zeroEx.exchange as any).exchangeContractIfExists).to.be.undefined; - expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.be.undefined; + expect((zeroEx.exchange as any).exchangeContractIfExists).to.be.undefined(); + expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.be.undefined(); // Check that all nested web3 instances return the updated provider const nestedWeb3WrapperProvider = (zeroEx as any).web3Wrapper.getCurrentProvider(); @@ -118,47 +120,47 @@ describe('ZeroEx library', () => { }); it('should return false if the data doesn\'t pertain to the signature & address', () => { const isValid = ZeroEx.isValidSignature('0x0', signature, address); - expect(isValid).to.be.false; + expect(isValid).to.be.false(); }); it('should return false if the address doesn\'t pertain to the signature & data', () => { const validUnrelatedAddress = '0x8b0292B11a196601eD2ce54B665CaFEca0347D42'; const isValid = ZeroEx.isValidSignature(data, signature, validUnrelatedAddress); - expect(isValid).to.be.false; + expect(isValid).to.be.false(); }); it('should return false if the signature doesn\'t pertain to the data & address', () => { const wrongSignature = _.assign({}, signature, {v: 28}); const isValid = ZeroEx.isValidSignature(data, wrongSignature, address); - expect(isValid).to.be.false; + expect(isValid).to.be.false(); }); it('should return true if the signature does pertain to the data & address', () => { const isValid = ZeroEx.isValidSignature(data, signature, address); - expect(isValid).to.be.true; + expect(isValid).to.be.true(); }); }); describe('#generateSalt', () => { it('generates different salts', () => { const equal = ZeroEx.generatePseudoRandomSalt().eq(ZeroEx.generatePseudoRandomSalt()); - expect(equal).to.be.false; + expect(equal).to.be.false(); }); it('generates salt in range [0..2^256)', () => { const salt = ZeroEx.generatePseudoRandomSalt(); - expect(salt.greaterThanOrEqualTo(0)).to.be.true; + expect(salt.greaterThanOrEqualTo(0)).to.be.true(); const twoPow256 = new BigNumber(2).pow(256); - expect(salt.lessThan(twoPow256)).to.be.true; + expect(salt.lessThan(twoPow256)).to.be.true(); }); }); describe('#isValidOrderHash', () => { it('returns false if the value is not a hex string', () => { const isValid = ZeroEx.isValidOrderHash('not a hex'); - expect(isValid).to.be.false; + expect(isValid).to.be.false(); }); it('returns false if the length is wrong', () => { const isValid = ZeroEx.isValidOrderHash('0xdeadbeef'); - expect(isValid).to.be.false; + expect(isValid).to.be.false(); }); it('returns true if order hash is correct', () => { const isValid = ZeroEx.isValidOrderHash('0x' + Array(65).join('0')); - expect(isValid).to.be.true; + expect(isValid).to.be.true(); }); }); describe('#toUnitAmount', () => { diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index c0d5b292b..ca040ab28 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -51,7 +51,7 @@ describe('ExchangeWrapper', () => { s: signature.s, }; expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address)) - .to.be.rejected; + .to.be.rejected(); }); it('r lacks 0x prefix', () => { const malformedR = signature.r.replace('0x', ''); @@ -61,7 +61,7 @@ describe('ExchangeWrapper', () => { s: signature.s, }; expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address)) - .to.be.rejected; + .to.be.rejected(); }); it('r is too short', () => { const malformedR = signature.r.substr(10); @@ -71,7 +71,7 @@ describe('ExchangeWrapper', () => { s: signature.s.replace('0', 'z'), }; expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address)) - .to.be.rejected; + .to.be.rejected(); }); it('s is not hex', () => { const malformedS = signature.s.replace('0', 'z'); @@ -81,26 +81,26 @@ describe('ExchangeWrapper', () => { s: malformedS, }; expect(zeroEx.exchange.isValidSignatureAsync(dataHex, malformedSignature, address)) - .to.be.rejected; + .to.be.rejected(); }); }); it('should return false if the data doesn\'t pertain to the signature & address', async () => { const isValid = await zeroEx.exchange.isValidSignatureAsync('0x0', signature, address); - expect(isValid).to.be.false; + expect(isValid).to.be.false(); }); it('should return false if the address doesn\'t pertain to the signature & dataHex', async () => { const validUnrelatedAddress = '0x8b0292B11a196601eD2ce54B665CaFEca0347D42'; const isValid = await zeroEx.exchange.isValidSignatureAsync(dataHex, signature, validUnrelatedAddress); - expect(isValid).to.be.false; + expect(isValid).to.be.false(); }); it('should return false if the signature doesn\'t pertain to the dataHex & address', async () => { const wrongSignature = {...signature, v: 28}; const isValid = await zeroEx.exchange.isValidSignatureAsync(dataHex, wrongSignature, address); - expect(isValid).to.be.false; + expect(isValid).to.be.false(); }); it('should return true if the signature does pertain to the dataHex & address', async () => { const isValid = await zeroEx.exchange.isValidSignatureAsync(dataHex, signature, address); - expect(isValid).to.be.true; + expect(isValid).to.be.true(); }); }); describe('#fillOrderAsync', () => { |