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

Commit

Permalink
chore: update ipld formats and cid versions (#473)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
  • Loading branch information
achingbrain authored and Alan Shaw committed May 21, 2019
1 parent 681473c commit 98e0f4b
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 259 deletions.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"bl": "^3.0.0",
"bs58": "^4.0.1",
"chai": "^4.2.0",
"cids": "~0.5.8",
"cids": "~0.7.1",
"concat-stream": "^2.0.0",
"dirty-chai": "^2.0.1",
"es6-promisify": "^6.0.1",
Expand All @@ -49,9 +49,9 @@
"ipfs-block": "~0.8.0",
"ipfs-unixfs": "~0.1.16",
"ipfs-utils": "~0.0.3",
"ipld-dag-cbor": "~0.13.1",
"ipld-dag-pb": "~0.15.3",
"is-ipfs": "~0.6.0",
"ipld-dag-cbor": "~0.15.0",
"ipld-dag-pb": "~0.17.3",
"is-ipfs": "~0.6.1",
"is-plain-object": "^3.0.0",
"libp2p-crypto": "~0.16.0",
"multiaddr": "^6.0.0",
Expand All @@ -62,7 +62,6 @@
"peer-info": "~0.15.0",
"pull-stream": "^3.6.11",
"pump": "^3.0.0",
"randombytes": "^2.0.6",
"readable-stream": "^3.1.1",
"through2": "^3.0.0"
},
Expand Down
99 changes: 52 additions & 47 deletions src/dag/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,45 @@ module.exports = (createCommon, options) => {
(cb) => {
const someData = Buffer.from('some other data')

DAGNode.create(someData, (err, node) => {
expect(err).to.not.exist()
pbNode = node
cb()
})
try {
pbNode = DAGNode.create(someData)
} catch (err) {
return cb(err)
}

cborNode = {
data: someData
}

cb()
},
(cb) => {
dagPB.DAGNode.create(Buffer.from('I am inside a Protobuf'), (err, node) => {
expect(err).to.not.exist()
nodePb = node
cb()
})
try {
nodePb = DAGNode.create(Buffer.from('I am inside a Protobuf'))
} catch (err) {
return cb(err)
}

cb()
},
(cb) => {
dagPB.util.cid(nodePb, (err, cid) => {
expect(err).to.not.exist()
cidPb = cid
cb()
})
dagPB.util.cid(dagPB.util.serialize(nodePb))
.then(cid => {
cidPb = cid
cb()
}, cb)
},
(cb) => {
nodeCbor = {
someData: 'I am inside a Cbor object',
pb: cidPb
}

dagCBOR.util.cid(nodeCbor, (err, cid) => {
expect(err).to.not.exist()
cidCbor = cid
cb()
})
dagCBOR.util.cid(dagCBOR.util.serialize(nodeCbor))
.then(cid => {
cidCbor = cid
cb()
}, cb)
},
(cb) => {
eachSeries([
Expand Down Expand Up @@ -135,11 +139,12 @@ module.exports = (createCommon, options) => {

const node = result.value

dagPB.util.cid(node, (err, cid) => {
expect(err).to.not.exist()
expect(cid).to.eql(cidPb)
done()
})
dagPB.util.cid(dagPB.util.serialize(node))
.then(cid => {
expect(cid).to.eql(cidPb)
done()
})
.catch(done)
})
})

Expand All @@ -160,11 +165,12 @@ module.exports = (createCommon, options) => {

const node = result.value

dagCBOR.util.cid(node, (err, cid) => {
expect(err).to.not.exist()
expect(cid).to.eql(cidCbor)
done()
})
dagCBOR.util.cid(dagCBOR.util.serialize(node))
.then(cid => {
expect(cid).to.eql(cidCbor)
done()
})
.catch(done)
})
})

Expand Down Expand Up @@ -196,11 +202,12 @@ module.exports = (createCommon, options) => {

const node = result.value

dagCBOR.util.cid(node, (err, cid) => {
expect(err).to.not.exist()
expect(cid).to.eql(cidCbor)
done()
})
dagCBOR.util.cid(dagCBOR.util.serialize(node))
.then(cid => {
expect(cid).to.eql(cidCbor)
done()
})
.catch(done)
})
})

Expand All @@ -225,20 +232,18 @@ module.exports = (createCommon, options) => {
it('should get a node added as CIDv0 with a CIDv1', done => {
const input = Buffer.from(`TEST${Date.now()}`)

dagPB.DAGNode.create(input, (err, node) => {
expect(err).to.not.exist()
const node = dagPB.DAGNode.create(input)

ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
expect(err).to.not.exist()
expect(cid.version).to.equal(0)
ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
expect(err).to.not.exist()
expect(cid.version).to.equal(0)

const cidv1 = cid.toV1()
const cidv1 = cid.toV1()

ipfs.dag.get(cidv1, (err, output) => {
expect(err).to.not.exist()
expect(output.value.data).to.eql(input)
done()
})
ipfs.dag.get(cidv1, (err, output) => {
expect(err).to.not.exist()
expect(output.value.Data).to.eql(input)
done()
})
})
})
Expand All @@ -256,7 +261,7 @@ module.exports = (createCommon, options) => {

ipfs.dag.get(cidv0, (err, output) => {
expect(err).to.not.exist()
expect(Unixfs.unmarshal(output.value.data).data).to.eql(input)
expect(Unixfs.unmarshal(output.value.Data).data).to.eql(input)
done()
})
})
Expand Down
23 changes: 13 additions & 10 deletions src/dag/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ module.exports = (createCommon, options) => {
before((done) => {
const someData = Buffer.from('some data')

DAGNode.create(someData, (err, node) => {
expect(err).to.not.exist()
pbNode = node
done()
})
try {
pbNode = DAGNode.create(someData)
} catch (err) {
return done(err)
}

cborNode = {
data: someData
}

done()
})

it('should put dag-pb with default hash func (sha2-256)', (done) => {
Expand Down Expand Up @@ -88,11 +90,12 @@ module.exports = (createCommon, options) => {
expect(err).to.not.exist()
expect(cid).to.exist()
expect(CID.isCID(cid)).to.equal(true)
dagCBOR.util.cid(cborNode, (err, _cid) => {
expect(err).to.not.exist()
expect(cid.buffer).to.eql(_cid.buffer)
done()
})
dagCBOR.util.cid(dagCBOR.util.serialize(cborNode))
.then(_cid => {
expect(cid.buffer).to.eql(_cid.buffer)
done()
})
.catch(done)
})
})

