Skip to content

Commit

Permalink
Merge pull request #47 from ipld/datastore
Browse files Browse the repository at this point in the history
feat: use new block api
  • Loading branch information
daviddias authored Mar 21, 2017
2 parents d0ae7b0 + 4ec9228 commit 9589ed2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 9589ed2

Please sign in to comment.