Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

fix: support for identity multihash #93

Merged
merged 2 commits into from
Jun 16, 2020
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
17 changes: 17 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ describe('CID', () => {
expect(cid.prefix.toString('hex')).to.equal('01711220')
})

it('.prefix identity multihash', () => {
const mh = multihash.encode(Buffer.from('abc'), 'identity')
const cid0 = new CID(0, 'dag-pb', mh)

expect(cid0).to.have.property('codec', 'dag-pb')
expect(cid0).to.have.property('version', 0)
expect(cid0).to.have.property('multihash').that.eql(mh)
expect(cid0.toBaseEncodedString()).to.eql('161g3c')
Copy link
Member

Choose a reason for hiding this comment

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

FYI (this is not blocking a merge): you can also use toString() instead of toBaseEncodedString().


const cid1 = new CID(1, 'dag-cbor', mh)

expect(cid1).to.have.property('codec', 'dag-cbor')
expect(cid1).to.have.property('version', 1)
expect(cid1).to.have.property('multihash').that.eql(mh)
expect(cid1.toBaseEncodedString()).to.eql('bafyqaa3bmjrq')
})

it('.buffer', () => {
const codec = 'dag-cbor' // Invalid codec will cause an error: Issue #46
const cid = new CID(1, codec, hash)
Expand Down