diff --git a/src/dag/get.js b/src/dag/get.js index 0be5898eb..9453445df 100644 --- a/src/dag/get.js +++ b/src/dag/get.js @@ -266,5 +266,61 @@ module.exports = (createCommon, options) => { }) }) }) + + it('should be able to get part of a dag-cbor node', (done) => { + const cbor = { + foo: 'dag-cbor-bar' + } + ipfs.dag.put(cbor, { format: 'dag-cbor', hashAlg: 'sha2-256' }, (err, cid) => { + expect(err).to.not.exist() + expect(cid.codec).to.equal('dag-cbor') + cid = cid.toBaseEncodedString('base32') + expect(cid).to.equal('bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce') + ipfs.dag.get(cid, 'foo', (err, result) => { + expect(err).to.not.exist() + expect(result.value).to.equal('dag-cbor-bar') + done() + }) + }) + }) + + it('should be able to traverse from one dag-cbor node to another', (done) => { + const cbor1 = { + foo: 'dag-cbor-bar' + } + + ipfs.dag.put(cbor1, { format: 'dag-cbor', hashAlg: 'sha2-256' }, (err, cid1) => { + expect(err).to.not.exist() + + const cbor2 = { other: cid1 } + + ipfs.dag.put(cbor2, { format: 'dag-cbor', hashAlg: 'sha2-256' }, (err, cid2) => { + expect(err).to.not.exist() + + ipfs.dag.get(cid2, 'other/foo', (err, result) => { + expect(err).to.not.exist() + expect(result.value).to.equal('dag-cbor-bar') + done() + }) + }) + }) + }) + + it('should be able to get a DAG node with format raw', (done) => { + const buf = Buffer.from([0, 1, 2, 3]) + + ipfs.dag.put(buf, { + format: 'raw', + hashAlg: 'sha2-256' + }, (err, cid) => { + expect(err).to.not.exist() + + ipfs.dag.get(cid, (err, result) => { + expect(err).to.not.exist() + expect(result.value).to.deep.equal(buf) + done() + }) + }) + }) }) }