Refactor toBaseUnitAmount so that it throws if user supplies unitAmount with too many decimals

This commit is contained in:
Fabio Berger
2017-12-21 09:34:50 +01:00
parent 85e16c1233
commit b94d13b413
2 changed files with 10 additions and 0 deletions

View File

@@ -136,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';