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

feat: test ipns resolve of peerid as cid #553

Merged
merged 1 commit into from
Nov 6, 2019
Merged
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
15 changes: 15 additions & 0 deletions src/name/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to use hash here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...all the others are using path, lets leave it for another day!

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 })
Expand Down