Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
test(dag): ensure dag.put can be called without options (#316)
Browse files Browse the repository at this point in the history
* test(dag): introduce test that ensure `dag.put` can be called without options

As discussed in ipfs/js-ipfs#1415 (comment)

* chore(SPEC/DAG): update DAG spec to cover optional `options` argument

License: MIT
Signed-off-by: Pascal Precht <[email protected]>

* test: add test to ensure defaults are set

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
  • Loading branch information
0x-r4bbit authored and alanshaw committed Jul 3, 2018
1 parent c47c4ce commit 011c417
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion SPEC/DAG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions js/src/dag/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -95,6 +96,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) => {})
Expand Down

0 comments on commit 011c417

Please sign in to comment.