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

Commit

Permalink
feat: test ipns resolve of peerid as cid (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel authored and Alan Shaw committed Nov 6, 2019
1 parent 3b4a76c commit 9193957
Showing 1 changed file with 15 additions and 0 deletions.
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'))
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

0 comments on commit 9193957

Please sign in to comment.