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

Commit

Permalink
fix: toV0 and toV1 create instances that cause isCID be false
Browse files Browse the repository at this point in the history
The `toV0` and `toV1` functions were returning instances of the unwrapped CID class not the wrapped one with the class-is smarts.

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
  • Loading branch information
Alan Shaw authored and vmx committed Sep 25, 2018
1 parent ebc21a2 commit 14ab8e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const withIs = require('class-is')
* , as defined in [ipld/cid](https://github.com/ipld/cid).
* @class CID
*/
class CID {
const CID = withIs(class {
/**
* Create a new CID.
*
Expand Down Expand Up @@ -229,11 +229,11 @@ class CID {
throw new Error(errorMsg)
}
}
}

CID.codecs = codecs

module.exports = withIs(CID, {
}, {
className: 'CID',
symbolName: '@ipld/js-cid/CID'
})

CID.codecs = codecs

module.exports = CID
8 changes: 8 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ describe('CID', () => {
expect(
CID.isCID(Buffer.from('hello world'))
).to.equal(false)

expect(
CID.isCID(new CID(h1).toV0())
).to.equal(true)

expect(
CID.isCID(new CID(h1).toV1())
).to.equal(true)
})

it('.toString() outputs default base encoded CID', () => {
Expand Down

0 comments on commit 14ab8e4

Please sign in to comment.