From e32b2025420fde4966d154fec20b75b92400209d Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Sun, 16 Dec 2018 20:23:53 +0000 Subject: [PATCH] test: cidBase option in resolve (#396) License: MIT Signed-off-by: Alan Shaw --- SPEC/MISCELLANEOUS.md | 1 + js/src/miscellaneous/resolve.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/SPEC/MISCELLANEOUS.md b/SPEC/MISCELLANEOUS.md index 91fe5884ac..ec2e9a27b2 100644 --- a/SPEC/MISCELLANEOUS.md +++ b/SPEC/MISCELLANEOUS.md @@ -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. diff --git a/js/src/miscellaneous/resolve.js b/js/src/miscellaneous/resolve.js index 2cdace5397..8122d7a6d4 100644 --- a/js/src/miscellaneous/resolve.js +++ b/js/src/miscellaneous/resolve.js @@ -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') @@ -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'