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

test: add additional DAG CBOR and raw tests #494

Merged
merged 1 commit into from
Jul 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/dag/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
})
})
}