From 08a57e3a2f354bfd912b46327103b24e928bdfa6 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Fri, 29 Jun 2018 22:31:38 +0100 Subject: [PATCH 1/3] test(dag): introduce test that ensure `dag.put` can be called without options As discussed in https://github.com/ipfs/js-ipfs/pull/1415#issue-198357338 --- js/src/dag/put.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/src/dag/put.js b/js/src/dag/put.js index dadcf6afa..e09e75962 100644 --- a/js/src/dag/put.js +++ b/js/src/dag/put.js @@ -113,6 +113,10 @@ module.exports = (createCommon, options) => { }) }) + it('should not fail when calling put without options', (done) => { + ipfs.dag.put(pbNode, done) + }) + it.skip('should put by passing the cid instead of format and hashAlg', (done) => {}) // TODO it.skip('Promises support', (done) => {}) From 1abc376e66f221fccecf89609aefadf0cefeec79 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Mon, 2 Jul 2018 13:34:57 +0200 Subject: [PATCH 2/3] chore(SPEC/DAG): update DAG spec to cover optional `options` argument License: MIT Signed-off-by: Pascal Precht --- SPEC/DAG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 From bc600b7b2fbb94faf0e735b86c0f60d207ddb1f9 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 3 Jul 2018 09:22:14 +0100 Subject: [PATCH 3/3] test: add test to ensure defaults are set License: MIT Signed-off-by: Alan Shaw --- js/src/dag/put.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/js/src/dag/put.js b/js/src/dag/put.js index e09e75962..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') @@ -114,7 +115,16 @@ module.exports = (createCommon, options) => { }) it('should not fail when calling put without options', (done) => { - ipfs.dag.put(pbNode, 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) => {})