Fixed nits

This commit is contained in:
Brandon Millman
2017-09-28 08:44:29 -07:00
parent 333665370f
commit d21fbbc4c8
2 changed files with 68 additions and 75 deletions

View File

@@ -41,6 +41,8 @@ import {TokenWrapper} from './token_wrapper';
import {decorators} from '../utils/decorators';
import {artifacts} from '../artifacts';
const SHOULD_VALIDATE_BY_DEFAULT = true;
/**
* This class includes all the functionality related to calling methods and subscribing to
* events of the 0x Exchange smart contract.
@@ -169,7 +171,9 @@ export class ExchangeWrapper extends ContractWrapper {
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const exchangeInstance = await this._getExchangeContractAsync();
const shouldValidate = _.isUndefined(orderTransactionOpts) ? true : orderTransactionOpts.shouldValidate;
const shouldValidate = _.isUndefined(orderTransactionOpts) ?
SHOULD_VALIDATE_BY_DEFAULT :
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
await this.validateFillOrderThrowIfInvalidAsync(signedOrder, fillTakerTokenAmount, takerAddress);
}
@@ -236,7 +240,9 @@ export class ExchangeWrapper extends ContractWrapper {
assert.isBoolean('shouldThrowOnInsufficientBalanceOrAllowance', shouldThrowOnInsufficientBalanceOrAllowance);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const shouldValidate = _.isUndefined(orderTransactionOpts) ? true : orderTransactionOpts.shouldValidate;
const shouldValidate = _.isUndefined(orderTransactionOpts) ?
SHOULD_VALIDATE_BY_DEFAULT :
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
await Promise.all(signedOrders.map(signedOrder => this.validateFillOrderThrowIfInvalidAsync(
signedOrder, fillTakerTokenAmount, takerAddress)));
@@ -320,10 +326,13 @@ export class ExchangeWrapper extends ContractWrapper {
ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
assert.isBoolean('shouldThrowOnInsufficientBalanceOrAllowance', shouldThrowOnInsufficientBalanceOrAllowance);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const shouldValidate = _.isUndefined(orderTransactionOpts) ? true : orderTransactionOpts.shouldValidate;
const shouldValidate = _.isUndefined(orderTransactionOpts) ?
SHOULD_VALIDATE_BY_DEFAULT :
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
await Promise.all(orderFillRequests.map(orderFillRequest => this.validateFillOrderThrowIfInvalidAsync(
orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount, takerAddress)));
orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount, takerAddress)),
);
}
if (_.isEmpty(orderFillRequests)) {
throw new Error(ExchangeContractErrs.BatchOrdersMustHaveAtLeastOneItem);
@@ -392,7 +401,9 @@ export class ExchangeWrapper extends ContractWrapper {
const exchangeInstance = await this._getExchangeContractAsync();
const shouldValidate = _.isUndefined(orderTransactionOpts) ? true : orderTransactionOpts.shouldValidate;
const shouldValidate = _.isUndefined(orderTransactionOpts) ?
SHOULD_VALIDATE_BY_DEFAULT :
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
await this.validateFillOrKillOrderThrowIfInvalidAsync(signedOrder, fillTakerTokenAmount, takerAddress);
}
@@ -451,10 +462,13 @@ export class ExchangeWrapper extends ContractWrapper {
}
const exchangeInstance = await this._getExchangeContractAsync();
const shouldValidate = _.isUndefined(orderTransactionOpts) ? true : orderTransactionOpts.shouldValidate;
const shouldValidate = _.isUndefined(orderTransactionOpts) ?
SHOULD_VALIDATE_BY_DEFAULT :
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
await Promise.all(orderFillOrKillRequests.map(request => this.validateFillOrKillOrderThrowIfInvalidAsync(
request.signedOrder, request.fillTakerAmount, takerAddress)));
request.signedOrder, request.fillTakerAmount, takerAddress)),
);
}
const orderAddressesValuesAndTakerTokenFillAmounts = _.map(orderFillOrKillRequests, request => {
@@ -514,7 +528,9 @@ export class ExchangeWrapper extends ContractWrapper {
const exchangeInstance = await this._getExchangeContractAsync();
const shouldValidate = _.isUndefined(orderTransactionOpts) ? true : orderTransactionOpts.shouldValidate;
const shouldValidate = _.isUndefined(orderTransactionOpts) ?
SHOULD_VALIDATE_BY_DEFAULT :
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
await this.validateCancelOrderThrowIfInvalidAsync(order, cancelTakerTokenAmount);
}
@@ -562,7 +578,9 @@ export class ExchangeWrapper extends ContractWrapper {
assert.hasAtMostOneUniqueValue(makers, ExchangeContractErrs.MultipleMakersInSingleCancelBatchDisallowed);
const maker = makers[0];
await assert.isSenderAddressAsync('maker', maker, this._web3Wrapper);
const shouldValidate = _.isUndefined(orderTransactionOpts) ? true : orderTransactionOpts.shouldValidate;
const shouldValidate = _.isUndefined(orderTransactionOpts) ?
SHOULD_VALIDATE_BY_DEFAULT :
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
await Promise.all(orderCancellationRequests.map(cancellationRequest =>
this.validateCancelOrderThrowIfInvalidAsync(

View File

@@ -114,18 +114,14 @@ describe('ExchangeWrapper', () => {
.to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
it('should validate when orderTransactionOptions specify to validate', async () => {
return expect(zeroEx.exchange.batchFillOrKillAsync(orderFillOrKillRequests, takerAddress,
{
shouldValidate: true,
},
)).to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
return expect(zeroEx.exchange.batchFillOrKillAsync(orderFillOrKillRequests, takerAddress, {
shouldValidate: true,
})).to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
it('should not validate when orderTransactionOptions specify not to validate', async () => {
return expect(zeroEx.exchange.batchFillOrKillAsync(orderFillOrKillRequests, takerAddress,
{
shouldValidate: false,
},
)).to.not.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
return expect(zeroEx.exchange.batchFillOrKillAsync(orderFillOrKillRequests, takerAddress, {
shouldValidate: false,
})).to.not.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
});
});
@@ -177,18 +173,14 @@ describe('ExchangeWrapper', () => {
.to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
it('should validate when orderTransactionOptions specify to validate', async () => {
return expect(zeroEx.exchange.fillOrKillOrderAsync(signedOrder, emptyFillableAmount, takerAddress,
{
shouldValidate: true,
},
)).to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
return expect(zeroEx.exchange.fillOrKillOrderAsync(signedOrder, emptyFillableAmount, takerAddress, {
shouldValidate: true,
})).to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
it('should not validate when orderTransactionOptions specify not to validate', async () => {
return expect(zeroEx.exchange.fillOrKillOrderAsync(signedOrder, emptyFillableAmount, takerAddress,
{
shouldValidate: false,
},
)).to.not.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
return expect(zeroEx.exchange.fillOrKillOrderAsync(signedOrder, emptyFillableAmount, takerAddress, {
shouldValidate: false,
})).to.not.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
});
});
@@ -277,22 +269,20 @@ describe('ExchangeWrapper', () => {
});
it('should validate when orderTransactionOptions are not present', async () => {
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, emptyFillTakerAmount, false, takerAddress,
signedOrder, emptyFillTakerAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress,
)).to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
it('should validate when orderTransactionOptions specify to validate', async () => {
return expect(zeroEx.exchange.fillOrderAsync(signedOrder, emptyFillTakerAmount, false, takerAddress,
{
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, emptyFillTakerAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, {
shouldValidate: true,
},
)).to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
})).to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
it('should not validate when orderTransactionOptions specify not to validate', async () => {
return expect(zeroEx.exchange.fillOrderAsync(signedOrder, emptyFillTakerAmount, false, takerAddress,
{
return expect(zeroEx.exchange.fillOrderAsync(
signedOrder, emptyFillTakerAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, {
shouldValidate: false,
},
)).to.not.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
})).to.not.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
});
});
@@ -361,19 +351,15 @@ describe('ExchangeWrapper', () => {
});
it('should validate when orderTransactionOptions specify to validate', async () => {
return expect(zeroEx.exchange.batchFillOrdersAsync(
orderFillBatch, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress,
{
orderFillBatch, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, {
shouldValidate: true,
},
)).to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
})).to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
it('should not validate when orderTransactionOptions specify not to validate', async () => {
return expect(zeroEx.exchange.batchFillOrdersAsync(
orderFillBatch, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress,
{
orderFillBatch, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, {
shouldValidate: false,
},
)).to.not.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
})).to.not.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
});
});
@@ -422,19 +408,15 @@ describe('ExchangeWrapper', () => {
});
it('should validate when orderTransactionOptions specify to validate', async () => {
return expect(zeroEx.exchange.fillOrdersUpToAsync(
signedOrders, emptyFillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress,
{
signedOrders, emptyFillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, {
shouldValidate: true,
},
)).to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
})).to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
it('should not validate when orderTransactionOptions specify not to validate', async () => {
return expect(zeroEx.exchange.fillOrdersUpToAsync(
signedOrders, emptyFillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress,
{
signedOrders, emptyFillUpToAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, {
shouldValidate: false,
},
)).to.not.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
})).to.not.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
});
});
});
@@ -469,23 +451,20 @@ describe('ExchangeWrapper', () => {
});
});
describe('order transaction options', () => {
const emptyCancelTakerTokenAmount = new BigNumber(0);
it('should validate when orderTransactionOptions are not present', async () => {
return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, new BigNumber(0)))
return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, emptyCancelTakerTokenAmount))
.to.be.rejectedWith(ExchangeContractErrs.OrderCancelAmountZero);
});
it('should validate when orderTransactionOptions specify to validate', async () => {
return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, new BigNumber(0),
{
shouldValidate: true,
},
)).to.be.rejectedWith(ExchangeContractErrs.OrderCancelAmountZero);
return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, emptyCancelTakerTokenAmount, {
shouldValidate: true,
})).to.be.rejectedWith(ExchangeContractErrs.OrderCancelAmountZero);
});
it('should not validate when orderTransactionOptions specify not to validate', async () => {
return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, new BigNumber(0),
{
shouldValidate: false,
},
)).to.not.be.rejectedWith(ExchangeContractErrs.OrderCancelAmountZero);
return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, emptyCancelTakerTokenAmount, {
shouldValidate: false,
})).to.not.be.rejectedWith(ExchangeContractErrs.OrderCancelAmountZero);
});
});
});
@@ -553,18 +532,14 @@ describe('ExchangeWrapper', () => {
.to.be.rejectedWith(ExchangeContractErrs.OrderCancelAmountZero);
});
it('should validate when orderTransactionOptions specify to validate', async () => {
return expect(zeroEx.exchange.batchCancelOrdersAsync(cancelBatch,
{
shouldValidate: true,
},
)).to.be.rejectedWith(ExchangeContractErrs.OrderCancelAmountZero);
return expect(zeroEx.exchange.batchCancelOrdersAsync(cancelBatch, {
shouldValidate: true,
})).to.be.rejectedWith(ExchangeContractErrs.OrderCancelAmountZero);
});
it('should not validate when orderTransactionOptions specify not to validate', async () => {
return expect(zeroEx.exchange.batchCancelOrdersAsync(cancelBatch,
{
shouldValidate: false,
},
)).to.not.be.rejectedWith(ExchangeContractErrs.OrderCancelAmountZero);
return expect(zeroEx.exchange.batchCancelOrdersAsync(cancelBatch, {
shouldValidate: false,
})).to.not.be.rejectedWith(ExchangeContractErrs.OrderCancelAmountZero);
});
});
});