|
| 1 | +/* eslint-env mocha */ |
| 2 | +/* eslint max-nested-callbacks: ["error", 8] */ |
| 3 | + |
| 4 | +'use strict' |
| 5 | + |
| 6 | +const expect = require('chai').expect |
| 7 | +const dagPB = require('ipld-dag-pb') |
| 8 | +const DAGNode = dagPB.DAGNode |
| 9 | +const dagCBOR = require('ipld-dag-pb') |
| 10 | +// const series = require('async/series') |
| 11 | + |
| 12 | +module.exports = (common) => { |
| 13 | + describe.only('.dag', () => { |
| 14 | + let ipfs |
| 15 | + |
| 16 | + before(function (done) { |
| 17 | + // CI is slow |
| 18 | + this.timeout(20 * 1000) |
| 19 | + |
| 20 | + common.setup((err, factory) => { |
| 21 | + expect(err).to.not.exist |
| 22 | + factory.spawnNode((err, node) => { |
| 23 | + expect(err).to.not.exist |
| 24 | + ipfs = node |
| 25 | + done() |
| 26 | + }) |
| 27 | + }) |
| 28 | + }) |
| 29 | + |
| 30 | + after((done) => { |
| 31 | + common.teardown(done) |
| 32 | + }) |
| 33 | + |
| 34 | + describe('callback API', () => { |
| 35 | + let pbNode |
| 36 | + let cborNode |
| 37 | + |
| 38 | + before((done) => { |
| 39 | + const someData = new Buffer('some data') |
| 40 | + |
| 41 | + pbNode = DAGNode.create(someData, (err, node) => { |
| 42 | + expect(err).to.not.exist |
| 43 | + pbNode = node |
| 44 | + done() |
| 45 | + }) |
| 46 | + |
| 47 | + cborNode = { |
| 48 | + data: someData |
| 49 | + } |
| 50 | + }) |
| 51 | + |
| 52 | + describe('.put', () => { |
| 53 | + it('dag-pb with default hash func (sha2-256)', (done) => { |
| 54 | + ipfs.dag.put(pbNode, 'dag-pb', 'sha2-256', done) |
| 55 | + }) |
| 56 | + |
| 57 | + it.skip('dag-pb with custom hash func (sha3-512)', (done) => { |
| 58 | + ipfs.dag.put(pbNode, 'dag-pb', 'sha3-512', done) |
| 59 | + }) |
| 60 | + |
| 61 | + it.skip('dag-pb node with wrong multicodec', (done) => { |
| 62 | + // This works because dag-cbor will just treat pbNode as a |
| 63 | + // regular object |
| 64 | + ipfs.dag.put(pbNode, 'dag-cbor', 'sha3-512', (err) => { |
| 65 | + expect(err).to.exist |
| 66 | + done() |
| 67 | + }) |
| 68 | + }) |
| 69 | + |
| 70 | + it('dag-cbor with default hash func (sha2-256)', (done) => { |
| 71 | + ipfs.dag.put(cborNode, 'dag-cbor', 'sha2-256', done) |
| 72 | + }) |
| 73 | + |
| 74 | + it.skip('dag-cbor with custom hash func (sha3-512)', (done) => { |
| 75 | + ipfs.dag.put(cborNode, 'dag-cbor', 'sha3-512', done) |
| 76 | + }) |
| 77 | + |
| 78 | + it('dag-cbor node with wrong multicodec', (done) => { |
| 79 | + ipfs.dag.put(cborNode, 'dag-pb', 'sha3-512', (err) => { |
| 80 | + expect(err).to.exist |
| 81 | + done() |
| 82 | + }) |
| 83 | + }) |
| 84 | + }) |
| 85 | + |
| 86 | + describe('.get', () => { |
| 87 | + let pbNode |
| 88 | + let cborNode |
| 89 | + |
| 90 | + before((done) => { |
| 91 | + const someData = new Buffer('some other data') |
| 92 | + |
| 93 | + pbNode = DAGNode.create(someData, (err, node) => { |
| 94 | + expect(err).to.not.exist |
| 95 | + pbNode = node |
| 96 | + done() |
| 97 | + }) |
| 98 | + |
| 99 | + cborNode = { |
| 100 | + data: someData |
| 101 | + } |
| 102 | + }) |
| 103 | + |
| 104 | + it('dag-pb node', (done) => { |
| 105 | + ipfs.dag.put(pbNode, 'dag-pb', 'sha2-256', (err) => { |
| 106 | + expect(err).to.not.exist |
| 107 | + dagPB.util.cid(pbNode, (err, cid) => { |
| 108 | + expect(err).to.not.exist |
| 109 | + ipfs.dag.get(cid, (err, node) => { |
| 110 | + expect(err).to.not.exist |
| 111 | + expect(pbNode.toJSON()).to.eql(node.toJSON()) |
| 112 | + done() |
| 113 | + }) |
| 114 | + }) |
| 115 | + }) |
| 116 | + }) |
| 117 | + |
| 118 | + it('dag-cbor node', (done) => { |
| 119 | + ipfs.dag.put(cborNode, 'dag-cbor', 'sha2-256', (err) => { |
| 120 | + expect(err).to.not.exist |
| 121 | + dagCBOR.util.cid(cborNode, (err, cid) => { |
| 122 | + expect(err).to.not.exist |
| 123 | + ipfs.dag.get(cid, (err, node) => { |
| 124 | + expect(err).to.not.exist |
| 125 | + expect(cborNode).to.eql(node) |
| 126 | + done() |
| 127 | + }) |
| 128 | + }) |
| 129 | + }) |
| 130 | + }) |
| 131 | + }) |
| 132 | + |
| 133 | + describe('.resolve', () => { |
| 134 | + it.skip('dag-pb local scope', (done) => {}) |
| 135 | + it.skip('dag-pb one level', (done) => {}) |
| 136 | + it.skip('dag-pb two levels', (done) => {}) |
| 137 | + it.skip('dag-cbor local scope', (done) => {}) |
| 138 | + it.skip('dag-cbor one level', (done) => {}) |
| 139 | + it.skip('dag-cbor two levels', (done) => {}) |
| 140 | + it.skip('from dag-pb to dag-cbor', (done) => {}) |
| 141 | + it.skip('from dag-cbor to dag-pb', (done) => {}) |
| 142 | + }) |
| 143 | + |
| 144 | + describe('.rm', () => { |
| 145 | + let pbNode |
| 146 | + |
| 147 | + before((done) => { |
| 148 | + const someData = new Buffer('some other data') |
| 149 | + |
| 150 | + pbNode = DAGNode.create(someData, (err, node) => { |
| 151 | + expect(err).to.not.exist |
| 152 | + pbNode = node |
| 153 | + done() |
| 154 | + }) |
| 155 | + }) |
| 156 | + |
| 157 | + it('dag-pb node', (done) => { |
| 158 | + ipfs.dag.put(pbNode, 'dag-pb', 'sha2-256', (err) => { |
| 159 | + expect(err).to.not.exist |
| 160 | + dagPB.util.cid(pbNode, (err, cid) => { |
| 161 | + expect(err).to.not.exist |
| 162 | + ipfs.dag.get(cid, (err, node) => { |
| 163 | + expect(err).to.not.exist |
| 164 | + ipfs.dag.rm(cid, done) |
| 165 | + // TODO When we get timeouts in js-ipfs, try to fetch again |
| 166 | + // and observe it timesout without the node |
| 167 | + }) |
| 168 | + }) |
| 169 | + }) |
| 170 | + }) |
| 171 | + }) |
| 172 | + }) |
| 173 | + |
| 174 | + describe('promise API', () => { |
| 175 | + describe('.put', () => {}) |
| 176 | + describe('.get', () => {}) |
| 177 | + describe('.resolve', () => {}) |
| 178 | + describe('.rm', () => {}) |
| 179 | + }) |
| 180 | + }) |
| 181 | +} |
0 commit comments