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

Commit e32b202

Browse files
author
Alan Shaw
authored
test: cidBase option in resolve (#396)
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 62dd354 commit e32b202

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

SPEC/MISCELLANEOUS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ Where:
256256
- `name` (string): The name to resolve
257257
- `options` is an optional object that might include the following properties:
258258
- `recursive` (boolean, default false): Resolve until the result is an IPFS name
259+
- `cidBase` (string): Multibase codec name the CID in the resolved path will be encoded with
259260

260261
`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.
261262

js/src/miscellaneous/resolve.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const isIpfs = require('is-ipfs')
55
const loadFixture = require('aegir/fixtures')
66
const hat = require('hat')
77
const waterfall = require('async/waterfall')
8+
const multibase = require('multibase')
89
const { spawnNodeWithId } = require('../utils/spawn')
910
const { connect } = require('../utils/swarm')
1011
const { getDescribe, getIt, expect } = require('../utils/mocha')
@@ -53,6 +54,21 @@ module.exports = (createCommon, options) => {
5354
})
5455
})
5556

57+
it('should resolve an IPFS hash and return a base64url encoded CID in path', (done) => {
58+
const content = Buffer.from('TEST' + Date.now())
59+
60+
ipfs.add(content, (err, res) => {
61+
expect(err).to.not.exist()
62+
63+
ipfs.resolve(`/ipfs/${res[0].hash}`, { cidBase: 'base64url' }, (err, path) => {
64+
expect(err).to.not.exist()
65+
const cid = path.split('/')[2]
66+
expect(multibase.isEncoded(cid)).to.equal('base64url')
67+
done()
68+
})
69+
})
70+
})
71+
5672
// Test resolve turns /ipfs/QmRootHash/path/to/file into /ipfs/QmFileHash
5773
it('should resolve an IPFS path link', (done) => {
5874
const path = '/path/to/testfile.txt'

0 commit comments

Comments
 (0)