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

Commit dba84b5

Browse files
author
Alan Shaw
authored
test: add additional DAG CBOR and raw tests (#494)
Made by @achingbrain for ipfs-inactive/js-ipfs-http-client#957 License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
1 parent 0234868 commit dba84b5

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/dag/get.js

+56
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,61 @@ module.exports = (createCommon, options) => {
266266
})
267267
})
268268
})
269+
270+
it('should be able to get part of a dag-cbor node', (done) => {
271+
const cbor = {
272+
foo: 'dag-cbor-bar'
273+
}
274+
ipfs.dag.put(cbor, { format: 'dag-cbor', hashAlg: 'sha2-256' }, (err, cid) => {
275+
expect(err).to.not.exist()
276+
expect(cid.codec).to.equal('dag-cbor')
277+
cid = cid.toBaseEncodedString('base32')
278+
expect(cid).to.equal('bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce')
279+
ipfs.dag.get(cid, 'foo', (err, result) => {
280+
expect(err).to.not.exist()
281+
expect(result.value).to.equal('dag-cbor-bar')
282+
done()
283+
})
284+
})
285+
})
286+
287+
it('should be able to traverse from one dag-cbor node to another', (done) => {
288+
const cbor1 = {
289+
foo: 'dag-cbor-bar'
290+
}
291+
292+
ipfs.dag.put(cbor1, { format: 'dag-cbor', hashAlg: 'sha2-256' }, (err, cid1) => {
293+
expect(err).to.not.exist()
294+
295+
const cbor2 = { other: cid1 }
296+
297+
ipfs.dag.put(cbor2, { format: 'dag-cbor', hashAlg: 'sha2-256' }, (err, cid2) => {
298+
expect(err).to.not.exist()
299+
300+
ipfs.dag.get(cid2, 'other/foo', (err, result) => {
301+
expect(err).to.not.exist()
302+
expect(result.value).to.equal('dag-cbor-bar')
303+
done()
304+
})
305+
})
306+
})
307+
})
308+
309+
it('should be able to get a DAG node with format raw', (done) => {
310+
const buf = Buffer.from([0, 1, 2, 3])
311+
312+
ipfs.dag.put(buf, {
313+
format: 'raw',
314+
hashAlg: 'sha2-256'
315+
}, (err, cid) => {
316+
expect(err).to.not.exist()
317+
318+
ipfs.dag.get(cid, (err, result) => {
319+
expect(err).to.not.exist()
320+
expect(result.value).to.deep.equal(buf)
321+
done()
322+
})
323+
})
324+
})
269325
})
270326
}

0 commit comments

Comments
 (0)