Skip to content

Commit d9eb8dc

Browse files
committed
test: add test to verify function accepts CID
1 parent c5bbb25 commit d9eb8dc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/peer-id/test/index.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-env mocha */
22
import { generateKeyPair } from '@libp2p/crypto/keys'
33
import { expect } from 'aegir/chai'
4+
import { base36 } from 'multiformats/bases/base36'
45
import { base58btc } from 'multiformats/bases/base58'
56
import { CID } from 'multiformats/cid'
67
import { identity } from 'multiformats/hashes/identity'
@@ -44,6 +45,14 @@ describe('PeerId', () => {
4445
expect(id.toCID().toString()).to.equal(peerId.toCID().toString())
4546
})
4647

48+
it('should create a PeerId from a CID string', async () => {
49+
const id = peerIdFromString(peerId.toCID().toString(base36), base36.decoder)
50+
expect(id.equals(peerId)).to.be.true()
51+
expect(id.type).to.equal(type)
52+
expect(id.toString()).to.equal(peerId.toString())
53+
expect(id.toCID().toString()).to.equal(peerId.toCID().toString())
54+
})
55+
4756
it('should stringify to the public key', async () => {
4857
expect(peerId.toString()).to.equal(peerId.publicKey?.toString())
4958
})

0 commit comments

Comments
 (0)