Expand Down
36 changes: 19 additions & 17 deletions src/dag/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,32 @@ module.exports = (createCommon, options) => {
before(function (done) {
series([
(cb) => {
dagPB.DAGNode.create(Buffer.from('I am inside a Protobuf'), (err, node) => {
expect(err).to.not.exist()
nodePb = node
cb()
})
try {
nodePb = dagPB.DAGNode.create(Buffer.from('I am inside a Protobuf'))
} catch (err) {
return cb(err)
}

cb()
},
(cb) => {
dagPB.util.cid(nodePb, (err, cid) => {
expect(err).to.not.exist()
cidPb = cid
cb()
})
dagPB.util.cid(dagPB.util.serialize(nodePb))
.then(cid => {
cidPb = cid
cb()
}, cb)
},
(cb) => {
nodeCbor = {
someData: 'I am inside a Cbor object',
pb: cidPb
}

dagCBOR.util.cid(nodeCbor, (err, cid) => {
expect(err).to.not.exist()
cidCbor = cid
cb()
})
dagCBOR.util.cid(dagCBOR.util.serialize(nodeCbor))
.then(cid => {
cidCbor = cid
cb()
}, cb)
},
(cb) => {
eachSeries([
Expand Down Expand Up @@ -113,7 +115,7 @@ module.exports = (createCommon, options) => {
it('should get tree with CID recursive (accross different formats)', (done) => {
ipfs.dag.tree(cidCbor, { recursive: true }, (err, paths) => {
expect(err).to.not.exist()
expect(paths).to.eql([
expect(paths).to.have.members([
'pb',
'someData',
'pb/Links',
Expand All @@ -126,7 +128,7 @@ module.exports = (createCommon, options) => {
it('should get tree with CID and path recursive', (done) => {
ipfs.dag.tree(cidCbor, 'pb', { recursive: true }, (err, paths) => {
expect(err).to.not.exist()
expect(paths).to.eql([
expect(paths).to.have.members([
'Links',
'Data'
])
Expand Down
1 change: 1 addition & 0 deletions src/files-mfs/read-readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = (createCommon, options) => {
const testDir = `/test-${hat()}`

const stream = ipfs.files.readReadableStream(`${testDir}/404`)
stream.on('data', () => {})

stream.once('error', (err) => {
expect(err).to.exist()
Expand Down
4 changes: 2 additions & 2 deletions src/files-regular/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ module.exports = (createCommon, options) => {
return ipfs.cat(fixtures.smallFile.cid + '/does-not-exist')
.catch((err) => {
expect(err).to.exist()
expect(err.message).to.oneOf([
'No such file',
expect(err.message).to.be.oneOf([
'file does not exist',
'no link named "does-not-exist" under Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'])
})
})
Expand Down
11 changes: 6 additions & 5 deletions src/files-regular/refs-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const mapSeries = require('async/mapSeries')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const loadFixture = require('aegir/fixtures')
const CID = require('cids')

module.exports = (createCommon, suiteName, ipfsRefs, options) => {
const describe = getDescribe(options)
Expand Down Expand Up @@ -110,10 +111,10 @@ module.exports = (createCommon, suiteName, ipfsRefs, options) => {
'QmdBcHbK7uDQav8YrHsfKju3EKn48knxjd96KRMFs3gtS9',
'QmeX96opBHZHLySMFoNiWS5msxjyX6rqtr3Rr1u7uxn7zJ',
'Qmf8MwTnY7VdcnF8WcoJ3GB24NmNd1HsGzuEWCtUYDP38x',
'zdpuAkqPgGuEFBFLcixZyFezWw3bsGUWVS6W7c8YhV5sdAc6E',
'zdpuArVVBgigTbs6FdyqFFWUSsXymdruTtCVoboc91L3WTXi1',
'zdpuAsrruPqzPDYs9c1FGNR5Wuyx8on64no6z62SRPv3viHGL',
'zdpuAxTXSfaHaZNed3JG2WvcYNgd64v27ztB2zknrz5noPhz5'
'bafyreiagelcmhfn33zuslkdo7fkes3dzcr2nju6meh75zm6vqklfqiojam',
'bafyreic2f6adq5tqnbrvwiqc3jkz2cf4tz3cz2rp6plpij2qaoufgsxwmi',
'bafyreidoqtyvflv5v4c3gd3izxvpq4flke55ayurbrnhsxh7z5wwjc6v6e',
'bafyreifs2ub2lnq6n2quqbi3zb5homs5iqlmm77b3am252cqzxiu7phwpy'
])

done()
Expand Down Expand Up @@ -365,7 +366,7 @@ function loadDagContent (ipfs, node, callback) {
putLinks: (links, cb) => {
const obj = {}
for (const { name, cid } of links) {
obj[name] = { '/': cid }
obj[name] = new CID(cid)
}
ipfs.dag.put(obj, cb)
}
Expand Down
Loading

0 comments on commit 98e0f4b

Please sign in to comment.