This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathprovide.js
76 lines (57 loc) · 2 KB
/
provide.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* eslint-env mocha */
'use strict'
const CID = require('cids')
const { getDescribe, getIt, expect } = require('../utils/mocha')
module.exports = (createCommon, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()
describe('.dht.provide', function () {
this.timeout(80 * 1000)
let ipfs
before(async function () {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)
ipfs = await common.setup()
const nodeB = await common.setup()
await ipfs.swarm.connect(nodeB.peerId.addresses[0])
})
after(function () {
this.timeout(50 * 1000)
return common.teardown()
})
it('should provide local CID', async () => {
const res = await ipfs.add(Buffer.from('test'))
await ipfs.dht.provide(new CID(res[0].hash))
})
it('should not provide if block not found locally', () => {
const cid = new CID('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxsZ')
return expect(ipfs.dht.provide(cid)).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
.and.have.property('message')
.that.include('not found locally')
})
it('should allow multiple CIDs to be passed', async () => {
const res = await ipfs.add([
{ content: Buffer.from('t0') },
{ content: Buffer.from('t1') }
])
await ipfs.dht.provide([
new CID(res[0].hash),
new CID(res[1].hash)
])
})
it('should provide a CIDv1', async () => {
const res = await ipfs.add(Buffer.from('test'), { cidVersion: 1 })
const cid = new CID(res[0].hash)
await ipfs.dht.provide(cid)
})
it('should error on non CID arg', () => {
return expect(ipfs.dht.provide({})).to.eventually.be.rejected()
})
it('should error on array containing non CID arg', () => {
return expect(ipfs.dht.provide([{}])).to.eventually.be.rejected()
})
})
}