This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathget.js
51 lines (41 loc) · 1.55 KB
/
get.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
/* eslint-env mocha */
'use strict'
const { getDescribe, getIt, expect } = require('../utils/mocha')
const testTimeout = require('../utils/test-timeout')
const all = require('it-all')
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
describe('.dht.get', function () {
let nodeA
let nodeB
before(async () => {
nodeA = (await common.spawn()).api
nodeB = (await common.spawn()).api
await nodeA.swarm.connect(nodeB.peerId.addresses[0])
})
after(() => common.clean())
it('should respect timeout option when getting a value from the DHT', async () => {
const [data] = await all(nodeA.add('should put a value to the DHT'))
const publish = await nodeA.name.publish(data.cid)
await testTimeout(() => nodeB.dht.get(`/ipns/${publish.name}`, {
timeout: 1
}))
})
it('should error when getting a non-existent key from the DHT', () => {
return expect(nodeA.dht.get('non-existing', { timeout: 100 })).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
})
it('should get a value after it was put on another node', async () => {
const [data] = await all(nodeA.add('should put a value to the DHT'))
const publish = await nodeA.name.publish(data.cid)
const record = await nodeA.dht.get(`/ipns/${publish.name}`)
expect(record.toString()).to.contain(data.cid.toString())
})
})
}