Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

test: cidBase option in resolve #396

Merged
merged 3 commits into from
Dec 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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