Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Util/validation update #4051

Merged
merged 7 commits into from
Jan 5, 2017
Merged

Util/validation update #4051

merged 7 commits into from
Jan 5, 2017

Conversation

jacogr
Copy link
Contributor

@jacogr jacogr commented Jan 5, 2017

  • add pre-emptive null code check in validateCode
  • don't pass external api to any functions
  • introduce tests for full suite

@jacogr jacogr added A0-pleasereview 🤓 Pull request needs code review. M7-ui labels Jan 5, 2017
@@ -42,9 +44,14 @@ export function validateAbi (abi) {
try {
abiParsed = JSON.parse(abi);

if (!util.isArray(abiParsed)) {
if (!apiutil.isArray(abiParsed)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

While we're at it: I'd prefer Array.isArray here. It's less brittle and it's widely known so you don't have to jump to another place to find out what it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly see no issue with the age-old Object.prototype.toString.call(obj) === '[object Array] underlying implementation there. Could also use lodash isArray here, etc. Don't see benefit of the one over the other, if the underlying implementation is an issue, would then see that adjusted since it is used is multiple places.

Copy link
Contributor

Choose a reason for hiding this comment

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

the underlying implementation is an issue. i can easily implement something that is not an array (not even iterable) but passes apiutil.isArray.

I'm suggesting you a API-compatible one-line change to the more robust, core JS Array.isArray. I'm also fine with lodash isArray`. I just see no reason to use homegrown check, especially if they're more brittle then the builtins.

I don't want to start an ideological war, this is only about reducing possible sources of errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not an ideological war - there is a reason the api utilities has the isFunction, isArray, isObject, etc. This is to allow consistency instead of things being done differently all-over. So if the underlying implementations can be made better and filter through to everything, we should do so by all means.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, then let's make apiutil.isArray reference Array.isArray.

});

it('fails on a non-full length 00..00 value', () => {
expect(isNullAddress(NULL_ADDRESS.slice(-1 * (NULL_ADDRESS.length - 2)))).to.be.false;
Copy link
Contributor

Choose a reason for hiding this comment

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

.slice(2)

expect(isNullAddress(NULL_ADDRESS.slice(-1 * (NULL_ADDRESS.length - 2)))).to.be.false;
});

it('fails on a valid addess, non 00..00 value', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

[tiny grumble] "fails" indicates that it throws an error, but it rather returns false.

@derhuerst
Copy link
Contributor

Would like Array.isArray, plus a few very tiny comments.

@derhuerst derhuerst added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jan 5, 2017
@jacogr jacogr merged commit 20ad2e7 into master Jan 5, 2017
@jacogr jacogr deleted the jg-util-validation branch January 5, 2017 15:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants