diff --git a/SPEC/DAG.md b/SPEC/DAG.md index 354e8a5d2..e97aa583c 100644 --- a/SPEC/DAG.md +++ b/SPEC/DAG.md @@ -15,11 +15,15 @@ ##### `JavaScript` - ipfs.dag.put(dagNode, options, callback) - `dagNode` - a DAG node that follows one of the supported IPLD formats. -- `options` - a object that might contain the follwing values: +- `options` - a object that might contain the following values: - `format` - The IPLD format multicodec. - `hashAlg` - The hash algorithm to be used over the serialized dagNode. - or - `cid` - the CID of the node passed. + - or + - if no `options` are given, `ipfs.dag.put()` uses the following defaults: + - `format: 'dag-cbor'` + - `hashAlg: 'sha2-256'` - **Note** - You should only pass the CID or the format + hashAlg pair and not both - `callback` must follow `function (err, cid) {}` signature, where `err` is an error if the operation was not successful and CID is the CID generated through the process or the one that was passed diff --git a/js/src/dag/put.js b/js/src/dag/put.js index dadcf6afa..02563d81d 100644 --- a/js/src/dag/put.js +++ b/js/src/dag/put.js @@ -5,6 +5,7 @@ const dagPB = require('ipld-dag-pb') const DAGNode = dagPB.DAGNode const dagCBOR = require('ipld-dag-cbor') const CID = require('cids') +const multihash = require('multihashes') const { spawnNodeWithId } = require('../utils/spawn') const { getDescribe, getIt, expect } = require('../utils/mocha') @@ -113,6 +114,19 @@ module.exports = (createCommon, options) => { }) }) + it('should not fail when calling put without options', (done) => { + ipfs.dag.put(cborNode, done) + }) + + it('should set defaults when calling put without options', (done) => { + ipfs.dag.put(cborNode, (err, cid) => { + expect(err).to.not.exist() + expect(cid.codec).to.equal('dag-cbor') + expect(multihash.decode(cid.multihash).name).to.equal('sha2-256') + done() + }) + }) + it.skip('should put by passing the cid instead of format and hashAlg', (done) => {}) // TODO it.skip('Promises support', (done) => {})