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

Commit 4b290ab

Browse files
committed
chore: update ipld formats and cid versions
May need merging with or replacing by #468.
1 parent b90d635 commit 4b290ab

File tree

13 files changed

+285
-251
lines changed

13 files changed

+285
-251
lines changed

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@
4040
"bl": "^2.1.2",
4141
"bs58": "^4.0.1",
4242
"chai": "^4.2.0",
43-
"cids": "~0.5.5",
43+
"cids": "~0.7.1",
4444
"concat-stream": "^2.0.0",
4545
"dirty-chai": "^2.0.1",
4646
"es6-promisify": "^6.0.1",
4747
"hat": "0.0.3",
4848
"into-stream": "^4.0.0",
4949
"ipfs-block": "~0.8.0",
5050
"ipfs-unixfs": "~0.1.16",
51-
"ipld-dag-cbor": "~0.13.1",
52-
"ipld-dag-pb": "~0.15.0",
51+
"ipld-dag-cbor": "~0.15.0",
52+
"ipld-dag-pb": "ipld/js-ipld-dag-pb#support-size-property",
5353
"is-ipfs": "~0.5.1",
5454
"is-plain-object": "^2.0.4",
5555
"libp2p-crypto": "~0.16.0",
@@ -61,7 +61,6 @@
6161
"peer-info": "~0.15.0",
6262
"pull-stream": "^3.6.9",
6363
"pump": "^3.0.0",
64-
"randombytes": "^2.0.6",
6564
"readable-stream": "^3.1.1",
6665
"through2": "^3.0.0"
6766
},

src/dag/get.js

Lines changed: 51 additions & 46 deletions
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
})

src/dag/put.js

Lines changed: 13 additions & 10 deletions
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

Lines changed: 17 additions & 15 deletions
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([

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ 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',
194-
'no link named "does-not-exist" under Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'])
192+
expect(err.message).to.include('file does not exist')
195193
})
196194
})
197195

0 commit comments

Comments
 (0)