diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/0x.js/CHANGELOG.md | 5 | ||||
-rw-r--r-- | packages/0x.js/src/0x.ts | 6 | ||||
-rw-r--r-- | packages/0x.js/test/0x.js_test.ts | 12 | ||||
-rw-r--r-- | packages/contracts/README.md | 70 | ||||
-rw-r--r-- | packages/website/ts/components/dialogs/eth_weth_conversion_dialog.tsx | 2 |
5 files changed, 65 insertions, 30 deletions
diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index d85ace89f..536b66fce 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +vx.x.x - _TBD_ +------------------------ + * Assert baseUnit amount supplied to `toUnitAmount` is integer amount. (#287) + * `toBaseUnitAmount` throws if amount supplied has too many decimals (#287) + v0.28.0 - _December 20, 2017_ ------------------------ * Add `etherTokenAddress` arg to `depositAsync` and `withdrawAsync` methods on `zeroEx.etherToken` (#267) diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 7393cc814..a18f1fc55 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -128,7 +128,7 @@ export class ZeroEx { * @return The amount in units. */ public static toUnitAmount(amount: BigNumber, decimals: number): BigNumber { - assert.isBigNumber('amount', amount); + assert.isValidBaseUnitAmount('amount', amount); assert.isNumber('decimals', decimals); const aUnit = new BigNumber(10).pow(decimals); @@ -149,6 +149,10 @@ export class ZeroEx { const unit = new BigNumber(10).pow(decimals); const baseUnitAmount = amount.times(unit); + const hasDecimals = baseUnitAmount.decimalPlaces() !== 0; + if (hasDecimals) { + throw new Error(`Invalid unit amount: ${amount.toString()} - Too many decimal places`); + } return baseUnitAmount; } /** diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index 8d62b3518..245946a89 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -114,6 +114,12 @@ describe('ZeroEx library', () => { }); }); describe('#toUnitAmount', () => { + it('should throw if invalid baseUnit amount supplied as argument', () => { + const invalidBaseUnitAmount = new BigNumber(1000000000.4); + const decimals = 6; + expect(() => ZeroEx.toUnitAmount(invalidBaseUnitAmount, decimals)) + .to.throw('amount should be in baseUnits (no decimals), found value: 1000000000.4'); + }); it('Should return the expected unit amount for the decimals passed in', () => { const baseUnitAmount = new BigNumber(1000000000); const decimals = 6; @@ -130,6 +136,12 @@ describe('ZeroEx library', () => { const expectedUnitAmount = new BigNumber(1000000000); expect(baseUnitAmount).to.be.bignumber.equal(expectedUnitAmount); }); + it('should throw if unitAmount has more decimals then specified as the max decimal precision', () => { + const unitAmount = new BigNumber(0.823091); + const decimals = 5; + expect(() => ZeroEx.toBaseUnitAmount(unitAmount, decimals)) + .to.throw('Invalid unit amount: 0.823091 - Too many decimal places'); + }); }); describe('#getOrderHashHex', () => { const expectedOrderHash = '0x39da987067a3c9e5f1617694f1301326ba8c8b0498ebef5df4863bed394e3c83'; diff --git a/packages/contracts/README.md b/packages/contracts/README.md index 57c75cb85..52fa6062d 100644 --- a/packages/contracts/README.md +++ b/packages/contracts/README.md @@ -1,51 +1,65 @@ Contracts ------ +-------- -## Useful 0x Wiki Articles +Smart contracts that implement the 0x protocol. -* [Architecture](https://0xproject.com/wiki#Architecture) -* [Contract Interactions](https://0xproject.com/wiki#Contract-Interactions) -* [Contract deployed addresses](https://0xproject.com/wiki#Deployed-Addresses) -* [0x Protocol Message Format](https://0xproject.com/wiki#Message-Format) -* [Bug Bounty Program](https://0xproject.com/wiki#Bug-Bounty) +## Usage -## Setup +* [Docs](https://0xproject.com/docs/contracts) +* [Overview of 0x protocol architecture](https://0xproject.com/wiki#Architecture) +* [0x smart contract interactions](https://0xproject.com/wiki#Contract-Interactions) +* [Deployed smart contract addresses](https://0xproject.com/wiki#Deployed-Addresses) +* [0x protocol message format](https://0xproject.com/wiki#Message-Format) -### Installing Dependencies +## Contributing -Install [Node](https://nodejs.org/en/download/releases/) +We strongly recommend that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository. -Install [yarn](https://yarnpkg.com/lang/en/docs/install/) in order to install the project dependencies more deterministically. +For proposals regarding the 0x protocol's smart contract architecture, message format, or additional functionality, go to the [0x Improvement Proposals (ZEIPs)](https://github.com/0xProject/ZEIPs) repository and follow the contribution guidelines provided therein. -Install project dependencies: +Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started. -``` -yarn +### Install Dependencies + +If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them: +```bash +yarn config set workspaces-experimental true ``` -### Running Tests +Then install dependencies +```bash +yarn install +``` -Start Testrpc +### Build -``` -yarn testrpc +```bash +yarn build ``` -Run tests +### Clean -``` -yarn test +```bash +yarn clean ``` -## Contributing +### Lint -0x protocol is intended to serve as an open technical standard for EVM blockchains and we strongly encourage our community members to help us make improvements and to determine the future direction of the protocol. To report bugs within the 0x smart contracts or unit tests, please create an issue in this repository. +```bash +yarn lint +``` -### ZEIPs -Significant changes to 0x protocol's smart contracts, architecture, message format or functionality should be proposed in the [0x Improvement Proposals (ZEIPs)](https://github.com/0xProject/ZEIPs) repository. Follow the contribution guidelines provided therein. +### Run Tests -### Coding conventions +Before running the tests, you will need to spin up a [TestRPC](https://www.npmjs.com/package/ethereumjs-testrpc) instance. -We use a custom set of [TSLint](https://palantir.github.io/tslint/) rules to enforce our coding conventions. +In a separate terminal, start TestRPC (a convenience command is provided as part of the [0x.js monorepo](https://github.com/0xProject/0x.js)) +```bash +cd ../.. +yarn testrpc +``` -In order to see style violation errors, install a tslinter for your text editor. e.g Atom's [atom-typescript](https://atom.io/packages/atom-typescript). +Then in your main terminal run +```bash +yarn test +``` diff --git a/packages/website/ts/components/dialogs/eth_weth_conversion_dialog.tsx b/packages/website/ts/components/dialogs/eth_weth_conversion_dialog.tsx index 0045a56c3..d78cbdc29 100644 --- a/packages/website/ts/components/dialogs/eth_weth_conversion_dialog.tsx +++ b/packages/website/ts/components/dialogs/eth_weth_conversion_dialog.tsx @@ -29,7 +29,7 @@ export class EthWethConversionDialog extends super(); this.state = { shouldShowIncompleteErrs: false, - hasErrors: true, + hasErrors: false, }; } public render() { |