Skip to content

Commit

Permalink
feat: add support for js-ipfs dag api and also some tests (ipfs#957)
Browse files Browse the repository at this point in the history
* feat: add support for js-ipfs dag api and also some tests

* test: move tests to interface suite

* chore: update interface-ipfs-core dep

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>

* chore: update interface-ipfs-core

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
achingbrain authored and Alan Shaw committed Jul 11, 2019
1 parent cd41a16 commit 8f378a3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"ipfs-utils": "~0.0.3",
"ipld-dag-cbor": "~0.15.0",
"ipld-dag-pb": "~0.17.3",
"ipld-raw": "^4.0.0",
"is-ipfs": "~0.6.1",
"is-pull-stream": "0.0.0",
"is-stream": "^2.0.0",
Expand Down Expand Up @@ -85,7 +86,7 @@
"cross-env": "^5.2.0",
"dirty-chai": "^2.0.1",
"go-ipfs-dep": "~0.4.21",
"interface-ipfs-core": "~0.107.0",
"interface-ipfs-core": "^0.107.1",
"ipfsd-ctl": "~0.43.0",
"nock": "^10.0.2",
"stream-equal": "^1.1.1"
Expand Down
7 changes: 5 additions & 2 deletions src/dag/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

const dagPB = require('ipld-dag-pb')
const dagCBOR = require('ipld-dag-cbor')
const raw = require('ipld-raw')
const promisify = require('promisify-es6')
const CID = require('cids')
const waterfall = require('async/waterfall')
const block = require('../block')

const resolvers = {
'dag-cbor': dagCBOR.resolver,
'dag-pb': dagPB.resolver
'dag-pb': dagPB.resolver,
raw: raw.resolver
}

module.exports = (send) => {
Expand Down Expand Up @@ -48,7 +50,7 @@ module.exports = (send) => {
const dagResolver = resolvers[ipfsBlock.cid.codec]

if (!dagResolver) {
const error = new Error('ipfs-http-client is missing DAG resolver for "' + ipfsBlock.cid.codec + '" multicodec')
const error = new Error(`Missing IPLD format "${ipfsBlock.cid.codec}"`)
error.missingMulticodec = ipfsBlock.cid.codec
return cb(error)
}
Expand All @@ -59,6 +61,7 @@ module.exports = (send) => {
} catch (err) {
return cb(err)
}

cb(null, res)
}
], callback)
Expand Down
13 changes: 6 additions & 7 deletions test/dag.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,15 @@ describe('.dag', function () {
})
})

it('should callback with error when missing DAG resolver for raw multicodec', (done) => {
ipfs.dag.put(Buffer.from([0, 1, 2, 3]), {
// CIDv1 with multicodec = raw
cid: new CID('bafkreigh2akiscaildcqabsyg3dfr6chu3fgpregiymsck7e7aqa4s52zy')
}, (err, cid) => {
it('should callback with error when missing DAG resolver for multicodec from requested CID', (done) => {
ipfs.block.put(Buffer.from([0, 1, 2, 3]), {
cid: new CID('z8mWaJ1dZ9fH5EetPuRsj8jj26pXsgpsr')
}, (err, block) => {
expect(err).to.not.exist()

ipfs.dag.get(cid, (err, result) => {
ipfs.dag.get(block.cid, (err, result) => {
expect(result).to.not.exist()
expect(err.message).to.equal('ipfs-http-client is missing DAG resolver for "raw" multicodec')
expect(err.message).to.equal('Missing IPLD format "git-raw"')
done()
})
})
Expand Down

0 comments on commit 8f378a3

Please sign in to comment.