Skip to content

Commit

Permalink
test: cidBase option in resolve (ipfs#396)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
Alan Shaw authored Dec 16, 2018
1 parent 62dd354 commit e32b202
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions SPEC/MISCELLANEOUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ Where:
- `name` (string): The name to resolve
- `options` is an optional object that might include the following properties:
- `recursive` (boolean, default false): Resolve until the result is an IPFS name
- `cidBase` (string): Multibase codec name the CID in the resolved path will be encoded with

`callback` must follow `function (err, res) {}` signature, where `err` is an error if the operation was not successful. `res` is a string, the resolved name.

Expand Down
16 changes: 16 additions & 0 deletions js/src/miscellaneous/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const isIpfs = require('is-ipfs')
const loadFixture = require('aegir/fixtures')
const hat = require('hat')
const waterfall = require('async/waterfall')
const multibase = require('multibase')
const { spawnNodeWithId } = require('../utils/spawn')
const { connect } = require('../utils/swarm')
const { getDescribe, getIt, expect } = require('../utils/mocha')
Expand Down Expand Up @@ -53,6 +54,21 @@ module.exports = (createCommon, options) => {
})
})

it('should resolve an IPFS hash and return a base64url encoded CID in path', (done) => {
const content = Buffer.from('TEST' + Date.now())

ipfs.add(content, (err, res) => {
expect(err).to.not.exist()

ipfs.resolve(`/ipfs/${res[0].hash}`, { cidBase: 'base64url' }, (err, path) => {
expect(err).to.not.exist()
const cid = path.split('/')[2]
expect(multibase.isEncoded(cid)).to.equal('base64url')
done()
})
})
})

// Test resolve turns /ipfs/QmRootHash/path/to/file into /ipfs/QmFileHash
it('should resolve an IPFS path link', (done) => {
const path = '/path/to/testfile.txt'
Expand Down

0 comments on commit e32b202

Please sign in to comment.