From 51105b60fd455a0da5e4ee74f7e0de0886b74672 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Tue, 16 Jun 2020 05:55:24 -0700 Subject: [PATCH] fix: fix support for identity multihash (#93) --- test/index.spec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/index.spec.js b/test/index.spec.js index de35651..9870118 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -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') + + 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)