diff options
-rw-r--r-- | src/ts/0x.js.ts | 23 | ||||
-rw-r--r-- | src/ts/utils/utils.ts | 11 | ||||
-rw-r--r-- | test/0x.js_test.ts | 5 |
3 files changed, 21 insertions, 18 deletions
diff --git a/src/ts/0x.js.ts b/src/ts/0x.js.ts index bd4978c96..1ebafc604 100644 --- a/src/ts/0x.js.ts +++ b/src/ts/0x.js.ts @@ -1,12 +1,12 @@ import * as _ from 'lodash'; import * as BigNumber from 'bignumber.js'; -import * as BN from 'bn.js'; import * as ethUtil from 'ethereumjs-util'; import contract = require('truffle-contract'); import * as Web3 from 'web3'; import * as ethABI from 'ethereumjs-abi'; import {Web3Wrapper} from './web3_wrapper'; import {constants} from './utils/constants'; +import {utils} from './utils/utils'; import {assert} from './utils/assert'; import {ExchangeWrapper} from './contract_wrappers/exchange_wrapper'; import {ECSignatureSchema} from './schemas/ec_signature_schema'; @@ -46,12 +46,12 @@ export class ZeroEx { {value: tokenMAddress, type: SolidityTypes.address}, {value: tokenTAddress, type: SolidityTypes.address}, {value: feeRecipient, type: SolidityTypes.address}, - {value: this.bigNumberToBN(valueM), type: SolidityTypes.uint256}, - {value: this.bigNumberToBN(valueT), type: SolidityTypes.uint256}, - {value: this.bigNumberToBN(makerFee), type: SolidityTypes.uint256}, - {value: this.bigNumberToBN(takerFee), type: SolidityTypes.uint256}, - {value: this.bigNumberToBN(expiration), type: SolidityTypes.uint256}, - {value: this.bigNumberToBN(salt), type: SolidityTypes.uint256}, + {value: utils.bigNumberToBN(valueM), type: SolidityTypes.uint256}, + {value: utils.bigNumberToBN(valueT), type: SolidityTypes.uint256}, + {value: utils.bigNumberToBN(makerFee), type: SolidityTypes.uint256}, + {value: utils.bigNumberToBN(takerFee), type: SolidityTypes.uint256}, + {value: utils.bigNumberToBN(expiration), type: SolidityTypes.uint256}, + {value: utils.bigNumberToBN(salt), type: SolidityTypes.uint256}, ]; const types = _.map(orderParts, o => o.type); const values = _.map(orderParts, o => o.value); @@ -127,15 +127,6 @@ export class ZeroEx { const baseUnitAmount = amount.times(unit); return baseUnitAmount; } - /** - * Converts BigNumber instance to BN - * The only we convert to BN is to remain compatible with `ethABI. soliditySHA3 ` that - * expects values of Solidity type `uint` to be of type `BN`. - * We do not use BN anywhere else in the codebase. - */ - private static bigNumberToBN(value: BigNumber.BigNumber) { - return new BN(value.toString(), 10); - } constructor(web3: Web3) { this.web3Wrapper = new Web3Wrapper(web3); this.exchange = new ExchangeWrapper(this.web3Wrapper); diff --git a/src/ts/utils/utils.ts b/src/ts/utils/utils.ts index 04ac36b54..b514b702d 100644 --- a/src/ts/utils/utils.ts +++ b/src/ts/utils/utils.ts @@ -1,4 +1,15 @@ +import * as BN from 'bn.js'; + export const utils = { + /** + * Converts BigNumber instance to BN + * The only reason we convert to BN is to remain compatible with `ethABI. soliditySHA3` that + * expects values of Solidity type `uint` to be passed as type `BN`. + * We do not use BN anywhere else in the codebase. + */ + bigNumberToBN(value: BigNumber.BigNumber) { + return new BN(value.toString(), 10); + }, consoleLog(message: string): void { /* tslint:disable */ console.log(message); diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index d5b2015fb..9c61c3e10 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -1,8 +1,9 @@ -import {ZeroEx} from '../src/ts/0x.js'; +import * as _ from 'lodash'; import * as chai from 'chai'; import 'mocha'; import * as BigNumber from 'bignumber.js'; import ChaiBigNumber = require('chai-bignumber'); +import {ZeroEx} from '../src/ts/0x.js'; import {constants} from '../src/ts/utils/constants'; // Use BigNumber chai add-on @@ -104,7 +105,7 @@ describe('ZeroEx library', () => { expect(isValid).to.be.false; }); it('should return false if the signature doesn\'t pertain to the data & address', () => { - const wrongSignature = Object.assign({}, signature, {v: 28}); + const wrongSignature = _.assign({}, signature, {v: 28}); const isValid = ZeroEx.isValidSignature(data, wrongSignature, address); expect(isValid).to.be.false; }); |