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

Commit 98e0f4b

Browse files
achingbrainAlan Shaw
authored and
Alan Shaw
committed
chore: update ipld formats and cid versions (#473)
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 681473c commit 98e0f4b

File tree

14 files changed

+333
-259
lines changed

14 files changed

+333
-259
lines changed

package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"bl": "^3.0.0",
4141
"bs58": "^4.0.1",
4242
"chai": "^4.2.0",
43-
"cids": "~0.5.8",
43+
"cids": "~0.7.1",
4444
"concat-stream": "^2.0.0",
4545
"dirty-chai": "^2.0.1",
4646
"es6-promisify": "^6.0.1",
@@ -49,9 +49,9 @@
4949
"ipfs-block": "~0.8.0",
5050
"ipfs-unixfs": "~0.1.16",
5151
"ipfs-utils": "~0.0.3",
52-
"ipld-dag-cbor": "~0.13.1",
53-
"ipld-dag-pb": "~0.15.3",
54-
"is-ipfs": "~0.6.0",
52+
"ipld-dag-cbor": "~0.15.0",
53+
"ipld-dag-pb": "~0.17.3",
54+
"is-ipfs": "~0.6.1",
5555
"is-plain-object": "^3.0.0",
5656
"libp2p-crypto": "~0.16.0",
5757
"multiaddr": "^6.0.0",
@@ -62,7 +62,6 @@
6262
"peer-info": "~0.15.0",
6363
"pull-stream": "^3.6.11",
6464
"pump": "^3.0.0",
65-
"randombytes": "^2.0.6",
6665
"readable-stream": "^3.1.1",
6766
"through2": "^3.0.0"
6867
},

src/dag/get.js

+52-47
Original file line numberDiff line numberDiff line change
@@ -48,41 +48,45 @@ module.exports = (createCommon, options) => {
4848
(cb) => {
4949
const someData = Buffer.from('some other data')
5050

51-
DAGNode.create(someData, (err, node) => {
52-
expect(err).to.not.exist()
53-
pbNode = node
54-
cb()
55-
})
51+
try {
52+
pbNode = DAGNode.create(someData)
53+
} catch (err) {
54+
return cb(err)
55+
}
5656

5757
cborNode = {
5858
data: someData
5959
}
60+
61+
cb()
6062
},
6163
(cb) => {
62-
dagPB.DAGNode.create(Buffer.from('I am inside a Protobuf'), (err, node) => {
63-
expect(err).to.not.exist()
64-
nodePb = node
65-
cb()
66-
})
64+
try {
65+
nodePb = DAGNode.create(Buffer.from('I am inside a Protobuf'))
66+
} catch (err) {
67+
return cb(err)
68+
}
69+
70+
cb()
6771
},
6872
(cb) => {
69-
dagPB.util.cid(nodePb, (err, cid) => {
70-
expect(err).to.not.exist()
71-
cidPb = cid
72-
cb()
73-
})
73+
dagPB.util.cid(dagPB.util.serialize(nodePb))
74+
.then(cid => {
75+
cidPb = cid
76+
cb()
77+
}, cb)
7478
},
7579
(cb) => {
7680
nodeCbor = {
7781
someData: 'I am inside a Cbor object',
7882
pb: cidPb
7983
}
8084

81-
dagCBOR.util.cid(nodeCbor, (err, cid) => {
82-
expect(err).to.not.exist()
83-
cidCbor = cid
84-
cb()
85-
})
85+
dagCBOR.util.cid(dagCBOR.util.serialize(nodeCbor))
86+
.then(cid => {
87+
cidCbor = cid
88+
cb()
89+
}, cb)
8690
},
8791
(cb) => {
8892
eachSeries([
@@ -135,11 +139,12 @@ module.exports = (createCommon, options) => {
135139

136140
const node = result.value
137141

138-
dagPB.util.cid(node, (err, cid) => {
139-
expect(err).to.not.exist()
140-
expect(cid).to.eql(cidPb)
141-
done()
142-
})
142+
dagPB.util.cid(dagPB.util.serialize(node))
143+
.then(cid => {
144+
expect(cid).to.eql(cidPb)
145+
done()
146+
})
147+
.catch(done)
143148
})
144149
})
145150

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

161166
const node = result.value
162167

163-
dagCBOR.util.cid(node, (err, cid) => {
164-
expect(err).to.not.exist()
165-
expect(cid).to.eql(cidCbor)
166-
done()
167-
})
168+
dagCBOR.util.cid(dagCBOR.util.serialize(node))
169+
.then(cid => {
170+
expect(cid).to.eql(cidCbor)
171+
done()
172+
})
173+
.catch(done)
168174
})
169175
})
170176

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

