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

Commit 9193957

Browse files
lidelAlan Shaw
authored and
Alan Shaw
committed
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 <[email protected]>
1 parent 3b4a76c commit 9193957

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/name/resolve.js

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const { spawnNodeWithId } = require('../utils/spawn')
66
const { getDescribe, getIt, expect } = require('../utils/mocha')
77
const delay = require('../utils/delay')
8+
const CID = require('cids')
89

910
module.exports = (createCommon, options) => {
1011
const describe = getDescribe(options)
@@ -45,6 +46,20 @@ module.exports = (createCommon, options) => {
4546
.to.eq(`/ipfs/${path}`)
4647
})
4748

49+
it('should resolve a record from peerid as cidv1 in base32', async function () {
50+
this.timeout(20 * 1000)
51+
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record from cidv1b32'))
52+
const { id: peerId } = await ipfs.id()
53+
await ipfs.name.publish(path, { 'allow-offline': true })
54+
55+
// Represent Peer ID as CIDv1 Base32
56+
// https://github.com/libp2p/specs/blob/master/RFC/0001-text-peerid-cid.md
57+
const keyCid = new CID(peerId).toV1().toString('base32')
58+
const resolvedPath = await ipfs.name.resolve(`/ipns/${keyCid}`)
59+
60+
return expect(resolvedPath).to.equal(`/ipfs/${path}`)
61+
})
62+
4863
it('should resolve a record recursive === false', async () => {
4964
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record recursive === false'))
5065
await ipfs.name.publish(path, { 'allow-offline': true })

0 commit comments

Comments
 (0)