aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/0x.js/src/0x.ts4
-rw-r--r--packages/0x.js/test/0x.js_test.ts6
2 files changed, 10 insertions, 0 deletions
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts
index 596d6ffba..a18f1fc55 100644
--- a/packages/0x.js/src/0x.ts
+++ b/packages/0x.js/src/0x.ts
@@ -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 9bf504909..245946a89 100644
--- a/packages/0x.js/test/0x.js_test.ts
+++ b/packages/0x.js/test/0x.js_test.ts
@@ -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';