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

Commit

Permalink
feat: add util.cid options
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jun 24, 2018
1 parent 8ecdb53 commit fd6e1bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ const deserialize = (binaryBlob, callback) => {
* Get the CID of the DAG-Node.
*
* @param {ZcashBlock} dagNode - Internal representation of a Zcash block
* @param {Object} [options] - Ignored
* @param {CidCallback} callback - Callback that handles the return value
* @returns {void}
*/
const cid = (dagNode, callback) => {
const cid = (dagNode, options, callback) => {
if (options instanceof Function) {
callback = options
options = {}
}
options = options || {}
let err = null
let cid
try {
Expand Down
19 changes: 19 additions & 0 deletions test/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ describe('IPLD format util API cid()', () => {
})
})

it('should encode the CID correctly and ignore options', (done) => {
IpldZcash.util.deserialize(fixtureBlock, (err, dagNode) => {
expect(err).to.not.exist()
verifyCid1(
dagNode,
{ hashAlg: 'unknown' },
'5620e1451fd8fecefdd9d443f294bc5ae918301922088ba51d35a2a4672c00000000',
done)
})
})

it('should error on an invalid internal representation', (done) => {
IpldZcash.util.cid(invalidDagNode, (err, cid) => {
expect(cid).to.not.exist()
Expand Down Expand Up @@ -90,3 +101,11 @@ const verifyCid = (dagNode, expectedCid, doneCb) => {
doneCb()
})
}

const verifyCid1 = (dagNode, options, expectedCid, doneCb) => {
IpldZcash.util.cid(dagNode, options, (err, cid) => {
expect(err).to.not.exist()
expect(cid.multihash.toString('hex')).to.equal(expectedCid)
doneCb()
})
}

0 comments on commit fd6e1bf

Please sign in to comment.