From 7b4e2257d8316ea12c1874b03d148a458318dbc1 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 13 Nov 2017 16:27:43 -0500 Subject: Re-add changelog for 0x.js --- packages/0x.js/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 84997389a..24d09e2ba 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -268,4 +268,4 @@ ## v0.5.1 - _Jun. 15, 2017_ - * Added `postpublish` script to publish to Github Releases with assets. + * Added `postpublish` script to publish to Github Releases with assets. \ No newline at end of file -- cgit From cfc868bf4dc371b299801dd24917a695387546e2 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 18 Jan 2018 18:17:22 +1100 Subject: Reject negative amounts in isValidBaseUnitAmount --- packages/0x.js/test/exchange_wrapper_test.ts | 47 ++++++++++++++++++++++++++++ packages/assert/src/index.ts | 2 ++ packages/assert/test/assert_test.ts | 10 ++++++ 3 files changed, 59 insertions(+) diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts index d2a2149a0..7e0ffd818 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -390,6 +390,29 @@ describe('ExchangeWrapper', () => { ).to.not.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero); }); }); + describe('negative fill amount', async () => { + let signedOrder: SignedOrder; + const negativeFillTakerAmount = new BigNumber(-100); + beforeEach(async () => { + signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, + takerTokenAddress, + makerAddress, + takerAddress, + fillableAmount, + ); + }); + it('should not allow the exchange wrapper to fill if amount is negative', async () => { + return expect( + zeroEx.exchange.fillOrderAsync( + signedOrder, + negativeFillTakerAmount, + shouldThrowOnInsufficientBalanceOrAllowance, + takerAddress, + ), + ).to.be.rejected(); + }); + }); }); describe('#batchFillOrdersAsync', () => { let signedOrder: SignedOrder; @@ -498,6 +521,30 @@ describe('ExchangeWrapper', () => { ).to.not.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero); }); }); + describe('negative batch fill amount', async () => { + beforeEach(async () => { + const negativeFillTakerAmount = new BigNumber(-100); + orderFillBatch = [ + { + signedOrder, + takerTokenFillAmount, + }, + { + signedOrder: anotherSignedOrder, + takerTokenFillAmount: negativeFillTakerAmount, + }, + ]; + }); + it('should not allow the exchange wrapper to batch fill if any amount is negative', async () => { + return expect( + zeroEx.exchange.batchFillOrdersAsync( + orderFillBatch, + shouldThrowOnInsufficientBalanceOrAllowance, + takerAddress, + ), + ).to.be.rejected(); + }); + }); }); describe('#fillOrdersUpTo', () => { let signedOrder: SignedOrder; diff --git a/packages/assert/src/index.ts b/packages/assert/src/index.ts index 56f663780..015ffe579 100644 --- a/packages/assert/src/index.ts +++ b/packages/assert/src/index.ts @@ -12,6 +12,8 @@ export const assert = { }, isValidBaseUnitAmount(variableName: string, value: BigNumber) { assert.isBigNumber(variableName, value); + const isNegative = value.lessThan(0); + this.assert(!isNegative, `${variableName} should not be a negative number, found value: ${value.toNumber()}` ); const hasDecimals = value.decimalPlaces() !== 0; this.assert( !hasDecimals, diff --git a/packages/assert/test/assert_test.ts b/packages/assert/test/assert_test.ts index ff337196d..732e99b3e 100644 --- a/packages/assert/test/assert_test.ts +++ b/packages/assert/test/assert_test.ts @@ -22,6 +22,16 @@ describe('Assertions', () => { invalidInputs.forEach(input => expect(assert.isBigNumber.bind(assert, variableName, input)).to.throw()); }); }); + describe('#isValidBaseUnitAmount', () => { + it('should not throw for valid input', () => { + const validInputs = [new BigNumber(23), new BigNumber('45000000')]; + validInputs.forEach(input => expect(assert.isValidBaseUnitAmount.bind(assert, variableName, input)).to.not.throw()); + }); + it('should throw for invalid input', () => { + const invalidInputs = [0, undefined, new BigNumber(3.145), 3.145, new BigNumber(-400)]; + invalidInputs.forEach(input => expect(assert.isValidBaseUnitAmount.bind(assert, variableName, input)).to.throw()); + }); + }); describe('#isString', () => { it('should not throw for valid input', () => { const validInputs = ['hello', 'goodbye']; -- cgit From ceb8a492b116f966e780d0ff4992ee0919963bd0 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 18 Jan 2018 18:59:47 +1100 Subject: Should not -> cannot --- packages/assert/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/assert/src/index.ts b/packages/assert/src/index.ts index 015ffe579..0ea666629 100644 --- a/packages/assert/src/index.ts +++ b/packages/assert/src/index.ts @@ -13,7 +13,7 @@ export const assert = { isValidBaseUnitAmount(variableName: string, value: BigNumber) { assert.isBigNumber(variableName, value); const isNegative = value.lessThan(0); - this.assert(!isNegative, `${variableName} should not be a negative number, found value: ${value.toNumber()}` ); + this.assert(!isNegative, `${variableName} cannot be a negative number, found value: ${value.toNumber()}` ); const hasDecimals = value.decimalPlaces() !== 0; this.assert( !hasDecimals, -- cgit From fb77817c2d5258ecf92901ed9bd7db35bc11078f Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Fri, 19 Jan 2018 10:32:51 +1100 Subject: Update CHANGELOG, rebase on development --- packages/0x.js/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 24d09e2ba..703640e48 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## v0.30.1 - _January 18, 2018_ + + * Fix a bug allowing negative fill values (#212) ## v0.30.0 - _January 17, 2018_ * Add an error parameter to the order watcher callback (#312) -- cgit From 2ac806ef088ef4e9d037bc0227ce493f8f09a19e Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Fri, 19 Jan 2018 10:51:57 +1100 Subject: Prettier --- packages/0x.js/CHANGELOG.md | 1 + packages/assert/src/index.ts | 2 +- packages/assert/test/assert_test.ts | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 703640e48..0846ee7c3 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -3,6 +3,7 @@ ## v0.30.1 - _January 18, 2018_ * Fix a bug allowing negative fill values (#212) + ## v0.30.0 - _January 17, 2018_ * Add an error parameter to the order watcher callback (#312) diff --git a/packages/assert/src/index.ts b/packages/assert/src/index.ts index 0ea666629..7ad574ec7 100644 --- a/packages/assert/src/index.ts +++ b/packages/assert/src/index.ts @@ -13,7 +13,7 @@ export const assert = { isValidBaseUnitAmount(variableName: string, value: BigNumber) { assert.isBigNumber(variableName, value); const isNegative = value.lessThan(0); - this.assert(!isNegative, `${variableName} cannot be a negative number, found value: ${value.toNumber()}` ); + this.assert(!isNegative, `${variableName} cannot be a negative number, found value: ${value.toNumber()}`); const hasDecimals = value.decimalPlaces() !== 0; this.assert( !hasDecimals, diff --git a/packages/assert/test/assert_test.ts b/packages/assert/test/assert_test.ts index 732e99b3e..b0fa398d6 100644 --- a/packages/assert/test/assert_test.ts +++ b/packages/assert/test/assert_test.ts @@ -25,11 +25,15 @@ describe('Assertions', () => { describe('#isValidBaseUnitAmount', () => { it('should not throw for valid input', () => { const validInputs = [new BigNumber(23), new BigNumber('45000000')]; - validInputs.forEach(input => expect(assert.isValidBaseUnitAmount.bind(assert, variableName, input)).to.not.throw()); + validInputs.forEach(input => + expect(assert.isValidBaseUnitAmount.bind(assert, variableName, input)).to.not.throw(), + ); }); it('should throw for invalid input', () => { const invalidInputs = [0, undefined, new BigNumber(3.145), 3.145, new BigNumber(-400)]; - invalidInputs.forEach(input => expect(assert.isValidBaseUnitAmount.bind(assert, variableName, input)).to.throw()); + invalidInputs.forEach(input => + expect(assert.isValidBaseUnitAmount.bind(assert, variableName, input)).to.throw(), + ); }); }); describe('#isString', () => { -- cgit From ab7f681f153778a5af4e2e2ac7713c384fe3ec79 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Fri, 19 Jan 2018 11:17:48 +1100 Subject: Prettier newline --- packages/0x.js/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 0846ee7c3..1a09eaf28 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -272,4 +272,4 @@ ## v0.5.1 - _Jun. 15, 2017_ - * Added `postpublish` script to publish to Github Releases with assets. \ No newline at end of file + * Added `postpublish` script to publish to Github Releases with assets. -- cgit