Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check ipfs path with is-ipfs #31

Merged
merged 7 commits into from
Mar 29, 2016
Merged

Check ipfs path with is-ipfs #31

merged 7 commits into from
Mar 29, 2016

Conversation

nginnever
Copy link
Member

This adds is-ipfs tests for correct paths and multihashes with is-ipfs.

@diasdavid had discussed adding buffer condition to is-ipfs. This checks the supplied path to the dag-service to see if it is a buffer first, if it is then it base58 encodes the buffer and then tests with is-ipfs.

If the path supplied to dag-service is a string then it checks to see if it is a path or a correct multihash.

dagService.add(node, (err) => {
expect(err).to.not.exist
var mh = node.multihash()
var encodedMh = bs58.encode(mh)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use a static string whose value is what you're expecting? This makes the test more explicit and doesn't rely on generated values to test assumptions.

Copy link
Member Author

Choose a reason for hiding this comment

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

sure thing

@hackergrrl
Copy link
Contributor

Woohoo! I've been wanting this for a while. 💯

this.getWith(ipfsKey, callback)
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

👍 @nginnever :D

Can we get all of this part of 'is-ipfs' logic? I'm sure @xicombd would be happy to include it there and it will be useful for a ton of other places.

btw, it would be stellar if mafmt from @whyrusleeping used this to check multiaddrs that are also ipfs multiaddrs with valid multihashes :)

@nginnever
Copy link
Member Author

Requires ipfs-shipyard/is-ipfs#5

@fbaiodias
Copy link
Member

ipfs-shipyard/is-ipfs#5 has now been merged and published as v0.2.0 🚀


this.bs.getBlock(multihash, (err, block) => {
this.getWith = function (key, callback) {
const formatted = typeof key === 'string' ? new Buffer(base58.decode(key)) : key
Copy link
Member

Choose a reason for hiding this comment

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

seems that there is already the formatting happening on line 37 and 41, is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

This format check is needed in this implementation. While the 'is-ipfs' module can handle any input, it only returns true or false and does not return a formatted key enforced to be a base58 decoded buffer.

'is-ipfs' could return a formatted key (buffer instead of string) if the key/path are valid multihashes, but then the name of the module wouldn't make much sense any more. And would probably need to be something like 'ipfs-format-key'

Copy link
Member

Choose a reason for hiding this comment

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

Understood. Nevertheless there are two transformation steps, one before calling the func and inside the func.

Copy link
Member Author

Choose a reason for hiding this comment

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

I took out the buffer encoding on the path to key since you are right, the check in getWith() function will catch it.

@daviddias daviddias merged commit 805aa79 into ipfs:master Mar 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants