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

Commit

Permalink
fix: updates ipld-dag-pb dep to version without .cid properties (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored and Alan Shaw committed Nov 12, 2018
1 parent 8483084 commit b8f7b9a
Show file tree
Hide file tree
Showing 14 changed files with 549 additions and 312 deletions.
2 changes: 1 addition & 1 deletion js/src/dag/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = (createCommon, options) => {
(cb) => {
const someData = Buffer.from('some other data')

pbNode = DAGNode.create(someData, (err, node) => {
DAGNode.create(someData, (err, node) => {
expect(err).to.not.exist()
pbNode = node
cb()
Expand Down
2 changes: 1 addition & 1 deletion js/src/dag/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = (createCommon, options) => {
before((done) => {
const someData = Buffer.from('some data')

pbNode = DAGNode.create(someData, (err, node) => {
DAGNode.create(someData, (err, node) => {
expect(err).to.not.exist()
pbNode = node
done()
Expand Down
86 changes: 51 additions & 35 deletions js/src/object/data.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* eslint-env mocha */
/* eslint-disable max-nested-callbacks */
'use strict'

const bs58 = require('bs58')
const hat = require('hat')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const {
calculateCid
} = require('../utils/dag-pb')

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
Expand Down Expand Up @@ -41,36 +45,40 @@ module.exports = (createCommon, options) => {
ipfs.object.put(testObj, (err, node) => {
expect(err).to.not.exist()

ipfs.object.data(node.multihash, (err, data) => {
calculateCid(node, (err, nodeCid) => {
expect(err).to.not.exist()

// because js-ipfs-api can't infer
// if the returned Data is Buffer or String
if (typeof data === 'string') {
data = Buffer.from(data)
}
expect(node.data).to.eql(data)
done()
ipfs.object.data(nodeCid, (err, data) => {
expect(err).to.not.exist()

// because js-ipfs-api can't infer
// if the returned Data is Buffer or String
if (typeof data === 'string') {
data = Buffer.from(data)
}
expect(node.data).to.eql(data)
done()
})
})
})
})

it('should get data by multihash (promised)', () => {
it('should get data by multihash (promised)', async () => {
const testObj = {
Data: Buffer.from(hat()),
Links: []
}

return ipfs.object.put(testObj).then((node) => {
return ipfs.object.data(node.multihash).then((data) => {
// because js-ipfs-api can't infer
// if the returned Data is Buffer or String
if (typeof data === 'string') {
data = Buffer.from(data)
}
expect(node.data).to.deep.equal(data)
})
})
const node = await ipfs.object.put(testObj)
const nodeCid = await calculateCid(node)
let data = await ipfs.object.data(nodeCid)

// because js-ipfs-api can't infer
// if the returned Data is Buffer or String
if (typeof data === 'string') {
data = Buffer.from(data)
}
expect(node.data).to.deep.equal(data)
})

it('should get data by base58 encoded multihash', (done) => {
Expand All @@ -82,16 +90,20 @@ module.exports = (createCommon, options) => {
ipfs.object.put(testObj, (err, node) => {
expect(err).to.not.exist()

ipfs.object.data(bs58.encode(node.multihash), { enc: 'base58' }, (err, data) => {
calculateCid(node, (err, nodeCid) => {
expect(err).to.not.exist()

// because js-ipfs-api can't infer
// if the returned Data is Buffer or String
if (typeof data === 'string') {
data = Buffer.from(data)
}
expect(node.data).to.eql(data)
done()
ipfs.object.data(bs58.encode(nodeCid.buffer), { enc: 'base58' }, (err, data) => {
expect(err).to.not.exist()

// because js-ipfs-api can't infer
// if the returned Data is Buffer or String
if (typeof data === 'string') {
data = Buffer.from(data)
}
expect(node.data).to.eql(data)
done()
})
})
})
})
Expand All @@ -105,16 +117,20 @@ module.exports = (createCommon, options) => {
ipfs.object.put(testObj, (err, node) => {
expect(err).to.not.exist()

ipfs.object.data(bs58.encode(node.multihash).toString(), { enc: 'base58' }, (err, data) => {
calculateCid(node, (err, nodeCid) => {
expect(err).to.not.exist()

// because js-ipfs-api can't infer if the
// returned Data is Buffer or String
if (typeof data === 'string') {
data = Buffer.from(data)
}
expect(node.data).to.eql(data)
done()
ipfs.object.data(bs58.encode(nodeCid.buffer).toString(), { enc: 'base58' }, (err, data) => {
expect(err).to.not.exist()

// because js-ipfs-api can't infer if the
// returned Data is Buffer or String
if (typeof data === 'string') {
data = Buffer.from(data)
}
expect(node.data).to.eql(data)
done()
})
})
})
})
Expand Down
Loading

0 comments on commit b8f7b9a

Please sign in to comment.