This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: dag.get return error on missing multicodec (#831)
Before this change it just failed silently for 'raw' DAGs such as `bafkreigh2akiscaildcqabsyg3dfr6chu3fgpregiymsck7e7aqa4s52zy` License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
- Loading branch information
Showing
2 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
|
||
'use strict' | ||
|
||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(dirtyChai) | ||
const series = require('async/series') | ||
const dagPB = require('ipld-dag-pb') | ||
const DAGNode = dagPB.DAGNode | ||
|
||
const IPFSApi = require('../src') | ||
const f = require('./utils/factory') | ||
|
||
let ipfsd | ||
let ipfs | ||
|
||
describe('.dag', function () { | ||
this.timeout(20 * 1000) | ||
before(function (done) { | ||
series([ | ||
(cb) => f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { | ||
expect(err).to.not.exist() | ||
ipfsd = _ipfsd | ||
ipfs = IPFSApi(_ipfsd.apiAddr) | ||
cb() | ||
}) | ||
], done) | ||
}) | ||
|
||
after((done) => { | ||
if (!ipfsd) return done() | ||
ipfsd.stop(done) | ||
}) | ||
|
||
it('should be able to put and get a DAG node with format dag-pb', (done) => { | ||
const data = Buffer.from('some data') | ||
DAGNode.create(data, (err, node) => { | ||
expect(err).to.not.exist() | ||
ipfs.dag.put(node, {format: 'dag-pb', hashAlg: 'sha2-256'}, (err, cid) => { | ||
expect(err).to.not.exist() | ||
cid = cid.toV0() | ||
expect(cid.codec).to.equal('dag-pb') | ||
cid = cid.toBaseEncodedString('base58btc') | ||
// expect(cid).to.equal('bafybeig3t3eugdchignsgkou3ly2mmy4ic4gtfor7inftnqn3yq4ws3a5u') | ||
expect(cid).to.equal('Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr') | ||
ipfs.dag.get(cid, (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result.value.data).to.deep.equal(data) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
it('should be able to put and get a DAG node with format dag-cbor', (done) => { | ||
const cbor = {foo: 'dag-cbor-bar'} | ||
ipfs.dag.put(cbor, {format: 'dag-cbor', hashAlg: 'sha2-256'}, (err, cid) => { | ||
expect(err).to.not.exist() | ||
expect(cid.codec).to.equal('dag-cbor') | ||
cid = cid.toBaseEncodedString('base32') | ||
expect(cid).to.equal('bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce') | ||
ipfs.dag.get(cid, (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result.value).to.deep.equal(cbor) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('should callback with error when missing DAG resolver for raw multicodec', (done) => { | ||
// CIDv1 with multicodec = raw | ||
const cid = 'bafkreigh2akiscaildcqabsyg3dfr6chu3fgpregiymsck7e7aqa4s52zy' | ||
ipfs.dag.get(cid, (err, result) => { | ||
expect(result).to.not.exist() | ||
expect(err.message).to.equal('ipfs-api is missing DAG resolver for "raw" multicodec') | ||
done() | ||
}) | ||
}) | ||
}) |