From 9193957e3f42ab92512a76e6b12fdd6b2376fe77 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 6 Nov 2019 13:05:17 +0100 Subject: [PATCH] feat: test ipns resolve of peerid as cid (#553) Context: https://github.com/libp2p/specs/blob/master/RFC/0001-text-peerid-cid.md License: MIT Signed-off-by: Marcin Rataj --- src/name/resolve.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/name/resolve.js b/src/name/resolve.js index 58e46c6b..be0e0d7a 100644 --- a/src/name/resolve.js +++ b/src/name/resolve.js @@ -5,6 +5,7 @@ const { spawnNodeWithId } = require('../utils/spawn') const { getDescribe, getIt, expect } = require('../utils/mocha') const delay = require('../utils/delay') +const CID = require('cids') module.exports = (createCommon, options) => { const describe = getDescribe(options) @@ -45,6 +46,20 @@ module.exports = (createCommon, options) => { .to.eq(`/ipfs/${path}`) }) + it('should resolve a record from peerid as cidv1 in base32', async function () { + this.timeout(20 * 1000) + const [{ path }] = await ipfs.add(Buffer.from('should resolve a record from cidv1b32')) + const { id: peerId } = await ipfs.id() + await ipfs.name.publish(path, { 'allow-offline': true }) + + // Represent Peer ID as CIDv1 Base32 + // https://github.com/libp2p/specs/blob/master/RFC/0001-text-peerid-cid.md + const keyCid = new CID(peerId).toV1().toString('base32') + const resolvedPath = await ipfs.name.resolve(`/ipns/${keyCid}`) + + return expect(resolvedPath).to.equal(`/ipfs/${path}`) + }) + it('should resolve a record recursive === false', async () => { const [{ path }] = await ipfs.add(Buffer.from('should resolve a record recursive === false')) await ipfs.name.publish(path, { 'allow-offline': true })