Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Add OrderTransactionOpts to enable optional validation to exchange_wr… #172

Merged
merged 3 commits into from
Sep 28, 2017

Conversation

BMillman19
Copy link
Contributor

@BMillman19 BMillman19 commented Sep 27, 2017

…apper

  • Added OrderTransactionOpts type for specifying extra options when calling certain exchange_wrapper methods involving transactions
  • Added tests

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 98.177% when pulling 3336653 on bmillman_optional_validation into be12c5b on development.

assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isBigNumber('fillTakerTokenAmount', fillTakerTokenAmount);
assert.isBoolean('shouldThrowOnInsufficientBalanceOrAllowance', shouldThrowOnInsufficientBalanceOrAllowance);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);

const exchangeInstance = await this._getExchangeContractAsync();
await this.validateFillOrderThrowIfInvalidAsync(signedOrder, fillTakerTokenAmount, takerAddress);
const shouldValidate = _.isUndefined(orderTransactionOpts) ? true : orderTransactionOpts.shouldValidate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's assign true to a constant defined at the top of the file called SHOULD_VALIDATE_BY_DEFAULT. I'm guessing we'd want to default to be the same for all methods.

const shouldValidate = _.isUndefined(orderTransactionOpts) ? true : orderTransactionOpts.shouldValidate;
if (shouldValidate) {
await Promise.all(orderFillRequests.map(orderFillRequest => this.validateFillOrderThrowIfInvalidAsync(
orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount, takerAddress)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Let's move the ending parens to the next line.

const shouldValidate = _.isUndefined(orderTransactionOpts) ? true : orderTransactionOpts.shouldValidate;
if (shouldValidate) {
await Promise.all(orderFillOrKillRequests.map(request => this.validateFillOrKillOrderThrowIfInvalidAsync(
request.signedOrder, request.fillTakerAmount, takerAddress)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: ditto above. We try to align starting and ending parens, brackets, dom elements, as best we can. Does this make sense? I'm open to alternative conventions.

return expect(zeroEx.exchange.batchFillOrKillAsync(orderFillOrKillRequests, takerAddress,
{
shouldValidate: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: No need to put the start and end curly brackets on a new line when using an anonymous object as a method param.

@@ -323,6 +468,26 @@ describe('ExchangeWrapper', () => {
expect(cancelledAmount).to.be.bignumber.equal(cancelAmount);
});
});
describe('order transaction options', () => {
it('should validate when orderTransactionOptions are not present', async () => {
return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, new BigNumber(0)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Let's not in-line instantiating new objects in method params. Instead declare outside with a descriptive variable name of what it represents.

Our convention is also not to pass numbers/strings/booleans directly at params but to always assign them to variables with readable names. Otherwise the reader needs to look at the method definition to figure out what the value represents (saves future devs time).

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 98.179% when pulling d21fbbc on bmillman_optional_validation into be12c5b on development.

@0xProject 0xProject deleted a comment from coveralls Sep 28, 2017
Copy link
Contributor

@fabioberger fabioberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT!

@BMillman19 BMillman19 merged commit a0af271 into development Sep 28, 2017
@BMillman19 BMillman19 deleted the bmillman_optional_validation branch September 28, 2017 16:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants