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 124
feat: DAG API basics (get, put, rm) #112
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,141 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
|
||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const dagPB = require('ipld-dag-pb') | ||
const DAGNode = dagPB.DAGNode | ||
const dagCBOR = require('ipld-dag-cbor') | ||
|
||
module.exports = (common) => { | ||
describe.only('.dag (basics)', () => { | ||
let ipfs | ||
|
||
before(function (done) { | ||
// CI is slow | ||
this.timeout(20 * 1000) | ||
|
||
common.setup((err, factory) => { | ||
expect(err).to.not.exist | ||
factory.spawnNode((err, node) => { | ||
expect(err).to.not.exist | ||
ipfs = node | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
common.teardown(done) | ||
}) | ||
|
||
describe('callback API', () => { | ||
let pbNode | ||
let cborNode | ||
|
||
before((done) => { | ||
const someData = new Buffer('some data') | ||
|
||
pbNode = DAGNode.create(someData, (err, node) => { | ||
expect(err).to.not.exist | ||
pbNode = node | ||
done() | ||
}) | ||
|
||
cborNode = { | ||
data: someData | ||
} | ||
}) | ||
|
||
describe('.put', () => { | ||
it('dag-pb with default hash func (sha2-256)', (done) => { | ||
ipfs.dag.put(pbNode, 'dag-pb', 'sha2-256', done) | ||
}) | ||
|
||
it('dag-pb with custom hash func (sha3-512)', (done) => { | ||
ipfs.dag.put(pbNode, 'dag-pb', 'sha3-512', done) | ||
}) | ||
|
||
/* | ||
* This works because dag-cbor will just treat pbNode as a regular object | ||
it.skip('dag-pb node with wrong multicodec', (done) => { | ||
// This works because dag-cbor will just treat pbNode as a | ||
// regular object | ||
ipfs.dag.put(pbNode, 'dag-cbor', 'sha3-512', (err) => { | ||
expect(err).to.exist | ||
done() | ||
}) | ||
}) | ||
*/ | ||
|
||
it('dag-cbor with default hash func (sha2-256)', (done) => { | ||
ipfs.dag.put(cborNode, 'dag-cbor', 'sha2-256', done) | ||
}) | ||
|
||
it('dag-cbor with custom hash func (sha3-512)', (done) => { | ||
ipfs.dag.put(cborNode, 'dag-cbor', 'sha3-512', done) | ||
}) | ||
|
||
it('dag-cbor node with wrong multicodec', (done) => { | ||
ipfs.dag.put(cborNode, 'dag-pb', 'sha3-512', (err) => { | ||
expect(err).to.exist | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('.get', () => { | ||
let pbNode | ||
let cborNode | ||
|
||
before((done) => { | ||
const someData = new Buffer('some other data') | ||
|
||
pbNode = DAGNode.create(someData, (err, node) => { | ||
expect(err).to.not.exist | ||
pbNode = node | ||
done() | ||
}) | ||
|
||
cborNode = { | ||
data: someData | ||
} | ||
}) | ||
|
||
it('dag-pb node', (done) => { | ||
ipfs.dag.put(pbNode, 'dag-pb', 'sha2-256', (err) => { | ||
expect(err).to.not.exist | ||
dagPB.util.cid(pbNode, (err, cid) => { | ||
expect(err).to.not.exist | ||
ipfs.dag.get(cid, (err, node) => { | ||
expect(err).to.not.exist | ||
expect(pbNode.toJSON()).to.eql(node.toJSON()) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
it('dag-cbor node', (done) => { | ||
ipfs.dag.put(cborNode, 'dag-cbor', 'sha2-256', (err) => { | ||
expect(err).to.not.exist | ||
dagCBOR.util.cid(cborNode, (err, cid) => { | ||
expect(err).to.not.exist | ||
ipfs.dag.get(cid, (err, node) => { | ||
expect(err).to.not.exist | ||
expect(cborNode).to.eql(node) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('promise API', () => { | ||
describe('.put', () => {}) | ||
describe('.get', () => {}) | ||
}) | ||
}) | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also get these nodes to check that they have been actually put in the correct way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is what happens in the get tests, this way put is tested in isolation and in conjunction with get
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But not for all the formats as far as I can see.