forked from ipfs-inactive/js-ipfs-http-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dht.spec.js
66 lines (55 loc) · 1.82 KB
/
dht.spec.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
/* eslint-env mocha */
/* globals apiClients */
'use strict'
const expect = require('chai').expect
describe('.dht', () => {
it('returns an error when getting a non-existent key from the DHT',
(done) => {
apiClients.a.dht.get('non-existent', {timeout: '100ms'}, (err, value) => {
expect(err).to.be.an.instanceof(Error)
done()
})
})
it('puts and gets a key value pair in the DHT', (done) => {
apiClients.a.dht.put('scope', 'interplanetary', (err, res) => {
expect(err).to.not.exist
expect(res).to.be.an('array')
done()
// non ipns or pk hashes fail to fetch, known bug
// bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234
// apiClients.a.dht.get('scope', (err, value) => {
// console.log('->>', err, value)
// expect(err).to.not.exist
// expect(value).to.be.equal('interplanetary')
// done()
// })
})
})
it('.dht.findprovs', (done) => {
apiClients.a.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => {
expect(err).to.not.exist
expect(res).to.be.an('array')
done()
})
})
describe('promise', () => {
it('returns an error when getting a non-existent key from the DHT', () => {
return apiClients.a.dht.get('non-existent', {timeout: '100ms'})
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})
it('puts a key value pair in the DHT', () => {
return apiClients.a.dht.put('scope', 'interplanetary')
.then((res) => {
expect(res).to.be.an('array')
})
})
it('.dht.findprovs', () => {
return apiClients.a.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
.then((res) => {
expect(res).to.be.an('array')
})
})
})
})