197203
const node = result.value
198204

199-
dagCBOR.util.cid(node, (err, cid) => {
200-
expect(err).to.not.exist()
201-
expect(cid).to.eql(cidCbor)
202-
done()
203-
})
205+
dagCBOR.util.cid(dagCBOR.util.serialize(node))
206+
.then(cid => {
207+
expect(cid).to.eql(cidCbor)
208+
done()
209+
})
210+
.catch(done)
204211
})
205212
})
206213

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

228-
dagPB.DAGNode.create(input, (err, node) => {
229-
expect(err).to.not.exist()
235+
const node = dagPB.DAGNode.create(input)
230236

231-
ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
232-
expect(err).to.not.exist()
233-
expect(cid.version).to.equal(0)
237+
ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
238+
expect(err).to.not.exist()
239+
expect(cid.version).to.equal(0)
234240

235-
const cidv1 = cid.toV1()
241+
const cidv1 = cid.toV1()
236242

237-
ipfs.dag.get(cidv1, (err, output) => {
238-
expect(err).to.not.exist()
239-
expect(output.value.data).to.eql(input)
240-
done()
241-
})
243+
ipfs.dag.get(cidv1, (err, output) => {
244+
expect(err).to.not.exist()
245+
expect(output.value.Data).to.eql(input)
246+
done()
242247
})
243248
})
244249
})
@@ -256,7 +261,7 @@ module.exports = (createCommon, options) => {
256261

257262
ipfs.dag.get(cidv0, (err, output) => {
258263
expect(err).to.not.exist()
259-
expect(Unixfs.unmarshal(output.value.data).data).to.eql(input)
264+
expect(Unixfs.unmarshal(output.value.Data).data).to.eql(input)
260265
done()
261266
})
262267
})

src/dag/put.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@ module.exports = (createCommon, options) => {
4141
before((done) => {
4242
const someData = Buffer.from('some data')
4343

44-
DAGNode.create(someData, (err, node) => {
45-
expect(err).to.not.exist()
46-
pbNode = node
47-
done()
48-
})
44+
try {
45+
pbNode = DAGNode.create(someData)
46+
} catch (err) {
47+
return done(err)
48+
}
4949

5050
cborNode = {
5151
data: someData
5252
}
53+
54+
done()
5355
})
5456

5557
it('should put dag-pb with default hash func (sha2-256)', (done) => {
@@ -88,11 +90,12 @@ module.exports = (createCommon, options) => {
8890
expect(err).to.not.exist()
8991
expect(cid).to.exist()
9092
expect(CID.isCID(cid)).to.equal(true)
91-
dagCBOR.util.cid(cborNode, (err, _cid) => {
92-
expect(err).to.not.exist()
93-
expect(cid.buffer).to.eql(_cid.buffer)
94-
done()
95-
})
93+
dagCBOR.util.cid(dagCBOR.util.serialize(cborNode))
94+
.then(_cid => {
95+
expect(cid.buffer).to.eql(_cid.buffer)
96+
done()
97+
})
98+
.catch(done)
9699
})
97100
})
98101

