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

Commit

Permalink
test: add additional DAG CBOR and raw tests
Browse files Browse the repository at this point in the history
Made by @achingbrain for ipfs-inactive/js-ipfs-http-client#957

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
  • Loading branch information
Alan Shaw committed Jul 11, 2019
1 parent 0234868 commit 8b8e972
Showing 1 changed file with 56 additions and 0 deletions.
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()
})
})
})
})
}

0 comments on commit 8b8e972

Please sign in to comment.