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

refactor: use new block api #47

Merged
merged 1 commit into from Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -32,7 +32,8 @@
"url": "https://github.com/ipld/js-ipld-dag-cbor/issues"
},
"engines": {
"node": ">=4.0.0"
"node": ">=4.0.0",
"npm": ">=3.0.0"
},
"homepage": "https://github.com/ipld/js-ipld-dag-cbor",
"dependencies": {
Expand All @@ -51,7 +52,7 @@
"deep-freeze": "0.0.1",
"dirty-chai": "^1.2.2",
"garbage": "0.0.0",
"ipfs-block": "~0.5.5",
"ipfs-block": "~0.6.0",
"pre-commit": "^1.2.2"
},
"contributors": [
Expand Down
2 changes: 1 addition & 1 deletion src/resolver.js
Expand Up @@ -9,7 +9,7 @@ exports.multicodec = 'dag-cbor'

/*
* resolve: receives a path and a block and returns the value on path,
* throw if not possible. `block` is an IPFS Block instance (contains data + key)
* throw if not possible. `block` is an IPFS Block instance (contains data + cid)
*/
exports.resolve = (block, path, callback) => {
if (typeof path === 'function') {
Expand Down
36 changes: 21 additions & 15 deletions test/resolver.spec.js
Expand Up @@ -6,11 +6,16 @@ const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const dagCBOR = require('../src')
const resolver = dagCBOR.resolver

const Block = require('ipfs-block')
const series = require('async/series')
const map = require('async/map')
const waterfall = require('async/waterfall')
const parallel = require('async/parallel')
const CID = require('cids')
const multihashing = require('multihashing-async')

const dagCBOR = require('../src')
const resolver = dagCBOR.resolver

describe('IPLD format resolver (local)', () => {
let emptyNodeBlock
Expand All @@ -32,20 +37,21 @@ describe('IPLD format resolver (local)', () => {
]
}

series([
(cb) => {
dagCBOR.util.serialize(emptyNode, (err, serialized) => {
expect(err).to.not.exist()
emptyNodeBlock = new Block(serialized)
cb()
})
},
(cb) => {
dagCBOR.util.serialize(node, (err, serialized) => {
waterfall([
(cb) => parallel([
(cb) => dagCBOR.util.serialize(emptyNode, cb),
(cb) => dagCBOR.util.serialize(node, cb)
], cb),
(res, cb) => map(res, (s, cb) => {
multihashing(s, 'sha2-256', (err, multihash) => {
expect(err).to.not.exist()
nodeBlock = new Block(serialized)
cb()
cb(null, new Block(s, new CID(multihash)))
})
}, cb),
(blocks, cb) => {
emptyNodeBlock = blocks[0]
nodeBlock = blocks[1]
cb()
}
], done)
})
Expand Down