src/dag/tree.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,32 @@ module.exports = (createCommon, options) => {
4242
before(function (done) {
4343
series([
4444
(cb) => {
45-
dagPB.DAGNode.create(Buffer.from('I am inside a Protobuf'), (err, node) => {
46-
expect(err).to.not.exist()
47-
nodePb = node
48-
cb()
49-
})
45+
try {
46+
nodePb = dagPB.DAGNode.create(Buffer.from('I am inside a Protobuf'))
47+
} catch (err) {
48+
return cb(err)
49+
}
50+
51+
cb()
5052
},
5153
(cb) => {
52-
dagPB.util.cid(nodePb, (err, cid) => {
53-
expect(err).to.not.exist()
54-
cidPb = cid
55-
cb()
56-
})
54+
dagPB.util.cid(dagPB.util.serialize(nodePb))
55+
.then(cid => {
56+
cidPb = cid
57+
cb()
58+
}, cb)
5759
},
5860
(cb) => {
5961
nodeCbor = {
6062
someData: 'I am inside a Cbor object',
6163
pb: cidPb
6264
}
6365

64-
dagCBOR.util.cid(nodeCbor, (err, cid) => {
65-
expect(err).to.not.exist()
66-
cidCbor = cid
67-
cb()
68-
})
66+
dagCBOR.util.cid(dagCBOR.util.serialize(nodeCbor))
67+
.then(cid => {
68+
cidCbor = cid
69+
cb()
70+
}, cb)
6971
},
7072
(cb) => {
7173
eachSeries([
@@ -113,7 +115,7 @@ module.exports = (createCommon, options) => {
113115
it('should get tree with CID recursive (accross different formats)', (done) => {
114116
ipfs.dag.tree(cidCbor, { recursive: true }, (err, paths) => {
115117
expect(err).to.not.exist()
116-
expect(paths).to.eql([
118+
expect(paths).to.have.members([
117119
'pb',
118120
'someData',
119121
'pb/Links',
@@ -126,7 +128,7 @@ module.exports = (createCommon, options) => {
126128
it('should get tree with CID and path recursive', (done) => {
127129
ipfs.dag.tree(cidCbor, 'pb', { recursive: true }, (err, paths) => {
128130
expect(err).to.not.exist()
129-
expect(paths).to.eql([
131+
expect(paths).to.have.members([
130132
'Links',
131133
'Data'
132134
])

src/files-mfs/read-readable-stream.js

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports = (createCommon, options) => {
3737
const testDir = `/test-${hat()}`
3838

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

4142
stream.once('error', (err) => {
4243
expect(err).to.exist()

src/files-regular/cat.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ module.exports = (createCommon, options) => {
189189
return ipfs.cat(fixtures.smallFile.cid + '/does-not-exist')
190190
.catch((err) => {
191191
expect(err).to.exist()
192-
expect(err.message).to.oneOf([
193-
'No such file',
192+
expect(err.message).to.be.oneOf([
193+
'file does not exist',
194194
'no link named "does-not-exist" under Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'])
195195
})
196196
})

src/files-regular/refs-tests.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const mapSeries = require('async/mapSeries')
55
const { getDescribe, getIt, expect } = require('../utils/mocha')
66
const loadFixture = require('aegir/fixtures')
7+
const CID = require('cids')
78

89
module.exports = (createCommon, suiteName, ipfsRefs, options) => {
910
const describe = getDescribe(options)
@@ -110,10 +111,10 @@ module.exports = (createCommon, suiteName, ipfsRefs, options) => {
110111
'QmdBcHbK7uDQav8YrHsfKju3EKn48knxjd96KRMFs3gtS9',
111112
'QmeX96opBHZHLySMFoNiWS5msxjyX6rqtr3Rr1u7uxn7zJ',
112113
'Qmf8MwTnY7VdcnF8WcoJ3GB24NmNd1HsGzuEWCtUYDP38x',
113-
'zdpuAkqPgGuEFBFLcixZyFezWw3bsGUWVS6W7c8YhV5sdAc6E',
114-
'zdpuArVVBgigTbs6FdyqFFWUSsXymdruTtCVoboc91L3WTXi1',
115-
'zdpuAsrruPqzPDYs9c1FGNR5Wuyx8on64no6z62SRPv3viHGL',
116-
'zdpuAxTXSfaHaZNed3JG2WvcYNgd64v27ztB2zknrz5noPhz5'
114+
'bafyreiagelcmhfn33zuslkdo7fkes3dzcr2nju6meh75zm6vqklfqiojam',
115+
'bafyreic2f6adq5tqnbrvwiqc3jkz2cf4tz3cz2rp6plpij2qaoufgsxwmi',
116+
'bafyreidoqtyvflv5v4c3gd3izxvpq4flke55ayurbrnhsxh7z5wwjc6v6e',
117+
'bafyreifs2ub2lnq6n2quqbi3zb5homs5iqlmm77b3am252cqzxiu7phwpy'
117118
])
118119

119120
done()
@@ -365,7 +366,7 @@ function loadDagContent (ipfs, node, callback) {
365366
putLinks: (links, cb) => {
366367
const obj = {}
367368
for (const { name, cid } of links) {
368-
obj[name] = { '/': cid }
369+
obj[name] = new CID(cid)
369370
}
370371
ipfs.dag.put(obj, cb)
371372
}

0 commit comments

Comments
 (0)